Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(insights): allow customizing result colors with data color themes #26862

Merged
merged 159 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 158 commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
7967289
add "color assignment by" option
thmsobrmlr Nov 13, 2024
6597def
make "color assignment by" a visualization only setting
thmsobrmlr Nov 13, 2024
049b30f
add "labels" to trends query schema
thmsobrmlr Nov 13, 2024
9e45fd9
base data color type on actual values
thmsobrmlr Nov 13, 2024
aee41f4
add data theme getter for tokens
thmsobrmlr Nov 13, 2024
6c96250
allow 3-digit hex colors in hexToRGB
thmsobrmlr Nov 13, 2024
cacbf9d
move gradate color function
thmsobrmlr Nov 13, 2024
9e5b109
refactor data-... colors
thmsobrmlr Nov 13, 2024
f5c41e2
add sections to colors file
thmsobrmlr Nov 13, 2024
29ac5a8
use in line graph
thmsobrmlr Nov 13, 2024
d71300c
wip
thmsobrmlr Nov 13, 2024
c4d83ee
wip
thmsobrmlr Nov 14, 2024
26aa80c
add getTrendDatasetKey
thmsobrmlr Nov 14, 2024
92ee1f8
update schema
thmsobrmlr Nov 14, 2024
daf4ea2
wip
thmsobrmlr Nov 14, 2024
8b3fd9e
wip
thmsobrmlr Nov 14, 2024
2b96eeb
add color assignment by type
thmsobrmlr Nov 14, 2024
c6544fe
wip
thmsobrmlr Nov 14, 2024
5cd41db
wip
thmsobrmlr Nov 15, 2024
b4fb417
add gear wheel to series column
thmsobrmlr Nov 15, 2024
8157dd9
wip
thmsobrmlr Nov 18, 2024
16da81a
wip
thmsobrmlr Nov 18, 2024
a122683
wip
thmsobrmlr Nov 18, 2024
513c10c
clean up
thmsobrmlr Nov 18, 2024
86825a8
Merge branch 'master' into insight-colors
thmsobrmlr Nov 18, 2024
3ad1528
refactor colorAssignmentBy to resultCustomizationBy
thmsobrmlr Nov 18, 2024
4aa3654
fixes
thmsobrmlr Nov 18, 2024
3d91b40
adapt copy
thmsobrmlr Nov 18, 2024
45582f8
refactor LegendEntryModal to ResultCustomizationsModal
thmsobrmlr Nov 18, 2024
decf688
refactor legendEntries to resultCustomizations
thmsobrmlr Nov 18, 2024
bcef721
refactor legendEntry to resultCustomization and change default to values
thmsobrmlr Nov 18, 2024
f9957ef
make pie chart work
thmsobrmlr Nov 18, 2024
174e134
stylistic adaptations
thmsobrmlr Nov 18, 2024
07585fe
Update UI snapshots for `chromium` (1)
github-actions[bot] Nov 18, 2024
6842f99
fix lint issue
thmsobrmlr Nov 18, 2024
0b7ecaf
make it work for horizontal bar chart
thmsobrmlr Nov 19, 2024
74c9fb8
add feature flag
thmsobrmlr Nov 19, 2024
032359f
types
thmsobrmlr Nov 19, 2024
0999c4c
types
thmsobrmlr Nov 19, 2024
b7afb82
Merge branch 'master' into insight-colors
thmsobrmlr Nov 19, 2024
698aff9
Update UI snapshots for `webkit` (2)
github-actions[bot] Nov 19, 2024
4cdb2bd
Update UI snapshots for `chromium` (1)
github-actions[bot] Nov 19, 2024
62d5030
Update UI snapshots for `chromium` (2)
github-actions[bot] Nov 19, 2024
49fa19f
fix import sort order
thmsobrmlr Nov 19, 2024
ba28634
move ResultCustomizationsModal to InsightVizDisplay
thmsobrmlr Nov 19, 2024
84d9155
add icon button for funnels
thmsobrmlr Nov 19, 2024
a898fd7
allow setting customizations for funnels
thmsobrmlr Nov 19, 2024
20fc3c4
display (almost) in funnel step table
thmsobrmlr Nov 19, 2024
c1fc1dc
display in step bars and add experiments special handling
thmsobrmlr Nov 20, 2024
bce6eb5
fix detailled results table in experiments
thmsobrmlr Nov 20, 2024
e89d3dd
don't display the edit button for funnels in experiments
thmsobrmlr Nov 20, 2024
51983f4
add support for top-to-bottom funnels
thmsobrmlr Nov 20, 2024
c3b8492
move resultCustomizations from query root to trendsFilter
thmsobrmlr Nov 20, 2024
80c767b
make changes to resultCustomizations a visualization only change (no …
thmsobrmlr Nov 20, 2024
24ef09b
fix supportsResultCustomizationBy
thmsobrmlr Nov 20, 2024
729c857
Update UI snapshots for `chromium` (2)
github-actions[bot] Nov 20, 2024
eff8077
fix cached properties and types
thmsobrmlr Nov 20, 2024
2fd38ce
scaffold data color theme setting
thmsobrmlr Nov 21, 2024
d9cb7c6
more scaffolding
thmsobrmlr Nov 21, 2024
1cd9607
add default theme
thmsobrmlr Nov 21, 2024
f4f7c56
display theme from backend
thmsobrmlr Nov 21, 2024
127fe5d
separate themes and theme colors
thmsobrmlr Nov 21, 2024
9f9d442
open modal with default theme
thmsobrmlr Nov 21, 2024
40b43ea
wip separating modal and form logic
thmsobrmlr Nov 21, 2024
d1ee461
initial form working
thmsobrmlr Nov 21, 2024
69656a3
make call to api
thmsobrmlr Nov 21, 2024
cce17f0
make call to api
thmsobrmlr Nov 21, 2024
f34ca7a
Update UI snapshots for `chromium` (1)
github-actions[bot] Nov 22, 2024
fe5ea15
fix constraint in migration and clean up
thmsobrmlr Nov 22, 2024
3c3a84a
add ability to override default theme
thmsobrmlr Nov 22, 2024
711821a
add basic admin interface for data color themes
thmsobrmlr Nov 22, 2024
04c8f9c
basic theme overrides
thmsobrmlr Nov 22, 2024
0c6a2b4
add storybook story for data colors
thmsobrmlr Nov 22, 2024
5e3efc6
allow setting custom theme on insight and add getTrendsColor selector
thmsobrmlr Nov 22, 2024
4a07588
wip
thmsobrmlr Nov 22, 2024
47f0572
wip
thmsobrmlr Nov 22, 2024
18d6080
make dataColorTheme visualization-only
thmsobrmlr Nov 22, 2024
ae2f49f
cleanup
thmsobrmlr Nov 22, 2024
ae1ba0e
Update query snapshots
github-actions[bot] Nov 22, 2024
2bc6c57
Update query snapshots
github-actions[bot] Nov 22, 2024
6627d50
Update query snapshots
github-actions[bot] Nov 22, 2024
30f1f98
Update UI snapshots for `chromium` (1)
github-actions[bot] Nov 22, 2024
272cacf
Update query snapshots
github-actions[bot] Nov 22, 2024
c0ccc4b
add icon for global themes
thmsobrmlr Nov 22, 2024
fd5d4cf
add ColorGlyph component
thmsobrmlr Nov 22, 2024
4256918
"add theme" does not fill name and instead has a placeholder and auto…
thmsobrmlr Nov 22, 2024
218f283
handle dirty forms and allow closing modal
thmsobrmlr Nov 22, 2024
cbe709f
make update work
thmsobrmlr Nov 22, 2024
d845843
allow adding and removing colors
thmsobrmlr Nov 22, 2024
50b0f45
allow duplicating color
thmsobrmlr Nov 22, 2024
6b9bd45
add permissions, tests and a couple of metadata columns
thmsobrmlr Nov 22, 2024
07c12af
make global themes un-editable
thmsobrmlr Nov 25, 2024
4605035
remove unused import
thmsobrmlr Nov 25, 2024
f10b23f
Update UI snapshots for `chromium` (2)
github-actions[bot] Nov 25, 2024
6f18439
Update UI snapshots for `chromium` (2)
github-actions[bot] Nov 25, 2024
0c48c8c
add error handling
thmsobrmlr Nov 26, 2024
5c60d12
wip
thmsobrmlr Nov 27, 2024
60b45a1
remove unique name constraint
thmsobrmlr Nov 28, 2024
3a0c3dc
fix rendering custom themes on page load
thmsobrmlr Nov 28, 2024
5672623
allow fetching relevant theme data from shared insights
thmsobrmlr Nov 28, 2024
a730604
expose team's default data theme to shared insights
thmsobrmlr Nov 28, 2024
62b8b59
wait for theme to be loaded
thmsobrmlr Nov 28, 2024
b133045
hide setting when flag is disabled
thmsobrmlr Nov 28, 2024
e25394f
clean up types
thmsobrmlr Nov 28, 2024
5254f8c
move DataColorThemeModel to types
thmsobrmlr Nov 28, 2024
789e945
fix lint issue
thmsobrmlr Nov 28, 2024
172d23d
fix opening modal when legend is open
thmsobrmlr Nov 28, 2024
7f7d0a5
feat(data-colors): add color descriptions
thmsobrmlr Nov 28, 2024
f858c49
emtpy commit
thmsobrmlr Nov 28, 2024
302ae69
Merge branch 'master' into data-color-themes
thmsobrmlr Dec 12, 2024
fe5c4a4
Merge branch 'master' into data-color-themes
thmsobrmlr Dec 12, 2024
bad9a51
Update query snapshots
github-actions[bot] Dec 12, 2024
60a2036
Update query snapshots
github-actions[bot] Dec 12, 2024
4cec8c0
Update query snapshots
github-actions[bot] Dec 12, 2024
8345aa4
combine migrations into a single one
thmsobrmlr Dec 12, 2024
b0e2cf5
Merge branch 'master' into data-color-themes
thmsobrmlr Dec 12, 2024
a7c03c5
Update query snapshots
github-actions[bot] Dec 12, 2024
7e8bc74
fix some lint issues
thmsobrmlr Dec 12, 2024
b53b1ad
fix more lint issues
thmsobrmlr Dec 12, 2024
f2fb7f8
add description to activity log
thmsobrmlr Dec 12, 2024
b68bac4
fallback colors while loading theme
thmsobrmlr Dec 12, 2024
4374650
add posthogTheme selector
thmsobrmlr Dec 12, 2024
d8ed52c
fix more lint issues
thmsobrmlr Dec 12, 2024
70b3758
mock theme in storybook
thmsobrmlr Dec 12, 2024
9d7faaf
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 12, 2024
ce2a35c
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 12, 2024
e8e0cdd
more kea-form fixes
thmsobrmlr Dec 12, 2024
644a2c6
update themes in list after successful form submission
thmsobrmlr Dec 12, 2024
a502a78
add success toast
thmsobrmlr Dec 12, 2024
58f775c
fix types
thmsobrmlr Dec 12, 2024
3e8235c
fix color token selector
thmsobrmlr Dec 13, 2024
0fa9eea
fix exported insights and dashboards
thmsobrmlr Dec 13, 2024
310b44d
Merge branch 'master' into data-color-themes
thmsobrmlr Dec 13, 2024
3107e74
fix types
thmsobrmlr Dec 13, 2024
a72d2cf
gray vs grey
thmsobrmlr Dec 13, 2024
9de5b73
export DataThemeLogicProps
thmsobrmlr Dec 13, 2024
c17184a
fix saving lifecycle insights
thmsobrmlr Dec 13, 2024
0ceabd6
"by name" and "by rank"
thmsobrmlr Dec 16, 2024
ee2e45b
"color customization by" instead of "result customization by”
thmsobrmlr Dec 16, 2024
a6713f2
copy and change display of series entity
thmsobrmlr Dec 16, 2024
b704124
Merge branch 'master' into data-color-themes
thmsobrmlr Dec 16, 2024
cec08b0
Merge branch 'master' into data-color-themes
thmsobrmlr Dec 16, 2024
5fcc50d
Update query snapshots
github-actions[bot] Dec 16, 2024
e9bffe9
Update query snapshots
github-actions[bot] Dec 16, 2024
d4168b8
Update query snapshots
github-actions[bot] Dec 16, 2024
8e2b2a0
Update query snapshots
github-actions[bot] Dec 16, 2024
f40304b
correctly format all breakdown values
thmsobrmlr Dec 16, 2024
73a3728
fix lint issue
thmsobrmlr Dec 16, 2024
92b3c35
hoverable icons in trends
thmsobrmlr Dec 16, 2024
91bcdaf
better spacer
thmsobrmlr Dec 16, 2024
414abef
hoverable icons in funnels
thmsobrmlr Dec 16, 2024
dfca3ac
fix clicking on series
thmsobrmlr Dec 16, 2024
9fb5547
Merge branch 'master' into data-color-themes
thmsobrmlr Dec 18, 2024
94a9bb2
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 18, 2024
f8441f7
Update query snapshots
github-actions[bot] Dec 18, 2024
5cb9a51
center icon
thmsobrmlr Dec 19, 2024
5ad245f
Merge branch 'master' into data-color-themes
thmsobrmlr Dec 31, 2024
78e012e
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 31, 2024
56cab31
Update frontend/src/queries/nodes/InsightViz/ResultCustomizationsModa…
thmsobrmlr Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions frontend/src/exporter/ExportedInsight/ExportedInsight.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import './ExportedInsight.scss'

import clsx from 'clsx'
import { BindLogic } from 'kea'
import { BindLogic, useMountedLogic } from 'kea'
import { TopHeading } from 'lib/components/Cards/InsightCard/TopHeading'
import { InsightLegend } from 'lib/components/InsightLegend/InsightLegend'
import {
DISPLAY_TYPES_WITHOUT_DETAILED_RESULTS,
DISPLAY_TYPES_WITHOUT_LEGEND,
} from 'lib/components/InsightLegend/utils'
import { SINGLE_SERIES_DISPLAY_TYPES } from 'lib/constants'
import { dataThemeLogic } from 'scenes/dataThemeLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
import { InsightsTable } from 'scenes/insights/views/InsightsTable/InsightsTable'

Expand All @@ -17,15 +18,19 @@ import { getQueryBasedInsightModel } from '~/queries/nodes/InsightViz/utils'
import { Query } from '~/queries/Query/Query'
import { isDataTableNode, isInsightVizNode, isTrendsQuery } from '~/queries/utils'
import { Logo } from '~/toolbar/assets/Logo'
import { ChartDisplayType, InsightLogicProps, InsightModel } from '~/types'
import { ChartDisplayType, DataColorThemeModel, InsightLogicProps, InsightModel } from '~/types'

export function ExportedInsight({
insight: legacyInsight,
themes,
exportOptions: { whitelabel, noHeader, legend, detailed: detailedResults },
}: {
insight: InsightModel
themes: DataColorThemeModel[]
exportOptions: ExportOptions
}): JSX.Element {
useMountedLogic(dataThemeLogic({ themes }))

const insight = getQueryBasedInsightModel(legacyInsight)

if (
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/exporter/Exporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { exporterViewLogic } from './exporterViewLogic'
export function Exporter(props: ExportedData): JSX.Element {
// NOTE: Mounting the logic is important as it is used by sub-logics
const { exportedData } = useValues(exporterViewLogic(props))
const { type, dashboard, insight, recording, accessToken, ...exportOptions } = exportedData
const { type, dashboard, insight, recording, themes, accessToken, ...exportOptions } = exportedData
const { whitelabel, showInspector = false } = exportOptions

const { currentTeam } = useValues(teamLogic)
Expand Down Expand Up @@ -75,12 +75,13 @@ export function Exporter(props: ExportedData): JSX.Element {
) : null
) : null}
{insight ? (
<ExportedInsight insight={insight} exportOptions={exportOptions} />
<ExportedInsight insight={insight} themes={themes!} exportOptions={exportOptions} />
) : dashboard ? (
<Dashboard
id={String(dashboard.id)}
dashboard={getQueryBasedDashboard(dashboard)!}
placement={type === ExportType.Image ? DashboardPlacement.Export : DashboardPlacement.Public}
themes={themes}
/>
) : recording ? (
<SessionRecordingPlayer
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/exporter/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DashboardType, InsightModel, SessionRecordingType } from '~/types'
import { DashboardType, DataColorThemeModel, InsightModel, SessionRecordingType } from '~/types'

export enum ExportType {
Image = 'image',
Expand All @@ -20,5 +20,6 @@ export interface ExportedData extends ExportOptions {
type: ExportType
dashboard?: DashboardType
insight?: InsightModel
themes?: DataColorThemeModel[]
recording?: SessionRecordingType
}
26 changes: 26 additions & 0 deletions frontend/src/lib/api.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { dayjs } from 'lib/dayjs'

import {
CohortType,
DataColorThemeModel,
FilterLogicalOperator,
GroupType,
OrganizationInviteType,
Expand Down Expand Up @@ -276,3 +277,28 @@ export const MOCK_DEFAULT_PLUGIN_CONFIG: PluginConfigWithPluginInfo = {
created_at: '2020-12-01T14:00:00.000Z',
plugin_info: MOCK_DEFAULT_PLUGIN,
}

export const MOCK_DATA_COLOR_THEMES: DataColorThemeModel[] = [
{
id: 1,
name: 'Default Theme',
colors: [
'#1d4aff',
'#621da6',
'#42827e',
'#ce0e74',
'#f14f58',
'#7c440e',
'#529a0a',
'#0476fb',
'#fe729e',
'#35416b',
'#41cbc4',
'#b64b02',
'#e4a604',
'#a56eff',
'#30d5c8',
],
is_global: true,
},
]
22 changes: 22 additions & 0 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
DashboardTemplateListParams,
DashboardTemplateType,
DashboardType,
DataColorThemeModel,
DataWarehouseSavedQuery,
DataWarehouseTable,
DataWarehouseViewLink,
Expand Down Expand Up @@ -944,6 +945,15 @@ class ApiRequest {
public async delete(): Promise<any> {
return await api.delete(this.assembleFullUrl())
}

// Data color themes
public dataColorThemes(teamId?: TeamType['id']): ApiRequest {
return this.environmentsDetail(teamId).addPathComponent('data_color_themes')
}

public dataColorTheme(id: DataColorThemeModel['id'], teamId?: TeamType['id']): ApiRequest {
return this.environmentsDetail(teamId).addPathComponent('data_color_themes').addPathComponent(id)
}
}

const normalizeUrl = (url: string): string => {
Expand Down Expand Up @@ -2520,6 +2530,18 @@ const api = {
},
},

dataColorThemes: {
async list(): Promise<DataColorThemeModel[]> {
return await new ApiRequest().dataColorThemes().get()
},
async create(data: Partial<DataColorThemeModel>): Promise<DataColorThemeModel> {
return await new ApiRequest().dataColorThemes().create({ data })
},
async update(id: DataColorThemeModel['id'], data: Partial<DataColorThemeModel>): Promise<DataColorThemeModel> {
return await new ApiRequest().dataColorTheme(id).update({ data })
},
},

queryURL: (): string => {
return new ApiRequest().query().assembleFullUrl(true)
},
Expand Down
105 changes: 59 additions & 46 deletions frontend/src/lib/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,49 @@ import { LifecycleToggle } from '~/types'

import { LemonTagType } from './lemon-ui/LemonTag'

/** --brand-blue in HSL for saturation mixing */
export const BRAND_BLUE_HSL: [number, number, number] = [228, 100, 56]
export const PURPLE: [number, number, number] = [260, 88, 71]
/*
* Data colors.
*/

/* Insight series colors. */
/** CSS variable names for the default posthog theme data colors. */
const dataColorVars = [
'color-1',
'color-2',
'color-3',
'color-4',
'color-5',
'color-6',
'color-7',
'color-8',
'color-9',
'color-10',
'color-11',
'color-12',
'color-13',
'color-14',
'color-15',
]
'data-color-1',
'data-color-2',
'data-color-3',
'data-color-4',
'data-color-5',
'data-color-6',
'data-color-7',
'data-color-8',
'data-color-9',
'data-color-10',
'data-color-11',
'data-color-12',
'data-color-13',
'data-color-14',
'data-color-15',
] as const

export const tagColors: LemonTagType[] = [
'primary',
'highlight',
'warning',
'danger',
'success',
'completion',
'caution',
'option',
]
export type DataColorToken =
| 'preset-1'
| 'preset-2'
| 'preset-3'
| 'preset-4'
| 'preset-5'
| 'preset-6'
| 'preset-7'
| 'preset-8'
| 'preset-9'
| 'preset-10'
| 'preset-11'
| 'preset-12'
| 'preset-13'
| 'preset-14'
| 'preset-15'

export type DataColorTheme = Partial<Record<DataColorToken, string>> & {
[key: `preset-${number}`]: string
}

export function getColorVar(variable: string): string {
const colorValue = getComputedStyle(document.body).getPropertyValue('--' + variable)
Expand All @@ -48,6 +58,10 @@ export function getColorVar(variable: string): string {
return colorValue.trim()
}

export function getDataThemeColor(theme: DataColorTheme, color: DataColorToken): string {
return theme[color] as string
}

/** Returns the color for the given series index.
*
* The returned colors are in hex format for compatibility with Chart.js. They repeat
Expand All @@ -57,12 +71,12 @@ export function getColorVar(variable: string): string {
*/
export function getSeriesColor(index: number = 0): string {
const adjustedIndex = index % dataColorVars.length
return getColorVar(`data-${dataColorVars[adjustedIndex]}`)
return getColorVar(dataColorVars[adjustedIndex])
}

/** Returns all color options for series */
export function getSeriesColorPalette(): string[] {
return dataColorVars.map((colorVar) => getColorVar(`data-${colorVar}`))
return dataColorVars.map((colorVar) => getColorVar(colorVar))
}

/** Return the background color for the given series index. */
Expand Down Expand Up @@ -104,18 +118,17 @@ export function getGraphColors(isDarkModeOn: boolean): Record<string, string | n
}
}

/**
* Gradate color saturation based on its intended strength.
* This is for visualizations where a data point's color depends on its value.
* @param hsl The HSL color to gradate.
* @param strength The strength of the data point.
* @param floor The minimum saturation. This preserves proportionality of strength, so doesn't just cut it off.
/*
* Tag colors.
*/
export function gradateColor(
hsl: [number, number, number],
strength: number,
floor: number = 0
): `hsla(${number}, ${number}%, ${number}%, ${string})` {
const saturation = floor + (1 - floor) * strength
return `hsla(${hsl[0]}, ${hsl[1]}%, ${hsl[2]}%, ${saturation.toPrecision(3)})`
}

export const tagColors: LemonTagType[] = [
'primary',
'highlight',
'warning',
'danger',
'success',
'completion',
'caution',
'option',
]
4 changes: 1 addition & 3 deletions frontend/src/lib/components/InsightLegend/InsightLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ export function InsightLegend({ horizontal, inCardView, readOnly = false }: Insi
>
<div className="grid grid-cols-1">
{indexedResults &&
indexedResults.map((item, index) => (
<InsightLegendRow key={index} item={item} totalItems={indexedResults.length} rowIndex={index} />
))}
indexedResults.map((item, index) => <InsightLegendRow key={index} item={item} rowIndex={index} />)}
</div>
</div>
) : null
Expand Down
15 changes: 8 additions & 7 deletions frontend/src/lib/components/InsightLegend/InsightLegendRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useActions, useValues } from 'kea'
import { getSeriesBackgroundColor, getTrendLikeSeriesColor } from 'lib/colors'
import { getSeriesBackgroundColor } from 'lib/colors'
import { InsightLabel } from 'lib/components/InsightLabel'
import { LemonCheckbox } from 'lib/lemon-ui/LemonCheckbox'
import { useEffect, useRef } from 'react'
Expand All @@ -19,15 +19,14 @@ import { shouldHighlightThisRow } from './utils'
type InsightLegendRowProps = {
rowIndex: number
item: IndexedTrendResult
totalItems: number
}

export function InsightLegendRow({ rowIndex, item, totalItems }: InsightLegendRowProps): JSX.Element {
export function InsightLegendRow({ rowIndex, item }: InsightLegendRowProps): JSX.Element {
const { cohorts } = useValues(cohortsModel)
const { formatPropertyValueForDisplay } = useValues(propertyDefinitionsModel)

const { insightProps, highlightedSeries } = useValues(insightLogic)
const { display, trendsFilter, breakdownFilter, isSingleSeries, hiddenLegendIndexes } = useValues(
const { display, trendsFilter, breakdownFilter, isSingleSeries, hiddenLegendIndexes, getTrendsColor } = useValues(
trendsDataLogic(insightProps)
)
const { toggleHiddenLegendIndex } = useActions(trendsDataLogic(insightProps))
Expand All @@ -54,21 +53,23 @@ export function InsightLegendRow({ rowIndex, item, totalItems }: InsightLegendRo
)

const isPrevious = !!item.compare && item.compare_label === 'previous'
const adjustedIndex = isPrevious ? item.seriesIndex - totalItems / 2 : item.seriesIndex

const themeColor = getTrendsColor(item)
const mainColor = isPrevious ? `${themeColor}80` : themeColor

return (
<div key={item.id} className="InsightLegendMenu-item p-2 flex flex-row" ref={rowRef} {...highlightStyle}>
<div className="grow">
<LemonCheckbox
className="text-xs mr-4"
color={getTrendLikeSeriesColor(adjustedIndex, isPrevious)}
color={mainColor}
checked={!hiddenLegendIndexes.includes(rowIndex)}
onChange={() => toggleHiddenLegendIndex(rowIndex)}
fullWidth
label={
<InsightLabel
key={item.id}
seriesColor={getTrendLikeSeriesColor(adjustedIndex, isPrevious)}
seriesColor={mainColor}
action={item.action}
fallbackName={item.breakdown_value === '' ? 'None' : item.label}
hasMultipleSeries={!isSingleSeries}
Expand Down
Loading
Loading