diff --git a/charts_common/lib/src/chart/common/behavior/legend/series_legend.dart b/charts_common/lib/src/chart/common/behavior/legend/series_legend.dart index b623a4997..478ff9191 100644 --- a/charts_common/lib/src/chart/common/behavior/legend/series_legend.dart +++ b/charts_common/lib/src/chart/common/behavior/legend/series_legend.dart @@ -39,6 +39,9 @@ class SeriesLegend extends Legend { /// List of series IDs that should not be hideable. List? _alwaysVisibleSeries; + /// List of all series IDs. + List? _allSeries; + /// Whether or not the series legend should show measures on datum selection. late bool _showMeasures; @@ -150,6 +153,9 @@ class SeriesLegend extends Legend { // of hidden series. final seriesIds = seriesList.map((MutableSeries series) => series.id); + // ger the list of all ids + _allSeries = seriesIds.toList(); + _hiddenSeriesList.removeWhere((String id) => !seriesIds.contains(id)); } @@ -171,6 +177,18 @@ class SeriesLegend extends Legend { } } + /// Only keep data for a series on the chart by [seriesId]. + /// + /// The other entries in the legend for this series will be grayed out to indicate + /// that they are hidden. + @protected + void onlyKeepSeries(String seriesId) { + if (!isSeriesAlwaysVisible(seriesId)) { + _allSeries?.forEach((element) => _hiddenSeriesList.add(element)); + _hiddenSeriesList.remove(seriesId); + } + } + /// Shows the data for a series on the chart by [seriesId]. /// /// The entry in the legend for this series will be returned to its normal