Skip to content

Commit 5351424

Browse files
DominikB2014claude
andcommitted
feat(chartcuterie): Add total period line chart type
Add SLACK_DISCOVER_TOTAL_PERIOD_LINE render descriptor for rendering single-series line charts in Slack unfurls. This complements the existing area (TOTAL_PERIOD) and bar (TOTAL_DAILY) variants so that Explore unfurls can match the user's selected chart type. Refs DAIN-1481 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5402dcb commit 5351424

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

static/app/chartcuterie/discover.tsx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,65 @@ export const makeDiscoverCharts = (theme: Theme): Array<RenderDescriptor<ChartTy
8484
...slackChartSize,
8585
});
8686

87+
discoverCharts.push({
88+
key: ChartType.SLACK_DISCOVER_TOTAL_PERIOD_LINE,
89+
getOption: (
90+
data:
91+
| {seriesName: string; stats: EventsStats}
92+
| {stats: Record<string, EventsStats>; seriesName?: string}
93+
) => {
94+
if (Array.isArray(data.stats.data)) {
95+
const color = theme.chart.getColorPalette(data.stats.data.length - 1);
96+
const lineSeries = LineSeries({
97+
name: data.seriesName,
98+
data: data.stats.data.map(([timestamp, countsForTimestamp]) => [
99+
timestamp * 1000,
100+
countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
101+
]),
102+
lineStyle: {color: color?.[0], opacity: 1},
103+
itemStyle: {color: color?.[0]},
104+
});
105+
106+
return {
107+
...slackChartDefaults,
108+
useUTC: true,
109+
color,
110+
series: [lineSeries],
111+
};
112+
}
113+
114+
const stats = Object.keys(data.stats).map(key =>
115+
Object.assign({}, {key}, (data.stats as any)[key])
116+
);
117+
const color = theme.chart.getColorPalette(stats.length - 1);
118+
119+
const series = stats
120+
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
121+
.map((s, i) =>
122+
LineSeries({
123+
name: s.key,
124+
data: s.data.map(
125+
([timestamp, countsForTimestamp]: [number, Array<{count: number}>]) => [
126+
timestamp * 1000,
127+
countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
128+
]
129+
),
130+
lineStyle: {color: color?.[i], opacity: 1},
131+
itemStyle: {color: color?.[i]},
132+
})
133+
);
134+
135+
return {
136+
...slackChartDefaults,
137+
xAxis: discoverxAxis,
138+
useUTC: true,
139+
color,
140+
series,
141+
};
142+
},
143+
...slackChartSize,
144+
});
145+
87146
discoverCharts.push({
88147
key: ChartType.SLACK_DISCOVER_TOTAL_DAILY,
89148
getOption: (

static/app/chartcuterie/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {EChartsOption} from 'echarts';
99
*/
1010
export enum ChartType {
1111
SLACK_DISCOVER_TOTAL_PERIOD = 'slack:discover.totalPeriod',
12+
SLACK_DISCOVER_TOTAL_PERIOD_LINE = 'slack:discover.totalPeriodLine',
1213
SLACK_DISCOVER_TOTAL_DAILY = 'slack:discover.totalDaily',
1314
SLACK_DISCOVER_TOP5_PERIOD = 'slack:discover.top5Period',
1415
SLACK_DISCOVER_TOP5_PERIOD_LINE = 'slack:discover.top5PeriodLine',

0 commit comments

Comments
 (0)