Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Clean up violations of Dart lint prefer_collection_literals
Browse files Browse the repository at this point in the history
Use collection literals where possible.  Because a lot of this code
explicitly uses `LinkedHashMap` to indicate that order is important,
add appropriate `// ignore` comments until
https://github.com/dart-lang/linter/issues/1649 is addressed.

PiperOrigin-RevId: 360552809
  • Loading branch information
jamesderlin authored and cbbraun committed Mar 8, 2021
1 parent 9515f4d commit 0e2bb2f
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion charts_common/lib/src/chart/bar/bar_lane_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ class BarLaneRenderer<D> extends BarRenderer<D> {
/// as the data was given to the chart. For the case where both grouping and
/// stacking are disabled, this means that bars for data later in the series
/// will be drawn "on top of" bars earlier in the series.
// ignore: prefer_collection_literals, https://github.com/dart-lang/linter/issues/1649
final _barLaneStackMap = LinkedHashMap<String, List<AnimatedBar<D>>>();

/// Store a map of flags to track whether all measure values for a given
/// domain value are null, for every series on the chart.
// ignore: prefer_collection_literals, https://github.com/dart-lang/linter/issues/1649
final _allMeasuresForDomainNullMap = LinkedHashMap<D, bool>();

factory BarLaneRenderer({BarLaneRendererConfig config, String rendererId}) {
Expand All @@ -89,7 +91,7 @@ class BarLaneRenderer<D> extends BarRenderer<D> {
final domainFn = series.domainFn;
final measureFn = series.rawMeasureFn;

final domainValues = Set<D>();
final domainValues = <D>{};

for (var barIndex = 0; barIndex < series.data.length; barIndex++) {
final domain = domainFn(barIndex);
Expand Down
4 changes: 3 additions & 1 deletion charts_common/lib/src/chart/bar/base_bar_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ abstract class BaseBarRenderer<D, R extends BaseBarRendererElement,
/// as the data was given to the chart. For the case where both grouping and
/// stacking are disabled, this means that bars for data later in the series
/// will be drawn "on top of" bars earlier in the series.
// ignore: prefer_collection_literals, https://github.com/dart-lang/linter/issues/1649
final _barStackMap = LinkedHashMap<String, List<B>>();

// Store a list of bar stacks that exist in the series data.
Expand All @@ -98,6 +99,7 @@ abstract class BaseBarRenderer<D, R extends BaseBarRendererElement,
final _currentKeys = <String>[];

/// Stores a list of stack keys for each group key.
// ignore: prefer_collection_literals, https://github.com/dart-lang/linter/issues/1649
final _currentGroupsStackKeys = LinkedHashMap<D, Set<String>>();

/// Optimization for getNearest to avoid scanning all data if possible.
Expand Down Expand Up @@ -462,7 +464,7 @@ abstract class BaseBarRenderer<D, R extends BaseBarRendererElement,
// Store off stack keys for each bar group to help getNearest identify
// groups of stacks.
_currentGroupsStackKeys
.putIfAbsent(domainValue, () => Set<String>())
.putIfAbsent(domainValue, () => <String>{})
.add(barStackMapKey);

// Get the barElement we are going to setup.
Expand Down
1 change: 1 addition & 0 deletions charts_common/lib/src/chart/cartesian/cartesian_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ abstract class CartesianChart<D> extends BaseChart<D> {
removeView(axis);
});

// ignore: prefer_collection_literals, https://github.com/dart-lang/linter/issues/1649
_disjointMeasureAxes = LinkedHashMap<String, NumericAxis>();
if (_disjointMeasureAxesSpec != null) {
_disjointMeasureAxesSpec.forEach((String axisId, AxisSpec axisSpec) {
Expand Down
4 changes: 2 additions & 2 deletions charts_common/lib/src/chart/common/base_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ abstract class BaseChart<D> {
/// initial draw cycle (e.g. a [Legend] may hide some series).
List<MutableSeries<D>> _currentSeriesList;

Set<String> _usingRenderers = Set<String>();
Set<String> _usingRenderers = <String>{};
Map<String, List<MutableSeries<D>>> _rendererToSeriesList;

final _seriesRenderers = <String, SeriesRenderer<D>>{};
Expand Down Expand Up @@ -585,7 +585,7 @@ abstract class BaseChart<D> {
Map<String, List<MutableSeries<D>>> rendererToSeriesList = {};

var unusedRenderers = _usingRenderers;
_usingRenderers = Set<String>();
_usingRenderers = <String>{};

// Build map of rendererIds to SeriesLists.
seriesList.forEach((MutableSeries<D> series) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import 'per_series_legend_entry_generator.dart';
/// By default this behavior creates a legend entry per series.
class SeriesLegend<D> extends Legend<D> {
/// List of currently hidden series, by ID.
final _hiddenSeriesList = Set<String>();
final _hiddenSeriesList = <String>{};

/// List of series IDs that should be hidden by default.
List<String> _defaultHiddenSeries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class LinePointHighlighter<D> implements ChartBehavior<D> {
///
/// [LinkedHashMap] is used to render the series on the canvas in the same
/// order as the data was provided by the selection model.
// ignore: prefer_collection_literals, https://github.com/dart-lang/linter/issues/1649
var _seriesPointMap = LinkedHashMap<String, _AnimatedPoint<D>>();

// Store a list of points that exist in the series data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class RangeAnnotation<D> implements ChartBehavior<D> {
///
/// [LinkedHashMap] is used to render the series on the canvas in the same
/// order as the data was given to the chart.
// ignore: prefer_collection_literals, https://github.com/dart-lang/linter/issues/1649
final _annotationMap = LinkedHashMap<String, _AnimatedAnnotation<D>>();

// Store a list of annotations that exist in the current annotation list.
Expand Down
2 changes: 1 addition & 1 deletion charts_common/lib/src/chart/line/line_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class LineRenderer<D> extends BaseCartesianRenderer<D> {
final styleSegments = <_LineRendererElement<D>>[];
var styleSegmentsIndex = 0;

final usedKeys = Set<String>();
final usedKeys = <String>{};

// Configure style segments for each series.
String previousSegmentKey;
Expand Down
1 change: 1 addition & 0 deletions charts_common/lib/src/chart/pie/arc_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ArcRenderer<D> extends BaseSeriesRenderer<D> {
///
/// [LinkedHashMap] is used to render the series on the canvas in the same
/// order as the data was given to the chart.
// ignore: prefer_collection_literals, https://github.com/dart-lang/linter/issues/1649
final _seriesArcMap = LinkedHashMap<String, _AnimatedArcList<D>>();

// Store a list of arcs that exist in the series data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class PointRenderer<D> extends BaseCartesianRenderer<D> {
/// [LinkedHashMap] is used to render the series on the canvas in the same
/// order as the data was given to the chart.
@protected
// ignore: prefer_collection_literals, https://github.com/dart-lang/linter/issues/1649
var seriesPointMap = LinkedHashMap<String, List<AnimatedPoint<D>>>();

// Store a list of lines that exist in the series data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class SymbolAnnotationRenderer<D> extends PointRenderer<D>

var _currentHeight = 0;

// ignore: prefer_collection_literals, https://github.com/dart-lang/linter/issues/1649
final _seriesInfo = LinkedHashMap<String, _SeriesInfo<D>>();

SymbolAnnotationRenderer(
Expand Down

0 comments on commit 0e2bb2f

Please sign in to comment.