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

Commit bcf2aef

Browse files
jamesderlincbbraun
authored andcommitted
Clean up violations of Dart lint unnecessary_getters_setters
Replace trivial getters and setters with fields. PiperOrigin-RevId: 360551490
1 parent 03a82e1 commit bcf2aef

File tree

8 files changed

+80
-206
lines changed

8 files changed

+80
-206
lines changed

charts_common/lib/src/chart/cartesian/axis/axis.dart

+45-76
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,16 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
8686

8787
final MutableScale<D> _defaultScale;
8888

89-
MutableScale<D> _scale;
90-
9189
/// [Scale] of this axis.
92-
MutableScale<D> get scale => _scale;
93-
94-
set scale(MutableScale<D> scale) {
95-
_scale = scale;
96-
}
90+
MutableScale<D> scale;
9791

9892
/// Previous [Scale] of this axis, used to calculate tick animation.
9993
MutableScale<D> _previousScale;
10094

10195
final TickProvider<D> _defaultTickProvider;
10296

103-
TickProvider<D> _tickProvider;
104-
10597
/// [TickProvider] for this axis.
106-
TickProvider<D> get tickProvider => _tickProvider;
107-
108-
set tickProvider(TickProvider<D> tickProvider) {
109-
_tickProvider = tickProvider;
110-
}
98+
TickProvider<D> tickProvider;
11199

112100
final TickFormatter<D> _defaultTickFormatter;
113101

@@ -136,9 +124,12 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
136124
/// If the output range should be reversed.
137125
bool reverseOutputRange = false;
138126

139-
/// Whether or not the axis will configure the viewport to have "niced" ticks
140-
/// around the domain values.
141-
bool _autoViewport = _autoViewportDefault;
127+
/// Configures whether the viewport should be reset back to default values
128+
/// when the domain is reset.
129+
///
130+
/// This should generally be disabled when the viewport will be managed
131+
/// externally, e.g. from pan and zoom behaviors.
132+
bool autoViewport = _autoViewportDefault;
142133

143134
/// If the axis line should always be drawn.
144135
bool forceDrawAxisLine;
@@ -157,48 +148,31 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
157148

158149
Rectangle<int> _componentBounds;
159150
Rectangle<int> _drawAreaBounds;
160-
GraphicsFactory _graphicsFactory;
161151

162152
/// Order for chart layout painting.
163153
///
164154
/// In general, domain axes should be drawn on top of measure axes to ensure
165155
/// that the domain axis line appears on top of any measure axis grid lines.
166156
int layoutPaintOrder = LayoutViewPaintOrder.measureAxis;
167157

168-
Axis(
169-
{TickProvider<D> tickProvider,
170-
TickFormatter<D> tickFormatter,
171-
MutableScale<D> scale})
158+
Axis({this.tickProvider, TickFormatter<D> tickFormatter, this.scale})
172159
: _defaultScale = scale,
173-
_scale = scale,
174160
_defaultTickProvider = tickProvider,
175-
_tickProvider = tickProvider,
176161
_defaultTickFormatter = tickFormatter,
177162
_tickFormatter = tickFormatter;
178163

179164
@protected
180-
MutableScale<D> get mutableScale => _scale;
165+
MutableScale<D> get mutableScale => scale;
181166

182167
/// Rangeband for this axis.
183168
@override
184-
double get rangeBand => _scale.rangeBand;
169+
double get rangeBand => scale.rangeBand;
185170

186171
@override
187-
double get stepSize => _scale.stepSize;
172+
double get stepSize => scale.stepSize;
188173

189174
@override
190-
ScaleOutputExtent get range => _scale.range;
191-
192-
/// Configures whether the viewport should be reset back to default values
193-
/// when the domain is reset.
194-
///
195-
/// This should generally be disabled when the viewport will be managed
196-
/// externally, e.g. from pan and zoom behaviors.
197-
set autoViewport(bool autoViewport) {
198-
_autoViewport = autoViewport;
199-
}
200-
201-
bool get autoViewport => _autoViewport;
175+
ScaleOutputExtent get range => scale.range;
202176

203177
void setRangeBandConfig(RangeBandConfig rangeBandConfig) {
204178
mutableScale.rangeBandConfig = rangeBandConfig;
@@ -215,15 +189,15 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
215189
return;
216190
}
217191

218-
_scale.addDomain(domain);
192+
scale.addDomain(domain);
219193
}
220194

221195
void resetDefaultConfiguration() {
222196
forceDrawAxisLine = null;
223-
_autoViewport = _autoViewportDefault;
224-
_scale = _defaultScale;
197+
autoViewport = _autoViewportDefault;
198+
scale = _defaultScale;
225199
_tickFormatter = _defaultTickFormatter;
226-
_tickProvider = _defaultTickProvider;
200+
tickProvider = _defaultTickProvider;
227201
}
228202

229203
void resetDomains() {
@@ -250,11 +224,11 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
250224
// regression for b/110371453.
251225
_formatterValueCache.clear();
252226

253-
_scale.resetDomain();
227+
scale.resetDomain();
254228
reverseOutputRange = false;
255229

256-
if (_autoViewport) {
257-
_scale.resetViewportSettings();
230+
if (autoViewport) {
231+
scale.resetViewportSettings();
258232
}
259233

260234
// TODO: Reset rangeband and step size when we port over config
@@ -266,16 +240,16 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
266240
double getLocation(D domain) {
267241
const epsilon = 2e-10;
268242
if (domain != null) {
269-
var domainLocation = _scale[domain];
243+
var domainLocation = scale[domain];
270244

271245
// If domain location is outside of scale range but only outside by less
272246
// than epsilon, correct the potential mislocation caused by floating
273247
// point computation by moving it inside of scale range.
274-
if (domainLocation > _scale.range.max &&
275-
domainLocation - epsilon < _scale.range.max) {
248+
if (domainLocation > scale.range.max &&
249+
domainLocation - epsilon < scale.range.max) {
276250
return domainLocation - epsilon;
277-
} else if (domainLocation < _scale.range.min &&
278-
domainLocation + epsilon > _scale.range.min) {
251+
} else if (domainLocation < scale.range.min &&
252+
domainLocation + epsilon > scale.range.min) {
279253
return domainLocation + epsilon;
280254
}
281255
return domainLocation;
@@ -284,15 +258,15 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
284258
}
285259

286260
@override
287-
D getDomain(double location) => _scale.reverse(location);
261+
D getDomain(double location) => scale.reverse(location);
288262

289263
@override
290264
int compareDomainValueToViewport(D domain) {
291-
return _scale.compareDomainValueToViewport(domain);
265+
return scale.compareDomainValueToViewport(domain);
292266
}
293267

294268
void setOutputRange(int start, int end) {
295-
_scale.range = ScaleOutputExtent(start, end);
269+
scale.range = ScaleOutputExtent(start, end);
296270
}
297271

298272
/// Request update ticks from tick provider and update the painted ticks.
@@ -312,12 +286,12 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
312286
_providedTicks = tickProvider.getTicks(
313287
context: context,
314288
graphicsFactory: graphicsFactory,
315-
scale: _scale,
289+
scale: scale,
316290
formatter: tickFormatter,
317291
formatterValueCache: _formatterValueCache,
318292
tickDrawStrategy: tickDrawStrategy,
319293
orientation: axisOrientation,
320-
viewportExtensionEnabled: _autoViewport);
294+
viewportExtensionEnabled: autoViewport);
321295
}
322296

323297
/// Updates the ticks that are actually used for drawing.
@@ -340,8 +314,8 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
340314
animatedTick.textElement, tick.textElement)) {
341315
animatedTick.textElement = tick.textElement;
342316
}
343-
var newTarget = _scale[tick.value];
344-
if (_scale.isRangeValueWithinViewport(newTarget)) {
317+
var newTarget = scale[tick.value];
318+
if (scale.isRangeValueWithinViewport(newTarget)) {
345319
// Update target for all existing ticks
346320
animatedTick.setNewTarget(newTarget);
347321
} else {
@@ -351,7 +325,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
351325
providedTicks.remove(tick);
352326
} else {
353327
// Animate out ticks that do not exist any more.
354-
animatedTick.animateOut(_scale[animatedTick.value].toDouble());
328+
animatedTick.animateOut(scale[animatedTick.value].toDouble());
355329
}
356330
}
357331

@@ -363,7 +337,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
363337
} else {
364338
animatedTick = AxisTicks<D>(tick);
365339
}
366-
if (_scale.isRangeValueWithinViewport(animatedTick.locationPx)) {
340+
if (scale.isRangeValueWithinViewport(animatedTick.locationPx)) {
367341
if (_previousScale != null) {
368342
animatedTick.animateInFrom(_previousScale[tick.value].toDouble());
369343
}
@@ -375,7 +349,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
375349

376350
// Save a copy of the current scale to be used as the previous scale when
377351
// ticks are updated.
378-
_previousScale = _scale.copy();
352+
_previousScale = scale.copy();
379353
}
380354

381355
/// Configures the zoom and translate.
@@ -400,7 +374,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
400374
viewportTranslatePx = _clampTranslatePx(viewportScale, viewportTranslatePx,
401375
drawAreaWidth: drawAreaWidth, drawAreaHeight: drawAreaHeight);
402376

403-
_scale.setViewportSettings(viewportScale, viewportTranslatePx);
377+
scale.setViewportSettings(viewportScale, viewportTranslatePx);
404378
}
405379

406380
/// Returns the current viewport scale.
@@ -409,14 +383,14 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
409383
/// value of 2.0 would map the data to an output of double the range so you
410384
/// only see half the data in the viewport. This is the equivalent to
411385
/// zooming. Its value is likely >= 1.0.
412-
double get viewportScalingFactor => _scale.viewportScalingFactor;
386+
double get viewportScalingFactor => scale.viewportScalingFactor;
413387

414388
/// Returns the current pixel viewport offset
415389
///
416390
/// The translate is used by the scale function when it applies the scale.
417391
/// This is the equivalent to panning. Its value is likely <= 0 to pan the
418392
/// data to the left.
419-
double get viewportTranslatePx => _scale?.viewportTranslatePx;
393+
double get viewportTranslatePx => scale?.viewportTranslatePx;
420394

421395
/// Clamps a possible change in domain translation to fit within the range of
422396
/// the data.
@@ -452,12 +426,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
452426
//
453427

454428
@override
455-
GraphicsFactory get graphicsFactory => _graphicsFactory;
456-
457-
@override
458-
set graphicsFactory(GraphicsFactory value) {
459-
_graphicsFactory = value;
460-
}
429+
GraphicsFactory graphicsFactory;
461430

462431
@override
463432
LayoutViewConfig get layoutConfig => LayoutViewConfig(
@@ -534,8 +503,8 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
534503
? ScaleOutputExtent(outputEnd, outputStart)
535504
: ScaleOutputExtent(outputStart, outputEnd);
536505

537-
if (_scale.range != outputRange) {
538-
_scale.range = outputRange;
506+
if (scale.range != outputRange) {
507+
scale.range = outputRange;
539508
}
540509

541510
_updateProvidedTicks();
@@ -591,7 +560,7 @@ class NumericAxis extends Axis<num> {
591560

592561
void setScaleViewport(NumericExtents viewport) {
593562
autoViewport = false;
594-
(_scale as NumericScale).viewportDomain = viewport;
563+
(scale as NumericScale).viewportDomain = viewport;
595564
}
596565
}
597566

@@ -608,7 +577,7 @@ class OrdinalAxis extends Axis<String> {
608577

609578
void setScaleViewport(OrdinalViewport viewport) {
610579
autoViewport = false;
611-
(_scale as OrdinalScale)
580+
(scale as OrdinalScale)
612581
.setViewport(viewport.dataSize, viewport.startingDomain);
613582
}
614583

@@ -628,7 +597,7 @@ class OrdinalAxis extends Axis<String> {
628597
// By resetting the viewport after layout, we guarantee the correct range
629598
// was used to apply the viewport and behaviors that update the viewport
630599
// based on translate and scale changes will not be affected (pan/zoom).
631-
(_scale as OrdinalScale).setViewport(null, null);
600+
(scale as OrdinalScale).setViewport(null, null);
632601
}
633602
}
634603

@@ -662,7 +631,7 @@ class AxisTester<D> {
662631

663632
List<AxisTicks<D>> get axisTicks => _axis._axisTicks;
664633

665-
MutableScale<D> get scale => _axis._scale;
634+
MutableScale<D> get scale => _axis.scale;
666635

667636
List<D> get axisValues => axisTicks.map((t) => t.value).toList();
668637
}

charts_common/lib/src/chart/common/behavior/chart_title/chart_title.dart

+2-9
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ class _ChartTitleLayoutView<D> extends LayoutView {
272272
Rectangle<int> _componentBounds;
273273
Rectangle<int> _drawAreaBounds;
274274

275-
GraphicsFactory _graphicsFactory;
275+
@override
276+
GraphicsFactory graphicsFactory;
276277

277278
/// Cached layout element for the title text.
278279
///
@@ -300,14 +301,6 @@ class _ChartTitleLayoutView<D> extends LayoutView {
300301
positionOrder: LayoutViewPositionOrder.chartTitle);
301302
}
302303

303-
@override
304-
GraphicsFactory get graphicsFactory => _graphicsFactory;
305-
306-
@override
307-
set graphicsFactory(GraphicsFactory value) {
308-
_graphicsFactory = value;
309-
}
310-
311304
/// Sets the configuration for the title behavior.
312305
set config(_ChartTitleConfig config) {
313306
_config = config;

0 commit comments

Comments
 (0)