Skip to content

Commit

Permalink
feat(data-warehouse): Add show legend to charts (#27983)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilbert09 authored Jan 28, 2025
1 parent 585165b commit 331e9db
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/src/products.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by utils.mjs on 2025-01-27 15:49 UTC, based on product folders
// Generated by utils.mjs on 2025-01-28 18:13 UTC, based on product folders

/** This const is auto-generated, as is the whole file */
export const productScenes: Record<string, any> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const LineGraph = (): JSX.Element => {

const data: ChartData = {
labels: xSeriesData.data,
datasets: ySeriesData.map(({ data, settings }, index) => {
datasets: ySeriesData.map(({ data, settings, ...rest }, index) => {
const color = settings?.display?.color ?? getSeriesColor(index)
const backgroundColor = isAreaChart ? hexToRGBA(color, 0.5) : color

Expand All @@ -151,8 +151,17 @@ export const LineGraph = (): JSX.Element => {
yAxisID = 'yRight'
}

const getLabel = (): string => {
if ('name' in rest) {
return rest.name
}

return rest.column.name
}

return {
data,
label: getLabel(),
borderColor: color,
backgroundColor: backgroundColor,
borderWidth: graphType === GraphType.Bar ? 0 : 2,
Expand Down Expand Up @@ -286,7 +295,7 @@ export const LineGraph = (): JSX.Element => {
borderColor: 'white',
},
legend: {
display: false,
display: chartSettings.showLegend ?? false,
},
annotation: annotations,
...(isBarChart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ export const DisplayTab = (): JSX.Element => {

return (
<div className="flex flex-col w-full">
<div className="mt-1 mb-2 flex flex-col">
<LemonSwitch
className="flex-1 mb-3 w-full"
label="Show legend"
checked={chartSettings.showLegend ?? false}
onChange={(value) => {
updateChartSettings({ showLegend: value })
}}
/>
</div>

<div className="mt-1 mb-2 flex flex-col">
<h3>Left Y-axis</h3>
<LemonField.Pure label="Scale" className="gap-0 mb-3">
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4103,6 +4103,9 @@
"seriesBreakdownColumn": {
"type": ["string", "null"]
},
"showLegend": {
"type": "boolean"
},
"stackBars100": {
"description": "Whether we fill the bars to 100% in stacked mode",
"type": "boolean"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/queries/schema/schema-general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ export interface ChartSettings {
/** Whether we fill the bars to 100% in stacked mode */
stackBars100?: boolean
seriesBreakdownColumn?: string | null
showLegend?: boolean
}

export interface ConditionalFormattingRule {
Expand Down
1 change: 1 addition & 0 deletions posthog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,7 @@ class ChartSettings(BaseModel):
leftYAxisSettings: Optional[YAxisSettings] = None
rightYAxisSettings: Optional[YAxisSettings] = None
seriesBreakdownColumn: Optional[str] = None
showLegend: Optional[bool] = None
stackBars100: Optional[bool] = Field(default=None, description="Whether we fill the bars to 100% in stacked mode")
xAxis: Optional[ChartAxis] = None
yAxis: Optional[list[ChartAxis]] = None
Expand Down

0 comments on commit 331e9db

Please sign in to comment.