mirror of
https://github.com/flutter/samples.git
synced 2026-04-05 11:11:23 +00:00
Web charts common update (#111)
This commit is contained in:
@@ -46,9 +46,9 @@ import 'tick_formatter.dart'
|
||||
show TickFormatter, OrdinalTickFormatter, NumericTickFormatter;
|
||||
import 'tick_provider.dart' show TickProvider;
|
||||
|
||||
const measureAxisIdKey = const AttributeKey<String>('Axis.measureAxisId');
|
||||
const measureAxisKey = const AttributeKey<Axis>('Axis.measureAxis');
|
||||
const domainAxisKey = const AttributeKey<Axis>('Axis.domainAxis');
|
||||
const measureAxisIdKey = AttributeKey<String>('Axis.measureAxisId');
|
||||
const measureAxisKey = AttributeKey<Axis>('Axis.measureAxis');
|
||||
const domainAxisKey = AttributeKey<Axis>('Axis.domainAxis');
|
||||
|
||||
/// Orientation of an Axis.
|
||||
enum AxisOrientation { top, right, bottom, left }
|
||||
@@ -89,14 +89,8 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
|
||||
/// Previous [Scale] of this axis, used to calculate tick animation.
|
||||
MutableScale<D> _previousScale;
|
||||
|
||||
TickProvider<D> _tickProvider;
|
||||
|
||||
/// [TickProvider] for this axis.
|
||||
TickProvider<D> get tickProvider => _tickProvider;
|
||||
|
||||
set tickProvider(TickProvider<D> tickProvider) {
|
||||
_tickProvider = tickProvider;
|
||||
}
|
||||
TickProvider<D> tickProvider;
|
||||
|
||||
/// [TickFormatter] for this axis.
|
||||
TickFormatter<D> _tickFormatter;
|
||||
@@ -122,9 +116,12 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
|
||||
/// If the output range should be reversed.
|
||||
bool reverseOutputRange = false;
|
||||
|
||||
/// Whether or not the axis will configure the viewport to have "niced" ticks
|
||||
/// around the domain values.
|
||||
bool _autoViewport = true;
|
||||
/// Configures whether the viewport should be reset back to default values
|
||||
/// when the domain is reset.
|
||||
///
|
||||
/// This should generally be disabled when the viewport will be managed
|
||||
/// externally, e.g. from pan and zoom behaviors.
|
||||
bool autoViewport = true;
|
||||
|
||||
/// If the axis line should always be drawn.
|
||||
bool forceDrawAxisLine;
|
||||
@@ -143,7 +140,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
|
||||
|
||||
Rectangle<int> _componentBounds;
|
||||
Rectangle<int> _drawAreaBounds;
|
||||
GraphicsFactory _graphicsFactory;
|
||||
GraphicsFactory graphicsFactory;
|
||||
|
||||
/// Order for chart layout painting.
|
||||
///
|
||||
@@ -156,7 +153,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
|
||||
TickFormatter<D> tickFormatter,
|
||||
MutableScale<D> scale})
|
||||
: this._scale = scale,
|
||||
this._tickProvider = tickProvider,
|
||||
this.tickProvider = tickProvider,
|
||||
this._tickFormatter = tickFormatter;
|
||||
|
||||
@protected
|
||||
@@ -172,17 +169,6 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
|
||||
@override
|
||||
ScaleOutputExtent get range => _scale.range;
|
||||
|
||||
/// Configures whether the viewport should be reset back to default values
|
||||
/// when the domain is reset.
|
||||
///
|
||||
/// This should generally be disabled when the viewport will be managed
|
||||
/// externally, e.g. from pan and zoom behaviors.
|
||||
set autoViewport(bool autoViewport) {
|
||||
_autoViewport = autoViewport;
|
||||
}
|
||||
|
||||
bool get autoViewport => _autoViewport;
|
||||
|
||||
void setRangeBandConfig(RangeBandConfig rangeBandConfig) {
|
||||
mutableScale.rangeBandConfig = rangeBandConfig;
|
||||
}
|
||||
@@ -222,7 +208,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
|
||||
_scale.resetDomain();
|
||||
reverseOutputRange = false;
|
||||
|
||||
if (_autoViewport) {
|
||||
if (autoViewport) {
|
||||
_scale.resetViewportSettings();
|
||||
}
|
||||
|
||||
@@ -243,7 +229,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
|
||||
}
|
||||
|
||||
void setOutputRange(int start, int end) {
|
||||
_scale.range = new ScaleOutputExtent(start, end);
|
||||
_scale.range = ScaleOutputExtent(start, end);
|
||||
}
|
||||
|
||||
/// Request update ticks from tick provider and update the painted ticks.
|
||||
@@ -268,7 +254,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
|
||||
formatterValueCache: _formatterValueCache,
|
||||
tickDrawStrategy: tickDrawStrategy,
|
||||
orientation: axisOrientation,
|
||||
viewportExtensionEnabled: _autoViewport);
|
||||
viewportExtensionEnabled: autoViewport);
|
||||
}
|
||||
|
||||
/// Updates the ticks that are actually used for drawing.
|
||||
@@ -277,7 +263,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
|
||||
return;
|
||||
}
|
||||
|
||||
final providedTicks = new List.from(_providedTicks ?? []);
|
||||
final providedTicks = List.from(_providedTicks ?? []);
|
||||
|
||||
for (AxisTicks<D> animatedTick in _axisTicks) {
|
||||
final tick = providedTicks?.firstWhere(
|
||||
@@ -302,7 +288,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
|
||||
|
||||
// Add new ticks
|
||||
providedTicks?.forEach((tick) {
|
||||
final animatedTick = new AxisTicks<D>(tick);
|
||||
final animatedTick = AxisTicks<D>(tick);
|
||||
if (_previousScale != null) {
|
||||
animatedTick.animateInFrom(_previousScale[tick.value].toDouble());
|
||||
}
|
||||
@@ -378,15 +364,7 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
|
||||
//
|
||||
|
||||
@override
|
||||
GraphicsFactory get graphicsFactory => _graphicsFactory;
|
||||
|
||||
@override
|
||||
set graphicsFactory(GraphicsFactory value) {
|
||||
_graphicsFactory = value;
|
||||
}
|
||||
|
||||
@override
|
||||
LayoutViewConfig get layoutConfig => new LayoutViewConfig(
|
||||
LayoutViewConfig get layoutConfig => LayoutViewConfig(
|
||||
paintOrder: layoutPaintOrder,
|
||||
position: _layoutPosition,
|
||||
positionOrder: LayoutViewPositionOrder.axis);
|
||||
@@ -457,8 +435,8 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
|
||||
isVertical ? _componentBounds.top : _componentBounds.right;
|
||||
|
||||
final outputRange = reverseOutputRange
|
||||
? new ScaleOutputExtent(outputEnd, outputStart)
|
||||
: new ScaleOutputExtent(outputStart, outputEnd);
|
||||
? ScaleOutputExtent(outputEnd, outputStart)
|
||||
: ScaleOutputExtent(outputStart, outputEnd);
|
||||
|
||||
if (_scale.range != outputRange) {
|
||||
_scale.range = outputRange;
|
||||
@@ -510,9 +488,9 @@ abstract class Axis<D> extends ImmutableAxis<D> implements LayoutView {
|
||||
class NumericAxis extends Axis<num> {
|
||||
NumericAxis({TickProvider<num> tickProvider})
|
||||
: super(
|
||||
tickProvider: tickProvider ?? new NumericTickProvider(),
|
||||
tickFormatter: new NumericTickFormatter(),
|
||||
scale: new LinearScale(),
|
||||
tickProvider: tickProvider ?? NumericTickProvider(),
|
||||
tickFormatter: NumericTickFormatter(),
|
||||
scale: LinearScale(),
|
||||
);
|
||||
|
||||
void setScaleViewport(NumericExtents viewport) {
|
||||
@@ -529,7 +507,7 @@ class OrdinalAxis extends Axis<String> {
|
||||
}) : super(
|
||||
tickProvider: tickProvider ?? const OrdinalTickProvider(),
|
||||
tickFormatter: tickFormatter ?? const OrdinalTickFormatter(),
|
||||
scale: new SimpleOrdinalScale(),
|
||||
scale: SimpleOrdinalScale(),
|
||||
);
|
||||
|
||||
void setScaleViewport(OrdinalViewport viewport) {
|
||||
|
||||
@@ -147,7 +147,7 @@ abstract class BaseTickDrawStrategy<D> implements TickDrawStrategy<D> {
|
||||
CollisionReport collides(List<Tick<D>> ticks, AxisOrientation orientation) {
|
||||
// If there are no ticks, they do not collide.
|
||||
if (ticks == null) {
|
||||
return new CollisionReport(
|
||||
return CollisionReport(
|
||||
ticksCollide: false, ticks: ticks, alternateTicksUsed: false);
|
||||
}
|
||||
|
||||
@@ -228,12 +228,12 @@ abstract class BaseTickDrawStrategy<D> implements TickDrawStrategy<D> {
|
||||
}
|
||||
|
||||
if (collides) {
|
||||
return new CollisionReport(
|
||||
return CollisionReport(
|
||||
ticksCollide: true, ticks: ticks, alternateTicksUsed: false);
|
||||
}
|
||||
}
|
||||
|
||||
return new CollisionReport(
|
||||
return CollisionReport(
|
||||
ticksCollide: false, ticks: ticks, alternateTicksUsed: false);
|
||||
}
|
||||
|
||||
@@ -245,13 +245,13 @@ abstract class BaseTickDrawStrategy<D> implements TickDrawStrategy<D> {
|
||||
final maxHorizontalSliceWidth = ticks
|
||||
.fold(
|
||||
0.0,
|
||||
(double prevMax, tick) => max(
|
||||
(prevMax, tick) => max<double>(
|
||||
prevMax,
|
||||
tick.textElement.measurement.horizontalSliceWidth +
|
||||
labelOffsetFromAxisPx))
|
||||
.round();
|
||||
|
||||
return new ViewMeasuredSizes(
|
||||
return ViewMeasuredSizes(
|
||||
preferredWidth: maxHorizontalSliceWidth, preferredHeight: maxHeight);
|
||||
}
|
||||
|
||||
@@ -261,11 +261,11 @@ abstract class BaseTickDrawStrategy<D> implements TickDrawStrategy<D> {
|
||||
final maxVerticalSliceWidth = ticks
|
||||
.fold(
|
||||
0.0,
|
||||
(double prevMax, tick) =>
|
||||
max(prevMax, tick.textElement.measurement.verticalSliceWidth))
|
||||
(prevMax, tick) => max<double>(
|
||||
prevMax, tick.textElement.measurement.verticalSliceWidth))
|
||||
.round();
|
||||
|
||||
return new ViewMeasuredSizes(
|
||||
return ViewMeasuredSizes(
|
||||
preferredWidth: maxWidth,
|
||||
preferredHeight: maxVerticalSliceWidth + labelOffsetFromAxisPx);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class GridlineRendererSpec<D> extends SmallTickRendererSpec<D> {
|
||||
@override
|
||||
TickDrawStrategy<D> createDrawStrategy(
|
||||
ChartContext context, GraphicsFactory graphicsFactory) =>
|
||||
new GridlineTickDrawStrategy<D>(context, graphicsFactory,
|
||||
GridlineTickDrawStrategy<D>(context, graphicsFactory,
|
||||
tickLengthPx: tickLengthPx,
|
||||
lineStyleSpec: lineStyle,
|
||||
labelStyleSpec: labelStyle,
|
||||
@@ -125,34 +125,34 @@ class GridlineTickDrawStrategy<D> extends BaseTickDrawStrategy<D> {
|
||||
switch (orientation) {
|
||||
case AxisOrientation.top:
|
||||
final x = tick.locationPx;
|
||||
lineStart = new Point(x, axisBounds.bottom - tickLength);
|
||||
lineEnd = new Point(x, drawAreaBounds.bottom);
|
||||
lineStart = Point(x, axisBounds.bottom - tickLength);
|
||||
lineEnd = Point(x, drawAreaBounds.bottom);
|
||||
break;
|
||||
case AxisOrientation.bottom:
|
||||
final x = tick.locationPx;
|
||||
lineStart = new Point(x, drawAreaBounds.top + tickLength);
|
||||
lineEnd = new Point(x, axisBounds.top);
|
||||
lineStart = Point(x, drawAreaBounds.top + tickLength);
|
||||
lineEnd = Point(x, axisBounds.top);
|
||||
break;
|
||||
case AxisOrientation.right:
|
||||
final y = tick.locationPx;
|
||||
if (tickLabelAnchor == TickLabelAnchor.after ||
|
||||
tickLabelAnchor == TickLabelAnchor.before) {
|
||||
lineStart = new Point(axisBounds.right, y);
|
||||
lineStart = Point(axisBounds.right, y);
|
||||
} else {
|
||||
lineStart = new Point(axisBounds.left + tickLength, y);
|
||||
lineStart = Point(axisBounds.left + tickLength, y);
|
||||
}
|
||||
lineEnd = new Point(drawAreaBounds.left, y);
|
||||
lineEnd = Point(drawAreaBounds.left, y);
|
||||
break;
|
||||
case AxisOrientation.left:
|
||||
final y = tick.locationPx;
|
||||
|
||||
if (tickLabelAnchor == TickLabelAnchor.after ||
|
||||
tickLabelAnchor == TickLabelAnchor.before) {
|
||||
lineStart = new Point(axisBounds.left, y);
|
||||
lineStart = Point(axisBounds.left, y);
|
||||
} else {
|
||||
lineStart = new Point(axisBounds.right - tickLength, y);
|
||||
lineStart = Point(axisBounds.right - tickLength, y);
|
||||
}
|
||||
lineEnd = new Point(drawAreaBounds.right, y);
|
||||
lineEnd = Point(drawAreaBounds.right, y);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class NoneRenderSpec<D> extends RenderSpec<D> {
|
||||
@override
|
||||
TickDrawStrategy<D> createDrawStrategy(
|
||||
ChartContext context, GraphicsFactory graphicFactory) =>
|
||||
new NoneDrawStrategy<D>(context, graphicFactory,
|
||||
NoneDrawStrategy<D>(context, graphicFactory,
|
||||
axisLineStyleSpec: axisLineStyle);
|
||||
|
||||
@override
|
||||
@@ -68,7 +68,7 @@ class NoneDrawStrategy<D> implements TickDrawStrategy<D> {
|
||||
|
||||
@override
|
||||
CollisionReport collides(List<Tick> ticks, AxisOrientation orientation) =>
|
||||
new CollisionReport(ticksCollide: false, ticks: ticks);
|
||||
CollisionReport(ticksCollide: false, ticks: ticks);
|
||||
|
||||
@override
|
||||
void decorateTicks(List<Tick> ticks) {
|
||||
@@ -125,12 +125,12 @@ class NoneDrawStrategy<D> implements TickDrawStrategy<D> {
|
||||
@override
|
||||
ViewMeasuredSizes measureHorizontallyDrawnTicks(
|
||||
List<Tick> ticks, int maxWidth, int maxHeight) {
|
||||
return new ViewMeasuredSizes(preferredWidth: 0, preferredHeight: 0);
|
||||
return ViewMeasuredSizes(preferredWidth: 0, preferredHeight: 0);
|
||||
}
|
||||
|
||||
@override
|
||||
ViewMeasuredSizes measureVerticallyDrawnTicks(
|
||||
List<Tick> ticks, int maxWidth, int maxHeight) {
|
||||
return new ViewMeasuredSizes(preferredWidth: 0, preferredHeight: 0);
|
||||
return ViewMeasuredSizes(preferredWidth: 0, preferredHeight: 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class SmallTickRendererSpec<D> extends BaseRenderSpec<D> {
|
||||
@override
|
||||
TickDrawStrategy<D> createDrawStrategy(
|
||||
ChartContext context, GraphicsFactory graphicsFactory) =>
|
||||
new SmallTickDrawStrategy<D>(context, graphicsFactory,
|
||||
SmallTickDrawStrategy<D>(context, graphicsFactory,
|
||||
tickLengthPx: tickLengthPx,
|
||||
lineStyleSpec: lineStyle,
|
||||
labelStyleSpec: labelStyle,
|
||||
@@ -128,25 +128,25 @@ class SmallTickDrawStrategy<D> extends BaseTickDrawStrategy<D> {
|
||||
switch (orientation) {
|
||||
case AxisOrientation.top:
|
||||
double x = tick.locationPx;
|
||||
tickStart = new Point(x, axisBounds.bottom - tickLength);
|
||||
tickEnd = new Point(x, axisBounds.bottom);
|
||||
tickStart = Point(x, axisBounds.bottom - tickLength);
|
||||
tickEnd = Point(x, axisBounds.bottom);
|
||||
break;
|
||||
case AxisOrientation.bottom:
|
||||
double x = tick.locationPx;
|
||||
tickStart = new Point(x, axisBounds.top);
|
||||
tickEnd = new Point(x, axisBounds.top + tickLength);
|
||||
tickStart = Point(x, axisBounds.top);
|
||||
tickEnd = Point(x, axisBounds.top + tickLength);
|
||||
break;
|
||||
case AxisOrientation.right:
|
||||
double y = tick.locationPx;
|
||||
|
||||
tickStart = new Point(axisBounds.left, y);
|
||||
tickEnd = new Point(axisBounds.left + tickLength, y);
|
||||
tickStart = Point(axisBounds.left, y);
|
||||
tickEnd = Point(axisBounds.left + tickLength, y);
|
||||
break;
|
||||
case AxisOrientation.left:
|
||||
double y = tick.locationPx;
|
||||
|
||||
tickStart = new Point(axisBounds.right - tickLength, y);
|
||||
tickEnd = new Point(axisBounds.right, y);
|
||||
tickStart = Point(axisBounds.right - tickLength, y);
|
||||
tickEnd = Point(axisBounds.right, y);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,12 +54,12 @@ class EndPointsTickProvider<D> extends BaseTickProvider<D> {
|
||||
final labels = formatter.format([start, end], formatterValueCache,
|
||||
stepSize: scale.domainStepSize);
|
||||
|
||||
ticks.add(new Tick(
|
||||
ticks.add(Tick(
|
||||
value: start,
|
||||
textElement: graphicsFactory.createTextElement(labels[0]),
|
||||
locationPx: scale[start]));
|
||||
|
||||
ticks.add(new Tick(
|
||||
ticks.add(Tick(
|
||||
value: end,
|
||||
textElement: graphicsFactory.createTextElement(labels[1]),
|
||||
locationPx: scale[end]));
|
||||
|
||||
@@ -48,8 +48,7 @@ class BucketingNumericAxis extends NumericAxis {
|
||||
/// [threshold] will be rendered at the baseline of the chart. The
|
||||
bool _showBucket;
|
||||
|
||||
BucketingNumericAxis()
|
||||
: super(tickProvider: new BucketingNumericTickProvider());
|
||||
BucketingNumericAxis() : super(tickProvider: BucketingNumericTickProvider());
|
||||
|
||||
set threshold(num threshold) {
|
||||
_threshold = threshold;
|
||||
|
||||
@@ -83,7 +83,7 @@ class BucketingNumericTickProvider extends NumericTickProvider {
|
||||
throw ('The showBucket flag must be set before getting ticks.');
|
||||
}
|
||||
|
||||
final localFormatter = new _BucketingFormatter()
|
||||
final localFormatter = _BucketingFormatter()
|
||||
..threshold = _threshold
|
||||
..originalFormatter = formatter;
|
||||
|
||||
@@ -100,7 +100,7 @@ class BucketingNumericTickProvider extends NumericTickProvider {
|
||||
assert(scale != null);
|
||||
|
||||
// Create a tick for the threshold.
|
||||
final thresholdTick = new Tick<num>(
|
||||
final thresholdTick = Tick<num>(
|
||||
value: _threshold,
|
||||
textElement: graphicsFactory
|
||||
.createTextElement(localFormatter.formatValue(_threshold)),
|
||||
@@ -110,8 +110,8 @@ class BucketingNumericTickProvider extends NumericTickProvider {
|
||||
tickDrawStrategy.decorateTicks(<Tick<num>>[thresholdTick]);
|
||||
|
||||
// Filter out ticks that sit below the threshold.
|
||||
ticks.removeWhere((Tick<num> tick) =>
|
||||
tick.value <= thresholdTick.value && tick.value != 0.0);
|
||||
ticks.removeWhere(
|
||||
(tick) => tick.value <= thresholdTick.value && tick.value != 0.0);
|
||||
|
||||
// Finally, add our threshold tick to the list.
|
||||
ticks.add(thresholdTick);
|
||||
|
||||
@@ -49,7 +49,7 @@ import 'linear_scale_viewport.dart' show LinearScaleViewportSettings;
|
||||
class LinearScale implements NumericScale {
|
||||
final LinearScaleDomainInfo _domainInfo;
|
||||
final LinearScaleViewportSettings _viewportSettings;
|
||||
final LinearScaleFunction _scaleFunction = new LinearScaleFunction();
|
||||
final LinearScaleFunction _scaleFunction = LinearScaleFunction();
|
||||
|
||||
RangeBandConfig rangeBandConfig = const RangeBandConfig.none();
|
||||
StepSizeConfig stepSizeConfig = const StepSizeConfig.auto();
|
||||
@@ -57,18 +57,18 @@ class LinearScale implements NumericScale {
|
||||
bool _scaleReady = false;
|
||||
|
||||
LinearScale()
|
||||
: _domainInfo = new LinearScaleDomainInfo(),
|
||||
_viewportSettings = new LinearScaleViewportSettings();
|
||||
: _domainInfo = LinearScaleDomainInfo(),
|
||||
_viewportSettings = LinearScaleViewportSettings();
|
||||
|
||||
LinearScale._copy(LinearScale other)
|
||||
: _domainInfo = new LinearScaleDomainInfo.copy(other._domainInfo),
|
||||
: _domainInfo = LinearScaleDomainInfo.copy(other._domainInfo),
|
||||
_viewportSettings =
|
||||
new LinearScaleViewportSettings.copy(other._viewportSettings),
|
||||
LinearScaleViewportSettings.copy(other._viewportSettings),
|
||||
rangeBandConfig = other.rangeBandConfig,
|
||||
stepSizeConfig = other.stepSizeConfig;
|
||||
|
||||
@override
|
||||
LinearScale copy() => new LinearScale._copy(this);
|
||||
LinearScale copy() => LinearScale._copy(this);
|
||||
|
||||
//
|
||||
// Domain methods
|
||||
@@ -91,8 +91,8 @@ class LinearScale implements NumericScale {
|
||||
}
|
||||
|
||||
@override
|
||||
NumericExtents get dataExtent => new NumericExtents(
|
||||
_domainInfo.dataDomainStart, _domainInfo.dataDomainEnd);
|
||||
NumericExtents get dataExtent =>
|
||||
NumericExtents(_domainInfo.dataDomainStart, _domainInfo.dataDomainEnd);
|
||||
|
||||
@override
|
||||
num get minimumDomainStep => _domainInfo.minimumDetectedDomainStep;
|
||||
|
||||
@@ -113,6 +113,6 @@ class LinearScaleDomainInfo {
|
||||
tmpDomainEnd = _dataDomainEnd.isFinite ? _dataDomainEnd : 1.0;
|
||||
}
|
||||
|
||||
return new NumericExtents(tmpDomainStart, tmpDomainEnd);
|
||||
return NumericExtents(tmpDomainStart, tmpDomainEnd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ class LinearScaleViewportSettings {
|
||||
double viewportStart =
|
||||
(-1.0 * translatePx / scaleScalingFactor) + domainInfo.extent.min;
|
||||
_domainExtent =
|
||||
new NumericExtents(viewportStart, viewportStart + viewportDomainDiff);
|
||||
NumericExtents(viewportStart, viewportStart + viewportDomainDiff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class NumericExtents implements Extents<num> {
|
||||
max = value;
|
||||
}
|
||||
}
|
||||
return new NumericExtents(min, max);
|
||||
return NumericExtents(min, max);
|
||||
}
|
||||
|
||||
/// Returns the union of this and other.
|
||||
@@ -50,13 +50,13 @@ class NumericExtents implements Extents<num> {
|
||||
if (max >= other.max) {
|
||||
return this;
|
||||
} else {
|
||||
return new NumericExtents(min, other.max);
|
||||
return NumericExtents(min, other.max);
|
||||
}
|
||||
} else {
|
||||
if (other.max >= max) {
|
||||
return other;
|
||||
} else {
|
||||
return new NumericExtents(other.min, max);
|
||||
return NumericExtents(other.min, max);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,6 @@ class NumericExtents implements Extents<num> {
|
||||
String toString() => 'Extent($min, $max)';
|
||||
|
||||
static const NumericExtents unbounded =
|
||||
const NumericExtents(double.negativeInfinity, double.infinity);
|
||||
static const NumericExtents empty = const NumericExtents(0.0, 0.0);
|
||||
NumericExtents(double.negativeInfinity, double.infinity);
|
||||
static const NumericExtents empty = NumericExtents(0.0, 0.0);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class NumericTickProvider extends BaseTickProvider<num> {
|
||||
static const MIN_DIPS_BETWEEN_TICKS = 25;
|
||||
|
||||
/// Potential steps available to the baseTen value of the data.
|
||||
static const DEFAULT_STEPS = const [
|
||||
static const DEFAULT_STEPS = [
|
||||
0.01,
|
||||
0.02,
|
||||
0.025,
|
||||
@@ -187,8 +187,8 @@ class NumericTickProvider extends BaseTickProvider<num> {
|
||||
assert(steps != null && steps.isNotEmpty);
|
||||
steps.sort();
|
||||
|
||||
final stepSet = new Set.from(steps);
|
||||
_allowedSteps = new List<double>(stepSet.length * 3);
|
||||
final stepSet = Set.from(steps);
|
||||
_allowedSteps = List<double>(stepSet.length * 3);
|
||||
int stepIndex = 0;
|
||||
for (double step in stepSet) {
|
||||
assert(1.0 <= step && step < 10.0);
|
||||
@@ -220,7 +220,7 @@ class NumericTickProvider extends BaseTickProvider<num> {
|
||||
: (tickHint.start / stepSize).ceil()));
|
||||
final tickStart =
|
||||
(scale.viewportDomain.min / stepSize).ceil() * stepSize + tickZeroShift;
|
||||
final stepInfo = new _TickStepInfo(stepSize.abs(), tickStart);
|
||||
final stepInfo = _TickStepInfo(stepSize.abs(), tickStart);
|
||||
final tickValues = _getTickValues(stepInfo, tickHint.tickCount);
|
||||
|
||||
// Create ticks from domain values.
|
||||
@@ -299,8 +299,7 @@ class NumericTickProvider extends BaseTickProvider<num> {
|
||||
final tickValues = _getTickValues(stepInfo, tickCount);
|
||||
|
||||
if (viewportExtensionEnabled) {
|
||||
mutableScale.viewportDomain =
|
||||
new NumericExtents(firstTick, lastTick);
|
||||
mutableScale.viewportDomain = NumericExtents(firstTick, lastTick);
|
||||
}
|
||||
|
||||
// Create ticks from domain values.
|
||||
@@ -434,7 +433,7 @@ class NumericTickProvider extends BaseTickProvider<num> {
|
||||
!(low < 0 &&
|
||||
high > 0 &&
|
||||
(negativeRegionCount == 0 || positiveRegionCount == 0)),
|
||||
'Numeric tick provider cannot generate ${tickCount} '
|
||||
'Numeric tick provider cannot generate $tickCount '
|
||||
'ticks when the axis range contains both positive and negative '
|
||||
'values. A minimum of three ticks are required to include zero.');
|
||||
|
||||
@@ -467,7 +466,7 @@ class NumericTickProvider extends BaseTickProvider<num> {
|
||||
double stepStart = negativeRegionCount > 0
|
||||
? (-1 * tmpStepSize * negativeRegionCount)
|
||||
: 0.0;
|
||||
return new _TickStepInfo(tmpStepSize, stepStart);
|
||||
return _TickStepInfo(tmpStepSize, stepStart);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -487,16 +486,16 @@ class NumericTickProvider extends BaseTickProvider<num> {
|
||||
// But wait until the last step to prevent the cost of the formatter.
|
||||
double tmpStepStart = _getStepLessThan(low, tmpStepSize);
|
||||
if (tmpStepStart + (tmpStepSize * regionCount) >= high) {
|
||||
return new _TickStepInfo(tmpStepSize, tmpStepStart);
|
||||
return _TickStepInfo(tmpStepSize, tmpStepStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new _TickStepInfo(1.0, low.floorToDouble());
|
||||
return _TickStepInfo(1.0, low.floorToDouble());
|
||||
}
|
||||
|
||||
List<double> _getTickValues(_TickStepInfo steps, int tickCount) {
|
||||
final tickValues = new List<double>(tickCount);
|
||||
final tickValues = List<double>(tickCount);
|
||||
// We have our size and start, assign all the tick values to the given array.
|
||||
for (int i = 0; i < tickCount; i++) {
|
||||
tickValues[i] = dataToAxisUnitConverter.invert(
|
||||
|
||||
@@ -27,11 +27,11 @@ class OrdinalExtents extends Extents<String> {
|
||||
/// [D] is the domain class type for the elements in the extents.
|
||||
OrdinalExtents(List<String> range) : _range = range {
|
||||
// This asserts that all elements in [range] are unique.
|
||||
final uniqueValueCount = new HashSet.from(_range).length;
|
||||
final uniqueValueCount = HashSet.from(_range).length;
|
||||
assert(uniqueValueCount == range.length);
|
||||
}
|
||||
|
||||
factory OrdinalExtents.all(List<String> range) => new OrdinalExtents(range);
|
||||
factory OrdinalExtents.all(List<String> range) => OrdinalExtents(range);
|
||||
|
||||
bool get isEmpty => _range.isEmpty;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class OrdinalScaleDomainInfo {
|
||||
int _index = 0;
|
||||
|
||||
/// A map of domain value and the order it was added.
|
||||
final _domainsToOrder = new HashMap<String, int>();
|
||||
final _domainsToOrder = HashMap<String, int>();
|
||||
|
||||
/// A list of domain values kept to support [getDomainAtIndex].
|
||||
final _domainList = <String>[];
|
||||
@@ -33,7 +33,7 @@ class OrdinalScaleDomainInfo {
|
||||
OrdinalScaleDomainInfo();
|
||||
|
||||
OrdinalScaleDomainInfo copy() {
|
||||
return new OrdinalScaleDomainInfo()
|
||||
return OrdinalScaleDomainInfo()
|
||||
.._domainsToOrder.addAll(_domainsToOrder)
|
||||
.._index = _index
|
||||
.._domainList.addAll(_domainList);
|
||||
@@ -64,7 +64,7 @@ class OrdinalScaleDomainInfo {
|
||||
bool get isEmpty => (_index == 0);
|
||||
bool get isNotEmpty => !isEmpty;
|
||||
|
||||
OrdinalExtents get extent => new OrdinalExtents.all(_domainList);
|
||||
OrdinalExtents get extent => OrdinalExtents.all(_domainList);
|
||||
|
||||
int get size => _index;
|
||||
|
||||
|
||||
@@ -32,12 +32,12 @@ import 'scale.dart'
|
||||
/// width of the bar is [rangeBand] and the position of the bar is retrieved
|
||||
/// by [[]].
|
||||
class SimpleOrdinalScale implements OrdinalScale {
|
||||
final _stepSizeConfig = new StepSizeConfig.auto();
|
||||
final _stepSizeConfig = StepSizeConfig.auto();
|
||||
OrdinalScaleDomainInfo _domain;
|
||||
ScaleOutputExtent _range = new ScaleOutputExtent(0, 1);
|
||||
ScaleOutputExtent _range = ScaleOutputExtent(0, 1);
|
||||
double _viewportScale = 1.0;
|
||||
double _viewportTranslatePx = 0.0;
|
||||
RangeBandConfig _rangeBandConfig = new RangeBandConfig.styleAssignedPercent();
|
||||
RangeBandConfig _rangeBandConfig = RangeBandConfig.styleAssignedPercent();
|
||||
|
||||
bool _scaleChanged = true;
|
||||
double _cachedStepSizePixels;
|
||||
@@ -47,11 +47,11 @@ class SimpleOrdinalScale implements OrdinalScale {
|
||||
int _viewportDataSize;
|
||||
String _viewportStartingDomain;
|
||||
|
||||
SimpleOrdinalScale() : _domain = new OrdinalScaleDomainInfo();
|
||||
SimpleOrdinalScale() : _domain = OrdinalScaleDomainInfo();
|
||||
|
||||
SimpleOrdinalScale._copy(SimpleOrdinalScale other)
|
||||
: _domain = other._domain.copy(),
|
||||
_range = new ScaleOutputExtent(other._range.start, other._range.end),
|
||||
_range = ScaleOutputExtent(other._range.start, other._range.end),
|
||||
_viewportScale = other._viewportScale,
|
||||
_viewportTranslatePx = other._viewportTranslatePx,
|
||||
_rangeBandConfig = other._rangeBandConfig;
|
||||
@@ -80,12 +80,12 @@ class SimpleOrdinalScale implements OrdinalScale {
|
||||
@override
|
||||
set rangeBandConfig(RangeBandConfig barGroupWidthConfig) {
|
||||
if (barGroupWidthConfig == null) {
|
||||
throw new ArgumentError.notNull('RangeBandConfig must not be null.');
|
||||
throw ArgumentError.notNull('RangeBandConfig must not be null.');
|
||||
}
|
||||
|
||||
if (barGroupWidthConfig.type == RangeBandType.fixedDomain ||
|
||||
barGroupWidthConfig.type == RangeBandType.none) {
|
||||
throw new ArgumentError(
|
||||
throw ArgumentError(
|
||||
'barGroupWidthConfig must not be NONE or FIXED_DOMAIN');
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ class SimpleOrdinalScale implements OrdinalScale {
|
||||
@override
|
||||
set stepSizeConfig(StepSizeConfig config) {
|
||||
if (config != null && config.type != StepSizeType.autoDetect) {
|
||||
throw new ArgumentError(
|
||||
throw ArgumentError(
|
||||
'Ordinal scales only support StepSizeConfig of type Auto');
|
||||
}
|
||||
// Nothing is set because only auto is supported.
|
||||
@@ -205,7 +205,7 @@ class SimpleOrdinalScale implements OrdinalScale {
|
||||
if (startingDomain != null &&
|
||||
viewportDataSize != null &&
|
||||
viewportDataSize <= 0) {
|
||||
throw new ArgumentError('viewportDataSize can' 't be less than 1.');
|
||||
throw ArgumentError('viewportDataSize can' 't be less than 1.');
|
||||
}
|
||||
|
||||
_scaleChanged = true;
|
||||
@@ -280,7 +280,7 @@ class SimpleOrdinalScale implements OrdinalScale {
|
||||
}
|
||||
|
||||
@override
|
||||
SimpleOrdinalScale copy() => new SimpleOrdinalScale._copy(this);
|
||||
SimpleOrdinalScale copy() => SimpleOrdinalScale._copy(this);
|
||||
|
||||
void _updateCachedFields(
|
||||
double stepSizePixels, double rangeBandPixels, double rangeBandShift) {
|
||||
@@ -335,7 +335,7 @@ class SimpleOrdinalScale implements OrdinalScale {
|
||||
case RangeBandType.fixedDomain:
|
||||
case RangeBandType.none:
|
||||
default:
|
||||
throw new StateError('RangeBandType must not be NONE or FIXED_DOMAIN');
|
||||
throw StateError('RangeBandType must not be NONE or FIXED_DOMAIN');
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class AxisSpec<D> {
|
||||
TickFormatterSpec<D> tickFormatterSpec,
|
||||
bool showAxisLine,
|
||||
}) {
|
||||
return new AxisSpec(
|
||||
return AxisSpec(
|
||||
renderSpec: renderSpec ?? other.renderSpec,
|
||||
tickProviderSpec: tickProviderSpec ?? other.tickProviderSpec,
|
||||
tickFormatterSpec: tickFormatterSpec ?? other.tickFormatterSpec,
|
||||
|
||||
@@ -80,8 +80,8 @@ class BucketingAxisSpec extends NumericAxisSpec {
|
||||
tickProviderSpec:
|
||||
tickProviderSpec ?? const BucketingNumericTickProviderSpec(),
|
||||
tickFormatterSpec: tickFormatterSpec ??
|
||||
new BasicNumericTickFormatterSpec.fromNumberFormat(
|
||||
new NumberFormat.percentPattern()),
|
||||
BasicNumericTickFormatterSpec.fromNumberFormat(
|
||||
NumberFormat.percentPattern()),
|
||||
showAxisLine: showAxisLine,
|
||||
viewport: viewport ?? const NumericExtents(0.0, 1.0));
|
||||
|
||||
@@ -104,7 +104,7 @@ class BucketingAxisSpec extends NumericAxisSpec {
|
||||
}
|
||||
|
||||
@override
|
||||
BucketingNumericAxis createAxis() => new BucketingNumericAxis();
|
||||
BucketingNumericAxis createAxis() => BucketingNumericAxis();
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
@@ -155,7 +155,7 @@ class BucketingNumericTickProviderSpec extends BasicNumericTickProviderSpec {
|
||||
|
||||
@override
|
||||
BucketingNumericTickProvider createTickProvider(ChartContext context) {
|
||||
final provider = new BucketingNumericTickProvider()
|
||||
final provider = BucketingNumericTickProvider()
|
||||
..zeroBound = zeroBound
|
||||
..dataIsInWholeNumbers = dataIsInWholeNumbers;
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class DateTimeAxisSpec extends AxisSpec<DateTime> {
|
||||
|
||||
/// Creates a [DateTimeAxis]. This should be called in place of createAxis.
|
||||
DateTimeAxis createDateTimeAxis(DateTimeFactory dateTimeFactory) =>
|
||||
new DateTimeAxis(dateTimeFactory);
|
||||
DateTimeAxis(dateTimeFactory);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
@@ -121,10 +121,10 @@ class AutoDateTimeTickProviderSpec implements DateTimeTickProviderSpec {
|
||||
@override
|
||||
AutoAdjustingDateTimeTickProvider createTickProvider(ChartContext context) {
|
||||
if (includeTime) {
|
||||
return new AutoAdjustingDateTimeTickProvider.createDefault(
|
||||
return AutoAdjustingDateTimeTickProvider.createDefault(
|
||||
context.dateTimeFactory);
|
||||
} else {
|
||||
return new AutoAdjustingDateTimeTickProvider.createWithoutTime(
|
||||
return AutoAdjustingDateTimeTickProvider.createWithoutTime(
|
||||
context.dateTimeFactory);
|
||||
}
|
||||
}
|
||||
@@ -151,8 +151,8 @@ class DayTickProviderSpec implements DateTimeTickProviderSpec {
|
||||
/// when searching for the appropriate tick intervals.
|
||||
@override
|
||||
AutoAdjustingDateTimeTickProvider createTickProvider(ChartContext context) {
|
||||
return new AutoAdjustingDateTimeTickProvider.createWith([
|
||||
new TimeRangeTickProviderImpl(new DayTimeStepper(context.dateTimeFactory,
|
||||
return AutoAdjustingDateTimeTickProvider.createWith([
|
||||
TimeRangeTickProviderImpl(DayTimeStepper(context.dateTimeFactory,
|
||||
allowedTickIncrements: increments))
|
||||
]);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ class DateTimeEndPointsTickProviderSpec implements DateTimeTickProviderSpec {
|
||||
/// two end points of the axis range
|
||||
@override
|
||||
EndPointsTickProvider<DateTime> createTickProvider(ChartContext context) {
|
||||
return new EndPointsTickProvider<DateTime>();
|
||||
return EndPointsTickProvider<DateTime>();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -191,7 +191,7 @@ class StaticDateTimeTickProviderSpec implements DateTimeTickProviderSpec {
|
||||
|
||||
@override
|
||||
StaticTickProvider<DateTime> createTickProvider(ChartContext context) =>
|
||||
new StaticTickProvider<DateTime>(tickSpecs);
|
||||
StaticTickProvider<DateTime>(tickSpecs);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
@@ -285,19 +285,19 @@ class AutoDateTimeTickFormatterSpec implements DateTimeTickFormatterSpec {
|
||||
_makeFormatter(year, CalendarField.year, context);
|
||||
}
|
||||
|
||||
return new DateTimeTickFormatter(context.dateTimeFactory, overrides: map);
|
||||
return DateTimeTickFormatter(context.dateTimeFactory, overrides: map);
|
||||
}
|
||||
|
||||
TimeTickFormatterImpl _makeFormatter(TimeFormatterSpec spec,
|
||||
CalendarField transitionField, ChartContext context) {
|
||||
if (spec.noonFormat != null) {
|
||||
return new HourTickFormatter(
|
||||
return HourTickFormatter(
|
||||
dateTimeFactory: context.dateTimeFactory,
|
||||
simpleFormat: spec.format,
|
||||
transitionFormat: spec.transitionFormat,
|
||||
noonFormat: spec.noonFormat);
|
||||
} else {
|
||||
return new TimeTickFormatterImpl(
|
||||
return TimeTickFormatterImpl(
|
||||
dateTimeFactory: context.dateTimeFactory,
|
||||
simpleFormat: spec.format,
|
||||
transitionFormat: spec.transitionFormat,
|
||||
|
||||
@@ -68,7 +68,7 @@ class NumericAxisSpec extends AxisSpec<num> {
|
||||
bool showAxisLine,
|
||||
NumericExtents viewport,
|
||||
}) {
|
||||
return new NumericAxisSpec(
|
||||
return NumericAxisSpec(
|
||||
renderSpec: renderSpec ?? other.renderSpec,
|
||||
tickProviderSpec: tickProviderSpec ?? other.tickProviderSpec,
|
||||
tickFormatterSpec: tickFormatterSpec ?? other.tickFormatterSpec,
|
||||
@@ -88,7 +88,7 @@ class NumericAxisSpec extends AxisSpec<num> {
|
||||
}
|
||||
|
||||
@override
|
||||
NumericAxis createAxis() => new NumericAxis();
|
||||
NumericAxis createAxis() => NumericAxis();
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
@@ -141,7 +141,7 @@ class BasicNumericTickProviderSpec implements NumericTickProviderSpec {
|
||||
|
||||
@override
|
||||
NumericTickProvider createTickProvider(ChartContext context) {
|
||||
final provider = new NumericTickProvider();
|
||||
final provider = NumericTickProvider();
|
||||
if (zeroBound != null) {
|
||||
provider.zeroBound = zeroBound;
|
||||
}
|
||||
@@ -188,7 +188,7 @@ class NumericEndPointsTickProviderSpec implements NumericTickProviderSpec {
|
||||
|
||||
@override
|
||||
EndPointsTickProvider<num> createTickProvider(ChartContext context) {
|
||||
return new EndPointsTickProvider<num>();
|
||||
return EndPointsTickProvider<num>();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -204,7 +204,7 @@ class StaticNumericTickProviderSpec implements NumericTickProviderSpec {
|
||||
|
||||
@override
|
||||
StaticTickProvider<num> createTickProvider(ChartContext context) =>
|
||||
new StaticTickProvider<num>(tickSpecs);
|
||||
StaticTickProvider<num>(tickSpecs);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
@@ -232,8 +232,8 @@ class BasicNumericTickFormatterSpec implements NumericTickFormatterSpec {
|
||||
@override
|
||||
NumericTickFormatter createTickFormatter(ChartContext context) {
|
||||
return numberFormat != null
|
||||
? new NumericTickFormatter.fromNumberFormat(numberFormat)
|
||||
: new NumericTickFormatter(formatter: formatter);
|
||||
? NumericTickFormatter.fromNumberFormat(numberFormat)
|
||||
: NumericTickFormatter(formatter: formatter);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -66,7 +66,7 @@ class OrdinalAxisSpec extends AxisSpec<String> {
|
||||
}
|
||||
|
||||
@override
|
||||
OrdinalAxis createAxis() => new OrdinalAxis();
|
||||
OrdinalAxis createAxis() => OrdinalAxis();
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
@@ -94,7 +94,7 @@ class BasicOrdinalTickProviderSpec implements OrdinalTickProviderSpec {
|
||||
|
||||
@override
|
||||
OrdinalTickProvider createTickProvider(ChartContext context) =>
|
||||
new OrdinalTickProvider();
|
||||
OrdinalTickProvider();
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is BasicOrdinalTickProviderSpec;
|
||||
@@ -112,7 +112,7 @@ class StaticOrdinalTickProviderSpec implements OrdinalTickProviderSpec {
|
||||
|
||||
@override
|
||||
StaticTickProvider<String> createTickProvider(ChartContext context) =>
|
||||
new StaticTickProvider<String>(tickSpecs);
|
||||
StaticTickProvider<String>(tickSpecs);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
@@ -129,7 +129,7 @@ class BasicOrdinalTickFormatterSpec implements OrdinalTickFormatterSpec {
|
||||
|
||||
@override
|
||||
OrdinalTickFormatter createTickFormatter(ChartContext context) =>
|
||||
new OrdinalTickFormatter();
|
||||
OrdinalTickFormatter();
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is BasicOrdinalTickFormatterSpec;
|
||||
|
||||
@@ -41,8 +41,8 @@ class PercentAxisSpec extends NumericAxisSpec {
|
||||
tickProviderSpec: tickProviderSpec ??
|
||||
const BasicNumericTickProviderSpec(dataIsInWholeNumbers: false),
|
||||
tickFormatterSpec: tickFormatterSpec ??
|
||||
new BasicNumericTickFormatterSpec.fromNumberFormat(
|
||||
new NumberFormat.percentPattern()),
|
||||
BasicNumericTickFormatterSpec.fromNumberFormat(
|
||||
NumberFormat.percentPattern()),
|
||||
showAxisLine: showAxisLine,
|
||||
viewport: viewport ?? const NumericExtents(0.0, 1.0));
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ class StaticTickProvider<D> extends TickProvider<D> {
|
||||
// We still check if the spec is within the viewport because we do not
|
||||
// extend the axis for OrdinalScale.
|
||||
if (scale.compareDomainValueToViewport(spec.value) == 0) {
|
||||
final tick = new Tick<D>(
|
||||
final tick = Tick<D>(
|
||||
value: spec.value,
|
||||
textElement: graphicsFactory
|
||||
.createTextElement(spec.label ?? formattedValues[i]),
|
||||
|
||||
@@ -34,7 +34,7 @@ abstract class SimpleTickFormatterBase<D> implements TickFormatter<D> {
|
||||
@override
|
||||
List<String> format(List<D> tickValues, Map<D, String> cache,
|
||||
{num stepSize}) =>
|
||||
tickValues.map((D value) {
|
||||
tickValues.map((value) {
|
||||
// Try to use the cached formats first.
|
||||
String formattedString = cache[value];
|
||||
if (formattedString == null) {
|
||||
@@ -75,24 +75,24 @@ class NumericTickFormatter extends SimpleTickFormatterBase<num> {
|
||||
/// [formatter] optionally specify a formatter to be used. Defaults to using
|
||||
/// [NumberFormat.decimalPattern] if none is specified.
|
||||
factory NumericTickFormatter({MeasureFormatter formatter}) {
|
||||
formatter ??= _getFormatter(new NumberFormat.decimalPattern());
|
||||
return new NumericTickFormatter._internal(formatter);
|
||||
formatter ??= _getFormatter(NumberFormat.decimalPattern());
|
||||
return NumericTickFormatter._internal(formatter);
|
||||
}
|
||||
|
||||
/// Constructs a new [NumericTickFormatter] that formats using [numberFormat].
|
||||
factory NumericTickFormatter.fromNumberFormat(NumberFormat numberFormat) {
|
||||
return new NumericTickFormatter._internal(_getFormatter(numberFormat));
|
||||
return NumericTickFormatter._internal(_getFormatter(numberFormat));
|
||||
}
|
||||
|
||||
/// Constructs a new formatter that uses [NumberFormat.compactCurrency].
|
||||
factory NumericTickFormatter.compactSimpleCurrency() {
|
||||
return new NumericTickFormatter._internal(
|
||||
_getFormatter(new NumberFormat.compactCurrency()));
|
||||
return NumericTickFormatter._internal(
|
||||
_getFormatter(NumberFormat.compactCurrency()));
|
||||
}
|
||||
|
||||
/// Returns a [MeasureFormatter] that calls format on [numberFormat].
|
||||
static MeasureFormatter _getFormatter(NumberFormat numberFormat) {
|
||||
return (num value) => numberFormat.format(value);
|
||||
return (value) => numberFormat.format(value);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -73,7 +73,7 @@ abstract class BaseTickProvider<D> implements TickProvider<D> {
|
||||
|
||||
for (var i = 0; i < domainValues.length; i++) {
|
||||
final value = domainValues[i];
|
||||
final tick = new Tick(
|
||||
final tick = Tick(
|
||||
value: value,
|
||||
textElement: graphicsFactory.createTextElement(labels[i]),
|
||||
locationPx: scale[value]);
|
||||
|
||||
@@ -54,7 +54,7 @@ class AutoAdjustingDateTimeTickProvider implements TickProvider<DateTime> {
|
||||
/// Creates a default [AutoAdjustingDateTimeTickProvider] for day and time.
|
||||
factory AutoAdjustingDateTimeTickProvider.createDefault(
|
||||
DateTimeFactory dateTimeFactory) {
|
||||
return new AutoAdjustingDateTimeTickProvider._internal([
|
||||
return AutoAdjustingDateTimeTickProvider._internal([
|
||||
createYearTickProvider(dateTimeFactory),
|
||||
createMonthTickProvider(dateTimeFactory),
|
||||
createDayTickProvider(dateTimeFactory),
|
||||
@@ -66,7 +66,7 @@ class AutoAdjustingDateTimeTickProvider implements TickProvider<DateTime> {
|
||||
/// Creates a default [AutoAdjustingDateTimeTickProvider] for day only.
|
||||
factory AutoAdjustingDateTimeTickProvider.createWithoutTime(
|
||||
DateTimeFactory dateTimeFactory) {
|
||||
return new AutoAdjustingDateTimeTickProvider._internal([
|
||||
return AutoAdjustingDateTimeTickProvider._internal([
|
||||
createYearTickProvider(dateTimeFactory),
|
||||
createMonthTickProvider(dateTimeFactory),
|
||||
createDayTickProvider(dateTimeFactory)
|
||||
@@ -80,11 +80,10 @@ class AutoAdjustingDateTimeTickProvider implements TickProvider<DateTime> {
|
||||
factory AutoAdjustingDateTimeTickProvider.createWith(
|
||||
List<TimeRangeTickProvider> potentialTickProviders) {
|
||||
if (potentialTickProviders == null || potentialTickProviders.isEmpty) {
|
||||
throw new ArgumentError('At least one TimeRangeTickProvider is required');
|
||||
throw ArgumentError('At least one TimeRangeTickProvider is required');
|
||||
}
|
||||
|
||||
return new AutoAdjustingDateTimeTickProvider._internal(
|
||||
potentialTickProviders);
|
||||
return AutoAdjustingDateTimeTickProvider._internal(potentialTickProviders);
|
||||
}
|
||||
|
||||
/// Generates a list of ticks for the given data which should not collide
|
||||
@@ -157,21 +156,21 @@ class AutoAdjustingDateTimeTickProvider implements TickProvider<DateTime> {
|
||||
|
||||
static TimeRangeTickProvider createYearTickProvider(
|
||||
DateTimeFactory dateTimeFactory) =>
|
||||
new TimeRangeTickProviderImpl(new YearTimeStepper(dateTimeFactory));
|
||||
TimeRangeTickProviderImpl(YearTimeStepper(dateTimeFactory));
|
||||
|
||||
static TimeRangeTickProvider createMonthTickProvider(
|
||||
DateTimeFactory dateTimeFactory) =>
|
||||
new TimeRangeTickProviderImpl(new MonthTimeStepper(dateTimeFactory));
|
||||
TimeRangeTickProviderImpl(MonthTimeStepper(dateTimeFactory));
|
||||
|
||||
static TimeRangeTickProvider createDayTickProvider(
|
||||
DateTimeFactory dateTimeFactory) =>
|
||||
new TimeRangeTickProviderImpl(new DayTimeStepper(dateTimeFactory));
|
||||
TimeRangeTickProviderImpl(DayTimeStepper(dateTimeFactory));
|
||||
|
||||
static TimeRangeTickProvider createHourTickProvider(
|
||||
DateTimeFactory dateTimeFactory) =>
|
||||
new TimeRangeTickProviderImpl(new HourTimeStepper(dateTimeFactory));
|
||||
TimeRangeTickProviderImpl(HourTimeStepper(dateTimeFactory));
|
||||
|
||||
static TimeRangeTickProvider createMinuteTickProvider(
|
||||
DateTimeFactory dateTimeFactory) =>
|
||||
new TimeRangeTickProviderImpl(new MinuteTimeStepper(dateTimeFactory));
|
||||
TimeRangeTickProviderImpl(MinuteTimeStepper(dateTimeFactory));
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ abstract class BaseTimeStepper implements TimeStepper {
|
||||
// Keep the steps iterable unless time extent changes, so the same iterator
|
||||
// can be used and reset for different increments.
|
||||
if (_stepsIterable == null || _stepsIterable.timeExtent != timeExtent) {
|
||||
_stepsIterable = new _TimeStepIteratorFactoryImpl(timeExtent, this);
|
||||
_stepsIterable = _TimeStepIteratorFactoryImpl(timeExtent, this);
|
||||
}
|
||||
return _stepsIterable;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ abstract class BaseTimeStepper implements TimeStepper {
|
||||
final stepBefore = getStepTimeBeforeInclusive(timeExtent.start, 1);
|
||||
final stepAfter = getStepTimeAfterInclusive(timeExtent.end, 1);
|
||||
|
||||
return new DateTimeExtents(start: stepBefore, end: stepAfter);
|
||||
return DateTimeExtents(start: stepBefore, end: stepAfter);
|
||||
}
|
||||
|
||||
DateTime getStepTimeAfterInclusive(DateTime time, int tickIncrement) {
|
||||
@@ -127,8 +127,8 @@ class _TimeStepIteratorFactoryImpl extends TimeStepIteratorFactory {
|
||||
DateTimeExtents timeExtent, BaseTimeStepper stepper) {
|
||||
final startTime = timeExtent.start;
|
||||
final endTime = timeExtent.end;
|
||||
return new _TimeStepIteratorFactoryImpl._internal(
|
||||
new _TimeStepIteratorImpl(startTime, endTime, stepper), timeExtent);
|
||||
return _TimeStepIteratorFactoryImpl._internal(
|
||||
_TimeStepIteratorImpl(startTime, endTime, stepper), timeExtent);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -28,11 +28,10 @@ class DateTimeAxis extends Axis<DateTime> {
|
||||
{TickProvider tickProvider, TickFormatter tickFormatter})
|
||||
: super(
|
||||
tickProvider: tickProvider ??
|
||||
new AutoAdjustingDateTimeTickProvider.createDefault(
|
||||
dateTimeFactory),
|
||||
AutoAdjustingDateTimeTickProvider.createDefault(dateTimeFactory),
|
||||
tickFormatter:
|
||||
tickFormatter ?? new DateTimeTickFormatter(dateTimeFactory),
|
||||
scale: new DateTimeScale(dateTimeFactory),
|
||||
tickFormatter ?? DateTimeTickFormatter(dateTimeFactory),
|
||||
scale: DateTimeScale(dateTimeFactory),
|
||||
);
|
||||
|
||||
void setScaleViewport(DateTimeExtents viewport) {
|
||||
|
||||
@@ -27,7 +27,7 @@ class DateTimeScale extends MutableScale<DateTime> {
|
||||
final DateTimeFactory dateTimeFactory;
|
||||
final LinearScale _linearScale;
|
||||
|
||||
DateTimeScale(this.dateTimeFactory) : _linearScale = new LinearScale();
|
||||
DateTimeScale(this.dateTimeFactory) : _linearScale = LinearScale();
|
||||
|
||||
DateTimeScale._copy(DateTimeScale other)
|
||||
: dateTimeFactory = other.dateTimeFactory,
|
||||
@@ -82,7 +82,7 @@ class DateTimeScale extends MutableScale<DateTime> {
|
||||
|
||||
DateTimeExtents get viewportDomain {
|
||||
final extents = _linearScale.viewportDomain;
|
||||
return new DateTimeExtents(
|
||||
return DateTimeExtents(
|
||||
start: dateTimeFactory
|
||||
.createDateTimeFromMilliSecondsSinceEpoch(extents.min.toInt()),
|
||||
end: dateTimeFactory
|
||||
@@ -90,13 +90,13 @@ class DateTimeScale extends MutableScale<DateTime> {
|
||||
}
|
||||
|
||||
set viewportDomain(DateTimeExtents extents) {
|
||||
_linearScale.viewportDomain = new NumericExtents(
|
||||
_linearScale.viewportDomain = NumericExtents(
|
||||
extents.start.millisecondsSinceEpoch,
|
||||
extents.end.millisecondsSinceEpoch);
|
||||
}
|
||||
|
||||
@override
|
||||
DateTimeScale copy() => new DateTimeScale._copy(this);
|
||||
DateTimeScale copy() => DateTimeScale._copy(this);
|
||||
|
||||
@override
|
||||
double get viewportTranslatePx => _linearScale.viewportTranslatePx;
|
||||
|
||||
@@ -56,27 +56,27 @@ class DateTimeTickFormatter implements TickFormatter<DateTime> {
|
||||
factory DateTimeTickFormatter(DateTimeFactory dateTimeFactory,
|
||||
{Map<int, TimeTickFormatter> overrides}) {
|
||||
final Map<int, TimeTickFormatter> map = {
|
||||
MINUTE: new TimeTickFormatterImpl(
|
||||
MINUTE: TimeTickFormatterImpl(
|
||||
dateTimeFactory: dateTimeFactory,
|
||||
simpleFormat: 'mm',
|
||||
transitionFormat: 'h mm',
|
||||
transitionField: CalendarField.hourOfDay),
|
||||
HOUR: new HourTickFormatter(
|
||||
HOUR: HourTickFormatter(
|
||||
dateTimeFactory: dateTimeFactory,
|
||||
simpleFormat: 'h',
|
||||
transitionFormat: 'MMM d ha',
|
||||
noonFormat: 'ha'),
|
||||
23 * HOUR: new TimeTickFormatterImpl(
|
||||
23 * HOUR: TimeTickFormatterImpl(
|
||||
dateTimeFactory: dateTimeFactory,
|
||||
simpleFormat: 'd',
|
||||
transitionFormat: 'MMM d',
|
||||
transitionField: CalendarField.month),
|
||||
28 * DAY: new TimeTickFormatterImpl(
|
||||
28 * DAY: TimeTickFormatterImpl(
|
||||
dateTimeFactory: dateTimeFactory,
|
||||
simpleFormat: 'MMM',
|
||||
transitionFormat: 'MMM yyyy',
|
||||
transitionField: CalendarField.year),
|
||||
364 * DAY: new TimeTickFormatterImpl(
|
||||
364 * DAY: TimeTickFormatterImpl(
|
||||
dateTimeFactory: dateTimeFactory,
|
||||
simpleFormat: 'yyyy',
|
||||
transitionFormat: 'yyyy',
|
||||
@@ -88,23 +88,23 @@ class DateTimeTickFormatter implements TickFormatter<DateTime> {
|
||||
map.addAll(overrides);
|
||||
}
|
||||
|
||||
return new DateTimeTickFormatter._internal(map);
|
||||
return DateTimeTickFormatter._internal(map);
|
||||
}
|
||||
|
||||
/// Creates a [DateTimeTickFormatter] without the time component.
|
||||
factory DateTimeTickFormatter.withoutTime(DateTimeFactory dateTimeFactory) {
|
||||
return new DateTimeTickFormatter._internal({
|
||||
23 * HOUR: new TimeTickFormatterImpl(
|
||||
return DateTimeTickFormatter._internal({
|
||||
23 * HOUR: TimeTickFormatterImpl(
|
||||
dateTimeFactory: dateTimeFactory,
|
||||
simpleFormat: 'd',
|
||||
transitionFormat: 'MMM d',
|
||||
transitionField: CalendarField.month),
|
||||
28 * DAY: new TimeTickFormatterImpl(
|
||||
28 * DAY: TimeTickFormatterImpl(
|
||||
dateTimeFactory: dateTimeFactory,
|
||||
simpleFormat: 'MMM',
|
||||
transitionFormat: 'MMM yyyy',
|
||||
transitionField: CalendarField.year),
|
||||
365 * DAY: new TimeTickFormatterImpl(
|
||||
365 * DAY: TimeTickFormatterImpl(
|
||||
dateTimeFactory: dateTimeFactory,
|
||||
simpleFormat: 'yyyy',
|
||||
transitionFormat: 'yyyy',
|
||||
@@ -119,7 +119,7 @@ class DateTimeTickFormatter implements TickFormatter<DateTime> {
|
||||
///
|
||||
/// [formatter] The format for all ticks.
|
||||
factory DateTimeTickFormatter.uniform(TimeTickFormatter formatter) {
|
||||
return new DateTimeTickFormatter._internal({ANY: formatter});
|
||||
return DateTimeTickFormatter._internal({ANY: formatter});
|
||||
}
|
||||
|
||||
/// Creates a [DateTimeTickFormatter] that formats ticks with [formatters].
|
||||
@@ -129,10 +129,10 @@ class DateTimeTickFormatter implements TickFormatter<DateTime> {
|
||||
Map<int, TimeTickFormatter> formatters) {
|
||||
// Formatters must be non empty.
|
||||
if (formatters == null || formatters.isEmpty) {
|
||||
throw new ArgumentError('At least one TimeTickFormatter is required.');
|
||||
throw ArgumentError('At least one TimeTickFormatter is required.');
|
||||
}
|
||||
|
||||
return new DateTimeTickFormatter._internal(formatters);
|
||||
return DateTimeTickFormatter._internal(formatters);
|
||||
}
|
||||
|
||||
DateTimeTickFormatter._internal(this._timeFormatters) {
|
||||
@@ -202,7 +202,7 @@ class DateTimeTickFormatter implements TickFormatter<DateTime> {
|
||||
// Only need to check the first value, because the values after are expected
|
||||
// to be greater.
|
||||
if (prev <= 0) {
|
||||
throw new ArgumentError('Formatter keys must be positive');
|
||||
throw ArgumentError('Formatter keys must be positive');
|
||||
}
|
||||
|
||||
while (valuesIterator.moveNext() && isSorted) {
|
||||
@@ -211,7 +211,7 @@ class DateTimeTickFormatter implements TickFormatter<DateTime> {
|
||||
}
|
||||
|
||||
if (!isSorted) {
|
||||
throw new ArgumentError(
|
||||
throw ArgumentError(
|
||||
'Formatters must be sorted with keys in increasing order');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import 'base_time_stepper.dart' show BaseTimeStepper;
|
||||
/// Day stepper.
|
||||
class DayTimeStepper extends BaseTimeStepper {
|
||||
// TODO: Remove the 14 day increment if we add week stepper.
|
||||
static const _defaultIncrements = const [1, 2, 3, 7, 14];
|
||||
static const _defaultIncrements = [1, 2, 3, 7, 14];
|
||||
static const _hoursInDay = 24;
|
||||
|
||||
final List<int> _allowedTickIncrements;
|
||||
@@ -39,7 +39,7 @@ class DayTimeStepper extends BaseTimeStepper {
|
||||
// All increments must be > 0.
|
||||
assert(allowedTickIncrements.any((increment) => increment <= 0) == false);
|
||||
|
||||
return new DayTimeStepper._internal(dateTimeFactory, allowedTickIncrements);
|
||||
return DayTimeStepper._internal(dateTimeFactory, allowedTickIncrements);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -60,7 +60,7 @@ class DayTimeStepper extends BaseTimeStepper {
|
||||
final dayRemainder = (time.day - 1) % tickIncrement;
|
||||
// Subtract an extra hour in case stepping through a daylight saving change.
|
||||
final dayBefore = dayRemainder > 0
|
||||
? time.subtract(new Duration(hours: (_hoursInDay * dayRemainder) - 1))
|
||||
? time.subtract(Duration(hours: (_hoursInDay * dayRemainder) - 1))
|
||||
: time;
|
||||
// Explicitly leaving off hours and beyond to truncate to start of day.
|
||||
final stepBefore = dateTimeFactory.createDateTime(
|
||||
@@ -73,7 +73,7 @@ class DayTimeStepper extends BaseTimeStepper {
|
||||
DateTime getNextStepTime(DateTime time, int tickIncrement) {
|
||||
// Add an extra hour in case stepping through a daylight saving change.
|
||||
final stepAfter =
|
||||
time.add(new Duration(hours: (_hoursInDay * tickIncrement) + 1));
|
||||
time.add(Duration(hours: (_hoursInDay * tickIncrement) + 1));
|
||||
// Explicitly leaving off hours and beyond to truncate to start of day.
|
||||
return dateTimeFactory.createDateTime(
|
||||
stepAfter.year, stepAfter.month, stepAfter.day);
|
||||
|
||||
@@ -18,7 +18,7 @@ import 'base_time_stepper.dart' show BaseTimeStepper;
|
||||
|
||||
/// Hour stepper.
|
||||
class HourTimeStepper extends BaseTimeStepper {
|
||||
static const _defaultIncrements = const [1, 2, 3, 4, 6, 12, 24];
|
||||
static const _defaultIncrements = [1, 2, 3, 4, 6, 12, 24];
|
||||
static const _hoursInDay = 24;
|
||||
static const _millisecondsInHour = 3600 * 1000;
|
||||
|
||||
@@ -41,8 +41,7 @@ class HourTimeStepper extends BaseTimeStepper {
|
||||
.any((increment) => increment <= 0 || increment > 24) ==
|
||||
false);
|
||||
|
||||
return new HourTimeStepper._internal(
|
||||
dateTimeFactory, allowedTickIncrements);
|
||||
return HourTimeStepper._internal(dateTimeFactory, allowedTickIncrements);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -60,7 +59,7 @@ class HourTimeStepper extends BaseTimeStepper {
|
||||
DateTime getStepTimeBeforeInclusive(DateTime time, int tickIncrement) {
|
||||
final nextDay = dateTimeFactory
|
||||
.createDateTime(time.year, time.month, time.day)
|
||||
.add(new Duration(hours: _hoursInDay + 1));
|
||||
.add(Duration(hours: _hoursInDay + 1));
|
||||
final nextDayStart = dateTimeFactory.createDateTime(
|
||||
nextDay.year, nextDay.month, nextDay.day);
|
||||
|
||||
@@ -83,6 +82,6 @@ class HourTimeStepper extends BaseTimeStepper {
|
||||
/// [time] is expected to be a [DateTime] with the hour at start of the hour.
|
||||
@override
|
||||
DateTime getNextStepTime(DateTime time, int tickIncrement) {
|
||||
return time.add(new Duration(hours: tickIncrement));
|
||||
return time.add(Duration(hours: tickIncrement));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import 'base_time_stepper.dart';
|
||||
|
||||
/// Minute stepper where ticks generated aligns with the hour.
|
||||
class MinuteTimeStepper extends BaseTimeStepper {
|
||||
static const _defaultIncrements = const [5, 10, 15, 20, 30];
|
||||
static const _defaultIncrements = [5, 10, 15, 20, 30];
|
||||
static const _millisecondsInMinute = 60 * 1000;
|
||||
|
||||
final List<int> _allowedTickIncrements;
|
||||
@@ -40,8 +40,7 @@ class MinuteTimeStepper extends BaseTimeStepper {
|
||||
.any((increment) => increment <= 0 || increment > 60) ==
|
||||
false);
|
||||
|
||||
return new MinuteTimeStepper._internal(
|
||||
dateTimeFactory, allowedTickIncrements);
|
||||
return MinuteTimeStepper._internal(dateTimeFactory, allowedTickIncrements);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -73,6 +72,6 @@ class MinuteTimeStepper extends BaseTimeStepper {
|
||||
|
||||
@override
|
||||
DateTime getNextStepTime(DateTime time, int tickIncrement) {
|
||||
return time.add(new Duration(minutes: tickIncrement));
|
||||
return time.add(Duration(minutes: tickIncrement));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import 'base_time_stepper.dart' show BaseTimeStepper;
|
||||
|
||||
/// Month stepper.
|
||||
class MonthTimeStepper extends BaseTimeStepper {
|
||||
static const _defaultIncrements = const [1, 2, 3, 4, 6, 12];
|
||||
static const _defaultIncrements = [1, 2, 3, 4, 6, 12];
|
||||
|
||||
final List<int> _allowedTickIncrements;
|
||||
|
||||
@@ -37,8 +37,7 @@ class MonthTimeStepper extends BaseTimeStepper {
|
||||
// All increments must be > 0.
|
||||
assert(allowedTickIncrements.any((increment) => increment <= 0) == false);
|
||||
|
||||
return new MonthTimeStepper._internal(
|
||||
dateTimeFactory, allowedTickIncrements);
|
||||
return MonthTimeStepper._internal(dateTimeFactory, allowedTickIncrements);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -18,7 +18,7 @@ import 'base_time_stepper.dart' show BaseTimeStepper;
|
||||
|
||||
/// Year stepper.
|
||||
class YearTimeStepper extends BaseTimeStepper {
|
||||
static const _defaultIncrements = const [1, 2, 5, 10, 50, 100, 500, 1000];
|
||||
static const _defaultIncrements = [1, 2, 5, 10, 50, 100, 500, 1000];
|
||||
|
||||
final List<int> _allowedTickIncrements;
|
||||
|
||||
@@ -37,8 +37,7 @@ class YearTimeStepper extends BaseTimeStepper {
|
||||
// All increments must be > 0.
|
||||
assert(allowedTickIncrements.any((increment) => increment <= 0) == false);
|
||||
|
||||
return new YearTimeStepper._internal(
|
||||
dateTimeFactory, allowedTickIncrements);
|
||||
return YearTimeStepper._internal(dateTimeFactory, allowedTickIncrements);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -55,14 +55,14 @@ class NumericCartesianChart extends CartesianChart<num> {
|
||||
: super(
|
||||
vertical: vertical,
|
||||
layoutConfig: layoutConfig,
|
||||
domainAxis: new NumericAxis(),
|
||||
domainAxis: NumericAxis(),
|
||||
primaryMeasureAxis: primaryMeasureAxis,
|
||||
secondaryMeasureAxis: secondaryMeasureAxis,
|
||||
disjointMeasureAxes: disjointMeasureAxes);
|
||||
|
||||
@protected
|
||||
void initDomainAxis() {
|
||||
_domainAxis.tickDrawStrategy = new SmallTickRendererSpec<num>()
|
||||
_domainAxis.tickDrawStrategy = SmallTickRendererSpec<num>()
|
||||
.createDrawStrategy(context, graphicsFactory);
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ class OrdinalCartesianChart extends CartesianChart<String> {
|
||||
: super(
|
||||
vertical: vertical,
|
||||
layoutConfig: layoutConfig,
|
||||
domainAxis: new OrdinalAxis(),
|
||||
domainAxis: OrdinalAxis(),
|
||||
primaryMeasureAxis: primaryMeasureAxis,
|
||||
secondaryMeasureAxis: secondaryMeasureAxis,
|
||||
disjointMeasureAxes: disjointMeasureAxes);
|
||||
@@ -85,17 +85,17 @@ class OrdinalCartesianChart extends CartesianChart<String> {
|
||||
@protected
|
||||
void initDomainAxis() {
|
||||
_domainAxis
|
||||
..tickDrawStrategy = new SmallTickRendererSpec<String>()
|
||||
..tickDrawStrategy = SmallTickRendererSpec<String>()
|
||||
.createDrawStrategy(context, graphicsFactory);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class CartesianChart<D> extends BaseChart<D> {
|
||||
static final _defaultLayoutConfig = new LayoutConfig(
|
||||
topSpec: new MarginSpec.fromPixel(minPixel: 20),
|
||||
bottomSpec: new MarginSpec.fromPixel(minPixel: 20),
|
||||
leftSpec: new MarginSpec.fromPixel(minPixel: 20),
|
||||
rightSpec: new MarginSpec.fromPixel(minPixel: 20),
|
||||
static final _defaultLayoutConfig = LayoutConfig(
|
||||
topSpec: MarginSpec.fromPixel(minPixel: 20),
|
||||
bottomSpec: MarginSpec.fromPixel(minPixel: 20),
|
||||
leftSpec: MarginSpec.fromPixel(minPixel: 20),
|
||||
rightSpec: MarginSpec.fromPixel(minPixel: 20),
|
||||
);
|
||||
|
||||
bool vertical;
|
||||
@@ -148,8 +148,8 @@ abstract class CartesianChart<D> extends BaseChart<D> {
|
||||
: vertical = vertical ?? true,
|
||||
// [domainAxis] will be set to the new axis in [configurationChanged].
|
||||
_newDomainAxis = domainAxis,
|
||||
_primaryMeasureAxis = primaryMeasureAxis ?? new NumericAxis(),
|
||||
_secondaryMeasureAxis = secondaryMeasureAxis ?? new NumericAxis(),
|
||||
_primaryMeasureAxis = primaryMeasureAxis ?? NumericAxis(),
|
||||
_secondaryMeasureAxis = secondaryMeasureAxis ?? NumericAxis(),
|
||||
_disjointMeasureAxes = disjointMeasureAxes ?? <String, NumericAxis>{},
|
||||
super(layoutConfig: layoutConfig ?? _defaultLayoutConfig) {
|
||||
// As a convenience for chart configuration, set the paint order on any axis
|
||||
@@ -157,7 +157,7 @@ abstract class CartesianChart<D> extends BaseChart<D> {
|
||||
_primaryMeasureAxis.layoutPaintOrder ??= LayoutViewPaintOrder.measureAxis;
|
||||
_secondaryMeasureAxis.layoutPaintOrder ??= LayoutViewPaintOrder.measureAxis;
|
||||
|
||||
_disjointMeasureAxes.forEach((String axisId, NumericAxis axis) {
|
||||
_disjointMeasureAxes.forEach((axisId, axis) {
|
||||
axis.layoutPaintOrder ??= LayoutViewPaintOrder.measureAxis;
|
||||
});
|
||||
}
|
||||
@@ -166,17 +166,16 @@ abstract class CartesianChart<D> extends BaseChart<D> {
|
||||
super.init(context, graphicsFactory);
|
||||
|
||||
_primaryMeasureAxis.context = context;
|
||||
_primaryMeasureAxis.tickDrawStrategy = new GridlineRendererSpec<num>()
|
||||
_primaryMeasureAxis.tickDrawStrategy = GridlineRendererSpec<num>()
|
||||
.createDrawStrategy(context, graphicsFactory);
|
||||
|
||||
_secondaryMeasureAxis.context = context;
|
||||
_secondaryMeasureAxis.tickDrawStrategy = new GridlineRendererSpec<num>()
|
||||
_secondaryMeasureAxis.tickDrawStrategy = GridlineRendererSpec<num>()
|
||||
.createDrawStrategy(context, graphicsFactory);
|
||||
|
||||
_disjointMeasureAxes.forEach((String axisId, NumericAxis axis) {
|
||||
_disjointMeasureAxes.forEach((axisId, axis) {
|
||||
axis.context = context;
|
||||
axis.tickDrawStrategy =
|
||||
new NoneDrawStrategy<num>(context, graphicsFactory);
|
||||
axis.tickDrawStrategy = NoneDrawStrategy<num>(context, graphicsFactory);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -277,7 +276,7 @@ abstract class CartesianChart<D> extends BaseChart<D> {
|
||||
/// A [LinkedHashMap] is used to ensure consistent ordering when painting the
|
||||
/// axes.
|
||||
set disjointMeasureAxisSpecs(LinkedHashMap<String, AxisSpec> axisSpecs) {
|
||||
axisSpecs.forEach((String axisId, AxisSpec axisSpec) {
|
||||
axisSpecs.forEach((axisId, axisSpec) {
|
||||
axisSpec.configure(
|
||||
_disjointMeasureAxes[axisId], context, graphicsFactory);
|
||||
});
|
||||
@@ -299,7 +298,7 @@ abstract class CartesianChart<D> extends BaseChart<D> {
|
||||
|
||||
@override
|
||||
SeriesRenderer<D> makeDefaultRenderer() {
|
||||
return new BarRenderer()..rendererId = SeriesRenderer.defaultRendererId;
|
||||
return BarRenderer()..rendererId = SeriesRenderer.defaultRendererId;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -331,7 +330,7 @@ abstract class CartesianChart<D> extends BaseChart<D> {
|
||||
}
|
||||
|
||||
// Add all disjoint axis views so that their range will be configured.
|
||||
_disjointMeasureAxes.forEach((String axisId, NumericAxis axis) {
|
||||
_disjointMeasureAxes.forEach((axisId, axis) {
|
||||
addView(axis);
|
||||
});
|
||||
|
||||
@@ -340,7 +339,7 @@ abstract class CartesianChart<D> extends BaseChart<D> {
|
||||
_primaryMeasureAxis.resetDomains();
|
||||
_secondaryMeasureAxis.resetDomains();
|
||||
|
||||
_disjointMeasureAxes.forEach((String axisId, NumericAxis axis) {
|
||||
_disjointMeasureAxes.forEach((axisId, axis) {
|
||||
axis.resetDomains();
|
||||
});
|
||||
|
||||
@@ -363,7 +362,7 @@ abstract class CartesianChart<D> extends BaseChart<D> {
|
||||
: AxisOrientation.right)
|
||||
..reverseOutputRange = flipVerticalAxisOutput;
|
||||
|
||||
_disjointMeasureAxes.forEach((String axisId, NumericAxis axis) {
|
||||
_disjointMeasureAxes.forEach((axisId, axis) {
|
||||
axis
|
||||
..axisOrientation = (reverseAxisDirection
|
||||
? AxisOrientation.left
|
||||
@@ -385,7 +384,7 @@ abstract class CartesianChart<D> extends BaseChart<D> {
|
||||
..axisOrientation = AxisOrientation.top
|
||||
..reverseOutputRange = reverseAxisDirection;
|
||||
|
||||
_disjointMeasureAxes.forEach((String axisId, NumericAxis axis) {
|
||||
_disjointMeasureAxes.forEach((axisId, axis) {
|
||||
axis
|
||||
..axisOrientation = AxisOrientation.top
|
||||
..reverseOutputRange = reverseAxisDirection;
|
||||
@@ -394,8 +393,7 @@ abstract class CartesianChart<D> extends BaseChart<D> {
|
||||
|
||||
// Have each renderer configure the axes with their domain and measure
|
||||
// values.
|
||||
rendererToSeriesList
|
||||
.forEach((String rendererId, List<MutableSeries<D>> seriesList) {
|
||||
rendererToSeriesList.forEach((rendererId, seriesList) {
|
||||
getSeriesRenderer(rendererId).configureDomainAxes(seriesList);
|
||||
getSeriesRenderer(rendererId).configureMeasureAxes(seriesList);
|
||||
});
|
||||
@@ -416,7 +414,7 @@ abstract class CartesianChart<D> extends BaseChart<D> {
|
||||
_secondaryMeasureAxis.updateTicks();
|
||||
}
|
||||
|
||||
_disjointMeasureAxes.forEach((String axisId, NumericAxis axis) {
|
||||
_disjointMeasureAxes.forEach((axisId, axis) {
|
||||
axis.updateTicks();
|
||||
});
|
||||
|
||||
@@ -449,11 +447,11 @@ abstract class CartesianChart<D> extends BaseChart<D> {
|
||||
final measurePosition =
|
||||
series.getAttr(measureAxisKey).getLocation(measure);
|
||||
|
||||
final chartPosition = new Point<double>(
|
||||
final chartPosition = Point<double>(
|
||||
vertical ? domainPosition : measurePosition,
|
||||
vertical ? measurePosition : domainPosition);
|
||||
|
||||
entries.add(new DatumDetails(
|
||||
entries.add(DatumDetails(
|
||||
datum: datum,
|
||||
domain: domain,
|
||||
measure: measure,
|
||||
|
||||
@@ -52,7 +52,7 @@ abstract class BaseCartesianRenderer<D> extends BaseSeriesRenderer<D>
|
||||
|
||||
@override
|
||||
void configureDomainAxes(List<MutableSeries<D>> seriesList) {
|
||||
seriesList.forEach((MutableSeries<D> series) {
|
||||
seriesList.forEach((series) {
|
||||
if (series.data.isEmpty) {
|
||||
return;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ abstract class BaseCartesianRenderer<D> extends BaseSeriesRenderer<D>
|
||||
|
||||
@override
|
||||
void configureMeasureAxes(List<MutableSeries<D>> seriesList) {
|
||||
seriesList.forEach((MutableSeries<D> series) {
|
||||
seriesList.forEach((series) {
|
||||
if (series.data.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user