From da98045ee8f98ab3b3633deff0425c89ab1c6699 Mon Sep 17 00:00:00 2001 From: Anton Standrik Date: Fri, 9 Dec 2022 19:05:17 +0300 Subject: [PATCH 1/2] fix: legend show and hide all button --- src/YagrCore/plugins/legend/legend.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/YagrCore/plugins/legend/legend.ts b/src/YagrCore/plugins/legend/legend.ts index 1ac8c9df..558632e8 100644 --- a/src/YagrCore/plugins/legend/legend.ts +++ b/src/YagrCore/plugins/legend/legend.ts @@ -38,6 +38,10 @@ const getPrependingTitle = (i18n: Yagr['utils']['i18n'], series: Series[]) => { return series.length > 3 && i18n(hasOneVisibleLine(series) ? 'hide-all' : 'show-all'); }; +const getPrependingTitleId = (series: Series[]) => { + return series.length > 3 && ALL_SERIES_IDX; +}; + export default class Legend { yagr: Yagr; uplot?: UPlot; @@ -327,6 +331,7 @@ export default class Legend { private renderItems(uplotOptions: Options) { const title = getPrependingTitle(this.yagr.utils.i18n, uplotOptions.series); + const titleId = getPrependingTitleId(uplotOptions.series); const series: (Series | string)[] = title ? [title] : []; for (let i = 1; i < uplotOptions.series.length; i++) { @@ -340,7 +345,7 @@ export default class Legend { if (typeof serie === 'string') { content = serie; - sId = serie; + sId = titleId; } else { sId = serie.id; const icon = this.createIconLineElement(serie); From 71ff5eafa4e1c8442e930f954fd50c4cf0a0524f Mon Sep 17 00:00:00 2001 From: Anton Standrik Date: Fri, 9 Dec 2022 19:13:15 +0300 Subject: [PATCH 2/2] better code --- src/YagrCore/plugins/legend/legend.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/YagrCore/plugins/legend/legend.ts b/src/YagrCore/plugins/legend/legend.ts index 558632e8..7408ff66 100644 --- a/src/YagrCore/plugins/legend/legend.ts +++ b/src/YagrCore/plugins/legend/legend.ts @@ -25,7 +25,7 @@ interface LegendState { pageSize: number; } -const ALL_SERIES_IDX = 'null'; +const ALL_SERIES_IDX = 'null' as const; const TOTAL_LEGEND_VERTICAL_PADDING = 20; const DEFAULT_FONT_SIZE = 12; const DEFAULT_LEGEND_PLACE_RATIO = 0.3; @@ -38,8 +38,8 @@ const getPrependingTitle = (i18n: Yagr['utils']['i18n'], series: Series[]) => { return series.length > 3 && i18n(hasOneVisibleLine(series) ? 'hide-all' : 'show-all'); }; -const getPrependingTitleId = (series: Series[]) => { - return series.length > 3 && ALL_SERIES_IDX; +const getPrependingTitleId = (series: Series[]): typeof ALL_SERIES_IDX | undefined => { + return series.length > 3 && ALL_SERIES_IDX || undefined; }; export default class Legend { @@ -332,7 +332,7 @@ export default class Legend { private renderItems(uplotOptions: Options) { const title = getPrependingTitle(this.yagr.utils.i18n, uplotOptions.series); const titleId = getPrependingTitleId(uplotOptions.series); - const series: (Series | string)[] = title ? [title] : []; + const series: (Series | typeof ALL_SERIES_IDX)[] = titleId ? [titleId] : []; for (let i = 1; i < uplotOptions.series.length; i++) { series.push(uplotOptions.series[i]); @@ -343,8 +343,8 @@ export default class Legend { let content; let sId; - if (typeof serie === 'string') { - content = serie; + if (serie === ALL_SERIES_IDX) { + content = title; sId = titleId; } else { sId = serie.id;