mirror of
https://github.com/flutter/samples.git
synced 2025-11-11 15:28:44 +00:00
Web charts common update (#111)
This commit is contained in:
@@ -46,7 +46,7 @@ void main() {
|
||||
var tester = AxisTester(axis);
|
||||
axis.tickDrawStrategy = MockTickDrawStrategy();
|
||||
axis.graphicsFactory = MockGraphicsFactory();
|
||||
tester.scale.range = new ScaleOutputExtent(0, 300);
|
||||
tester.scale.range = ScaleOutputExtent(0, 300);
|
||||
|
||||
axis.updateTicks();
|
||||
|
||||
|
||||
@@ -36,9 +36,9 @@ class FakeTextElement implements TextElement {
|
||||
|
||||
/// Helper to create a tick for testing.
|
||||
Tick<String> _createTestTick(String value, double locationPx) {
|
||||
return new Tick(
|
||||
return Tick(
|
||||
value: value,
|
||||
textElement: new FakeTextElement(value),
|
||||
textElement: FakeTextElement(value),
|
||||
locationPx: locationPx);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ void _verify(Tick<String> tick, {double location, double opacity}) {
|
||||
void main() {
|
||||
// Tick first render.
|
||||
test('tick created for the first time', () {
|
||||
final tick = new AxisTicks(_createTestTick('a', 100.0));
|
||||
final tick = AxisTicks(_createTestTick('a', 100.0));
|
||||
|
||||
// Animate in the tick, there was no previous position to animated in from
|
||||
// so the tick appears in the target immediately.
|
||||
@@ -69,8 +69,7 @@ void main() {
|
||||
|
||||
// Tick that is animated in.
|
||||
test('tick created with a previous location', () {
|
||||
final tick = new AxisTicks(_createTestTick('a', 200.0))
|
||||
..animateInFrom(100.0);
|
||||
final tick = AxisTicks(_createTestTick('a', 200.0))..animateInFrom(100.0);
|
||||
|
||||
tick.setCurrentTick(0.0);
|
||||
_verify(tick, location: 100.0, opacity: 0.0);
|
||||
@@ -87,7 +86,7 @@ void main() {
|
||||
|
||||
// Tick that is being animated out.
|
||||
test('tick is animated in and then out', () {
|
||||
final tick = new AxisTicks(_createTestTick('a', 100.0));
|
||||
final tick = AxisTicks(_createTestTick('a', 100.0));
|
||||
|
||||
// Animate in the tick, there was no previous position to animated in from
|
||||
// so the tick appears in the target immediately.
|
||||
@@ -113,7 +112,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('tick target change after reaching target', () {
|
||||
final tick = new AxisTicks(_createTestTick('a', 100.0));
|
||||
final tick = AxisTicks(_createTestTick('a', 100.0));
|
||||
|
||||
// Animate in the tick.
|
||||
tick.setCurrentTick(1.0);
|
||||
@@ -137,7 +136,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('tick target change before reaching initial target', () {
|
||||
final tick = new AxisTicks(_createTestTick('a', 400.0))..animateInFrom(0.0);
|
||||
final tick = AxisTicks(_createTestTick('a', 400.0))..animateInFrom(0.0);
|
||||
|
||||
// Animate in the tick.
|
||||
tick.setCurrentTick(0.25);
|
||||
@@ -161,7 +160,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('tick target animate out before reaching initial target', () {
|
||||
final tick = new AxisTicks(_createTestTick('a', 400.0))..animateInFrom(0.0);
|
||||
final tick = AxisTicks(_createTestTick('a', 400.0))..animateInFrom(0.0);
|
||||
|
||||
// Animate in the tick.
|
||||
tick.setCurrentTick(0.25);
|
||||
|
||||
@@ -48,14 +48,14 @@ class FakeDrawStrategy extends BaseTickDrawStrategy<num> {
|
||||
|
||||
FakeDrawStrategy(
|
||||
this.collidesAfterTickCount, this.alternateRenderingAfterTickCount)
|
||||
: super(null, new FakeGraphicsFactory());
|
||||
: super(null, FakeGraphicsFactory());
|
||||
|
||||
@override
|
||||
CollisionReport collides(List<Tick<num>> ticks, _) {
|
||||
final ticksCollide = ticks.length >= collidesAfterTickCount;
|
||||
final alternateTicksUsed = ticks.length >= alternateRenderingAfterTickCount;
|
||||
|
||||
return new CollisionReport(
|
||||
return CollisionReport(
|
||||
ticksCollide: ticksCollide,
|
||||
ticks: ticks,
|
||||
alternateTicksUsed: alternateTicksUsed);
|
||||
@@ -73,13 +73,13 @@ class FakeDrawStrategy extends BaseTickDrawStrategy<num> {
|
||||
/// A fake [GraphicsFactory] that returns [MockTextStyle] and [MockTextElement].
|
||||
class FakeGraphicsFactory extends GraphicsFactory {
|
||||
@override
|
||||
TextStyle createTextPaint() => new MockTextStyle();
|
||||
TextStyle createTextPaint() => MockTextStyle();
|
||||
|
||||
@override
|
||||
TextElement createTextElement(String text) => new MockTextElement(text);
|
||||
TextElement createTextElement(String text) => MockTextElement(text);
|
||||
|
||||
@override
|
||||
LineStyle createLinePaint() => new MockLinePaint();
|
||||
LineStyle createLinePaint() => MockLinePaint();
|
||||
}
|
||||
|
||||
class MockTextStyle extends Mock implements TextStyle {}
|
||||
@@ -113,11 +113,11 @@ void main() {
|
||||
ChartContext context;
|
||||
|
||||
setUp(() {
|
||||
graphicsFactory = new FakeGraphicsFactory();
|
||||
scale = new MockNumericScale();
|
||||
tickProvider = new BucketingNumericTickProvider();
|
||||
formatter = new NumericTickFormatter();
|
||||
context = new MockChartContext();
|
||||
graphicsFactory = FakeGraphicsFactory();
|
||||
scale = MockNumericScale();
|
||||
tickProvider = BucketingNumericTickProvider();
|
||||
formatter = NumericTickFormatter();
|
||||
context = MockChartContext();
|
||||
});
|
||||
|
||||
group('threshold', () {
|
||||
@@ -128,8 +128,8 @@ void main() {
|
||||
..showBucket = true
|
||||
..setFixedTickCount(21)
|
||||
..allowedSteps = [1.0, 2.5, 5.0];
|
||||
final drawStrategy = new FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(0.1, 0.7));
|
||||
final drawStrategy = FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(0.1, 0.7));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
when(scale[0.1]).thenReturn(90.0);
|
||||
when(scale[0]).thenReturn(100.0);
|
||||
@@ -163,17 +163,16 @@ void main() {
|
||||
// Verify that the rest of the ticks are all above the threshold in value
|
||||
// and have normal labels.
|
||||
var aboveThresholdTicks = ticks.sublist(2);
|
||||
aboveThresholdTicks.retainWhere((Tick tick) => tick.value > 0.1);
|
||||
aboveThresholdTicks.retainWhere((tick) => tick.value > 0.1);
|
||||
expect(aboveThresholdTicks, hasLength(18));
|
||||
|
||||
aboveThresholdTicks = ticks.sublist(2);
|
||||
aboveThresholdTicks.retainWhere((Tick tick) =>
|
||||
aboveThresholdTicks.retainWhere((tick) =>
|
||||
tick.textElement.text != '' && !tick.textElement.text.contains('<'));
|
||||
expect(aboveThresholdTicks, hasLength(18));
|
||||
|
||||
aboveThresholdTicks = ticks.sublist(2);
|
||||
aboveThresholdTicks
|
||||
.retainWhere((Tick tick) => tick.labelOffsetPx == null);
|
||||
aboveThresholdTicks.retainWhere((tick) => tick.labelOffsetPx == null);
|
||||
expect(aboveThresholdTicks, hasLength(18));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -75,7 +75,7 @@ class FakeTextElement implements TextElement {
|
||||
this.textDirection,
|
||||
double horizontalSliceWidth,
|
||||
double verticalSliceWidth,
|
||||
) : measurement = new TextMeasurement(
|
||||
) : measurement = TextMeasurement(
|
||||
horizontalSliceWidth: horizontalSliceWidth,
|
||||
verticalSliceWidth: verticalSliceWidth);
|
||||
}
|
||||
@@ -91,10 +91,10 @@ Tick<String> createTick(String value, double locationPx,
|
||||
{double horizontalWidth,
|
||||
double verticalWidth,
|
||||
TextDirection textDirection}) {
|
||||
return new Tick<String>(
|
||||
return Tick<String>(
|
||||
value: value,
|
||||
locationPx: locationPx,
|
||||
textElement: new FakeTextElement(
|
||||
textElement: FakeTextElement(
|
||||
value, textDirection, horizontalWidth, verticalWidth));
|
||||
}
|
||||
|
||||
@@ -103,18 +103,18 @@ void main() {
|
||||
ChartContext chartContext;
|
||||
|
||||
setUpAll(() {
|
||||
graphicsFactory = new MockGraphicsFactory();
|
||||
when(graphicsFactory.createLinePaint()).thenReturn(new MockLineStyle());
|
||||
when(graphicsFactory.createTextPaint()).thenReturn(new MockTextStyle());
|
||||
graphicsFactory = MockGraphicsFactory();
|
||||
when(graphicsFactory.createLinePaint()).thenReturn(MockLineStyle());
|
||||
when(graphicsFactory.createTextPaint()).thenReturn(MockTextStyle());
|
||||
|
||||
chartContext = new MockContext();
|
||||
chartContext = MockContext();
|
||||
when(chartContext.chartContainerIsRtl).thenReturn(false);
|
||||
when(chartContext.isRtl).thenReturn(false);
|
||||
});
|
||||
|
||||
group('collision detection - vertically drawn axis', () {
|
||||
test('ticks do not collide', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 2);
|
||||
|
||||
@@ -130,7 +130,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('ticks collide because it does not have minimum padding', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 2);
|
||||
|
||||
@@ -146,7 +146,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('first tick causes collision', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 0);
|
||||
|
||||
@@ -162,7 +162,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('last tick causes collision', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 0);
|
||||
|
||||
@@ -178,7 +178,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('ticks do not collide for inside tick label anchor', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 2,
|
||||
labelAnchor: TickLabelAnchor.inside);
|
||||
@@ -195,7 +195,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('ticks collide for inside anchor - first tick too large', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 2,
|
||||
labelAnchor: TickLabelAnchor.inside);
|
||||
@@ -212,7 +212,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('ticks collide for inside anchor - center tick too large', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 2,
|
||||
labelAnchor: TickLabelAnchor.inside);
|
||||
@@ -229,7 +229,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('ticks collide for inside anchor - last tick too large', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 2,
|
||||
labelAnchor: TickLabelAnchor.inside);
|
||||
@@ -248,7 +248,7 @@ void main() {
|
||||
|
||||
group('collision detection - horizontally drawn axis', () {
|
||||
test('ticks do not collide for TickLabelAnchor.before', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 2,
|
||||
labelAnchor: TickLabelAnchor.before);
|
||||
@@ -265,7 +265,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('ticks do not collide for TickLabelAnchor.inside', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 0,
|
||||
labelAnchor: TickLabelAnchor.inside);
|
||||
@@ -288,7 +288,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('ticks collide - first tick too large', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 0,
|
||||
labelAnchor: TickLabelAnchor.inside);
|
||||
@@ -305,7 +305,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('ticks collide - middle tick too large', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 0,
|
||||
labelAnchor: TickLabelAnchor.inside);
|
||||
@@ -322,7 +322,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('ticks collide - last tick too large', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 0,
|
||||
labelAnchor: TickLabelAnchor.inside);
|
||||
@@ -341,7 +341,7 @@ void main() {
|
||||
|
||||
group('collision detection - unsorted ticks', () {
|
||||
test('ticks do not collide', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 0,
|
||||
labelAnchor: TickLabelAnchor.inside);
|
||||
@@ -358,7 +358,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('ticks collide - tick B is too large', () {
|
||||
final drawStrategy = new BaseTickDrawStrategyImpl(
|
||||
final drawStrategy = BaseTickDrawStrategyImpl(
|
||||
chartContext, graphicsFactory,
|
||||
minimumPaddingBetweenLabelsPx: 0,
|
||||
labelAnchor: TickLabelAnchor.inside);
|
||||
@@ -378,7 +378,7 @@ void main() {
|
||||
group('collision detection - corner cases', () {
|
||||
test('null ticks do not collide', () {
|
||||
final drawStrategy =
|
||||
new BaseTickDrawStrategyImpl(chartContext, graphicsFactory);
|
||||
BaseTickDrawStrategyImpl(chartContext, graphicsFactory);
|
||||
|
||||
final report = drawStrategy.collides(null, AxisOrientation.left);
|
||||
|
||||
@@ -387,7 +387,7 @@ void main() {
|
||||
|
||||
test('empty tick list do not collide', () {
|
||||
final drawStrategy =
|
||||
new BaseTickDrawStrategyImpl(chartContext, graphicsFactory);
|
||||
BaseTickDrawStrategyImpl(chartContext, graphicsFactory);
|
||||
|
||||
final report = drawStrategy.collides([], AxisOrientation.left);
|
||||
|
||||
@@ -396,7 +396,7 @@ void main() {
|
||||
|
||||
test('single tick does not collide', () {
|
||||
final drawStrategy =
|
||||
new BaseTickDrawStrategyImpl(chartContext, graphicsFactory);
|
||||
BaseTickDrawStrategyImpl(chartContext, graphicsFactory);
|
||||
|
||||
final report = drawStrategy.collides(
|
||||
[createTick('A', 10.0, horizontalWidth: 10.0)],
|
||||
|
||||
@@ -57,14 +57,14 @@ class FakeDrawStrategy<D> extends BaseTickDrawStrategy<D> {
|
||||
|
||||
FakeDrawStrategy(
|
||||
this.collidesAfterTickCount, this.alternateRenderingAfterTickCount)
|
||||
: super(null, new FakeGraphicsFactory());
|
||||
: super(null, FakeGraphicsFactory());
|
||||
|
||||
@override
|
||||
CollisionReport collides(List<Tick<D>> ticks, _) {
|
||||
final ticksCollide = ticks.length >= collidesAfterTickCount;
|
||||
final alternateTicksUsed = ticks.length >= alternateRenderingAfterTickCount;
|
||||
|
||||
return new CollisionReport(
|
||||
return CollisionReport(
|
||||
ticksCollide: ticksCollide,
|
||||
ticks: ticks,
|
||||
alternateTicksUsed: alternateTicksUsed);
|
||||
@@ -82,13 +82,13 @@ class FakeDrawStrategy<D> extends BaseTickDrawStrategy<D> {
|
||||
/// A fake [GraphicsFactory] that returns [MockTextStyle] and [MockTextElement].
|
||||
class FakeGraphicsFactory extends GraphicsFactory {
|
||||
@override
|
||||
TextStyle createTextPaint() => new MockTextStyle();
|
||||
TextStyle createTextPaint() => MockTextStyle();
|
||||
|
||||
@override
|
||||
TextElement createTextElement(String text) => new MockTextElement();
|
||||
TextElement createTextElement(String text) => MockTextElement();
|
||||
|
||||
@override
|
||||
LineStyle createLinePaint() => new MockLinePaint();
|
||||
LineStyle createLinePaint() => MockLinePaint();
|
||||
}
|
||||
|
||||
class MockTextStyle extends Mock implements TextStyle {}
|
||||
@@ -100,24 +100,24 @@ class MockLinePaint extends Mock implements LineStyle {}
|
||||
class MockChartContext extends Mock implements ChartContext {}
|
||||
|
||||
void main() {
|
||||
const dateTimeFactory = const SimpleDateTimeFactory();
|
||||
const dateTimeFactory = SimpleDateTimeFactory();
|
||||
FakeGraphicsFactory graphicsFactory;
|
||||
EndPointsTickProvider tickProvider;
|
||||
ChartContext context;
|
||||
|
||||
setUp(() {
|
||||
graphicsFactory = new FakeGraphicsFactory();
|
||||
context = new MockChartContext();
|
||||
graphicsFactory = FakeGraphicsFactory();
|
||||
context = MockChartContext();
|
||||
});
|
||||
|
||||
test('dateTime_choosesEndPointTicks', () {
|
||||
final formatter = new DateTimeTickFormatter(dateTimeFactory);
|
||||
final scale = new MockDateTimeScale();
|
||||
tickProvider = new EndPointsTickProvider<DateTime>();
|
||||
final formatter = DateTimeTickFormatter(dateTimeFactory);
|
||||
final scale = MockDateTimeScale();
|
||||
tickProvider = EndPointsTickProvider<DateTime>();
|
||||
|
||||
final drawStrategy = new FakeDrawStrategy<DateTime>(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(new DateTimeExtents(
|
||||
start: new DateTime(2018, 8, 1), end: new DateTime(2018, 8, 11)));
|
||||
final drawStrategy = FakeDrawStrategy<DateTime>(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(DateTimeExtents(
|
||||
start: DateTime(2018, 8, 1), end: DateTime(2018, 8, 11)));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
when(scale.domainStepSize).thenReturn(1000.0);
|
||||
|
||||
@@ -131,17 +131,17 @@ void main() {
|
||||
orientation: null);
|
||||
|
||||
expect(ticks, hasLength(2));
|
||||
expect(ticks[0].value, equals(new DateTime(2018, 8, 1)));
|
||||
expect(ticks[1].value, equals(new DateTime(2018, 8, 11)));
|
||||
expect(ticks[0].value, equals(DateTime(2018, 8, 1)));
|
||||
expect(ticks[1].value, equals(DateTime(2018, 8, 11)));
|
||||
});
|
||||
|
||||
test('numeric_choosesEndPointTicks', () {
|
||||
final formatter = new NumericTickFormatter();
|
||||
final scale = new MockNumericScale();
|
||||
tickProvider = new EndPointsTickProvider<num>();
|
||||
final formatter = NumericTickFormatter();
|
||||
final scale = MockNumericScale();
|
||||
tickProvider = EndPointsTickProvider<num>();
|
||||
|
||||
final drawStrategy = new FakeDrawStrategy<num>(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(10.0, 70.0));
|
||||
final drawStrategy = FakeDrawStrategy<num>(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(10.0, 70.0));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
when(scale.domainStepSize).thenReturn(1000.0);
|
||||
|
||||
@@ -160,15 +160,15 @@ void main() {
|
||||
});
|
||||
|
||||
test('ordinal_choosesEndPointTicks', () {
|
||||
final formatter = new OrdinalTickFormatter();
|
||||
final scale = new SimpleOrdinalScale();
|
||||
final formatter = OrdinalTickFormatter();
|
||||
final scale = SimpleOrdinalScale();
|
||||
scale.addDomain('A');
|
||||
scale.addDomain('B');
|
||||
scale.addDomain('C');
|
||||
scale.addDomain('D');
|
||||
tickProvider = new EndPointsTickProvider<String>();
|
||||
tickProvider = EndPointsTickProvider<String>();
|
||||
|
||||
final drawStrategy = new FakeDrawStrategy<String>(10, 10);
|
||||
final drawStrategy = FakeDrawStrategy<String>(10, 10);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
context: context,
|
||||
@@ -185,13 +185,13 @@ void main() {
|
||||
});
|
||||
|
||||
test('dateTime_emptySeriesChoosesNoTicks', () {
|
||||
final formatter = new DateTimeTickFormatter(dateTimeFactory);
|
||||
final scale = new MockDateTimeScale();
|
||||
tickProvider = new EndPointsTickProvider<DateTime>();
|
||||
final formatter = DateTimeTickFormatter(dateTimeFactory);
|
||||
final scale = MockDateTimeScale();
|
||||
tickProvider = EndPointsTickProvider<DateTime>();
|
||||
|
||||
final drawStrategy = new FakeDrawStrategy<DateTime>(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(new DateTimeExtents(
|
||||
start: new DateTime(2018, 8, 1), end: new DateTime(2018, 8, 11)));
|
||||
final drawStrategy = FakeDrawStrategy<DateTime>(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(DateTimeExtents(
|
||||
start: DateTime(2018, 8, 1), end: DateTime(2018, 8, 11)));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
// An un-configured axis has no domain step size, and its scale defaults to
|
||||
@@ -211,12 +211,12 @@ void main() {
|
||||
});
|
||||
|
||||
test('numeric_emptySeriesChoosesNoTicks', () {
|
||||
final formatter = new NumericTickFormatter();
|
||||
final scale = new MockNumericScale();
|
||||
tickProvider = new EndPointsTickProvider<num>();
|
||||
final formatter = NumericTickFormatter();
|
||||
final scale = MockNumericScale();
|
||||
tickProvider = EndPointsTickProvider<num>();
|
||||
|
||||
final drawStrategy = new FakeDrawStrategy<num>(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(10.0, 70.0));
|
||||
final drawStrategy = FakeDrawStrategy<num>(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(10.0, 70.0));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
// An un-configured axis has no domain step size, and its scale defaults to
|
||||
|
||||
@@ -26,12 +26,12 @@ const EPSILON = 0.001;
|
||||
void main() {
|
||||
group('Stacking bars', () {
|
||||
test('basic apply survives copy and reset', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
LinearScale scale = LinearScale();
|
||||
scale.addDomain(100.0);
|
||||
scale.addDomain(130.0);
|
||||
scale.addDomain(200.0);
|
||||
scale.addDomain(170.0);
|
||||
scale.range = new ScaleOutputExtent(2000, 1000);
|
||||
scale.range = ScaleOutputExtent(2000, 1000);
|
||||
|
||||
expect(scale.range.start, equals(2000));
|
||||
expect(scale.range.end, equals(1000));
|
||||
@@ -71,11 +71,11 @@ void main() {
|
||||
});
|
||||
|
||||
test('viewport assigned domain extent applies to scale', () {
|
||||
LinearScale scale = new LinearScale()..keepViewportWithinData = false;
|
||||
LinearScale scale = LinearScale()..keepViewportWithinData = false;
|
||||
scale.addDomain(50.0);
|
||||
scale.addDomain(70.0);
|
||||
scale.viewportDomain = new NumericExtents(100.0, 200.0);
|
||||
scale.range = new ScaleOutputExtent(0, 200);
|
||||
scale.viewportDomain = NumericExtents(100.0, 200.0);
|
||||
scale.range = ScaleOutputExtent(0, 200);
|
||||
|
||||
expect(scale[200.0], closeTo(200, EPSILON));
|
||||
expect(scale[100.0], closeTo(0, EPSILON));
|
||||
@@ -86,8 +86,8 @@ void main() {
|
||||
scale.resetViewportSettings();
|
||||
scale.addDomain(50.0);
|
||||
scale.addDomain(100.0);
|
||||
scale.viewportDomain = new NumericExtents(0.0, 100.0);
|
||||
scale.range = new ScaleOutputExtent(0, 200);
|
||||
scale.viewportDomain = NumericExtents(0.0, 100.0);
|
||||
scale.range = ScaleOutputExtent(0, 200);
|
||||
|
||||
expect(scale[0.0], closeTo(0, EPSILON));
|
||||
expect(scale[100.0], closeTo(200, EPSILON));
|
||||
@@ -96,12 +96,12 @@ void main() {
|
||||
});
|
||||
|
||||
test('comparing domain and range to viewport handles extent edges', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
scale.range = new ScaleOutputExtent(1000, 1400);
|
||||
scale.domainOverride = new NumericExtents(100.0, 300.0);
|
||||
scale.viewportDomain = new NumericExtents(200.0, 300.0);
|
||||
LinearScale scale = LinearScale();
|
||||
scale.range = ScaleOutputExtent(1000, 1400);
|
||||
scale.domainOverride = NumericExtents(100.0, 300.0);
|
||||
scale.viewportDomain = NumericExtents(200.0, 300.0);
|
||||
|
||||
expect(scale.viewportDomain, equals(new NumericExtents(200.0, 300.0)));
|
||||
expect(scale.viewportDomain, equals(NumericExtents(200.0, 300.0)));
|
||||
|
||||
expect(scale[210.0], closeTo(1040, EPSILON));
|
||||
expect(scale[400.0], closeTo(1800, EPSILON));
|
||||
@@ -120,10 +120,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('scale applies in reverse', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
scale.range = new ScaleOutputExtent(1000, 1400);
|
||||
scale.domainOverride = new NumericExtents(100.0, 300.0);
|
||||
scale.viewportDomain = new NumericExtents(200.0, 300.0);
|
||||
LinearScale scale = LinearScale();
|
||||
scale.range = ScaleOutputExtent(1000, 1400);
|
||||
scale.domainOverride = NumericExtents(100.0, 300.0);
|
||||
scale.viewportDomain = NumericExtents(200.0, 300.0);
|
||||
|
||||
expect(scale.reverse(1040.0), closeTo(210.0, EPSILON));
|
||||
expect(scale.reverse(1800.0), closeTo(400.0, EPSILON));
|
||||
@@ -131,10 +131,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('scale works with a range from larger to smaller', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
scale.range = new ScaleOutputExtent(1400, 1000);
|
||||
scale.domainOverride = new NumericExtents(100.0, 300.0);
|
||||
scale.viewportDomain = new NumericExtents(200.0, 300.0);
|
||||
LinearScale scale = LinearScale();
|
||||
scale.range = ScaleOutputExtent(1400, 1000);
|
||||
scale.domainOverride = NumericExtents(100.0, 300.0);
|
||||
scale.viewportDomain = NumericExtents(200.0, 300.0);
|
||||
|
||||
expect(scale[200.0], closeTo(1400.0, EPSILON));
|
||||
expect(scale[250.0], closeTo(1200.0, EPSILON));
|
||||
@@ -142,9 +142,9 @@ void main() {
|
||||
});
|
||||
|
||||
test('scaleFactor and translate applies to scale', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
scale.range = new ScaleOutputExtent(1000, 1200);
|
||||
scale.domainOverride = new NumericExtents(100.0, 200.0);
|
||||
LinearScale scale = LinearScale();
|
||||
scale.range = ScaleOutputExtent(1000, 1200);
|
||||
scale.domainOverride = NumericExtents(100.0, 200.0);
|
||||
scale.setViewportSettings(4.0, -50.0);
|
||||
|
||||
expect(scale[100.0], closeTo(950.0, EPSILON));
|
||||
@@ -167,8 +167,8 @@ void main() {
|
||||
});
|
||||
|
||||
test('scale handles single point', () {
|
||||
LinearScale domainScale = new LinearScale();
|
||||
domainScale.range = new ScaleOutputExtent(1000, 1200);
|
||||
LinearScale domainScale = LinearScale();
|
||||
domainScale.range = ScaleOutputExtent(1000, 1200);
|
||||
domainScale.addDomain(50.0);
|
||||
|
||||
// A single point should render in the middle of the scale.
|
||||
@@ -176,125 +176,125 @@ void main() {
|
||||
});
|
||||
|
||||
test('testAllZeros', () {
|
||||
LinearScale measureScale = new LinearScale();
|
||||
measureScale.range = new ScaleOutputExtent(1000, 1200);
|
||||
LinearScale measureScale = LinearScale();
|
||||
measureScale.range = ScaleOutputExtent(1000, 1200);
|
||||
measureScale.addDomain(0.0);
|
||||
|
||||
expect(measureScale[0.0], closeTo(1100.0, EPSILON));
|
||||
});
|
||||
|
||||
test('scale calculates step size', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
scale.rangeBandConfig = new RangeBandConfig.percentOfStep(1.0);
|
||||
LinearScale scale = LinearScale();
|
||||
scale.rangeBandConfig = RangeBandConfig.percentOfStep(1.0);
|
||||
scale.addDomain(1.0);
|
||||
scale.addDomain(3.0);
|
||||
scale.addDomain(11.0);
|
||||
scale.range = new ScaleOutputExtent(100, 200);
|
||||
scale.range = ScaleOutputExtent(100, 200);
|
||||
|
||||
// 1 - 11 has 6 steps of size 2, 0 - 12
|
||||
expect(scale.rangeBand, closeTo(100.0 / 6.0, EPSILON));
|
||||
});
|
||||
|
||||
test('scale applies rangeBand to detected step size', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
scale.rangeBandConfig = new RangeBandConfig.percentOfStep(0.5);
|
||||
LinearScale scale = LinearScale();
|
||||
scale.rangeBandConfig = RangeBandConfig.percentOfStep(0.5);
|
||||
scale.addDomain(1.0);
|
||||
scale.addDomain(2.0);
|
||||
scale.addDomain(10.0);
|
||||
scale.range = new ScaleOutputExtent(100, 200);
|
||||
scale.range = ScaleOutputExtent(100, 200);
|
||||
|
||||
// 100 range / 10 steps * 0.5percentStep = 5
|
||||
expect(scale.rangeBand, closeTo(5.0, EPSILON));
|
||||
});
|
||||
|
||||
test('scale stepSize calculation survives copy', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
scale.stepSizeConfig = new StepSizeConfig.fixedDomain(1.0);
|
||||
scale.rangeBandConfig = new RangeBandConfig.percentOfStep(1.0);
|
||||
LinearScale scale = LinearScale();
|
||||
scale.stepSizeConfig = StepSizeConfig.fixedDomain(1.0);
|
||||
scale.rangeBandConfig = RangeBandConfig.percentOfStep(1.0);
|
||||
scale.addDomain(1.0);
|
||||
scale.addDomain(3.0);
|
||||
scale.range = new ScaleOutputExtent(100, 200);
|
||||
scale.range = ScaleOutputExtent(100, 200);
|
||||
expect(scale.copy().rangeBand, closeTo(100.0 / 3.0, EPSILON));
|
||||
});
|
||||
|
||||
test('scale rangeBand calculation survives copy', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
scale.rangeBandConfig = new RangeBandConfig.fixedPixel(123.0);
|
||||
LinearScale scale = LinearScale();
|
||||
scale.rangeBandConfig = RangeBandConfig.fixedPixel(123.0);
|
||||
scale.addDomain(1.0);
|
||||
scale.addDomain(3.0);
|
||||
scale.range = new ScaleOutputExtent(100, 200);
|
||||
scale.range = ScaleOutputExtent(100, 200);
|
||||
|
||||
expect(scale.copy().rangeBand, closeTo(123, EPSILON));
|
||||
});
|
||||
|
||||
test('scale rangeBand works for single domain value', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
scale.rangeBandConfig = new RangeBandConfig.percentOfStep(1.0);
|
||||
LinearScale scale = LinearScale();
|
||||
scale.rangeBandConfig = RangeBandConfig.percentOfStep(1.0);
|
||||
scale.addDomain(1.0);
|
||||
scale.range = new ScaleOutputExtent(100, 200);
|
||||
scale.range = ScaleOutputExtent(100, 200);
|
||||
|
||||
expect(scale.rangeBand, closeTo(100, EPSILON));
|
||||
});
|
||||
|
||||
test('scale rangeBand works for multiple domains of the same value', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
scale.rangeBandConfig = new RangeBandConfig.percentOfStep(1.0);
|
||||
LinearScale scale = LinearScale();
|
||||
scale.rangeBandConfig = RangeBandConfig.percentOfStep(1.0);
|
||||
scale.addDomain(1.0);
|
||||
scale.addDomain(1.0);
|
||||
scale.range = new ScaleOutputExtent(100, 200);
|
||||
scale.range = ScaleOutputExtent(100, 200);
|
||||
|
||||
expect(scale.rangeBand, closeTo(100.0, EPSILON));
|
||||
});
|
||||
|
||||
test('scale rangeBand is zero when no domains are added', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
scale.range = new ScaleOutputExtent(100, 200);
|
||||
LinearScale scale = LinearScale();
|
||||
scale.range = ScaleOutputExtent(100, 200);
|
||||
|
||||
expect(scale.rangeBand, closeTo(0.0, EPSILON));
|
||||
});
|
||||
|
||||
test('scale domain info reset on resetDomain', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
LinearScale scale = LinearScale();
|
||||
scale.addDomain(1.0);
|
||||
scale.addDomain(3.0);
|
||||
scale.range = new ScaleOutputExtent(100, 200);
|
||||
scale.range = ScaleOutputExtent(100, 200);
|
||||
scale.setViewportSettings(1000.0, 2000.0);
|
||||
|
||||
scale.resetDomain();
|
||||
scale.resetViewportSettings();
|
||||
expect(scale.viewportScalingFactor, closeTo(1.0, EPSILON));
|
||||
expect(scale.viewportTranslatePx, closeTo(0, EPSILON));
|
||||
expect(scale.range, equals(new ScaleOutputExtent(100, 200)));
|
||||
expect(scale.range, equals(ScaleOutputExtent(100, 200)));
|
||||
});
|
||||
|
||||
test('scale handles null domain values', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
scale.rangeBandConfig = new RangeBandConfig.percentOfStep(1.0);
|
||||
LinearScale scale = LinearScale();
|
||||
scale.rangeBandConfig = RangeBandConfig.percentOfStep(1.0);
|
||||
scale.addDomain(1.0);
|
||||
scale.addDomain(null);
|
||||
scale.addDomain(3.0);
|
||||
scale.addDomain(11.0);
|
||||
scale.range = new ScaleOutputExtent(100, 200);
|
||||
scale.range = ScaleOutputExtent(100, 200);
|
||||
|
||||
expect(scale.rangeBand, closeTo(100.0 / 6.0, EPSILON));
|
||||
});
|
||||
|
||||
test('scale domainOverride survives copy', () {
|
||||
LinearScale scale = new LinearScale()..keepViewportWithinData = false;
|
||||
LinearScale scale = LinearScale()..keepViewportWithinData = false;
|
||||
scale.addDomain(1.0);
|
||||
scale.addDomain(3.0);
|
||||
scale.range = new ScaleOutputExtent(100, 200);
|
||||
scale.range = ScaleOutputExtent(100, 200);
|
||||
scale.setViewportSettings(2.0, 10.0);
|
||||
scale.domainOverride = new NumericExtents(0.0, 100.0);
|
||||
scale.domainOverride = NumericExtents(0.0, 100.0);
|
||||
|
||||
LinearScale other = scale.copy();
|
||||
|
||||
expect(other.domainOverride, equals(new NumericExtents(0.0, 100.0)));
|
||||
expect(other.domainOverride, equals(NumericExtents(0.0, 100.0)));
|
||||
expect(other[5.0], closeTo(120.0, EPSILON));
|
||||
});
|
||||
|
||||
test('scale calculates a scaleFactor given a domain window', () {
|
||||
LinearScale scale = new LinearScale();
|
||||
LinearScale scale = LinearScale();
|
||||
scale.addDomain(100.0);
|
||||
scale.addDomain(130.0);
|
||||
scale.addDomain(200.0);
|
||||
|
||||
@@ -49,14 +49,14 @@ class FakeDrawStrategy extends BaseTickDrawStrategy<num> {
|
||||
|
||||
FakeDrawStrategy(
|
||||
this.collidesAfterTickCount, this.alternateRenderingAfterTickCount)
|
||||
: super(null, new FakeGraphicsFactory());
|
||||
: super(null, FakeGraphicsFactory());
|
||||
|
||||
@override
|
||||
CollisionReport collides(List<Tick<num>> ticks, _) {
|
||||
final ticksCollide = ticks.length >= collidesAfterTickCount;
|
||||
final alternateTicksUsed = ticks.length >= alternateRenderingAfterTickCount;
|
||||
|
||||
return new CollisionReport(
|
||||
return CollisionReport(
|
||||
ticksCollide: ticksCollide,
|
||||
ticks: ticks,
|
||||
alternateTicksUsed: alternateTicksUsed);
|
||||
@@ -74,13 +74,13 @@ class FakeDrawStrategy extends BaseTickDrawStrategy<num> {
|
||||
/// A fake [GraphicsFactory] that returns [MockTextStyle] and [MockTextElement].
|
||||
class FakeGraphicsFactory extends GraphicsFactory {
|
||||
@override
|
||||
TextStyle createTextPaint() => new MockTextStyle();
|
||||
TextStyle createTextPaint() => MockTextStyle();
|
||||
|
||||
@override
|
||||
TextElement createTextElement(String text) => new MockTextElement();
|
||||
TextElement createTextElement(String text) => MockTextElement();
|
||||
|
||||
@override
|
||||
LineStyle createLinePaint() => new MockLinePaint();
|
||||
LineStyle createLinePaint() => MockLinePaint();
|
||||
}
|
||||
|
||||
class MockTextStyle extends Mock implements TextStyle {}
|
||||
@@ -110,11 +110,11 @@ void main() {
|
||||
ChartContext context;
|
||||
|
||||
setUp(() {
|
||||
graphicsFactory = new FakeGraphicsFactory();
|
||||
scale = new MockNumericScale();
|
||||
tickProvider = new NumericTickProvider();
|
||||
formatter = new NumericTickFormatter();
|
||||
context = new MockChartContext();
|
||||
graphicsFactory = FakeGraphicsFactory();
|
||||
scale = MockNumericScale();
|
||||
tickProvider = NumericTickProvider();
|
||||
formatter = NumericTickFormatter();
|
||||
context = MockChartContext();
|
||||
});
|
||||
|
||||
test('singleTickCount_choosesTicksWithSmallestStepCoveringDomain', () {
|
||||
@@ -123,8 +123,8 @@ void main() {
|
||||
..dataIsInWholeNumbers = false
|
||||
..setFixedTickCount(4)
|
||||
..allowedSteps = [1.0, 2.5, 5.0];
|
||||
final drawStrategy = new FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(10.0, 70.0));
|
||||
final drawStrategy = FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(10.0, 70.0));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
@@ -151,8 +151,8 @@ void main() {
|
||||
..dataIsInWholeNumbers = false
|
||||
..setTickCount(5, 3)
|
||||
..allowedSteps = [1.0, 2.5, 5.0];
|
||||
final drawStrategy = new FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(10.0, 80.0));
|
||||
final drawStrategy = FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(10.0, 80.0));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
@@ -178,8 +178,8 @@ void main() {
|
||||
..dataIsInWholeNumbers = false
|
||||
..setTickCount(5, 3)
|
||||
..allowedSteps = [1.0, 2.5, 6.0];
|
||||
final drawStrategy = new FakeDrawStrategy(10, 5);
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(10.0, 80.0));
|
||||
final drawStrategy = FakeDrawStrategy(10, 5);
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(10.0, 80.0));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
@@ -203,8 +203,8 @@ void main() {
|
||||
..dataIsInWholeNumbers = false
|
||||
..setTickCount(5, 3)
|
||||
..allowedSteps = [1.0, 2.5, 6.0];
|
||||
final drawStrategy = new FakeDrawStrategy(5, 5);
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(10.0, 80.0));
|
||||
final drawStrategy = FakeDrawStrategy(5, 5);
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(10.0, 80.0));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
@@ -228,8 +228,8 @@ void main() {
|
||||
..dataIsInWholeNumbers = false
|
||||
..setFixedTickCount(3)
|
||||
..allowedSteps = [1.0, 2.5, 5.0];
|
||||
final drawStrategy = new FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(55.0, 135.0));
|
||||
final drawStrategy = FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(55.0, 135.0));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
@@ -252,8 +252,8 @@ void main() {
|
||||
..dataIsInWholeNumbers = false
|
||||
..setFixedTickCount(3)
|
||||
..allowedSteps = [1.0, 2.5, 5.0];
|
||||
final drawStrategy = new FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(-55.0, 135.0));
|
||||
final drawStrategy = FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(-55.0, 135.0));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
@@ -271,8 +271,8 @@ void main() {
|
||||
});
|
||||
|
||||
test('boundsCrossOrigin_returnsValidTickRange', () {
|
||||
final drawStrategy = new FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(-55.0, 135.0));
|
||||
final drawStrategy = FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(-55.0, 135.0));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
@@ -297,9 +297,9 @@ void main() {
|
||||
..dataIsInWholeNumbers = true
|
||||
..setFixedTickCount(3)
|
||||
..allowedSteps = [1.0, 2.5, 5.0];
|
||||
final drawStrategy = new FakeDrawStrategy(10, 10);
|
||||
final drawStrategy = FakeDrawStrategy(10, 10);
|
||||
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(0.25, 0.75));
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(0.25, 0.75));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
@@ -324,9 +324,9 @@ void main() {
|
||||
..allowedSteps = [5.0]
|
||||
..dataToAxisUnitConverter = const CelsiusToFahrenheitConverter();
|
||||
|
||||
final drawStrategy = new FakeDrawStrategy(10, 10);
|
||||
final drawStrategy = FakeDrawStrategy(10, 10);
|
||||
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(0.0, 20.0));
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(0.0, 20.0));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
@@ -349,10 +349,9 @@ void main() {
|
||||
..dataIsInWholeNumbers = false
|
||||
..setFixedTickCount(5);
|
||||
|
||||
final drawStrategy = new FakeDrawStrategy(10, 10);
|
||||
final drawStrategy = FakeDrawStrategy(10, 10);
|
||||
|
||||
when(scale.viewportDomain)
|
||||
.thenReturn(new NumericExtents(0.000001, 0.000002));
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(0.000001, 0.000002));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
@@ -378,10 +377,9 @@ void main() {
|
||||
..dataIsInWholeNumbers = true
|
||||
..setFixedTickCount(5);
|
||||
|
||||
final drawStrategy = new FakeDrawStrategy(10, 10);
|
||||
final drawStrategy = FakeDrawStrategy(10, 10);
|
||||
|
||||
when(scale.viewportDomain)
|
||||
.thenReturn(new NumericExtents(0.000001, 0.000002));
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(0.000001, 0.000002));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
@@ -407,10 +405,10 @@ void main() {
|
||||
..dataIsInWholeNumbers = true
|
||||
..setFixedTickCount(5);
|
||||
|
||||
final drawStrategy = new FakeDrawStrategy(10, 10);
|
||||
final drawStrategy = FakeDrawStrategy(10, 10);
|
||||
|
||||
when(scale.viewportDomain)
|
||||
.thenReturn(new NumericExtents(101.000001, 101.000002));
|
||||
.thenReturn(NumericExtents(101.000001, 101.000002));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
@@ -431,15 +429,15 @@ void main() {
|
||||
});
|
||||
|
||||
test('handles tick hint for non zero ticks', () {
|
||||
final drawStrategy = new FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(20.0, 35.0));
|
||||
final drawStrategy = FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(20.0, 35.0));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
// Step Size: 3,
|
||||
// Previous start tick: 10
|
||||
// Previous window: 10 - 25
|
||||
// Previous ticks: 10, 13, 16, 19, 22, 25
|
||||
final tickHint = new TickHint(10, 25, tickCount: 6);
|
||||
final tickHint = TickHint(10, 25, tickCount: 6);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
context: context,
|
||||
@@ -464,15 +462,15 @@ void main() {
|
||||
});
|
||||
|
||||
test('handles tick hint for negative starting ticks', () {
|
||||
final drawStrategy = new FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(new NumericExtents(-35.0, -20.0));
|
||||
final drawStrategy = FakeDrawStrategy(10, 10);
|
||||
when(scale.viewportDomain).thenReturn(NumericExtents(-35.0, -20.0));
|
||||
when(scale.rangeWidth).thenReturn(1000);
|
||||
|
||||
// Step Size: 3,
|
||||
// Previous start tick: -25
|
||||
// Previous window: -25 to -10
|
||||
// Previous ticks: -25, -22, -19, -16, -13, -10
|
||||
final tickHint = new TickHint(-25, -10, tickCount: 6);
|
||||
final tickHint = TickHint(-25, -10, tickCount: 6);
|
||||
|
||||
final ticks = tickProvider.getTicks(
|
||||
context: context,
|
||||
|
||||
@@ -24,13 +24,13 @@ void main() {
|
||||
SimpleOrdinalScale scale;
|
||||
|
||||
setUp(() {
|
||||
scale = new SimpleOrdinalScale();
|
||||
scale = SimpleOrdinalScale();
|
||||
scale.addDomain('a');
|
||||
scale.addDomain('b');
|
||||
scale.addDomain('c');
|
||||
scale.addDomain('d');
|
||||
|
||||
scale.range = new ScaleOutputExtent(2000, 1000);
|
||||
scale.range = ScaleOutputExtent(2000, 1000);
|
||||
});
|
||||
|
||||
group('conversion', () {
|
||||
@@ -81,7 +81,7 @@ void main() {
|
||||
|
||||
group('set RangeBandConfig', () {
|
||||
test('fixed pixel range band changes range band', () {
|
||||
scale.rangeBandConfig = new RangeBandConfig.fixedPixel(123.0);
|
||||
scale.rangeBandConfig = RangeBandConfig.fixedPixel(123.0);
|
||||
|
||||
expect(scale.rangeBand, closeTo(123.0, EPSILON));
|
||||
|
||||
@@ -91,25 +91,24 @@ void main() {
|
||||
});
|
||||
|
||||
test('percent range band changes range band', () {
|
||||
scale.rangeBandConfig = new RangeBandConfig.percentOfStep(0.5);
|
||||
scale.rangeBandConfig = RangeBandConfig.percentOfStep(0.5);
|
||||
// 125 = 0.5f * 1000pixels / 4domains
|
||||
expect(scale.rangeBand, closeTo(125.0, EPSILON));
|
||||
});
|
||||
|
||||
test('space from step changes range band', () {
|
||||
scale.rangeBandConfig =
|
||||
new RangeBandConfig.fixedPixelSpaceBetweenStep(50.0);
|
||||
scale.rangeBandConfig = RangeBandConfig.fixedPixelSpaceBetweenStep(50.0);
|
||||
// 200 = 1000pixels / 4domains) - 50
|
||||
expect(scale.rangeBand, closeTo(200.0, EPSILON));
|
||||
});
|
||||
|
||||
test('fixed domain throws argument exception', () {
|
||||
expect(() => scale.rangeBandConfig = new RangeBandConfig.fixedDomain(5.0),
|
||||
expect(() => scale.rangeBandConfig = RangeBandConfig.fixedDomain(5.0),
|
||||
throwsArgumentError);
|
||||
});
|
||||
|
||||
test('type of none throws argument exception', () {
|
||||
expect(() => scale.rangeBandConfig = new RangeBandConfig.none(),
|
||||
expect(() => scale.rangeBandConfig = RangeBandConfig.none(),
|
||||
throwsArgumentError);
|
||||
});
|
||||
|
||||
@@ -124,16 +123,16 @@ void main() {
|
||||
});
|
||||
|
||||
test('to auto does not throw', () {
|
||||
scale.stepSizeConfig = new StepSizeConfig.auto();
|
||||
scale.stepSizeConfig = StepSizeConfig.auto();
|
||||
});
|
||||
|
||||
test('to fixed domain throw arugment exception', () {
|
||||
expect(() => scale.stepSizeConfig = new StepSizeConfig.fixedDomain(1.0),
|
||||
expect(() => scale.stepSizeConfig = StepSizeConfig.fixedDomain(1.0),
|
||||
throwsArgumentError);
|
||||
});
|
||||
|
||||
test('to fixed pixel throw arugment exception', () {
|
||||
expect(() => scale.stepSizeConfig = new StepSizeConfig.fixedPixels(1.0),
|
||||
expect(() => scale.stepSizeConfig = StepSizeConfig.fixedPixels(1.0),
|
||||
throwsArgumentError);
|
||||
});
|
||||
});
|
||||
@@ -165,15 +164,15 @@ void main() {
|
||||
|
||||
test('rangeband is scaled', () {
|
||||
scale.setViewportSettings(2.0, -700.0);
|
||||
scale.rangeBandConfig = new RangeBandConfig.percentOfStep(1.0);
|
||||
scale.rangeBandConfig = RangeBandConfig.percentOfStep(1.0);
|
||||
|
||||
expect(scale.rangeBand, closeTo(500.0, EPSILON));
|
||||
});
|
||||
|
||||
test('translate to pixels is scaled', () {
|
||||
scale.setViewportSettings(2.0, -700.0);
|
||||
scale.rangeBandConfig = new RangeBandConfig.percentOfStep(1.0);
|
||||
scale.range = new ScaleOutputExtent(1000, 2000);
|
||||
scale.rangeBandConfig = RangeBandConfig.percentOfStep(1.0);
|
||||
scale.range = ScaleOutputExtent(1000, 2000);
|
||||
|
||||
final scaledStepWidth = 500.0;
|
||||
final scaledInitialShift = 250.0;
|
||||
@@ -186,8 +185,8 @@ void main() {
|
||||
|
||||
test('only b and c should be within the viewport', () {
|
||||
scale.setViewportSettings(2.0, -700.0);
|
||||
scale.rangeBandConfig = new RangeBandConfig.percentOfStep(1.0);
|
||||
scale.range = new ScaleOutputExtent(1000, 2000);
|
||||
scale.rangeBandConfig = RangeBandConfig.percentOfStep(1.0);
|
||||
scale.range = ScaleOutputExtent(1000, 2000);
|
||||
|
||||
expect(scale.compareDomainValueToViewport('a'), equals(-1));
|
||||
expect(scale.compareDomainValueToViewport('c'), equals(0));
|
||||
@@ -198,8 +197,8 @@ void main() {
|
||||
|
||||
group('viewport', () {
|
||||
test('set adjust scale to show viewport', () {
|
||||
scale.range = new ScaleOutputExtent(1000, 2000);
|
||||
scale.rangeBandConfig = new RangeBandConfig.percentOfStep(0.5);
|
||||
scale.range = ScaleOutputExtent(1000, 2000);
|
||||
scale.rangeBandConfig = RangeBandConfig.percentOfStep(0.5);
|
||||
scale.setViewport(2, 'b');
|
||||
|
||||
expect(scale['a'], closeTo(750, EPSILON));
|
||||
@@ -217,8 +216,8 @@ void main() {
|
||||
});
|
||||
|
||||
test('set starting value if starting domain is not in domain list', () {
|
||||
scale.range = new ScaleOutputExtent(1000, 2000);
|
||||
scale.rangeBandConfig = new RangeBandConfig.percentOfStep(0.5);
|
||||
scale.range = ScaleOutputExtent(1000, 2000);
|
||||
scale.rangeBandConfig = RangeBandConfig.percentOfStep(0.5);
|
||||
scale.setViewport(2, 'f');
|
||||
|
||||
expect(scale['a'], closeTo(1250, EPSILON));
|
||||
@@ -228,7 +227,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('get size returns number of full steps that fit scale range', () {
|
||||
scale.range = new ScaleOutputExtent(1000, 2000);
|
||||
scale.range = ScaleOutputExtent(1000, 2000);
|
||||
|
||||
scale.setViewportSettings(2.0, 0.0);
|
||||
expect(scale.viewportDataSize, equals(2));
|
||||
@@ -238,7 +237,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('get starting viewport gets first fully visible domain', () {
|
||||
scale.range = new ScaleOutputExtent(1000, 2000);
|
||||
scale.range = ScaleOutputExtent(1000, 2000);
|
||||
|
||||
scale.setViewportSettings(2.0, -500.0);
|
||||
expect(scale.viewportStartingDomain, equals('b'));
|
||||
|
||||
@@ -52,19 +52,19 @@ void main() {
|
||||
LinearScale scale;
|
||||
|
||||
setUp(() {
|
||||
context = new MockChartContext();
|
||||
graphicsFactory = new MockGraphicsFactory();
|
||||
formatter = new MockNumericTickFormatter();
|
||||
drawStrategy = new MockDrawStrategy();
|
||||
scale = new LinearScale()..range = new ScaleOutputExtent(0, 300);
|
||||
context = MockChartContext();
|
||||
graphicsFactory = MockGraphicsFactory();
|
||||
formatter = MockNumericTickFormatter();
|
||||
drawStrategy = MockDrawStrategy();
|
||||
scale = LinearScale()..range = ScaleOutputExtent(0, 300);
|
||||
});
|
||||
|
||||
group('scale is extended with static tick values', () {
|
||||
test('values extend existing domain values', () {
|
||||
final tickProvider = new StaticTickProvider<num>([
|
||||
new TickSpec<num>(50, label: '50'),
|
||||
new TickSpec<num>(75, label: '75'),
|
||||
new TickSpec<num>(100, label: '100'),
|
||||
final tickProvider = StaticTickProvider<num>([
|
||||
TickSpec<num>(50, label: '50'),
|
||||
TickSpec<num>(75, label: '75'),
|
||||
TickSpec<num>(100, label: '100'),
|
||||
]);
|
||||
|
||||
scale.addDomain(60);
|
||||
@@ -87,10 +87,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('values within data extent', () {
|
||||
final tickProvider = new StaticTickProvider<num>([
|
||||
new TickSpec<num>(50, label: '50'),
|
||||
new TickSpec<num>(75, label: '75'),
|
||||
new TickSpec<num>(100, label: '100'),
|
||||
final tickProvider = StaticTickProvider<num>([
|
||||
TickSpec<num>(50, label: '50'),
|
||||
TickSpec<num>(75, label: '75'),
|
||||
TickSpec<num>(100, label: '100'),
|
||||
]);
|
||||
|
||||
scale.addDomain(0);
|
||||
@@ -115,13 +115,13 @@ void main() {
|
||||
|
||||
group('formatter', () {
|
||||
test('is not called when all ticks have labels', () {
|
||||
final tickProvider = new StaticTickProvider<num>([
|
||||
new TickSpec<num>(50, label: '50'),
|
||||
new TickSpec<num>(75, label: '75'),
|
||||
new TickSpec<num>(100, label: '100'),
|
||||
final tickProvider = StaticTickProvider<num>([
|
||||
TickSpec<num>(50, label: '50'),
|
||||
TickSpec<num>(75, label: '75'),
|
||||
TickSpec<num>(100, label: '100'),
|
||||
]);
|
||||
|
||||
final fakeFormatter = new FakeNumericTickFormatter();
|
||||
final fakeFormatter = FakeNumericTickFormatter();
|
||||
|
||||
tickProvider.getTicks(
|
||||
context: context,
|
||||
@@ -136,13 +136,13 @@ void main() {
|
||||
});
|
||||
|
||||
test('is called when one ticks does not have label', () {
|
||||
final tickProvider = new StaticTickProvider<num>([
|
||||
new TickSpec<num>(50, label: '50'),
|
||||
new TickSpec<num>(75),
|
||||
new TickSpec<num>(100, label: '100'),
|
||||
final tickProvider = StaticTickProvider<num>([
|
||||
TickSpec<num>(50, label: '50'),
|
||||
TickSpec<num>(75),
|
||||
TickSpec<num>(100, label: '100'),
|
||||
]);
|
||||
|
||||
final fakeFormatter = new FakeNumericTickFormatter();
|
||||
final fakeFormatter = FakeNumericTickFormatter();
|
||||
|
||||
tickProvider.getTicks(
|
||||
context: context,
|
||||
@@ -157,13 +157,13 @@ void main() {
|
||||
});
|
||||
|
||||
test('is called when all ticks do not have labels', () {
|
||||
final tickProvider = new StaticTickProvider<num>([
|
||||
new TickSpec<num>(50),
|
||||
new TickSpec<num>(75),
|
||||
new TickSpec<num>(100),
|
||||
final tickProvider = StaticTickProvider<num>([
|
||||
TickSpec<num>(50),
|
||||
TickSpec<num>(75),
|
||||
TickSpec<num>(100),
|
||||
]);
|
||||
|
||||
final fakeFormatter = new FakeNumericTickFormatter();
|
||||
final fakeFormatter = FakeNumericTickFormatter();
|
||||
|
||||
tickProvider.getTicks(
|
||||
context: context,
|
||||
|
||||
@@ -19,7 +19,8 @@ import 'package:test/test.dart';
|
||||
|
||||
const EPSILON = 0.001;
|
||||
|
||||
typedef bool IsTransitionFunction(DateTime tickValue, DateTime prevTickValue);
|
||||
typedef IsTransitionFunction = bool Function(
|
||||
DateTime tickValue, DateTime prevTickValue);
|
||||
|
||||
class FakeTimeTickFormatter implements TimeTickFormatter {
|
||||
static const firstTick = '-firstTick-';
|
||||
@@ -56,41 +57,41 @@ void main() {
|
||||
TimeTickFormatter timeFormatter3;
|
||||
|
||||
setUp(() {
|
||||
timeFormatter1 = new FakeTimeTickFormatter('fake1');
|
||||
timeFormatter2 = new FakeTimeTickFormatter('fake2');
|
||||
timeFormatter3 = new FakeTimeTickFormatter('fake3');
|
||||
timeFormatter1 = FakeTimeTickFormatter('fake1');
|
||||
timeFormatter2 = FakeTimeTickFormatter('fake2');
|
||||
timeFormatter3 = FakeTimeTickFormatter('fake3');
|
||||
});
|
||||
|
||||
group('Uses formatter', () {
|
||||
test('with largest interval less than diff between tickValues', () {
|
||||
final formatter = new DateTimeTickFormatter.withFormatters(
|
||||
final formatter = DateTimeTickFormatter.withFormatters(
|
||||
{10: timeFormatter1, 100: timeFormatter2, 1000: timeFormatter3});
|
||||
final formatterCache = <DateTime, String>{};
|
||||
|
||||
final ticksWith10Diff = [
|
||||
new DateTime.fromMillisecondsSinceEpoch(0),
|
||||
new DateTime.fromMillisecondsSinceEpoch(10),
|
||||
new DateTime.fromMillisecondsSinceEpoch(20)
|
||||
DateTime.fromMillisecondsSinceEpoch(0),
|
||||
DateTime.fromMillisecondsSinceEpoch(10),
|
||||
DateTime.fromMillisecondsSinceEpoch(20)
|
||||
];
|
||||
final ticksWith20Diff = [
|
||||
new DateTime.fromMillisecondsSinceEpoch(0),
|
||||
new DateTime.fromMillisecondsSinceEpoch(20),
|
||||
new DateTime.fromMillisecondsSinceEpoch(40)
|
||||
DateTime.fromMillisecondsSinceEpoch(0),
|
||||
DateTime.fromMillisecondsSinceEpoch(20),
|
||||
DateTime.fromMillisecondsSinceEpoch(40)
|
||||
];
|
||||
final ticksWith100Diff = [
|
||||
new DateTime.fromMillisecondsSinceEpoch(0),
|
||||
new DateTime.fromMillisecondsSinceEpoch(100),
|
||||
new DateTime.fromMillisecondsSinceEpoch(200)
|
||||
DateTime.fromMillisecondsSinceEpoch(0),
|
||||
DateTime.fromMillisecondsSinceEpoch(100),
|
||||
DateTime.fromMillisecondsSinceEpoch(200)
|
||||
];
|
||||
final ticksWith200Diff = [
|
||||
new DateTime.fromMillisecondsSinceEpoch(0),
|
||||
new DateTime.fromMillisecondsSinceEpoch(200),
|
||||
new DateTime.fromMillisecondsSinceEpoch(400)
|
||||
DateTime.fromMillisecondsSinceEpoch(0),
|
||||
DateTime.fromMillisecondsSinceEpoch(200),
|
||||
DateTime.fromMillisecondsSinceEpoch(400)
|
||||
];
|
||||
final ticksWith1000Diff = [
|
||||
new DateTime.fromMillisecondsSinceEpoch(0),
|
||||
new DateTime.fromMillisecondsSinceEpoch(1000),
|
||||
new DateTime.fromMillisecondsSinceEpoch(2000)
|
||||
DateTime.fromMillisecondsSinceEpoch(0),
|
||||
DateTime.fromMillisecondsSinceEpoch(1000),
|
||||
DateTime.fromMillisecondsSinceEpoch(2000)
|
||||
];
|
||||
|
||||
final expectedLabels10Diff = [
|
||||
@@ -139,14 +140,14 @@ void main() {
|
||||
});
|
||||
|
||||
test('with smallest interval when no smaller one exists', () {
|
||||
final formatter = new DateTimeTickFormatter.withFormatters(
|
||||
final formatter = DateTimeTickFormatter.withFormatters(
|
||||
{10: timeFormatter1, 100: timeFormatter2});
|
||||
final formatterCache = <DateTime, String>{};
|
||||
|
||||
final ticks = [
|
||||
new DateTime.fromMillisecondsSinceEpoch(0),
|
||||
new DateTime.fromMillisecondsSinceEpoch(1),
|
||||
new DateTime.fromMillisecondsSinceEpoch(2)
|
||||
DateTime.fromMillisecondsSinceEpoch(0),
|
||||
DateTime.fromMillisecondsSinceEpoch(1),
|
||||
DateTime.fromMillisecondsSinceEpoch(2)
|
||||
];
|
||||
final expectedLabels = [
|
||||
'fake1-firstTick-0',
|
||||
@@ -159,11 +160,11 @@ void main() {
|
||||
});
|
||||
|
||||
test('with smallest interval for single tick input', () {
|
||||
final formatter = new DateTimeTickFormatter.withFormatters(
|
||||
final formatter = DateTimeTickFormatter.withFormatters(
|
||||
{10: timeFormatter1, 100: timeFormatter2});
|
||||
final formatterCache = <DateTime, String>{};
|
||||
|
||||
final ticks = [new DateTime.fromMillisecondsSinceEpoch(5000)];
|
||||
final ticks = [DateTime.fromMillisecondsSinceEpoch(5000)];
|
||||
final expectedLabels = ['fake1-firstTick-5000'];
|
||||
final actualLabels = formatter.format(ticks, formatterCache, stepSize: 0);
|
||||
expect(actualLabels, equals(expectedLabels));
|
||||
@@ -171,7 +172,7 @@ void main() {
|
||||
|
||||
test('on empty input doesnt break', () {
|
||||
final formatter =
|
||||
new DateTimeTickFormatter.withFormatters({10: timeFormatter1});
|
||||
DateTimeTickFormatter.withFormatters({10: timeFormatter1});
|
||||
final formatterCache = <DateTime, String>{};
|
||||
|
||||
final actualLabels =
|
||||
@@ -180,19 +181,19 @@ void main() {
|
||||
});
|
||||
|
||||
test('that formats transition tick with transition format', () {
|
||||
final timeFormatter = new FakeTimeTickFormatter('fake',
|
||||
isTransitionFunction: (DateTime tickValue, _) =>
|
||||
final timeFormatter = FakeTimeTickFormatter('fake',
|
||||
isTransitionFunction: (tickValue, _) =>
|
||||
tickValue.millisecondsSinceEpoch == 20);
|
||||
final formatterCache = <DateTime, String>{};
|
||||
|
||||
final formatter =
|
||||
new DateTimeTickFormatter.withFormatters({10: timeFormatter});
|
||||
DateTimeTickFormatter.withFormatters({10: timeFormatter});
|
||||
|
||||
final ticks = [
|
||||
new DateTime.fromMillisecondsSinceEpoch(0),
|
||||
new DateTime.fromMillisecondsSinceEpoch(10),
|
||||
new DateTime.fromMillisecondsSinceEpoch(20),
|
||||
new DateTime.fromMillisecondsSinceEpoch(30)
|
||||
DateTime.fromMillisecondsSinceEpoch(0),
|
||||
DateTime.fromMillisecondsSinceEpoch(10),
|
||||
DateTime.fromMillisecondsSinceEpoch(20),
|
||||
DateTime.fromMillisecondsSinceEpoch(30)
|
||||
];
|
||||
|
||||
final expectedLabels = [
|
||||
@@ -212,21 +213,21 @@ void main() {
|
||||
test('throws arugment error if time resolution key is not positive', () {
|
||||
// -1 is reserved for any, if there is only one formatter, -1 is allowed.
|
||||
expect(
|
||||
() => new DateTimeTickFormatter.withFormatters(
|
||||
() => DateTimeTickFormatter.withFormatters(
|
||||
{-1: timeFormatter1, 2: timeFormatter2}),
|
||||
throwsArgumentError);
|
||||
});
|
||||
|
||||
test('throws argument error if formatters is null or empty', () {
|
||||
expect(() => new DateTimeTickFormatter.withFormatters(null),
|
||||
throwsArgumentError);
|
||||
expect(() => new DateTimeTickFormatter.withFormatters({}),
|
||||
expect(() => DateTimeTickFormatter.withFormatters(null),
|
||||
throwsArgumentError);
|
||||
expect(
|
||||
() => DateTimeTickFormatter.withFormatters({}), throwsArgumentError);
|
||||
});
|
||||
|
||||
test('throws arugment error if formatters are not sorted', () {
|
||||
expect(
|
||||
() => new DateTimeTickFormatter.withFormatters({
|
||||
() => DateTimeTickFormatter.withFormatters({
|
||||
3: timeFormatter1,
|
||||
1: timeFormatter2,
|
||||
2: timeFormatter3,
|
||||
@@ -234,7 +235,7 @@ void main() {
|
||||
throwsArgumentError);
|
||||
|
||||
expect(
|
||||
() => new DateTimeTickFormatter.withFormatters({
|
||||
() => DateTimeTickFormatter.withFormatters({
|
||||
1: timeFormatter1,
|
||||
3: timeFormatter2,
|
||||
2: timeFormatter3,
|
||||
@@ -242,7 +243,7 @@ void main() {
|
||||
throwsArgumentError);
|
||||
|
||||
expect(
|
||||
() => new DateTimeTickFormatter.withFormatters({
|
||||
() => DateTimeTickFormatter.withFormatters({
|
||||
2: timeFormatter1,
|
||||
3: timeFormatter2,
|
||||
1: timeFormatter3,
|
||||
|
||||
@@ -23,7 +23,7 @@ class SimpleDateTimeFactory implements DateTimeFactory {
|
||||
@override
|
||||
DateTime createDateTimeFromMilliSecondsSinceEpoch(
|
||||
int millisecondsSinceEpoch) =>
|
||||
new DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch);
|
||||
DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch);
|
||||
|
||||
@override
|
||||
DateTime createDateTime(int year,
|
||||
@@ -34,9 +34,9 @@ class SimpleDateTimeFactory implements DateTimeFactory {
|
||||
int second = 0,
|
||||
int millisecond = 0,
|
||||
int microsecond = 0]) =>
|
||||
new DateTime(
|
||||
DateTime(
|
||||
year, month, day, hour, minute, second, millisecond, microsecond);
|
||||
|
||||
@override
|
||||
DateFormat createDateFormat(String pattern) => new DateFormat(pattern);
|
||||
DateFormat createDateFormat(String pattern) => DateFormat(pattern);
|
||||
}
|
||||
|
||||
@@ -25,16 +25,16 @@ import 'simple_date_time_factory.dart' show SimpleDateTimeFactory;
|
||||
const EPSILON = 0.001;
|
||||
|
||||
void main() {
|
||||
const dateTimeFactory = const SimpleDateTimeFactory();
|
||||
const dateTimeFactory = SimpleDateTimeFactory();
|
||||
const millisecondsInHour = 3600 * 1000;
|
||||
|
||||
setUp(() {});
|
||||
|
||||
group('Day time stepper', () {
|
||||
test('get steps with 1 day increments', () {
|
||||
final stepper = new DayTimeStepper(dateTimeFactory);
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 8, 20), end: new DateTime(2017, 8, 25));
|
||||
final stepper = DayTimeStepper(dateTimeFactory);
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 8, 20), end: DateTime(2017, 8, 25));
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(1);
|
||||
final steps = stepIterable.toList();
|
||||
|
||||
@@ -42,20 +42,20 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 8, 20),
|
||||
new DateTime(2017, 8, 21),
|
||||
new DateTime(2017, 8, 22),
|
||||
new DateTime(2017, 8, 23),
|
||||
new DateTime(2017, 8, 24),
|
||||
new DateTime(2017, 8, 25),
|
||||
DateTime(2017, 8, 20),
|
||||
DateTime(2017, 8, 21),
|
||||
DateTime(2017, 8, 22),
|
||||
DateTime(2017, 8, 23),
|
||||
DateTime(2017, 8, 24),
|
||||
DateTime(2017, 8, 25),
|
||||
]));
|
||||
});
|
||||
|
||||
test('get steps with 5 day increments', () {
|
||||
final stepper = new DayTimeStepper(dateTimeFactory);
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 8, 10),
|
||||
end: new DateTime(2017, 8, 26),
|
||||
final stepper = DayTimeStepper(dateTimeFactory);
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 8, 10),
|
||||
end: DateTime(2017, 8, 26),
|
||||
);
|
||||
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(5);
|
||||
@@ -66,19 +66,19 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 8, 11),
|
||||
new DateTime(2017, 8, 16),
|
||||
new DateTime(2017, 8, 21),
|
||||
new DateTime(2017, 8, 26),
|
||||
DateTime(2017, 8, 11),
|
||||
DateTime(2017, 8, 16),
|
||||
DateTime(2017, 8, 21),
|
||||
DateTime(2017, 8, 26),
|
||||
]));
|
||||
});
|
||||
|
||||
test('step through daylight saving forward change', () {
|
||||
final stepper = new DayTimeStepper(dateTimeFactory);
|
||||
final stepper = DayTimeStepper(dateTimeFactory);
|
||||
// DST for PST 2017 begin on March 12
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 3, 11),
|
||||
end: new DateTime(2017, 3, 13),
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 3, 11),
|
||||
end: DateTime(2017, 3, 13),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(1);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -87,18 +87,18 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 3, 11),
|
||||
new DateTime(2017, 3, 12),
|
||||
new DateTime(2017, 3, 13),
|
||||
DateTime(2017, 3, 11),
|
||||
DateTime(2017, 3, 12),
|
||||
DateTime(2017, 3, 13),
|
||||
]));
|
||||
});
|
||||
|
||||
test('step through daylight saving backward change', () {
|
||||
final stepper = new DayTimeStepper(dateTimeFactory);
|
||||
final stepper = DayTimeStepper(dateTimeFactory);
|
||||
// DST for PST 2017 end on November 5
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 11, 4),
|
||||
end: new DateTime(2017, 11, 6),
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 11, 4),
|
||||
end: DateTime(2017, 11, 6),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(1);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -107,19 +107,19 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 11, 4),
|
||||
new DateTime(2017, 11, 5),
|
||||
new DateTime(2017, 11, 6),
|
||||
DateTime(2017, 11, 4),
|
||||
DateTime(2017, 11, 5),
|
||||
DateTime(2017, 11, 6),
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
||||
group('Hour time stepper', () {
|
||||
test('gets steps in 1 hour increments', () {
|
||||
final stepper = new HourTimeStepper(dateTimeFactory);
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 8, 20, 10),
|
||||
end: new DateTime(2017, 8, 20, 15),
|
||||
final stepper = HourTimeStepper(dateTimeFactory);
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 8, 20, 10),
|
||||
end: DateTime(2017, 8, 20, 15),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(1);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -128,20 +128,20 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 8, 20, 10),
|
||||
new DateTime(2017, 8, 20, 11),
|
||||
new DateTime(2017, 8, 20, 12),
|
||||
new DateTime(2017, 8, 20, 13),
|
||||
new DateTime(2017, 8, 20, 14),
|
||||
new DateTime(2017, 8, 20, 15),
|
||||
DateTime(2017, 8, 20, 10),
|
||||
DateTime(2017, 8, 20, 11),
|
||||
DateTime(2017, 8, 20, 12),
|
||||
DateTime(2017, 8, 20, 13),
|
||||
DateTime(2017, 8, 20, 14),
|
||||
DateTime(2017, 8, 20, 15),
|
||||
]));
|
||||
});
|
||||
|
||||
test('gets steps in 4 hour increments', () {
|
||||
final stepper = new HourTimeStepper(dateTimeFactory);
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 8, 20, 10),
|
||||
end: new DateTime(2017, 8, 21, 10),
|
||||
final stepper = HourTimeStepper(dateTimeFactory);
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 8, 20, 10),
|
||||
end: DateTime(2017, 8, 21, 10),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(4);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -150,22 +150,22 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 8, 20, 12),
|
||||
new DateTime(2017, 8, 20, 16),
|
||||
new DateTime(2017, 8, 20, 20),
|
||||
new DateTime(2017, 8, 21, 0),
|
||||
new DateTime(2017, 8, 21, 4),
|
||||
new DateTime(2017, 8, 21, 8),
|
||||
DateTime(2017, 8, 20, 12),
|
||||
DateTime(2017, 8, 20, 16),
|
||||
DateTime(2017, 8, 20, 20),
|
||||
DateTime(2017, 8, 21, 0),
|
||||
DateTime(2017, 8, 21, 4),
|
||||
DateTime(2017, 8, 21, 8),
|
||||
]));
|
||||
});
|
||||
|
||||
test('step through daylight saving forward change in 1 hour increments',
|
||||
() {
|
||||
final stepper = new HourTimeStepper(dateTimeFactory);
|
||||
final stepper = HourTimeStepper(dateTimeFactory);
|
||||
// DST for PST 2017 begin on March 12. At 2am clocks are turned to 3am.
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 3, 12, 0),
|
||||
end: new DateTime(2017, 3, 12, 5),
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 3, 12, 0),
|
||||
end: DateTime(2017, 3, 12, 5),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(1);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -174,21 +174,21 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 3, 12, 0),
|
||||
new DateTime(2017, 3, 12, 1),
|
||||
new DateTime(2017, 3, 12, 3),
|
||||
new DateTime(2017, 3, 12, 4),
|
||||
new DateTime(2017, 3, 12, 5),
|
||||
DateTime(2017, 3, 12, 0),
|
||||
DateTime(2017, 3, 12, 1),
|
||||
DateTime(2017, 3, 12, 3),
|
||||
DateTime(2017, 3, 12, 4),
|
||||
DateTime(2017, 3, 12, 5),
|
||||
]));
|
||||
});
|
||||
|
||||
test('step through daylight saving backward change in 1 hour increments',
|
||||
() {
|
||||
final stepper = new HourTimeStepper(dateTimeFactory);
|
||||
final stepper = HourTimeStepper(dateTimeFactory);
|
||||
// DST for PST 2017 end on November 5. At 2am, clocks are turned to 1am.
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 11, 5, 0),
|
||||
end: new DateTime(2017, 11, 5, 4),
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 11, 5, 0),
|
||||
end: DateTime(2017, 11, 5, 4),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(1);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -197,24 +197,24 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 11, 5, 0),
|
||||
new DateTime(2017, 11, 5, 0)
|
||||
.add(new Duration(milliseconds: millisecondsInHour)),
|
||||
new DateTime(2017, 11, 5, 0)
|
||||
.add(new Duration(milliseconds: millisecondsInHour * 2)),
|
||||
new DateTime(2017, 11, 5, 2),
|
||||
new DateTime(2017, 11, 5, 3),
|
||||
new DateTime(2017, 11, 5, 4),
|
||||
DateTime(2017, 11, 5, 0),
|
||||
DateTime(2017, 11, 5, 0)
|
||||
.add(Duration(milliseconds: millisecondsInHour)),
|
||||
DateTime(2017, 11, 5, 0)
|
||||
.add(Duration(milliseconds: millisecondsInHour * 2)),
|
||||
DateTime(2017, 11, 5, 2),
|
||||
DateTime(2017, 11, 5, 3),
|
||||
DateTime(2017, 11, 5, 4),
|
||||
]));
|
||||
});
|
||||
|
||||
test('step through daylight saving forward change in 4 hour increments',
|
||||
() {
|
||||
final stepper = new HourTimeStepper(dateTimeFactory);
|
||||
final stepper = HourTimeStepper(dateTimeFactory);
|
||||
// DST for PST 2017 begin on March 12. At 2am clocks are turned to 3am.
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 3, 12, 0),
|
||||
end: new DateTime(2017, 3, 13, 0),
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 3, 12, 0),
|
||||
end: DateTime(2017, 3, 13, 0),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(4);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -223,23 +223,23 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 3, 12, 4),
|
||||
new DateTime(2017, 3, 12, 8),
|
||||
new DateTime(2017, 3, 12, 12),
|
||||
new DateTime(2017, 3, 12, 16),
|
||||
new DateTime(2017, 3, 12, 20),
|
||||
new DateTime(2017, 3, 13, 0),
|
||||
DateTime(2017, 3, 12, 4),
|
||||
DateTime(2017, 3, 12, 8),
|
||||
DateTime(2017, 3, 12, 12),
|
||||
DateTime(2017, 3, 12, 16),
|
||||
DateTime(2017, 3, 12, 20),
|
||||
DateTime(2017, 3, 13, 0),
|
||||
]));
|
||||
});
|
||||
|
||||
test('step through daylight saving backward change in 4 hour increments',
|
||||
() {
|
||||
final stepper = new HourTimeStepper(dateTimeFactory);
|
||||
final stepper = HourTimeStepper(dateTimeFactory);
|
||||
// DST for PST 2017 end on November 5.
|
||||
// At 2am, clocks are turned to 1am.
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 11, 5, 0),
|
||||
end: new DateTime(2017, 11, 6, 0),
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 11, 5, 0),
|
||||
end: DateTime(2017, 11, 6, 0),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(4);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -248,24 +248,24 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 11, 5, 0)
|
||||
.add(new Duration(milliseconds: millisecondsInHour)),
|
||||
new DateTime(2017, 11, 5, 4),
|
||||
new DateTime(2017, 11, 5, 8),
|
||||
new DateTime(2017, 11, 5, 12),
|
||||
new DateTime(2017, 11, 5, 16),
|
||||
new DateTime(2017, 11, 5, 20),
|
||||
new DateTime(2017, 11, 6, 0),
|
||||
DateTime(2017, 11, 5, 0)
|
||||
.add(Duration(milliseconds: millisecondsInHour)),
|
||||
DateTime(2017, 11, 5, 4),
|
||||
DateTime(2017, 11, 5, 8),
|
||||
DateTime(2017, 11, 5, 12),
|
||||
DateTime(2017, 11, 5, 16),
|
||||
DateTime(2017, 11, 5, 20),
|
||||
DateTime(2017, 11, 6, 0),
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
||||
group('Minute time stepper', () {
|
||||
test('gets steps with 5 minute increments', () {
|
||||
final stepper = new MinuteTimeStepper(dateTimeFactory);
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 8, 20, 3, 46),
|
||||
end: new DateTime(2017, 8, 20, 4, 02),
|
||||
final stepper = MinuteTimeStepper(dateTimeFactory);
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 8, 20, 3, 46),
|
||||
end: DateTime(2017, 8, 20, 4, 02),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(5);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -274,18 +274,18 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 8, 20, 3, 50),
|
||||
new DateTime(2017, 8, 20, 3, 55),
|
||||
new DateTime(2017, 8, 20, 4),
|
||||
DateTime(2017, 8, 20, 3, 50),
|
||||
DateTime(2017, 8, 20, 3, 55),
|
||||
DateTime(2017, 8, 20, 4),
|
||||
]));
|
||||
});
|
||||
|
||||
test('step through daylight saving forward change', () {
|
||||
final stepper = new MinuteTimeStepper(dateTimeFactory);
|
||||
final stepper = MinuteTimeStepper(dateTimeFactory);
|
||||
// DST for PST 2017 begin on March 12. At 2am clocks are turned to 3am.
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 3, 12, 1, 40),
|
||||
end: new DateTime(2017, 3, 12, 4, 02),
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 3, 12, 1, 40),
|
||||
end: DateTime(2017, 3, 12, 4, 02),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(15);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -294,21 +294,21 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 3, 12, 1, 45),
|
||||
new DateTime(2017, 3, 12, 3),
|
||||
new DateTime(2017, 3, 12, 3, 15),
|
||||
new DateTime(2017, 3, 12, 3, 30),
|
||||
new DateTime(2017, 3, 12, 3, 45),
|
||||
new DateTime(2017, 3, 12, 4),
|
||||
DateTime(2017, 3, 12, 1, 45),
|
||||
DateTime(2017, 3, 12, 3),
|
||||
DateTime(2017, 3, 12, 3, 15),
|
||||
DateTime(2017, 3, 12, 3, 30),
|
||||
DateTime(2017, 3, 12, 3, 45),
|
||||
DateTime(2017, 3, 12, 4),
|
||||
]));
|
||||
});
|
||||
|
||||
test('steps correctly after daylight saving forward change', () {
|
||||
final stepper = new MinuteTimeStepper(dateTimeFactory);
|
||||
final stepper = MinuteTimeStepper(dateTimeFactory);
|
||||
// DST for PST 2017 begin on March 12. At 2am clocks are turned to 3am.
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 3, 12, 3, 02),
|
||||
end: new DateTime(2017, 3, 12, 4, 02),
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 3, 12, 3, 02),
|
||||
end: DateTime(2017, 3, 12, 4, 02),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(30);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -317,19 +317,18 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 3, 12, 3, 30),
|
||||
new DateTime(2017, 3, 12, 4),
|
||||
DateTime(2017, 3, 12, 3, 30),
|
||||
DateTime(2017, 3, 12, 4),
|
||||
]));
|
||||
});
|
||||
|
||||
test('step through daylight saving backward change', () {
|
||||
final stepper = new MinuteTimeStepper(dateTimeFactory);
|
||||
final stepper = MinuteTimeStepper(dateTimeFactory);
|
||||
// DST for PST 2017 end on November 5.
|
||||
// At 2am, clocks are turned to 1am.
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 11, 5)
|
||||
.add(new Duration(hours: 1, minutes: 29)),
|
||||
end: new DateTime(2017, 11, 5, 3, 02));
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 11, 5).add(Duration(hours: 1, minutes: 29)),
|
||||
end: DateTime(2017, 11, 5, 3, 02));
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(30);
|
||||
final steps = stepIterable.toList();
|
||||
|
||||
@@ -338,27 +337,27 @@ void main() {
|
||||
steps,
|
||||
equals([
|
||||
// The first 1:30am
|
||||
new DateTime(2017, 11, 5).add(new Duration(hours: 1, minutes: 30)),
|
||||
DateTime(2017, 11, 5).add(Duration(hours: 1, minutes: 30)),
|
||||
// The 2nd 1am.
|
||||
new DateTime(2017, 11, 5).add(new Duration(hours: 2)),
|
||||
DateTime(2017, 11, 5).add(Duration(hours: 2)),
|
||||
// The 2nd 1:30am
|
||||
new DateTime(2017, 11, 5).add(new Duration(hours: 2, minutes: 30)),
|
||||
DateTime(2017, 11, 5).add(Duration(hours: 2, minutes: 30)),
|
||||
// 2am
|
||||
new DateTime(2017, 11, 5).add(new Duration(hours: 3)),
|
||||
DateTime(2017, 11, 5).add(Duration(hours: 3)),
|
||||
// 2:30am
|
||||
new DateTime(2017, 11, 5).add(new Duration(hours: 3, minutes: 30)),
|
||||
DateTime(2017, 11, 5).add(Duration(hours: 3, minutes: 30)),
|
||||
// 3am
|
||||
new DateTime(2017, 11, 5, 3)
|
||||
DateTime(2017, 11, 5, 3)
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
||||
group('Month time stepper', () {
|
||||
test('steps crosses the year', () {
|
||||
final stepper = new MonthTimeStepper(dateTimeFactory);
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 5),
|
||||
end: new DateTime(2018, 9),
|
||||
final stepper = MonthTimeStepper(dateTimeFactory);
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 5),
|
||||
end: DateTime(2018, 9),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(4);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -367,18 +366,18 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 8),
|
||||
new DateTime(2017, 12),
|
||||
new DateTime(2018, 4),
|
||||
new DateTime(2018, 8),
|
||||
DateTime(2017, 8),
|
||||
DateTime(2017, 12),
|
||||
DateTime(2018, 4),
|
||||
DateTime(2018, 8),
|
||||
]));
|
||||
});
|
||||
|
||||
test('steps within one year', () {
|
||||
final stepper = new MonthTimeStepper(dateTimeFactory);
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017, 1),
|
||||
end: new DateTime(2017, 5),
|
||||
final stepper = MonthTimeStepper(dateTimeFactory);
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017, 1),
|
||||
end: DateTime(2017, 5),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(2);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -387,66 +386,66 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2017, 2),
|
||||
new DateTime(2017, 4),
|
||||
DateTime(2017, 2),
|
||||
DateTime(2017, 4),
|
||||
]));
|
||||
});
|
||||
|
||||
test('step before would allow ticks to include last month of the year', () {
|
||||
final stepper = new MonthTimeStepper(dateTimeFactory);
|
||||
final time = new DateTime(2017, 10);
|
||||
final stepper = MonthTimeStepper(dateTimeFactory);
|
||||
final time = DateTime(2017, 10);
|
||||
|
||||
expect(stepper.getStepTimeBeforeInclusive(time, 1),
|
||||
equals(new DateTime(2017, 10)));
|
||||
equals(DateTime(2017, 10)));
|
||||
|
||||
// Months - 3, 6, 9, 12
|
||||
expect(stepper.getStepTimeBeforeInclusive(time, 3),
|
||||
equals(new DateTime(2017, 9)));
|
||||
equals(DateTime(2017, 9)));
|
||||
|
||||
// Months - 6, 12
|
||||
expect(stepper.getStepTimeBeforeInclusive(time, 6),
|
||||
equals(new DateTime(2017, 6)));
|
||||
equals(DateTime(2017, 6)));
|
||||
});
|
||||
|
||||
test('step before for January', () {
|
||||
final stepper = new MonthTimeStepper(dateTimeFactory);
|
||||
final time = new DateTime(2017, 1);
|
||||
final stepper = MonthTimeStepper(dateTimeFactory);
|
||||
final time = DateTime(2017, 1);
|
||||
|
||||
expect(stepper.getStepTimeBeforeInclusive(time, 1),
|
||||
equals(new DateTime(2017, 1)));
|
||||
equals(DateTime(2017, 1)));
|
||||
|
||||
// Months - 3, 6, 9, 12
|
||||
expect(stepper.getStepTimeBeforeInclusive(time, 3),
|
||||
equals(new DateTime(2016, 12)));
|
||||
equals(DateTime(2016, 12)));
|
||||
|
||||
// Months - 6, 12
|
||||
expect(stepper.getStepTimeBeforeInclusive(time, 6),
|
||||
equals(new DateTime(2016, 12)));
|
||||
equals(DateTime(2016, 12)));
|
||||
});
|
||||
|
||||
test('step before for December', () {
|
||||
final stepper = new MonthTimeStepper(dateTimeFactory);
|
||||
final time = new DateTime(2017, 12);
|
||||
final stepper = MonthTimeStepper(dateTimeFactory);
|
||||
final time = DateTime(2017, 12);
|
||||
|
||||
expect(stepper.getStepTimeBeforeInclusive(time, 1),
|
||||
equals(new DateTime(2017, 12)));
|
||||
equals(DateTime(2017, 12)));
|
||||
|
||||
// Months - 3, 6, 9, 12
|
||||
expect(stepper.getStepTimeBeforeInclusive(time, 3),
|
||||
equals(new DateTime(2017, 12)));
|
||||
equals(DateTime(2017, 12)));
|
||||
|
||||
// Months - 6, 12
|
||||
expect(stepper.getStepTimeBeforeInclusive(time, 6),
|
||||
equals(new DateTime(2017, 12)));
|
||||
equals(DateTime(2017, 12)));
|
||||
});
|
||||
});
|
||||
|
||||
group('Year stepper', () {
|
||||
test('steps in 10 year increments', () {
|
||||
final stepper = new YearTimeStepper(dateTimeFactory);
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(2017),
|
||||
end: new DateTime(2042),
|
||||
final stepper = YearTimeStepper(dateTimeFactory);
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(2017),
|
||||
end: DateTime(2042),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(10);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -455,17 +454,17 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(2020),
|
||||
new DateTime(2030),
|
||||
new DateTime(2040),
|
||||
DateTime(2020),
|
||||
DateTime(2030),
|
||||
DateTime(2040),
|
||||
]));
|
||||
});
|
||||
|
||||
test('steps through negative year', () {
|
||||
final stepper = new YearTimeStepper(dateTimeFactory);
|
||||
final extent = new DateTimeExtents(
|
||||
start: new DateTime(-420),
|
||||
end: new DateTime(240),
|
||||
final stepper = YearTimeStepper(dateTimeFactory);
|
||||
final extent = DateTimeExtents(
|
||||
start: DateTime(-420),
|
||||
end: DateTime(240),
|
||||
);
|
||||
final stepIterable = stepper.getSteps(extent)..iterator.reset(200);
|
||||
final steps = stepIterable.toList();
|
||||
@@ -474,10 +473,10 @@ void main() {
|
||||
expect(
|
||||
steps,
|
||||
equals([
|
||||
new DateTime(-400),
|
||||
new DateTime(-200),
|
||||
new DateTime(0),
|
||||
new DateTime(200),
|
||||
DateTime(-400),
|
||||
DateTime(-200),
|
||||
DateTime(0),
|
||||
DateTime(200),
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,13 +20,13 @@ import 'simple_date_time_factory.dart' show SimpleDateTimeFactory;
|
||||
const EPSILON = 0.001;
|
||||
|
||||
void main() {
|
||||
const dateTimeFactory = const SimpleDateTimeFactory();
|
||||
const dateTimeFactory = SimpleDateTimeFactory();
|
||||
|
||||
group('Find closest step size from stepper', () {
|
||||
test('from exactly matching step size', () {
|
||||
final stepper = AutoAdjustingDateTimeTickProvider.createHourTickProvider(
|
||||
dateTimeFactory);
|
||||
final oneHourMs = (new Duration(hours: 1)).inMilliseconds;
|
||||
final oneHourMs = (Duration(hours: 1)).inMilliseconds;
|
||||
final closestStepSize = stepper.getClosestStepSize(oneHourMs);
|
||||
|
||||
expect(closestStepSize, equals(oneHourMs));
|
||||
@@ -36,9 +36,9 @@ void main() {
|
||||
() {
|
||||
final stepper = AutoAdjustingDateTimeTickProvider.createHourTickProvider(
|
||||
dateTimeFactory);
|
||||
final oneHourMs = (new Duration(hours: 1)).inMilliseconds;
|
||||
final closestStepSize = stepper
|
||||
.getClosestStepSize((new Duration(minutes: 56)).inMilliseconds);
|
||||
final oneHourMs = (Duration(hours: 1)).inMilliseconds;
|
||||
final closestStepSize =
|
||||
stepper.getClosestStepSize((Duration(minutes: 56)).inMilliseconds);
|
||||
|
||||
expect(closestStepSize, equals(oneHourMs));
|
||||
});
|
||||
@@ -47,9 +47,9 @@ void main() {
|
||||
() {
|
||||
final stepper = AutoAdjustingDateTimeTickProvider.createHourTickProvider(
|
||||
dateTimeFactory);
|
||||
final oneDayMs = (new Duration(hours: 24)).inMilliseconds;
|
||||
final oneDayMs = (Duration(hours: 24)).inMilliseconds;
|
||||
final closestStepSize =
|
||||
stepper.getClosestStepSize((new Duration(hours: 25)).inMilliseconds);
|
||||
stepper.getClosestStepSize((Duration(hours: 25)).inMilliseconds);
|
||||
|
||||
expect(closestStepSize, equals(oneDayMs));
|
||||
});
|
||||
@@ -57,9 +57,9 @@ void main() {
|
||||
test('choose closest increment if exact not found', () {
|
||||
final stepper = AutoAdjustingDateTimeTickProvider.createHourTickProvider(
|
||||
dateTimeFactory);
|
||||
final threeHoursMs = (new Duration(hours: 3)).inMilliseconds;
|
||||
final closestStepSize = stepper.getClosestStepSize(
|
||||
(new Duration(hours: 3, minutes: 28)).inMilliseconds);
|
||||
final threeHoursMs = (Duration(hours: 3)).inMilliseconds;
|
||||
final closestStepSize = stepper
|
||||
.getClosestStepSize((Duration(hours: 3, minutes: 28)).inMilliseconds);
|
||||
|
||||
expect(closestStepSize, equals(threeHoursMs));
|
||||
});
|
||||
|
||||
@@ -30,8 +30,8 @@ class MockGraphicsFactory extends Mock implements GraphicsFactory {}
|
||||
|
||||
class FakeNumericChart extends NumericCartesianChart {
|
||||
FakeNumericChart() {
|
||||
context = new MockContext();
|
||||
graphicsFactory = new MockGraphicsFactory();
|
||||
context = MockContext();
|
||||
graphicsFactory = MockGraphicsFactory();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -42,8 +42,8 @@ class FakeNumericChart extends NumericCartesianChart {
|
||||
|
||||
class FakeOrdinalChart extends OrdinalCartesianChart {
|
||||
FakeOrdinalChart() {
|
||||
context = new MockContext();
|
||||
graphicsFactory = new MockGraphicsFactory();
|
||||
context = MockContext();
|
||||
graphicsFactory = MockGraphicsFactory();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -54,8 +54,8 @@ class FakeOrdinalChart extends OrdinalCartesianChart {
|
||||
|
||||
class FakeTimeSeries extends TimeSeriesChart {
|
||||
FakeTimeSeries() {
|
||||
context = new MockContext();
|
||||
graphicsFactory = new MockGraphicsFactory();
|
||||
context = MockContext();
|
||||
graphicsFactory = MockGraphicsFactory();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -67,36 +67,36 @@ class FakeTimeSeries extends TimeSeriesChart {
|
||||
void main() {
|
||||
group('Axis reset with new axis spec', () {
|
||||
test('for ordinal chart', () {
|
||||
final chart = new FakeOrdinalChart();
|
||||
final chart = FakeOrdinalChart();
|
||||
chart.configurationChanged();
|
||||
final domainAxis = chart.domainAxis;
|
||||
expect(domainAxis, isNotNull);
|
||||
|
||||
chart.domainAxisSpec = new OrdinalAxisSpec();
|
||||
chart.domainAxisSpec = OrdinalAxisSpec();
|
||||
chart.configurationChanged();
|
||||
|
||||
expect(domainAxis, isNot(chart.domainAxis));
|
||||
});
|
||||
|
||||
test('for numeric chart', () {
|
||||
final chart = new FakeNumericChart();
|
||||
final chart = FakeNumericChart();
|
||||
chart.configurationChanged();
|
||||
final domainAxis = chart.domainAxis;
|
||||
expect(domainAxis, isNotNull);
|
||||
|
||||
chart.domainAxisSpec = new NumericAxisSpec();
|
||||
chart.domainAxisSpec = NumericAxisSpec();
|
||||
chart.configurationChanged();
|
||||
|
||||
expect(domainAxis, isNot(chart.domainAxis));
|
||||
});
|
||||
|
||||
test('for time series chart', () {
|
||||
final chart = new FakeTimeSeries();
|
||||
final chart = FakeTimeSeries();
|
||||
chart.configurationChanged();
|
||||
final domainAxis = chart.domainAxis;
|
||||
expect(domainAxis, isNotNull);
|
||||
|
||||
chart.domainAxisSpec = new DateTimeAxisSpec();
|
||||
chart.domainAxisSpec = DateTimeAxisSpec();
|
||||
chart.configurationChanged();
|
||||
|
||||
expect(domainAxis, isNot(chart.domainAxis));
|
||||
|
||||
@@ -54,14 +54,14 @@ void main() {
|
||||
BaseCartesianRenderer renderer;
|
||||
|
||||
setUp(() {
|
||||
renderer = new FakeCartesianRenderer();
|
||||
renderer = FakeCartesianRenderer();
|
||||
});
|
||||
|
||||
group('find viewport start', () {
|
||||
test('several domains are in the viewport', () {
|
||||
final data = [0, 1, 2, 3, 4, 5, 6];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(0)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(1)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(2)).thenReturn(0);
|
||||
@@ -78,8 +78,8 @@ void main() {
|
||||
test('extents are all in the viewport, use the first domain', () {
|
||||
// Start of viewport is the same as the start of the domain.
|
||||
final data = [0, 1, 2, 3];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(any)).thenReturn(0);
|
||||
|
||||
final start = renderer.findNearestViewportStart(axis, domainFn, data);
|
||||
@@ -89,8 +89,8 @@ void main() {
|
||||
|
||||
test('is the first domain', () {
|
||||
final data = [0, 1, 2, 3];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(0)).thenReturn(0);
|
||||
when(axis.compareDomainValueToViewport(1)).thenReturn(1);
|
||||
when(axis.compareDomainValueToViewport(2)).thenReturn(1);
|
||||
@@ -103,8 +103,8 @@ void main() {
|
||||
|
||||
test('is the last domain', () {
|
||||
final data = [0, 1, 2, 3];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(0)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(1)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(2)).thenReturn(-1);
|
||||
@@ -117,8 +117,8 @@ void main() {
|
||||
|
||||
test('is the middle', () {
|
||||
final data = [0, 1, 2, 3, 4, 5, 6];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(0)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(1)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(2)).thenReturn(-1);
|
||||
@@ -134,8 +134,8 @@ void main() {
|
||||
|
||||
test('viewport is between data', () {
|
||||
final data = [0, 1, 2, 3];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(0)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(1)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(2)).thenReturn(1);
|
||||
@@ -151,8 +151,8 @@ void main() {
|
||||
test('all extents greater than viewport ', () {
|
||||
// Return the right most value as start of viewport.
|
||||
final data = [0, 1, 2, 3];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(any)).thenReturn(1);
|
||||
|
||||
final start = renderer.findNearestViewportStart(axis, domainFn, data);
|
||||
@@ -165,8 +165,8 @@ void main() {
|
||||
test('all extents less than viewport ', () {
|
||||
// Return the left most value as the start of the viewport.
|
||||
final data = [0, 1, 2, 3];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(any)).thenReturn(-1);
|
||||
|
||||
final start = renderer.findNearestViewportStart(axis, domainFn, data);
|
||||
@@ -178,8 +178,8 @@ void main() {
|
||||
group('find viewport end', () {
|
||||
test('several domains are in the viewport', () {
|
||||
final data = [0, 1, 2, 3, 4, 5, 6];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(0)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(1)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(2)).thenReturn(0);
|
||||
@@ -196,8 +196,8 @@ void main() {
|
||||
test('extents are all in the viewport, use the last domain', () {
|
||||
// Start of viewport is the same as the end of the domain.
|
||||
final data = [0, 1, 2, 3];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(any)).thenReturn(0);
|
||||
|
||||
final start = renderer.findNearestViewportEnd(axis, domainFn, data);
|
||||
@@ -207,8 +207,8 @@ void main() {
|
||||
|
||||
test('is the first domain', () {
|
||||
final data = [0, 1, 2, 3];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(0)).thenReturn(0);
|
||||
when(axis.compareDomainValueToViewport(1)).thenReturn(1);
|
||||
when(axis.compareDomainValueToViewport(2)).thenReturn(1);
|
||||
@@ -221,8 +221,8 @@ void main() {
|
||||
|
||||
test('is the last domain', () {
|
||||
final data = [0, 1, 2, 3];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(0)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(1)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(2)).thenReturn(-1);
|
||||
@@ -235,8 +235,8 @@ void main() {
|
||||
|
||||
test('is the middle', () {
|
||||
final data = [0, 1, 2, 3, 4, 5, 6];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(0)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(1)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(2)).thenReturn(-1);
|
||||
@@ -252,8 +252,8 @@ void main() {
|
||||
|
||||
test('viewport is between data', () {
|
||||
final data = [0, 1, 2, 3];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(0)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(1)).thenReturn(-1);
|
||||
when(axis.compareDomainValueToViewport(2)).thenReturn(1);
|
||||
@@ -269,8 +269,8 @@ void main() {
|
||||
test('all extents greater than viewport ', () {
|
||||
// Return the right most value as start of viewport.
|
||||
final data = [0, 1, 2, 3];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(any)).thenReturn(1);
|
||||
|
||||
final start = renderer.findNearestViewportEnd(axis, domainFn, data);
|
||||
@@ -283,8 +283,8 @@ void main() {
|
||||
test('all extents less than viewport ', () {
|
||||
// Return the left most value as the start of the viewport.
|
||||
final data = [0, 1, 2, 3];
|
||||
final domainFn = (int index) => data[index];
|
||||
final axis = new MockAxis();
|
||||
final domainFn = (index) => data[index];
|
||||
final axis = MockAxis();
|
||||
when(axis.compareDomainValueToViewport(any)).thenReturn(-1);
|
||||
|
||||
final start = renderer.findNearestViewportEnd(axis, domainFn, data);
|
||||
|
||||
Reference in New Issue
Block a user