Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(bi): clarify chart controls and automatic selection (#115524)

Marius Andraacea3a393d78
diff --git a/docs/published/handbook/engineering/data-warehouse.md b/docs/published/handbook/engineering/data-warehouse.md
index 4b7ae19678d7..0a355492b7ec 100644
--- a/docs/published/handbook/engineering/data-warehouse.md
+++ b/docs/published/handbook/engineering/data-warehouse.md
@@ -86,6 +86,12 @@ With `SQL_EDITOR_BI_MODE` enabled, choose **Add calculated field** in the data p
Calculated fields appear in Dimensions or Measures with a ƒ indicator. Drag or double-click them to reuse the definition. Editing a definition updates its name and expression on every shelf, including duplicated uses; date granularities and measure display settings remain independent. A field's role cannot change after creation. **Delete field and all uses** removes the local definition and its shelf/filter uses; Undo restores them. Clear sheet retains the definitions. Save, reload, and Save a copy preserve them inside the worksheet, without creating source-table or project-wide fields.
+The result footer reports distinct dimension groups and non-empty measure values (marks), rather than source-row counts. It excludes total rows and marks truncated results as limited. The grouping labels describe the executed query while edits await Run.
+
+Date and timestamp drops start with daily buckets. A date pill offers **Timeline (keeps the year)** buckets and **Date part (combines years)** choices: month of year, quarter of year, and day of week. **Duplicate** creates an independently configurable shelf field, so the same date can appear at two granularities.
+
+**Marks → Color** separates series coloring from shelf grouping. **Single color** preserves every group and series while using one color; switching back restores automatic or customized colors. With two categorical dimensions, select either field to define the colored series and use the other on the axis. Date dimensions remain on the timeline. Automatic uses lines for dates, grouped bars for one or two categorical dimensions, and a number for a single total. Explicit chart choices remain selected. **New worksheet** is available directly in the worksheet header.
+
## Filters in BI mode
Drop a field onto the compact Filters shelf beside or below the data pane. Quick filters on the right
@@ -311,7 +317,3 @@ inside expanded connections, and a failed field load has a Retry button.
Aliases load any intermediate tables automatically. Loading and failed connections stay visible during search.
Virtual connections expose the field names provided by the existing schema as dimensions. The schema does
not include their field types or nested link definitions, so these connections do not infer measures or further links.
-
-The result footer reports distinct dimension groups and non-empty measure values (marks), rather than source-row counts. It excludes total rows and marks truncated results as limited. The grouping labels describe the executed query while edits await Run.
-
-Date and timestamp drops start with daily buckets. A date pill offers **Timeline (keeps the year)** buckets and **Date part (combines years)** choices: month of year, quarter of year, and day of week. **Duplicate** creates an independently configurable shelf field, so the same date can appear at two granularities.
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 26c17e389ad9..f1051b2963a7 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -9943,69 +9943,69 @@ snapshots:
scenes-app-data-warehouse-sql-editor--bi-calculated-measure-editor--light:
hash: v1.k794b7964.69c71d482b1b19aa18a81b5ba0fc0bb038d8f3bdc9bdb0a7286c9addb4893dc2.LjgKhmcTELX-Cd50ZnnKmKLTGxv3AH0cD5BfLrBKfQ8
scenes-app-data-warehouse-sql-editor--bi-category-groups--dark:
- hash: v1.k794b7964.eb98c0116ba6fe8bcad6beea54489fb21d5e64dd3b7cf84267350c8047ea480f.mTgjY1-3pp84Pc4fiL_YQ9pJ-ifytiMHhGVIqkNuVnA
+ hash: v1.k794b7964.4862f067a79916c1bc7631cc581155719af255322b0d08285364e70d53b70d31.Y5LRP10StWiZcr-NqzWFC4UPVlr9HZn-V4mYhtyzBhg
scenes-app-data-warehouse-sql-editor--bi-category-groups--light:
- hash: v1.k794b7964.db53ed05e271f18f7b0e86e5ab650776c31f685a60a7d1d632cdda490f50b22f.AGY5g2q8RluaG1p1iMgAz-1cA7D6_iacY_S8XZavR50
+ hash: v1.k794b7964.62b584942db83429d5384454db46559325a38aae7461fe858dca39d924c19b0c.bjTFL_dJv0ZVEJPu7g47thm4JpPkUi92CbW2jdQVksU
scenes-app-data-warehouse-sql-editor--bi-combined-measures--dark:
- hash: v1.k794b7964.152596990efb73f9fe9be619fd0fdf67f41c4d32e15ef9072e1e9006424602da.2lYM93hUInzL9lnC_SifYei0ujNfwQKqAX7zqydfCKc
+ hash: v1.k794b7964.2e8dbc1f0bb7bb1dcf836c5d4707c424d0141f0028125a4cb8d7c21090ccc431.5GXasdCC9-YudIAt1e1OtBh5E_I7A-AUg9hKCwbXQcA
scenes-app-data-warehouse-sql-editor--bi-combined-measures--light:
- hash: v1.k794b7964.f4734da48d473607ff8a4f7595e63a851f2d55bb5b93c3e936737cb35fc1e125.FmoY8CKGtO4yvYl12tA5vxgb8sOwEifLiiOkmQH1Sec
+ hash: v1.k794b7964.04dd9cdc2ab2406095e54ac83367eb03e934d8077ffc7b91cbcc91c6353464f8.3qw_aAJ3Q9irvPSh21Es3dt_dfn8bAvwujrBfwiCJR0
scenes-app-data-warehouse-sql-editor--bi-connections--dark:
- hash: v1.k794b7964.827df95285053f00e6ff757a56998cf511fe43f7bb2ef8e78b063789001f42b9.Lpb29Ois4zRiuCJsOKA9wrrK3GRGSJSREgI_2Z8BUiE
+ hash: v1.k794b7964.b5b95871212596a43997b44286c217f1da94aaa8e13366b56ff98e9549040cc3.HqBVXoKkdHSEAU9IEyXRcTjcs4bubpYrtK1yJAa8e-M
scenes-app-data-warehouse-sql-editor--bi-connections--light:
- hash: v1.k794b7964.c69c63760747793c5cadd04aa7d7a4d63790f7c54a502deb3179f0988f31fd60.AMgf31G-4p7wTvEGTHfHknWD1J-PV9ES8ab29-4nQRs
+ hash: v1.k794b7964.653dba05f6a4fc4a6a89a75e7bd1fa711b0a4d55aac4c7f9d88a67629a42e9e6.wTdD8tsecGW5H2Ar2A3Fy5wneuEDttDOxW0Yi3NGWQc
scenes-app-data-warehouse-sql-editor--bi-data-source-picker--dark:
- hash: v1.k794b7964.f95cc2f2a8f6c53c8cda15529ef45e743bfa6afbb492a210f3562da6b3bd4e9a.0lE_inPkEDjkfDEdp3GQguxeeBUMQfYdpjdXCxAccsQ
+ hash: v1.k794b7964.a1acb6f3170a9596f63792895642e0ed3b586a9f08c38439462711cabba2a246.y22PV6f4Ujxe7EbYAlaLmH0En029zIxy87yjmI6NKE8
scenes-app-data-warehouse-sql-editor--bi-data-source-picker--light:
- hash: v1.k794b7964.10e0bc5cb45924e8717fafe675ab8174159045951c39ed61cc445ec660b7c685.tVrtUTBDehKND4yeVJ_TiEWPuKW8cX4ZG9_A_OX1T2E
+ hash: v1.k794b7964.cf8e82ca118c7c0f291e6845f5352dfbcbd39f064b6a8a3ead91c273a579bab1.YST8V7RCw2m5rYEqwe6PntWswvzLAFXOf9J6PNNl3LU
scenes-app-data-warehouse-sql-editor--bi-drilldown--dark:
- hash: v1.k794b7964.08db0d1af995b93f629d5f9dd62bf2d28d3d3092370300287c766bfbec8dce0c.LhsqG-jRrxEs1cJgLZidBWN1Cruwyz99pMYvtpkHL2M
+ hash: v1.k794b7964.9fd7e2b550133c59d23548fc93ce1fc21d0dd7d27d639dad0c1a7d2c4be19a5c.5lCBDuriW0rgnKdzO1qNP7X_VniN9tGjVd5Qlksn-v4
scenes-app-data-warehouse-sql-editor--bi-drilldown--light:
- hash: v1.k794b7964.64086844ccfeee7b554e8800720fbdc36338ff0be87382481ed98a357bd7eada.1bOKRn1KYdVw_meBxCBcLH0l6KYqr7wUFFhwZG2d3dM
+ hash: v1.k794b7964.b2266ab9657760714ace53bafc6dfae78d1ed3756381b80e35aa19b6e14d0b82.8ubL2UjpqJoH1-tlcOEdGRXniFokK5S-DfgWKZQesz0
scenes-app-data-warehouse-sql-editor--bi-edit-saved-insight--dark:
- hash: v1.k794b7964.85ae1a2c0c30cb8efb2d695de6e15f4da8e0f69be6782e9d1f7c3ee5276e5c49.6iYD5ycB0xcxcSIqohCvRz-BrvWNWAZHvYO4v290cfE
+ hash: v1.k794b7964.dde6db21dad04e4870d7dcf7f38b639ab698eeed34992ec45a397fb21452ebe5.rPCZTPMbg05x1wH9_25RBmOzgm4pMDL_oG0QMvkZlh8
scenes-app-data-warehouse-sql-editor--bi-edit-saved-insight--light:
- hash: v1.k794b7964.e3d8ee3a779dcf83973fa21136c882b51ed0a19ed4645ed84a68452761b56d24.GSAwAM4EWuoAMVQ2f36WXD-rbC0p_JklVPB367G28bw
+ hash: v1.k794b7964.fbf1fa5ab5874f2d9c4f2624fe6aa4b76cad0a17c264c6853fb2f9a5256220ec.TVT1O281QsSfgk9oewf8sCN5Nv9B3TZZMg4iyOveN3g
scenes-app-data-warehouse-sql-editor--bi-empty-worksheet--dark:
- hash: v1.k794b7964.c0918b4e1a449da65dacb438f9a82f06a320ac80d55f0cfba78272a85c61f779.QDZBhUdS8See7ooivQEJfykKGrlvyqpPMk7shDIwRb0
+ hash: v1.k794b7964.e04efd2d904c679ad656e1f2d3488282878630f06ecd0095a1e47e35495e3d9a.DpXUbjEI1TCHqpbQ-C2fobq1FpcTuELnaytl6xL5ZbQ
scenes-app-data-warehouse-sql-editor--bi-empty-worksheet--light:
- hash: v1.k794b7964.ac5b35044efab39569660efa75f5aa17ea2fb907ebbfaafb096c2d5f51b2e12e.lja2d0iU53cK5AijffEU5sVXSL4sBbOq34pueAPknh0
+ hash: v1.k794b7964.0fbe28f84f58be50be293c845f98411f085d5f31c31b6f0c4ca6009227c22732.WTvi3OA8bCbV_S8vl-nGOfmZsRrO-Sd5w9ZHnKuop7E
scenes-app-data-warehouse-sql-editor--bi-measure-display--dark:
- hash: v1.k794b7964.484b79b45832ad6c51b76327fa3b5ceb80ae06ac10a57b48feb671b2d308b8e8.R_8_S_cmi1cfr01L9-3bzjPGm8tyDvO7c_UokxFWgXE
+ hash: v1.k794b7964.dd41e905894dc0aacc8080b7652f205852a6f78a6d70d7467a0ab8b87a1b2f27.y-Nv6h67bqBVn838NeDf5j83Pm4IKE3Ot5udeXgzG00
scenes-app-data-warehouse-sql-editor--bi-measure-display--light:
- hash: v1.k794b7964.bc7307f398f9ba781ed82c34b7f3a64dad0016d8400b7bb3ecb8f78703197db9.aV7TppVqdGqb9lzSj8IGXK5eHGAwMKK_nu2qvaUZTwo
+ hash: v1.k794b7964.7b331ceb80f9a23068ca09166dca0cc16f7421c3c6e0b14dcefe4e1af59f10d3.jJWvOUZAxEuUuoyfb4ZsUGc-bNWQGSf_MdPBaJuwhXc
scenes-app-data-warehouse-sql-editor--bi-mode-worksheet--dark:
hash: v1.k794b7964.6309ca3f3ecb88032969e856079e14cda460aa306a5172863693ff8a95ea011c.dIXWRHfmipDgezW97RK0MYne72aosXhe0o1S_uXrt_w
scenes-app-data-warehouse-sql-editor--bi-mode-worksheet--light:
hash: v1.k794b7964.d60ca4f154f5b6aa7dfe97f5907d32aeb07d408ef2ccfdd9b86bd8880c17ba6b.m2J3D-2Zw-ub5S6SSZk2MFZf3rAXWA6146N6UMKx2Xo
scenes-app-data-warehouse-sql-editor--bi-numeric-bins--dark:
- hash: v1.k794b7964.47520202399691f3aa530aa15394892862dbe64497b1aa17eb4d558e614d072b.KaJHIxqAUO7qfDIrW37_ELsRarsP_uISPeOtmI1w7Zw
+ hash: v1.k794b7964.4532221938c1106707fc5f0c0b5d3d46190a3fe1aa308c8c171e4a388740c1dc.UFEB1zCEm5S6DQuqCv3qzsDKUwXT-Q4r1NRsdjuOiDw
scenes-app-data-warehouse-sql-editor--bi-numeric-bins--light:
- hash: v1.k794b7964.ac95f7a6c2b3b8a21835980ae2109c44245839dd8f8e26525b9c179ed411acd8.aQZyNjqz935HNWBH_KDygzX_ECnjLmaoTehfG7gPpfE
+ hash: v1.k794b7964.e657e5340fa1f9cc5e47629bf17ea1bed6e13a8c7a97da216c55695be518f999.x1iI2nub4uOCHgHIXDykRlEWgr1sLn9d8vUeGjm_8ps
scenes-app-data-warehouse-sql-editor--bi-one-click-comparison--dark:
- hash: v1.k794b7964.9ff010a668065a17008a94772c6379703cfd40c10a74dea924f0714852d54ff2.N2m_PxHYmn7iAiGZ1tD8zFzqzAmxUNTw1XDO5EhjAwA
+ hash: v1.k794b7964.2df94a5485dcafae44f3d5809fc628beaa922709115b7054e7efb718586d45bc.egZdKfplib4AJI3CBOZujqfjklXOm8uHI9Lmf0u98Ps
scenes-app-data-warehouse-sql-editor--bi-one-click-comparison--light:
- hash: v1.k794b7964.e2fd4b21aa8a2e9c90959027e70650f8c63010014d499ef693d70bf76a8caa30.bDTHHqvNe-J74iSTfPOblMeUenzY4Rh8oWwUZaJrDiA
+ hash: v1.k794b7964.a3926ec3e83f1cef8fe147b81cf08283f51c3aad4920bfea1c085aeee40b946b.8CViwZqXmORumx6eOxuwKRdUt5D-6Q0z9CpWrsASbDs
scenes-app-data-warehouse-sql-editor--bi-pivot-totals--dark:
- hash: v1.k794b7964.7b6c2578c87fff5e899143965b31aaccf76f312b63e8f16032cdb5a2a1d6c124.eQNO4CoJV5FdhCvqUhfq5wA2tsHT59K0Wu42TtFYSRw
+ hash: v1.k794b7964.e5736ef2dcfc2608754b7493341cc964e0af8c7788658c90e514b69f26d3b727.TMtZn2SGceTopszPWbY6ztXn5OVT9EdfBu6i2FwYfLc
scenes-app-data-warehouse-sql-editor--bi-pivot-totals--light:
- hash: v1.k794b7964.67ee5de9e2f4a0c1af2fe6f5282e9f63ae4a61a2078e0bea74ad9201142396f4.FUYG41lDePAI3e_vahLiDLzZr3uHAFsBzbm3A8HWpTk
+ hash: v1.k794b7964.3e9e6693cdaec06f1a553f39cf7f97d00984facd799ab56b927fc38888d1f2c4.-VauPY5Ge0wgD6A0KSw6YqfUWySn0aXVeXX52nZAggg
scenes-app-data-warehouse-sql-editor--bi-quick-filters--dark:
- hash: v1.k794b7964.1054726b3c7d62c00fb218f79cf460b28bc6363a4405a57965451eb1a6c83e4a.ZGHgHKGU2r8BQpr6omg2YGDRJ0FijxPCypHC5YsYxZk
+ hash: v1.k794b7964.6d873d5abb4a5e222b8a10efbd84fa54add1ade2800fc934d080915f2140ca61.wL5Kxg_Hvcjs-Ym7UEnxjVMq7Kif5dHEYFMOLQkWTEc
scenes-app-data-warehouse-sql-editor--bi-quick-filters--light:
- hash: v1.k794b7964.e1cc84afbf9401c2e88538e5f6afb9056e0d9693be4a3c211a892d6bd70c77a1.NymFaclvHrxgQW2VYDpcYNk4WJFiZKbYAVIocq0enEw
+ hash: v1.k794b7964.36f528a219125afe7c4b3560c23186d45ccd168c425b71dc7b3aa3ad4eceb75f.DkHc1_D-S2BUrITOk9Pq6PrjOe1PWiBq13riygF45jU
scenes-app-data-warehouse-sql-editor--bi-quick-filters-narrow--dark:
- hash: v1.k794b7964.091d05fb9c40b05c4aad2ab106fbb67512f604e692a2ca858dfa0d0c00601198.kP7jRmsrb5_JfzEZy9Gw1f_p7KsViCRG_AbDGmOR6PY
+ hash: v1.k794b7964.b9e08999b9e7fa195b3049a27590f7b26d00f32ed21abbc03083dcf5be095fa9.uIKlPLFSpiY_QsB1ywcr0HpTU4lYG4Wv7X9d8z9WgK0
scenes-app-data-warehouse-sql-editor--bi-quick-filters-narrow--light:
- hash: v1.k794b7964.d3a14111f6d0c02cf2884c6c09a88f73e34cd69a3adb67d67afa5e270ca65e95.olfq2wvtKhq3FiRHdlLiTClMFJNRcus3M3nbn8LyEiE
+ hash: v1.k794b7964.f0c45d8ef51292e34cffbfd727f8b3f0a01656288add9fda1c21329d3ab58552.pcHNenr182WYRP2IV1_lySz3HYGcTJ_4bhjs2fi5FFc
scenes-app-data-warehouse-sql-editor--bi-saved-insight--dark:
hash: v1.k794b7964.06df092616d217a4ebdaf0f5f35015c05fe63f5bc1e9b9c39dcdf6594293c0e3.D8zEjaefT5868HRYC8F6GkfsuMMlcxSxekM5z-VoXyM
scenes-app-data-warehouse-sql-editor--bi-saved-insight--light:
hash: v1.k794b7964.2c5f15b06d4347f767fc34bf934ea1bd53e988c443d528edb457795e778cc556.FcMHWv530RuOEcqg3G_bnos4zzZ4mku3Q9pdsK-VCXU
scenes-app-data-warehouse-sql-editor--bi-table-analysis--dark:
- hash: v1.k794b7964.698efecc8dd863d7eec52fb2a4e7bf55de1fa9d498cdc2f527cf09b7eb6dedab.V1VDO9CX4qvGtZPcmWuKwoUUKr5ykUOljulg_TAkjpI
+ hash: v1.k794b7964.a7986c7b8b9ad4a0884ba0489f52a8323242a6a53b260e2399d7379d207afade.JkJDxNwruFZswiNwBftXGjW9YagyU6DYgCtRzeTqRb4
scenes-app-data-warehouse-sql-editor--bi-table-analysis--light:
- hash: v1.k794b7964.7c0758873b738fa29b6235ff169cc4154ec2272487ef6c015deb133d97648a1b.4J9w34_-Z43HNL-yAhrYMLDTvlq_Yp_zS5TKl-gKktg
+ hash: v1.k794b7964.80a5f32a5368ac18ec4bd247ff941b379e911dc06c7c89c265eb5b4589854560.B6VtR_Glmq1fsWgXY2MqxRVapmAo3EGjgrnAmujymAc
scenes-app-data-warehouse-sql-editor--edited-insight--dark:
hash: v1.k794b7964.334b216a8359c768613cdec5b99a8a8ee26b6b5fac76397eaed8d6d1401a23c0.0pI7NMTufzUIfDel9Ngmhv3P3sdBu6IgpSj5xYNmYrY
scenes-app-data-warehouse-sql-editor--edited-insight--light:
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlPieGraphAdapter.test.ts b/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlPieGraphAdapter.test.ts
index 0cea72a6ec6c..196322ce3758 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlPieGraphAdapter.test.ts
+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlPieGraphAdapter.test.ts
@@ -68,6 +68,8 @@ describe('sqlPieGraphAdapter', () => {
{ label: 'alpha', value: 7, color: getSeriesColor(0) },
{ label: 'beta', value: 3, color: getSeriesColor(1) },
])
+ yData[0].settings = { display: { color: '#123456' } }
+ expect(buildPieSlices(xData, yData).map((slice) => slice.color)).toEqual(['#123456', '#123456'])
})
it('treats a non-finite value as zero instead of making the whole label non-finite', () => {
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlPieGraphAdapter.ts b/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlPieGraphAdapter.ts
index ca652be53ee5..dbb796310c32 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlPieGraphAdapter.ts
+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/sqlPieGraphAdapter.ts
@@ -83,7 +83,7 @@ export const buildPieSlices = (
.map(([label, value], index) => ({
label,
value,
- color: getSeriesColor(index),
+ color: yData[0].settings?.display?.color ?? getSeriesColor(index),
}))
.filter((slice) => slice.value > 0)
}
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/seriesBreakdownLogic.ts b/frontend/src/queries/nodes/DataVisualization/Components/seriesBreakdownLogic.ts
index 988c3a778632..c5f5f46a3a3d 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/seriesBreakdownLogic.ts
+++ b/frontend/src/queries/nodes/DataVisualization/Components/seriesBreakdownLogic.ts
@@ -3,6 +3,8 @@ import { MakeLogicType, actions, afterMount, connect, kea, key, listeners, path,
import { DataColorTheme } from 'lib/colors'
import { dataThemeLogic, getColorFromToken } from 'scenes/dataThemeLogic'
+import { getBISeriesSettings } from 'products/business_intelligence/frontend/biQueryResults'
+
import type { AnyResponseType, ChartSettings, VisualizationNode } from '../../../schema/schema-general'
import { AxisSeries, AxisSeriesSettings, SelectedYAxis, dataVisualizationLogic } from '../dataVisualizationLogic'
import type { Column } from '../dataVisualizationLogic'
@@ -128,7 +130,8 @@ export interface seriesBreakdownLogicMeta {
response: AnyResponseType | null,
columns: Column[],
chartSettings: ChartSettings,
- getTheme: (themeId: number | string | null | undefined) => DataColorTheme | null
+ getTheme: (themeId: number | string | null | undefined) => DataColorTheme | null, // dataThemeLogic
+ query: VisualizationNode
) => BreakdownSeriesData<number | null>
}
}
@@ -215,6 +218,7 @@ export const seriesBreakdownLogic = kea<seriesBreakdownLogicType>([
s.columns,
s.chartSettings,
s.getTheme,
+ s.query,
],
(
selectedBreakdownColumn: string | null | undefined,
@@ -238,7 +242,8 @@ export const seriesBreakdownLogic = kea<seriesBreakdownLogicType>([
| import('../../../schema').TraceSpansQueryResponse,
columns: import('../dataVisualizationLogic').Column[],
chartSettings: import('../../../schema').ChartSettings,
- getTheme: (themeId: string | number | null | undefined) => DataColorTheme | null
+ getTheme: (themeId: string | number | null | undefined) => DataColorTheme | null,
+ query: VisualizationNode
): BreakdownSeriesData<number | null> => {
if (
!response ||
@@ -332,7 +337,10 @@ export const seriesBreakdownLogic = kea<seriesBreakdownLogicType>([
name: seriesName,
breakdownValue,
data: [],
- settings: customColor ? { display: { color: customColor } } : undefined,
+ settings: getBISeriesSettings(
+ query,
+ customColor ? { display: { color: customColor } } : undefined
+ ),
}
}
@@ -370,14 +378,14 @@ export const seriesBreakdownLogic = kea<seriesBreakdownLogicType>([
// breakdown series at the moment. The per-breakdown
// color customization (if any) wins over the inherited
// y-axis color.
- settings: {
+ settings: getBISeriesSettings(query, {
formatting: selectedYAxis.settings.formatting,
display: {
yAxisPosition: selectedYAxis.settings?.display?.yAxisPosition,
displayType: selectedYAxis.settings?.display?.displayType,
- color: customColor,
+ color: customColor ?? selectedYAxis.settings?.display?.color,
},
- },
+ }),
}
})
})
diff --git a/frontend/src/queries/nodes/DataVisualization/dataVisualizationLogic.test.ts b/frontend/src/queries/nodes/DataVisualization/dataVisualizationLogic.test.ts
index fbb99182dc64..e5146ec57e68 100644
--- a/frontend/src/queries/nodes/DataVisualization/dataVisualizationLogic.test.ts
+++ b/frontend/src/queries/nodes/DataVisualization/dataVisualizationLogic.test.ts
@@ -9,6 +9,7 @@ import { buildBIQuery, DEFAULT_BI_CONFIG } from 'products/business_intelligence/
import { getBIVisualizationSource } from 'products/business_intelligence/frontend/biQueryResults'
import { dataNodeLogic } from '../DataNode/dataNodeLogic'
+import { seriesBreakdownLogic } from './Components/seriesBreakdownLogic'
import {
AxisSeriesSettings,
DataVisualizationLogicProps,
@@ -56,6 +57,65 @@ describe('dataVisualizationLogic', () => {
logic.unmount()
})
+ it('shows grouped BI categories as bars and toggles color without dropping groups or explicit chart choices', () => {
+ logic.unmount()
+ const field = { source: { table: 'events' }, type: 'string' as const }
+ const config = {
+ ...DEFAULT_BI_CONFIG,
+ source: field.source,
+ rows: [{ ...field, id: 'event', name: 'event', expression: 'event' }],
+ columns: [{ ...field, id: 'browser', name: 'browser', expression: 'properties.browser' }],
+ }
+ const generated = buildBIQuery(config)!.node
+ const query: VisualizationNode = { ...generated, kind: NodeKind.BIVisualizationNode, config }
+ logic = dataVisualizationLogic({
+ key: testKey,
+ query,
+ dataNodeCollectionId,
+ cachedResults: {
+ columns: ['bi_row_event', 'bi_column_browser', 'count'],
+ types: [
+ ['bi_row_event', 'String'],
+ ['bi_column_browser', 'String'],
+ ['count', 'Int64'],
+ ],
+ results: [
+ ['signup', 'Safari', 10],
+ ['purchase', 'Safari', 20],
+ ],
+ },
+ })
+ logic.mount()
+ const breakdown = seriesBreakdownLogic({ key: testKey })
+ breakdown.mount()
+ try {
+ expect(logic.values.effectiveVisualizationType).toBe(ChartDisplayType.ActionsBar)
+ expect(logic.values.autoVisualizationType).toBe(ChartDisplayType.ActionsBar)
+ const data = breakdown.values.seriesBreakdownData.seriesData.map((series) => series.data)
+ logic.actions._setQuery({ ...query, config: { ...config, colorBy: null } })
+ expect(breakdown.values.seriesBreakdownData.seriesData.map((series) => series.data)).toEqual(data)
+ const colors = breakdown.values.seriesBreakdownData.seriesData.map(
+ (series) => series.settings?.display?.color
+ )
+ expect(colors).toHaveLength(2)
+ expect(colors[0]).toBeTruthy()
+ expect(new Set(colors).size).toBe(1)
+ logic.actions._setQuery({
+ ...query,
+ display: ChartDisplayType.ActionsTable,
+ config: { ...config, chartType: ChartDisplayType.ActionsTable },
+ })
+ expect(logic.values.effectiveVisualizationType).toBe(ChartDisplayType.ActionsTable)
+ expect(
+ breakdown.values.seriesBreakdownData.seriesData.every(
+ (series) => series.settings?.display?.color === undefined
+ )
+ ).toBe(true)
+ } finally {
+ breakdown.unmount()
+ }
+ })
+
test.each([
[true, 0, false],
[true, 99, false],
diff --git a/frontend/src/queries/nodes/DataVisualization/dataVisualizationLogic.ts b/frontend/src/queries/nodes/DataVisualization/dataVisualizationLogic.ts
index b7b1856d503d..bcb0e2dcb01b 100644
--- a/frontend/src/queries/nodes/DataVisualization/dataVisualizationLogic.ts
+++ b/frontend/src/queries/nodes/DataVisualization/dataVisualizationLogic.ts
@@ -41,13 +41,16 @@ import {
DashboardFilter,
ConditionalFormattingRule,
VisualizationNode,
+ NodeKind,
HeatmapSettings,
HogQLVariable,
} from '~/queries/schema/schema-general'
import { QueryContext } from '~/queries/types'
import { ChartDisplayType, DashboardType } from '~/types'
+import { getBIAutoChartType } from 'products/business_intelligence/frontend/biEditorTypes'
import {
+ getBISeriesSettings,
getBIVisualizationResponse,
getBIVisualizationSource,
} from 'products/business_intelligence/frontend/biQueryResults'
@@ -906,7 +909,8 @@ export interface dataVisualizationLogicMeta {
response: AnyResponseType | null,
columns: Column[],
chartSettings: ChartSettings,
- effectiveVisualizationType: ChartDisplayType
+ effectiveVisualizationType: ChartDisplayType,
+ query: VisualizationNode
) => AxisSeries<number | null>[]
xData: (
selectedXAxis: string | null,
@@ -938,7 +942,11 @@ export interface dataVisualizationLogicMeta {
visualizationType: ChartDisplayType,
autoVisualizationType: ChartDisplayType
) => ChartDisplayType
- autoVisualizationType: (columns: Column[], response: AnyResponseType | null) => ChartDisplayType
+ autoVisualizationType: (
+ columns: Column[],
+ response: AnyResponseType | null,
+ query: VisualizationNode
+ ) => ChartDisplayType
needsHogVm: (
visualizationType: ChartDisplayType,
effectiveVisualizationType: ChartDisplayType,
@@ -1481,7 +1489,7 @@ export const dataVisualizationLogic = kea<dataVisualizationLogicType>([
(query: VisualizationNode): boolean => query.tableSettings?.transpose ?? false,
],
yData: [
- (s) => [s.selectedYAxis, s.response, s.columns, s.chartSettings, s.effectiveVisualizationType],
+ (s) => [s.selectedYAxis, s.response, s.columns, s.chartSettings, s.effectiveVisualizationType, s.query],
(
ySeries: (SelectedYAxis | null)[] | null,
response:
@@ -1501,7 +1509,8 @@ export const dataVisualizationLogic = kea<dataVisualizationLogicType>([
| import('~/queries/schema/schema-general').TraceSpansQueryResponse,
columns: Column[],
chartSettings: ChartSettings,
- visualizationType: ChartDisplayType
+ visualizationType: ChartDisplayType,
+ query: VisualizationNode
): AxisSeries<number | null>[] => {
if (!response || ySeries === null || ySeries.length === 0) {
return [EmptyYAxisSeries]
@@ -1552,7 +1561,7 @@ export const dataVisualizationLogic = kea<dataVisualizationLogicType>([
return showNullsAsZero ? 0 : null
}
}),
- settings: series.settings,
+ settings: getBISeriesSettings(query, series.settings),
}
})
.filter((series): series is AxisSeries<number | null> => Boolean(series))
@@ -1857,16 +1866,11 @@ export const dataVisualizationLogic = kea<dataVisualizationLogicType>([
dataVisualizationProps: [() => [(_, props) => props], (props): DataVisualizationLogicProps => props],
effectiveVisualizationType: [
(s) => [s.visualizationType, s.autoVisualizationType],
- (visualizationType: ChartDisplayType, autoVisualizationType: ChartDisplayType): ChartDisplayType => {
- if (visualizationType === ChartDisplayType.Auto) {
- return autoVisualizationType
- }
-
- return visualizationType
- },
+ (visualizationType: ChartDisplayType, autoVisualizationType: ChartDisplayType): ChartDisplayType =>
+ visualizationType === ChartDisplayType.Auto ? autoVisualizationType : visualizationType,
],
autoVisualizationType: [
- (s) => [s.columns, s.response],
+ (s) => [s.columns, s.response, s.query],
(
columns: Column[],
response:
@@ -1883,8 +1887,12 @@ export const dataVisualizationLogic = kea<dataVisualizationLogicType>([
| import('~/queries/schema/schema-general').SessionsQueryResponse
| import('~/queries/schema/schema-general').TraceSpansAggregationQueryResponse
| import('~/queries/schema/schema-general').TraceSpansAttributeBreakdownQueryResponse
- | import('~/queries/schema/schema-general').TraceSpansQueryResponse
- ): ChartDisplayType => getAutoVisualizationType(columns, rowCountFromResponse(response)),
+ | import('~/queries/schema/schema-general').TraceSpansQueryResponse,
+ query: VisualizationNode
+ ): ChartDisplayType =>
+ query.kind === NodeKind.BIVisualizationNode
+ ? getBIAutoChartType(query.config)
+ : getAutoVisualizationType(columns, rowCountFromResponse(response)),
],
// The Hog VM and its crypto polyfills are large, so only a table that shows formatting rules loads them.
// Auto resolves to a table until columns arrive, so it waits for them before it decides.
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index 49814f8ea18c..5dd5cc56e05e 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -6147,6 +6147,9 @@
"chartType": {
"$ref": "#/definitions/ChartDisplayType"
},
+ "colorBy": {
+ "type": ["string", "null"]
+ },
"columns": {
"items": {
"$ref": "#/definitions/BIField"
diff --git a/frontend/src/queries/schema/schema-business-intelligence.ts b/frontend/src/queries/schema/schema-business-intelligence.ts
index e0a51c9ca4ed..a82ec36a5cbc 100644
--- a/frontend/src/queries/schema/schema-business-intelligence.ts
+++ b/frontend/src/queries/schema/schema-business-intelligence.ts
@@ -134,6 +134,7 @@ export interface BIConfig {
source: BIDataSource | null
/** Reusable expressions owned by this worksheet only. */
localFields?: BIField[]
+ colorBy?: string | null
/** Column that receives the worksheet and dashboard date range. */
dateField?: BIField | null
dateRange?: DateRange
diff --git a/posthog/schema.py b/posthog/schema.py
index 0bc74b652828..21688d4b0406 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -11347,6 +11347,7 @@ class BIConfig(BaseModel):
extra="forbid",
)
chartType: ChartDisplayType
+ colorBy: str | None = None
columns: list[BIField]
compareFilter: CompareFilter | None = None
comparisonPeriod: ComparisonPeriod | None = Field(
diff --git a/products/business_intelligence/frontend/BIMeasureAnalysis.tsx b/products/business_intelligence/frontend/BIMeasureAnalysis.tsx
index 932164334425..3ed4cbdeec73 100644
--- a/products/business_intelligence/frontend/BIMeasureAnalysis.tsx
+++ b/products/business_intelligence/frontend/BIMeasureAnalysis.tsx
@@ -39,6 +39,7 @@ export function BIMeasureAnalysis({ index }: { index: number }): JSX.Element {
size="xsmall"
fullWidth
aria-label="Compute using"
+ tooltip="Traverse this dimension in ascending order. Other dimensions define separate groups; Entire table uses one group."
value={calculation.computeUsing ?? null}
options={[
{ value: null, label: 'Automatic (date first)' },
@@ -90,7 +91,7 @@ export function BIMeasureAnalysis({ index }: { index: number }): JSX.Element {
</>
) : null}
<span className="text-xs text-secondary">
- Ascending order.{' '}
+ Calculated after aggregation, before the result limit. Ascending order.{' '}
{missingDates === 'zero'
? 'Empty date buckets contribute zero.'
: missingDates === 'gap'
diff --git a/products/business_intelligence/frontend/BusinessIntelligenceScene.tsx b/products/business_intelligence/frontend/BusinessIntelligenceScene.tsx
index 6343bc54baac..c17ff01ac5fc 100644
--- a/products/business_intelligence/frontend/BusinessIntelligenceScene.tsx
+++ b/products/business_intelligence/frontend/BusinessIntelligenceScene.tsx
@@ -1,6 +1,6 @@
import { BindLogic, useActions, useValues } from 'kea'
-import { IconShare } from '@posthog/icons'
+import { IconPlus, IconShare } from '@posthog/icons'
import { LemonBanner, LemonButton, LemonInput, LemonModal, Spinner } from '@posthog/lemon-ui'
import { AccessDenied } from 'lib/components/AccessDenied'
@@ -90,6 +90,9 @@ export function BusinessIntelligenceScene({ tabId = 'bi-default' }: { tabId?: st
<LemonButton size="small" to={urls.businessIntelligence()}>
Worksheets
</LemonButton>
+ <LemonButton size="small" icon={<IconPlus />} to={`${urls.businessIntelligenceNew()}#q=`}>
+ New worksheet
+ </LemonButton>
<LemonInput
aria-label="Worksheet name"
value={name}
@@ -183,7 +186,7 @@ export function BusinessIntelligenceScene({ tabId = 'bi-default' }: { tabId?: st
worksheet.config.columns.length ||
worksheet.config.values.length
? 'Press Run to see the results of this worksheet.'
- : 'Drag a field to rows or columns to build your worksheet.'
+ : 'Drag or double-click a field to start. Dimensions define groups; measures calculate a value for each group.'
: 'Select a table and add fields to build your worksheet.'}
</div>
)}
diff --git a/products/business_intelligence/frontend/biEditorLogic.ts b/products/business_intelligence/frontend/biEditorLogic.ts
index 7075d2ad58b3..62462f1c9176 100644
--- a/products/business_intelligence/frontend/biEditorLogic.ts
+++ b/products/business_intelligence/frontend/biEditorLogic.ts
@@ -93,6 +93,7 @@ function setDataSourceInConfig(config: BIConfig, source: BIDataSource): BIConfig
...config,
source,
localFields: undefined,
+ colorBy: undefined,
comparisonPeriod: undefined,
rows: [],
columns: [],
@@ -510,6 +511,9 @@ export interface biEditorLogicActions {
setChartTypesOpen: (chartTypesOpen: boolean) => {
chartTypesOpen: boolean
}
+ setColorBy: (colorBy: string | null | undefined) => {
+ colorBy: string | null | undefined
+ }
setCompareFilter: (compareFilter: CompareFilter) => {
compareFilter: CompareFilter
}
@@ -753,6 +757,7 @@ export const biEditorLogic = kea<biEditorLogicType>([
}),
setMeasureShelf: (index: number, shelf: 'rows' | 'columns') => ({ index, shelf }),
swapRowsAndColumns: true,
+ setColorBy: (colorBy: string | null | undefined) => ({ colorBy }),
editCalculatedField: (field?: BIField) => ({ field }),
removeLocalField: (fieldId: string) => ({ fieldId }),
duplicateField: (shelf: Exclude<BIShelf, 'filters'>, index: number) => ({ shelf, index, fieldId: uuid() }),
@@ -1036,6 +1041,7 @@ export const biEditorLogic = kea<biEditorLogicType>([
: config.chartType,
}),
setChartType: (config, { chartType }) => normalizeBIConfig({ ...config, chartType }),
+ setColorBy: (config, { colorBy }) => normalizeBIConfig({ ...config, colorBy }),
setDateRange: (config, { dateRange }) => ({ ...config, dateRange }),
setCompareFilter: (config, { compareFilter }) => ({ ...config, compareFilter }),
setMissingDates: (config, { missingDates }) => ({ ...config, missingDates }),
@@ -1394,6 +1400,7 @@ export const biEditorLogic = kea<biEditorLogicType>([
addBlankFieldToShelf: () => actions.runAfterChange(),
removeFieldFromShelf: () => actions.runAfterChange(),
setChartType: () => actions.runAfterChange(),
+ setColorBy: () => actions.runAfterChange(),
setDateRange: () => actions.runAfterChange(),
setCompareFilter: () => actions.runAfterChange(),
setMissingDates: () => actions.runAfterChange(),
diff --git a/products/business_intelligence/frontend/biEditorOptions.tsx b/products/business_intelligence/frontend/biEditorOptions.tsx
index fc5100992e0e..6769a6e248ed 100644
--- a/products/business_intelligence/frontend/biEditorOptions.tsx
+++ b/products/business_intelligence/frontend/biEditorOptions.tsx
@@ -28,6 +28,11 @@ export const CHART_TYPE_OPTIONS: { value: ChartDisplayType; label: string; icon:
{ value: ChartDisplayType.ActionsLineGraph, label: 'Line chart', icon: <IconTrends /> },
{ value: ChartDisplayType.ActionsAreaGraph, label: 'Area chart', icon: <IconAreaChart /> },
{ value: ChartDisplayType.ActionsBar, label: 'Bar chart', icon: <IconGraph /> },
+ {
+ value: ChartDisplayType.ActionsBarValue,
+ label: 'Horizontal bar chart',
+ icon: <IconGraph className="rotate-90" />,
+ },
{ value: ChartDisplayType.ActionsStackedBar, label: 'Stacked bar chart', icon: <IconLifecycle /> },
{ value: ChartDisplayType.ActionsPie, label: 'Pie chart', icon: <IconPieChart /> },
{ value: ChartDisplayType.ActionsDonut, label: 'Donut chart', icon: <IconDonutChart /> },
diff --git a/products/business_intelligence/frontend/biEditorTypes.test.ts b/products/business_intelligence/frontend/biEditorTypes.test.ts
index 4792f8c3d867..a36fd0d0664f 100644
--- a/products/business_intelligence/frontend/biEditorTypes.test.ts
+++ b/products/business_intelligence/frontend/biEditorTypes.test.ts
@@ -362,6 +362,27 @@ describe('BI editor query generation', () => {
expect(result.node.display).toBe(chartType)
})
+ it('changes color grouping without changing aggregation, and persists single-color mode', () => {
+ const config: BIConfig = {
+ ...DEFAULT_BI_CONFIG,
+ source: eventField.source,
+ rows: [eventField],
+ columns: [browserField],
+ }
+ const automatic = buildBIQuery(config)!
+ const colorByColumn = buildBIQuery({ ...config, colorBy: browserField.id })!
+ expect(colorByColumn.query).toBe(automatic.query)
+ expect(colorByColumn.node.chartSettings?.seriesBreakdownColumn).toBe('bi_column_browser')
+ expect(colorByColumn.node.chartSettings?.xAxis?.column).toBe('bi_row_event')
+ const single = buildBIQuery({ ...config, colorBy: null })!
+ expect(single.query).toBe(automatic.query)
+ expect(single.node.chartSettings?.seriesBreakdownColumn).toBe(
+ automatic.node.chartSettings?.seriesBreakdownColumn
+ )
+ expect(parseBIEditorState(BIEditorView.BI, { ...config, colorBy: null })?.config.colorBy).toBeNull()
+ expect(parseBIEditorState(BIEditorView.BI, { ...config, colorBy: 'removed' })?.config.colorBy).toBeUndefined()
+ })
+
it('keeps a numeric column dimension on the x-axis instead of treating it as a measure', () => {
const result = buildBIQuery({
...DEFAULT_BI_CONFIG,
diff --git a/products/business_intelligence/frontend/biEditorTypes.ts b/products/business_intelligence/frontend/biEditorTypes.ts
index 92cde7c8f817..9225ab70fea3 100644
--- a/products/business_intelligence/frontend/biEditorTypes.ts
+++ b/products/business_intelligence/frontend/biEditorTypes.ts
@@ -148,6 +148,13 @@ export const DEFAULT_BI_CONFIG: BIConfig = {
export function normalizeBIConfig(config: BIConfig): BIConfig {
let normalized = normalizeBIDates(config)
+ if (
+ normalized.colorBy &&
+ (normalized.rows.length + normalized.columns.length !== 2 ||
+ ![...normalized.rows, ...normalized.columns].some((field) => field.id === normalized.colorBy))
+ ) {
+ normalized = { ...normalized, colorBy: undefined }
+ }
if (normalized.comparisonPeriod) {
normalized = { ...normalized, compareFilter: { ...normalized.compareFilter, compare: false } }
}
@@ -355,6 +362,22 @@ export interface BIChartFit {
requirement: string
}
+export function getBIAutoChartType(config: BIConfig): ChartDisplayType {
+ const dimensions = [...config.rows, ...config.columns]
+ if (dimensions.length > 2) {
+ return ChartDisplayType.ActionsTable
+ }
+ if (dimensions.some(isDateTimeBIField)) {
+ return ChartDisplayType.ActionsLineGraph
+ }
+ if (dimensions.length) {
+ return config.values.length && config.values.every((value) => value.shelf === 'columns')
+ ? ChartDisplayType.ActionsBarValue
+ : ChartDisplayType.ActionsBar
+ }
+ return config.values.length <= 1 ? ChartDisplayType.BoldNumber : ChartDisplayType.ActionsTable
+}
+
/** Describes the chart types panel: which chart types suit the fields on the shelves. */
export function getBIChartFit(config: BIConfig, chartType: ChartDisplayType): BIChartFit {
const rowCount = config.rows.length
@@ -364,7 +387,11 @@ export function getBIChartFit(config: BIConfig, chartType: ChartDisplayType): BI
switch (chartType) {
case ChartDisplayType.Auto:
- return { fits: true, requirement: 'Picks a chart type from the query results' }
+ return {
+ fits: true,
+ requirement:
+ 'Uses lines for dates, bars for one or two categorical dimensions, and a number for a single total',
+ }
case ChartDisplayType.ActionsTable:
return { fits: true, requirement: 'any combination of fields' }
case ChartDisplayType.ActionsLineGraph:
@@ -376,6 +403,7 @@ export function getBIChartFit(config: BIConfig, chartType: ChartDisplayType): BI
: '1 date, up to 1 more dimension, and any measures',
}
case ChartDisplayType.ActionsBar:
+ case ChartDisplayType.ActionsBarValue:
case ChartDisplayType.ActionsStackedBar:
return {
fits: dimensionCount >= 1 && (dimensionCount <= 2 || !!config.compareFilter?.compare),
@@ -639,6 +667,7 @@ export function parseBIEditorState(editorViewValue: unknown, configValue: unknow
const config: BIConfig = {
source,
+ ...(candidate.colorBy === null || typeof candidate.colorBy === 'string' ? { colorBy: candidate.colorBy } : {}),
...(candidate.localFields ? { localFields: candidate.localFields } : {}),
...(candidate.comparisonPeriod ? { comparisonPeriod: candidate.comparisonPeriod } : {}),
...(candidate.rowFilterGroup ? { rowFilterGroup: candidate.rowFilterGroup } : {}),
@@ -1073,6 +1102,7 @@ export function getBIResultDimensions(config: BIConfig): { field: BIField; colum
[
ChartDisplayType.Auto,
ChartDisplayType.ActionsBar,
+ ChartDisplayType.ActionsBarValue,
ChartDisplayType.ActionsStackedBar,
ChartDisplayType.ActionsLineGraph,
ChartDisplayType.ActionsAreaGraph,
@@ -1323,8 +1353,10 @@ export function buildBIQuery(config: BIConfig, probeForMoreRows = false): BIQuer
let query = queryParts.join('\n')
const chartDimensions = [...columnDimensions, ...rowDimensions]
- const xDimension = chartDimensions.find(({ field }) => isDateTimeBIField(field)) ?? chartDimensions[0]
- const breakdownDimension = chartDimensions.find((dimension) => dimension !== xDimension)
+ const colorDimension = chartDimensions.find(({ field }) => field.id === config.colorBy)
+ const axisDimensions = chartDimensions.filter((dimension) => dimension !== colorDimension)
+ const xDimension = axisDimensions.find(({ field }) => isDateTimeBIField(field)) ?? axisDimensions[0]
+ const breakdownDimension = colorDimension ?? chartDimensions.find((dimension) => dimension !== xDimension)
let seriesSettings: ChartSettings | undefined =
hasSeriesBreakdown && xDimension && breakdownDimension
? {
diff --git a/products/business_intelligence/frontend/biQueryResults.ts b/products/business_intelligence/frontend/biQueryResults.ts
index b762d0c0e7b8..5726ba4e1a09 100644
--- a/products/business_intelligence/frontend/biQueryResults.ts
+++ b/products/business_intelligence/frontend/biQueryResults.ts
@@ -1,8 +1,16 @@
-import { AnyResponseType, NodeKind, VisualizationNode } from '~/queries/schema/schema-general'
+import { getSeriesColor } from 'lib/colors'
+
+import { AnyResponseType, ChartAxis, NodeKind, VisualizationNode } from '~/queries/schema/schema-general'
import { getBIComparisonGroupLimit } from './biComparisonLimit'
import { buildBIQuery, getBIResultDimensions, getBIResultMeasureColumns } from './biEditorTypes'
+export function getBISeriesSettings(query: VisualizationNode, settings: ChartAxis['settings']): ChartAxis['settings'] {
+ return query.kind === NodeKind.BIVisualizationNode && query.config.colorBy === null
+ ? { ...settings, display: { ...settings?.display, color: getSeriesColor(0) } }
+ : settings
+}
+
export function getBIResultSummary(
query: VisualizationNode,
response: AnyResponseType | null
diff --git a/products/business_intelligence/frontend/components/BIDateControls.tsx b/products/business_intelligence/frontend/components/BIDateControls.tsx
index dc3d37f5ac1d..7514cb30d6e1 100644
--- a/products/business_intelligence/frontend/components/BIDateControls.tsx
+++ b/products/business_intelligence/frontend/components/BIDateControls.tsx
@@ -35,7 +35,7 @@ export function BIDateControls(): JSX.Element {
setDateField(dateFields.find((field) => field.expression === expression) ?? null)
}
renderButtonContent={(option) => `Date: ${option?.label}`}
- tooltip="The dashboard date range applies to this column and overrides the worksheet range."
+ tooltip="This column filters source rows by the selected date range. Set grouping granularity on a date pill. Dashboard date ranges override this range."
aria-label="Dashboard date column"
data-attr="bi-editor-date-field"
/>
diff --git a/products/business_intelligence/frontend/components/BIMarksCard.tsx b/products/business_intelligence/frontend/components/BIMarksCard.tsx
index 8c52b2297cdb..3478e1ab6887 100644
--- a/products/business_intelligence/frontend/components/BIMarksCard.tsx
+++ b/products/business_intelligence/frontend/components/BIMarksCard.tsx
@@ -1,18 +1,19 @@
import { useActions, useValues } from 'kea'
-import { LemonButton, LemonSelect } from '@posthog/lemon-ui'
+import { LemonButton, LemonLabel, LemonSelect } from '@posthog/lemon-ui'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { biEditorLogic } from 'products/business_intelligence/frontend/biEditorLogic'
import { getChartTypeOptions } from 'products/business_intelligence/frontend/biEditorOptions'
+import { getBIFieldPillLabel, isDateTimeBIField } from 'products/business_intelligence/frontend/biEditorTypes'
import { BIShelfCard } from 'products/business_intelligence/frontend/components/BIShelfCard'
import { BIMeasureAnalysis } from '../BIMeasureAnalysis'
export function BIMarksCard(): JSX.Element {
const { config } = useValues(biEditorLogic)
- const { setChartType, combineMeasures } = useActions(biEditorLogic)
+ const { setChartType, combineMeasures, setColorBy } = useActions(biEditorLogic)
const { featureFlags } = useValues(featureFlagLogic)
return (
@@ -29,8 +30,29 @@ export function BIMarksCard(): JSX.Element {
fullWidth
aria-label="Mark type"
data-attr="bi-editor-mark-type"
- tooltip="Change how measures on Rows are displayed"
+ tooltip="Choose how to display the worksheet's measures"
/>
+ <LemonLabel className="mt-2 text-xs">Color</LemonLabel>
+ <LemonSelect
+ value={config.colorBy === undefined ? '__automatic' : config.colorBy}
+ options={[
+ { value: '__automatic', label: 'Automatic colors' },
+ { value: null, label: 'Single color' },
+ ...(config.rows.length + config.columns.length === 2 && !config.compareFilter?.compare
+ ? [...config.rows, ...config.columns]
+ .filter((field) => !isDateTimeBIField(field))
+ .map((field) => ({ value: field.id, label: `By ${getBIFieldPillLabel(field)}` }))
+ : []),
+ ]}
+ onChange={(colorBy) => setColorBy(colorBy === '__automatic' ? undefined : colorBy)}
+ aria-label="Color series by"
+ size="xsmall"
+ fullWidth
+ data-attr="bi-editor-color-by"
+ />
+ <span className="text-xs text-secondary">
+ Shelves define the groups. Color changes how series are distinguished.
+ </span>
{config.values.length === 2 ? (
<LemonButton
size="xsmall"
diff --git a/products/business_intelligence/frontend/components/BIShelfCard.tsx b/products/business_intelligence/frontend/components/BIShelfCard.tsx
index 5b8a31e07d9d..b5fe85ccea97 100644
--- a/products/business_intelligence/frontend/components/BIShelfCard.tsx
+++ b/products/business_intelligence/frontend/components/BIShelfCard.tsx
@@ -3,8 +3,8 @@ import type { ReactNode } from 'react'
/** A titled card in the column next to the data pane, like the Filters and Marks cards. */
export function BIShelfCard({ title, children }: { title: string; children: ReactNode }): JSX.Element {
return (
- <section className="flex flex-col gap-1 border-b px-2 py-1.5">
- <h3 className="m-0 text-xs font-semibold">{title}</h3>
+ <section className="flex flex-col gap-1 border-b bg-surface-primary px-2 py-2">
+ <h3 className="m-0 pb-1 text-xs font-semibold">{title}</h3>
{children}
</section>
)
diff --git a/products/business_intelligence/frontend/components/BIToolbar.tsx b/products/business_intelligence/frontend/components/BIToolbar.tsx
index 638a97f23bc3..0e68f97c541e 100644
--- a/products/business_intelligence/frontend/components/BIToolbar.tsx
+++ b/products/business_intelligence/frontend/components/BIToolbar.tsx
@@ -131,6 +131,7 @@ export function BIToolbar(): JSX.Element {
onChange={setLimit}
renderButtonContent={(option) => `Limit: ${option?.label ?? config.limit}`}
aria-label="Query row limit"
+ tooltip="Maximum aggregated result rows, after grouping and calculations. This does not limit the source rows read."
size="xsmall"
type="tertiary"
dropdownMatchSelectWidth={false}
diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.ts
index 73c82df7493a..cb82e8761ce3 100644
--- a/products/dashboards/frontend/generated/api.schemas.ts
+++ b/products/dashboards/frontend/generated/api.schemas.ts
@@ -9672,6 +9672,7 @@ export interface BIValueApi {
export interface BIConfigApi {
chartType: ChartDisplayTypeApi
+ colorBy?: string | null
columns: BIFieldApi[]
compareFilter?: CompareFilterApi | null
/** Explore only the comparison window, using dateRange as its reference window. */
diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.ts
index e6529172b713..5162a4c404e0 100644
--- a/products/product_analytics/frontend/generated/api.schemas.ts
+++ b/products/product_analytics/frontend/generated/api.schemas.ts
@@ -8536,6 +8536,7 @@ export interface BIValueApi {
export interface BIConfigApi {
chartType: ChartDisplayTypeApi
+ colorBy?: string | null
columns: BIFieldApi[]
compareFilter?: CompareFilterApi | null
/** Explore only the comparison window, using dateRange as its reference window. */
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 8e189eafd351..9e963a9841c1 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -10986,6 +10986,7 @@ export namespace Schemas {
export interface BIConfig {
chartType: ChartDisplayType;
+ colorBy?: string | null;
columns: BIField[];
compareFilter?: CompareFilter | null;
/** Explore only the comparison window, using dateRange as its reference window. */