Skip to content

Commit

Permalink
Merge pull request #47 from gravity-ui/astandrik.fix-legend-show-all
Browse files Browse the repository at this point in the history
fix: legend show and hide all button
  • Loading branch information
astandrik authored Dec 12, 2022
2 parents d123d9b + 71ff5ea commit 08eeec8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/YagrCore/plugins/legend/legend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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[]): typeof ALL_SERIES_IDX | undefined => {
return series.length > 3 && ALL_SERIES_IDX || undefined;
};

export default class Legend {
yagr: Yagr;
uplot?: UPlot;
Expand Down Expand Up @@ -327,7 +331,8 @@ export default class Legend {

private renderItems(uplotOptions: Options) {
const title = getPrependingTitle(this.yagr.utils.i18n, uplotOptions.series);
const series: (Series | string)[] = title ? [title] : [];
const titleId = getPrependingTitleId(uplotOptions.series);
const series: (Series | typeof ALL_SERIES_IDX)[] = titleId ? [titleId] : [];

for (let i = 1; i < uplotOptions.series.length; i++) {
series.push(uplotOptions.series[i]);
Expand All @@ -338,9 +343,9 @@ export default class Legend {
let content;
let sId;

if (typeof serie === 'string') {
content = serie;
sId = serie;
if (serie === ALL_SERIES_IDX) {
content = title;
sId = titleId;
} else {
sId = serie.id;
const icon = this.createIconLineElement(serie);
Expand Down

0 comments on commit 08eeec8

Please sign in to comment.