Skip to content

Commit

Permalink
fix: show value on the selected series (#1429)
Browse files Browse the repository at this point in the history
* fix: show value on the selected series

* fix: callback
  • Loading branch information
stephenLYZ authored and zhaoyongjie committed Nov 26, 2021
1 parent 8666f63 commit 3a5bfa6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,33 @@ export default function EchartsTimeseries({
const lastSelectedLegend = useRef('');
const clickTimer = useRef<ReturnType<typeof setTimeout>>();

const handleDoubleClickChange = useCallback((name?: string) => {
const echartInstance = echartRef.current?.getEchartInstance();
if (!name) {
echartInstance?.dispatchAction({
type: 'legendAllSelect',
});
} else {
legendData.forEach(datum => {
if (datum === name) {
echartInstance?.dispatchAction({
type: 'legendSelect',
name: datum,
});
} else {
echartInstance?.dispatchAction({
type: 'legendUnSelect',
name: datum,
});
}
});
}
}, []);
const handleDoubleClickChange = useCallback(
(name?: string) => {
const echartInstance = echartRef.current?.getEchartInstance();
if (!name) {
currentSeries.legend = '';
echartInstance?.dispatchAction({
type: 'legendAllSelect',
});
} else {
legendData.forEach(datum => {
if (datum === name) {
currentSeries.legend = datum;
echartInstance?.dispatchAction({
type: 'legendSelect',
name: datum,
});
} else {
echartInstance?.dispatchAction({
type: 'legendUnSelect',
name: datum,
});
}
});
}
},
[legendData],
);

const getModelInfo = (target: ViewRootGroup, globalModel: GlobalModel) => {
let el = target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
formatAnnotationLabel,
parseAnnotationOpacity,
} from '../utils/annotation';
import { getChartPadding } from '../utils/series';
import { currentSeries, getChartPadding } from '../utils/series';
import { OpacityEnum, TIMESERIES_CONSTANTS } from '../constants';

export function transformSeries(
Expand Down Expand Up @@ -194,9 +194,11 @@ export function transformSeries(
value: [, numericValue],
dataIndex,
seriesIndex,
seriesName,
} = params;
const isSelectedLegend = currentSeries.legend === seriesName;
if (!formatter) return numericValue;
if (!stack || !onlyTotal) {
if (!stack || !onlyTotal || isSelectedLegend) {
return formatter(numericValue);
}
if (seriesIndex === showValueIndexes[dataIndex]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ const onlyTotalControl = {
label: t('Only Total'),
default: true,
renderTrigger: true,
description: t('Only show the total value on the stacked chart'),
description: t(
'Only show the total value on the stacked chart, and not show on the selected category',
),
visibility: ({ controls }: ControlPanelsContainerProps) =>
Boolean(controls?.show_value?.value) && Boolean(controls?.stack?.value),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,5 @@ export function sanitizeHtml(text: string): string {
// TODO: Better use other method to maintain this state
export const currentSeries = {
name: '',
legend: '',
};

0 comments on commit 3a5bfa6

Please sign in to comment.