123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- import isArray from 'lodash/isArray';
- import XAxis from 'app/components/charts/components/xAxis';
- import AreaSeries from 'app/components/charts/series/areaSeries';
- import BarSeries from 'app/components/charts/series/barSeries';
- import {EventsStats} from 'app/types';
- import {lightTheme as theme} from 'app/utils/theme';
- import {slackChartDefaults, slackChartSize} from './slack';
- import {ChartType, RenderDescriptor} from './types';
- const discoverxAxis = XAxis({
- theme,
- boundaryGap: true,
- splitNumber: 3,
- isGroupedByDate: true,
- axisLabel: {fontSize: 11},
- });
- export const discoverCharts: RenderDescriptor<ChartType>[] = [];
- discoverCharts.push({
- key: ChartType.SLACK_DISCOVER_TOTAL_PERIOD,
- getOption: (
- data:
- | {seriesName: string; stats: EventsStats}
- | {seriesName?: string; stats: Record<string, EventsStats>}
- ) => {
- if (isArray(data.stats.data)) {
- const color = theme.charts.getColorPalette(data.stats.data.length - 2);
- const areaSeries = AreaSeries({
- name: data.seriesName,
- data: data.stats.data.map(([timestamp, countsForTimestamp]) => [
- timestamp * 1000,
- countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
- ]),
- lineStyle: {color: color?.[0], opacity: 1, width: 0.4},
- areaStyle: {color: color?.[0], opacity: 1},
- });
- return {
- ...slackChartDefaults,
- useUTC: true,
- color,
- series: [areaSeries],
- };
- }
- const stats = Object.keys(data.stats).map(key =>
- Object.assign({}, {key}, data.stats[key])
- );
- const color = theme.charts.getColorPalette(stats.length - 2);
- const series = stats
- .sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
- .map((s, i) =>
- AreaSeries({
- name: s.key,
- stack: 'area',
- data: s.data.map(([timestamp, countsForTimestamp]) => [
- timestamp * 1000,
- countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
- ]),
- lineStyle: {color: color?.[i], opacity: 1, width: 0.4},
- areaStyle: {color: color?.[i], opacity: 1},
- })
- );
- return {
- ...slackChartDefaults,
- xAxis: discoverxAxis,
- useUTC: true,
- color,
- series,
- };
- },
- ...slackChartSize,
- });
- discoverCharts.push({
- key: ChartType.SLACK_DISCOVER_TOTAL_DAILY,
- getOption: (
- data:
- | {seriesName: string; stats: EventsStats}
- | {seriesName?: string; stats: Record<string, EventsStats>}
- ) => {
- if (isArray(data.stats.data)) {
- const color = theme.charts.getColorPalette(data.stats.data.length - 2);
- const barSeries = BarSeries({
- name: data.seriesName,
- data: data.stats.data.map(([timestamp, countsForTimestamp]) => ({
- value: [
- timestamp * 1000,
- countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
- ],
- })),
- itemStyle: {color: color?.[0], opacity: 1},
- });
- return {
- ...slackChartDefaults,
- xAxis: discoverxAxis,
- useUTC: true,
- color,
- series: [barSeries],
- };
- }
- const stats = Object.keys(data.stats).map(key =>
- Object.assign({}, {key}, data.stats[key])
- );
- const color = theme.charts.getColorPalette(stats.length - 2);
- const series = stats
- .sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
- .map((s, i) =>
- BarSeries({
- name: s.key,
- stack: 'area',
- data: s.data.map(([timestamp, countsForTimestamp]) => ({
- value: [
- timestamp * 1000,
- countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
- ],
- })),
- itemStyle: {color: color?.[i], opacity: 1},
- })
- );
- return {
- ...slackChartDefaults,
- xAxis: discoverxAxis,
- useUTC: true,
- color,
- series,
- };
- },
- ...slackChartSize,
- });
- discoverCharts.push({
- key: ChartType.SLACK_DISCOVER_TOP5_PERIOD,
- getOption: (
- data: {stats: Record<string, EventsStats>} | {seriesName?: string; stats: EventsStats}
- ) => {
- if (isArray(data.stats.data)) {
- const color = theme.charts.getColorPalette(data.stats.data.length - 2);
- const areaSeries = AreaSeries({
- data: data.stats.data.map(([timestamp, countsForTimestamp]) => [
- timestamp * 1000,
- countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
- ]),
- lineStyle: {color: color?.[0], opacity: 1, width: 0.4},
- areaStyle: {color: color?.[0], opacity: 1},
- });
- return {
- ...slackChartDefaults,
- useUTC: true,
- color,
- series: [areaSeries],
- };
- }
- const stats = Object.values(data.stats);
- const color = theme.charts.getColorPalette(stats.length - 2);
- const series = stats
- .sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
- .map((topSeries, i) =>
- AreaSeries({
- stack: 'area',
- data: topSeries.data.map(([timestamp, countsForTimestamp]) => [
- timestamp * 1000,
- countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
- ]),
- lineStyle: {color: color?.[i], opacity: 1, width: 0.4},
- areaStyle: {color: color?.[i], opacity: 1},
- })
- );
- return {
- ...slackChartDefaults,
- xAxis: discoverxAxis,
- useUTC: true,
- color,
- series,
- };
- },
- ...slackChartSize,
- });
- discoverCharts.push({
- key: ChartType.SLACK_DISCOVER_TOP5_DAILY,
- getOption: (
- data: {stats: Record<string, EventsStats>} | {seriesName?: string; stats: EventsStats}
- ) => {
- if (isArray(data.stats.data)) {
- const color = theme.charts.getColorPalette(data.stats.data.length - 2);
- const areaSeries = AreaSeries({
- data: data.stats.data.map(([timestamp, countsForTimestamp]) => [
- timestamp * 1000,
- countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
- ]),
- lineStyle: {color: color?.[0], opacity: 1, width: 0.4},
- areaStyle: {color: color?.[0], opacity: 1},
- });
- return {
- ...slackChartDefaults,
- useUTC: true,
- color,
- series: [areaSeries],
- };
- }
- const stats = Object.values(data.stats);
- const color = theme.charts.getColorPalette(stats.length - 2);
- const series = stats
- .sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
- .map((topSeries, i) =>
- BarSeries({
- stack: 'area',
- data: topSeries.data.map(([timestamp, countsForTimestamp]) => [
- timestamp * 1000,
- countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
- ]),
- itemStyle: {color: color?.[i], opacity: 1},
- })
- );
- return {
- ...slackChartDefaults,
- xAxis: discoverxAxis,
- useUTC: true,
- color,
- series,
- };
- },
- ...slackChartSize,
- });
|