Skip to content

Commit

Permalink
fix(Highcharts plugin): show totals of selected series on legend click (
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmadom authored Jun 19, 2023
1 parent 9d6d482 commit ac7fe22
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
16 changes: 16 additions & 0 deletions src/plugins/highcharts/__stories__/pie/WithTotals.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import {Meta, Story} from '@storybook/react';
import {ChartKit} from '../../../../components/ChartKit';
import {data} from '../../mocks/pie-with-totals';
import {ChartStory} from '../components/ChartStory';

export default {
title: 'Plugins/Highcharts/Pie',
component: ChartKit,
} as Meta;

const Template: Story<any> = () => {
return <ChartStory data={data} />;
};

export const WithTotals = Template.bind({});
45 changes: 45 additions & 0 deletions src/plugins/highcharts/mocks/pie-with-totals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {HighchartsWidgetData} from '../types';

export const data: HighchartsWidgetData = {
data: {
graphs: [
{
name: 'Number of requests',
tooltip: {
chartKitFormatting: true,
chartKitPrecision: 0,
},
dataLabels: {
format: null,
chartKitFormatting: true,
chartKitPrecision: 0,
chartKitPrefix: '',
chartKitPostfix: '',
chartKitLabelMode: 'absolute',
chartKitFormat: 'number',
chartKitShowRankDelimiter: true,
},
data: [
{name: 'Furniture', y: 14344, label: 14344},
{name: 'Domestic chemistry', y: 14244, label: 14244},
{name: 'Household goods', y: 14181, label: 14181},
],
},
],
categories: ['Furniture', 'Domestic chemistry', 'Household goods'],
totals: 42769,
},
config: {
showPercentInTooltip: true,
},
libraryConfig: {
chart: {
type: 'pie',
},
plotOptions: {
pie: {
innerSize: '50%',
},
},
},
};
11 changes: 5 additions & 6 deletions src/plugins/highcharts/renderer/helpers/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -1622,13 +1622,12 @@ export function prepareConfig(data, options, isMobile, holidays) {
const chart = this;
const chartSeries = chart.series[0];
const innerWidth = chartSeries?.center[3];
const formatOptions = chartSeries?.userOptions?.tooltip;
const value =
formatDonutTotals(chartSeries?.total, formatOptions) || totals;

if (innerWidth) {
debouncedAdjustDonutFontSize(
chart,
chartSeries,
innerWidth,
totals,
);
debouncedAdjustDonutFontSize(chart, chartSeries, innerWidth, value);
}
},
}),
Expand Down
1 change: 1 addition & 0 deletions src/plugins/highcharts/types/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type HighchartsWidgetData = {
| {
graphs: CkHighchartsSeriesOptionsType[];
categories: string[];
totals?: number | string;
}
| {
graphs: CkHighchartsSeriesOptionsType[];
Expand Down

0 comments on commit ac7fe22

Please sign in to comment.