@@ -86,28 +86,16 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
86
86
87
87
final MutableScale <D > _defaultScale;
88
88
89
- MutableScale <D > _scale;
90
-
91
89
/// [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;
97
91
98
92
/// Previous [Scale] of this axis, used to calculate tick animation.
99
93
MutableScale <D > _previousScale;
100
94
101
95
final TickProvider <D > _defaultTickProvider;
102
96
103
- TickProvider <D > _tickProvider;
104
-
105
97
/// [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;
111
99
112
100
final TickFormatter <D > _defaultTickFormatter;
113
101
@@ -136,9 +124,12 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
136
124
/// If the output range should be reversed.
137
125
bool reverseOutputRange = false ;
138
126
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;
142
133
143
134
/// If the axis line should always be drawn.
144
135
bool forceDrawAxisLine;
@@ -157,48 +148,31 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
157
148
158
149
Rectangle <int > _componentBounds;
159
150
Rectangle <int > _drawAreaBounds;
160
- GraphicsFactory _graphicsFactory;
161
151
162
152
/// Order for chart layout painting.
163
153
///
164
154
/// In general, domain axes should be drawn on top of measure axes to ensure
165
155
/// that the domain axis line appears on top of any measure axis grid lines.
166
156
int layoutPaintOrder = LayoutViewPaintOrder .measureAxis;
167
157
168
- Axis (
169
- {TickProvider <D > tickProvider,
170
- TickFormatter <D > tickFormatter,
171
- MutableScale <D > scale})
158
+ Axis ({this .tickProvider, TickFormatter <D > tickFormatter, this .scale})
172
159
: _defaultScale = scale,
173
- _scale = scale,
174
160
_defaultTickProvider = tickProvider,
175
- _tickProvider = tickProvider,
176
161
_defaultTickFormatter = tickFormatter,
177
162
_tickFormatter = tickFormatter;
178
163
179
164
@protected
180
- MutableScale <D > get mutableScale => _scale ;
165
+ MutableScale <D > get mutableScale => scale ;
181
166
182
167
/// Rangeband for this axis.
183
168
@override
184
- double get rangeBand => _scale .rangeBand;
169
+ double get rangeBand => scale .rangeBand;
185
170
186
171
@override
187
- double get stepSize => _scale .stepSize;
172
+ double get stepSize => scale .stepSize;
188
173
189
174
@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;
202
176
203
177
void setRangeBandConfig (RangeBandConfig rangeBandConfig) {
204
178
mutableScale.rangeBandConfig = rangeBandConfig;
@@ -215,15 +189,15 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
215
189
return ;
216
190
}
217
191
218
- _scale .addDomain (domain);
192
+ scale .addDomain (domain);
219
193
}
220
194
221
195
void resetDefaultConfiguration () {
222
196
forceDrawAxisLine = null ;
223
- _autoViewport = _autoViewportDefault;
224
- _scale = _defaultScale;
197
+ autoViewport = _autoViewportDefault;
198
+ scale = _defaultScale;
225
199
_tickFormatter = _defaultTickFormatter;
226
- _tickProvider = _defaultTickProvider;
200
+ tickProvider = _defaultTickProvider;
227
201
}
228
202
229
203
void resetDomains () {
@@ -250,11 +224,11 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
250
224
// regression for b/110371453.
251
225
_formatterValueCache.clear ();
252
226
253
- _scale .resetDomain ();
227
+ scale .resetDomain ();
254
228
reverseOutputRange = false ;
255
229
256
- if (_autoViewport ) {
257
- _scale .resetViewportSettings ();
230
+ if (autoViewport ) {
231
+ scale .resetViewportSettings ();
258
232
}
259
233
260
234
// TODO: Reset rangeband and step size when we port over config
@@ -266,16 +240,16 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
266
240
double getLocation (D domain) {
267
241
const epsilon = 2e-10 ;
268
242
if (domain != null ) {
269
- var domainLocation = _scale [domain];
243
+ var domainLocation = scale [domain];
270
244
271
245
// If domain location is outside of scale range but only outside by less
272
246
// than epsilon, correct the potential mislocation caused by floating
273
247
// 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) {
276
250
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) {
279
253
return domainLocation + epsilon;
280
254
}
281
255
return domainLocation;
@@ -284,15 +258,15 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
284
258
}
285
259
286
260
@override
287
- D getDomain (double location) => _scale .reverse (location);
261
+ D getDomain (double location) => scale .reverse (location);
288
262
289
263
@override
290
264
int compareDomainValueToViewport (D domain) {
291
- return _scale .compareDomainValueToViewport (domain);
265
+ return scale .compareDomainValueToViewport (domain);
292
266
}
293
267
294
268
void setOutputRange (int start, int end) {
295
- _scale .range = ScaleOutputExtent (start, end);
269
+ scale .range = ScaleOutputExtent (start, end);
296
270
}
297
271
298
272
/// Request update ticks from tick provider and update the painted ticks.
@@ -312,12 +286,12 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
312
286
_providedTicks = tickProvider.getTicks (
313
287
context: context,
314
288
graphicsFactory: graphicsFactory,
315
- scale: _scale ,
289
+ scale: scale ,
316
290
formatter: tickFormatter,
317
291
formatterValueCache: _formatterValueCache,
318
292
tickDrawStrategy: tickDrawStrategy,
319
293
orientation: axisOrientation,
320
- viewportExtensionEnabled: _autoViewport );
294
+ viewportExtensionEnabled: autoViewport );
321
295
}
322
296
323
297
/// Updates the ticks that are actually used for drawing.
@@ -340,8 +314,8 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
340
314
animatedTick.textElement, tick.textElement)) {
341
315
animatedTick.textElement = tick.textElement;
342
316
}
343
- var newTarget = _scale [tick.value];
344
- if (_scale .isRangeValueWithinViewport (newTarget)) {
317
+ var newTarget = scale [tick.value];
318
+ if (scale .isRangeValueWithinViewport (newTarget)) {
345
319
// Update target for all existing ticks
346
320
animatedTick.setNewTarget (newTarget);
347
321
} else {
@@ -351,7 +325,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
351
325
providedTicks.remove (tick);
352
326
} else {
353
327
// Animate out ticks that do not exist any more.
354
- animatedTick.animateOut (_scale [animatedTick.value].toDouble ());
328
+ animatedTick.animateOut (scale [animatedTick.value].toDouble ());
355
329
}
356
330
}
357
331
@@ -363,7 +337,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
363
337
} else {
364
338
animatedTick = AxisTicks <D >(tick);
365
339
}
366
- if (_scale .isRangeValueWithinViewport (animatedTick.locationPx)) {
340
+ if (scale .isRangeValueWithinViewport (animatedTick.locationPx)) {
367
341
if (_previousScale != null ) {
368
342
animatedTick.animateInFrom (_previousScale[tick.value].toDouble ());
369
343
}
@@ -375,7 +349,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
375
349
376
350
// Save a copy of the current scale to be used as the previous scale when
377
351
// ticks are updated.
378
- _previousScale = _scale .copy ();
352
+ _previousScale = scale .copy ();
379
353
}
380
354
381
355
/// Configures the zoom and translate.
@@ -400,7 +374,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
400
374
viewportTranslatePx = _clampTranslatePx (viewportScale, viewportTranslatePx,
401
375
drawAreaWidth: drawAreaWidth, drawAreaHeight: drawAreaHeight);
402
376
403
- _scale .setViewportSettings (viewportScale, viewportTranslatePx);
377
+ scale .setViewportSettings (viewportScale, viewportTranslatePx);
404
378
}
405
379
406
380
/// Returns the current viewport scale.
@@ -409,14 +383,14 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
409
383
/// value of 2.0 would map the data to an output of double the range so you
410
384
/// only see half the data in the viewport. This is the equivalent to
411
385
/// zooming. Its value is likely >= 1.0.
412
- double get viewportScalingFactor => _scale .viewportScalingFactor;
386
+ double get viewportScalingFactor => scale .viewportScalingFactor;
413
387
414
388
/// Returns the current pixel viewport offset
415
389
///
416
390
/// The translate is used by the scale function when it applies the scale.
417
391
/// This is the equivalent to panning. Its value is likely <= 0 to pan the
418
392
/// data to the left.
419
- double get viewportTranslatePx => _scale ? .viewportTranslatePx;
393
+ double get viewportTranslatePx => scale ? .viewportTranslatePx;
420
394
421
395
/// Clamps a possible change in domain translation to fit within the range of
422
396
/// the data.
@@ -452,12 +426,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
452
426
//
453
427
454
428
@override
455
- GraphicsFactory get graphicsFactory => _graphicsFactory;
456
-
457
- @override
458
- set graphicsFactory (GraphicsFactory value) {
459
- _graphicsFactory = value;
460
- }
429
+ GraphicsFactory graphicsFactory;
461
430
462
431
@override
463
432
LayoutViewConfig get layoutConfig => LayoutViewConfig (
@@ -534,8 +503,8 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
534
503
? ScaleOutputExtent (outputEnd, outputStart)
535
504
: ScaleOutputExtent (outputStart, outputEnd);
536
505
537
- if (_scale .range != outputRange) {
538
- _scale .range = outputRange;
506
+ if (scale .range != outputRange) {
507
+ scale .range = outputRange;
539
508
}
540
509
541
510
_updateProvidedTicks ();
@@ -591,7 +560,7 @@ class NumericAxis extends Axis<num> {
591
560
592
561
void setScaleViewport (NumericExtents viewport) {
593
562
autoViewport = false ;
594
- (_scale as NumericScale ).viewportDomain = viewport;
563
+ (scale as NumericScale ).viewportDomain = viewport;
595
564
}
596
565
}
597
566
@@ -608,7 +577,7 @@ class OrdinalAxis extends Axis<String> {
608
577
609
578
void setScaleViewport (OrdinalViewport viewport) {
610
579
autoViewport = false ;
611
- (_scale as OrdinalScale )
580
+ (scale as OrdinalScale )
612
581
.setViewport (viewport.dataSize, viewport.startingDomain);
613
582
}
614
583
@@ -628,7 +597,7 @@ class OrdinalAxis extends Axis<String> {
628
597
// By resetting the viewport after layout, we guarantee the correct range
629
598
// was used to apply the viewport and behaviors that update the viewport
630
599
// 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 );
632
601
}
633
602
}
634
603
@@ -662,7 +631,7 @@ class AxisTester<D> {
662
631
663
632
List <AxisTicks <D >> get axisTicks => _axis._axisTicks;
664
633
665
- MutableScale <D > get scale => _axis._scale ;
634
+ MutableScale <D > get scale => _axis.scale ;
666
635
667
636
List <D > get axisValues => axisTicks.map ((t) => t.value).toList ();
668
637
}
0 commit comments