1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 22:38:42 +00:00

web/chart: fix sample (#909)

This commit is contained in:
Brett Morgan
2021-10-07 08:10:34 +11:00
committed by GitHub
parent 0fe216a1cf
commit 2d9ba2f9eb
118 changed files with 3655 additions and 3511 deletions

View File

@@ -25,11 +25,12 @@ class LineAnimationZoomChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
LineAnimationZoomChart(this.seriesList, {this.animate});
const LineAnimationZoomChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and no transition.
factory LineAnimationZoomChart.withSampleData() {
return new LineAnimationZoomChart(
return LineAnimationZoomChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -41,21 +42,21 @@ class LineAnimationZoomChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory LineAnimationZoomChart.withRandomData() {
return new LineAnimationZoomChart(_createRandomData());
return LineAnimationZoomChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
final data = <LinearSales>[];
for (var i = 0; i < 100; i++) {
data.add(new LinearSales(i, random.nextInt(100)));
data.add(LinearSales(i, random.nextInt(100)));
}
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
@@ -67,22 +68,22 @@ class LineAnimationZoomChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList, animate: animate, behaviors: [
new charts.PanAndZoomBehavior(),
return charts.LineChart(seriesList, animate: animate, behaviors: [
charts.PanAndZoomBehavior(),
]);
}
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final data = [
new LinearSales(0, 5),
new LinearSales(1, 25),
new LinearSales(2, 100),
new LinearSales(3, 75),
LinearSales(0, 5),
LinearSales(1, 25),
LinearSales(2, 100),
LinearSales(3, 75),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,

View File

@@ -24,11 +24,12 @@ class AreaAndLineChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
AreaAndLineChart(this.seriesList, {this.animate});
const AreaAndLineChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and no transition.
factory AreaAndLineChart.withSampleData() {
return new AreaAndLineChart(
return AreaAndLineChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -40,36 +41,36 @@ class AreaAndLineChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory AreaAndLineChart.withRandomData() {
return new AreaAndLineChart(_createRandomData());
return AreaAndLineChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
final myFakeDesktopData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
];
var myFakeTabletData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Desktop',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeDesktopData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Tablet',
colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
@@ -84,10 +85,10 @@ class AreaAndLineChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList,
return charts.LineChart(seriesList,
animate: animate,
customSeriesRenderers: [
new charts.LineRendererConfig(
charts.LineRendererConfig(
// ID used to link series to this renderer.
customRendererId: 'customArea',
includeArea: true,
@@ -98,21 +99,21 @@ class AreaAndLineChart extends StatelessWidget {
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final myFakeDesktopData = [
new LinearSales(0, 5),
new LinearSales(1, 25),
new LinearSales(2, 100),
new LinearSales(3, 75),
LinearSales(0, 5),
LinearSales(1, 25),
LinearSales(2, 100),
LinearSales(3, 75),
];
var myFakeTabletData = [
new LinearSales(0, 10),
new LinearSales(1, 50),
new LinearSales(2, 200),
new LinearSales(3, 150),
LinearSales(0, 10),
LinearSales(1, 50),
LinearSales(2, 200),
LinearSales(3, 150),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Desktop',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
@@ -121,7 +122,7 @@ class AreaAndLineChart extends StatelessWidget {
)
// Configure our custom bar target renderer for this series.
..setAttribute(charts.rendererIdKey, 'customArea'),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Tablet',
colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,

View File

@@ -25,11 +25,12 @@ class DashPatternLineChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
DashPatternLineChart(this.seriesList, {this.animate});
const DashPatternLineChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and no transition.
factory DashPatternLineChart.withSampleData() {
return new DashPatternLineChart(
return DashPatternLineChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -41,43 +42,43 @@ class DashPatternLineChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory DashPatternLineChart.withRandomData() {
return new DashPatternLineChart(_createRandomData());
return DashPatternLineChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
final myFakeDesktopData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
];
var myFakeTabletData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
];
var myFakeMobileData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Desktop',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeDesktopData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Tablet',
colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault,
dashPatternFn: (_, __) => [2, 2],
@@ -85,7 +86,7 @@ class DashPatternLineChart extends StatelessWidget {
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeTabletData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Mobile',
colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault,
dashPatternFn: (_, __) => [8, 3, 2, 3],
@@ -99,41 +100,41 @@ class DashPatternLineChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList, animate: animate);
return charts.LineChart(seriesList, animate: animate);
}
/// Create three series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final myFakeDesktopData = [
new LinearSales(0, 5),
new LinearSales(1, 25),
new LinearSales(2, 100),
new LinearSales(3, 75),
LinearSales(0, 5),
LinearSales(1, 25),
LinearSales(2, 100),
LinearSales(3, 75),
];
var myFakeTabletData = [
new LinearSales(0, 10),
new LinearSales(1, 50),
new LinearSales(2, 200),
new LinearSales(3, 150),
LinearSales(0, 10),
LinearSales(1, 50),
LinearSales(2, 200),
LinearSales(3, 150),
];
var myFakeMobileData = [
new LinearSales(0, 15),
new LinearSales(1, 75),
new LinearSales(2, 300),
new LinearSales(3, 225),
LinearSales(0, 15),
LinearSales(1, 75),
LinearSales(2, 300),
LinearSales(3, 225),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Desktop',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeDesktopData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Tablet',
colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault,
dashPatternFn: (_, __) => [2, 2],
@@ -141,7 +142,7 @@ class DashPatternLineChart extends StatelessWidget {
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeTabletData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Mobile',
colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault,
dashPatternFn: (_, __) => [8, 3, 2, 3],

View File

@@ -24,7 +24,8 @@ class LineLineAnnotationChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
LineLineAnnotationChart(this.seriesList, {this.animate});
const LineLineAnnotationChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and line annotations.
///
@@ -32,7 +33,7 @@ class LineLineAnnotationChart extends StatelessWidget {
/// demonstrating the effect of the [Charts.RangeAnnotation.extendAxis] flag.
/// This can be set to false to disable range extension.
factory LineLineAnnotationChart.withSampleData() {
return new LineLineAnnotationChart(
return LineLineAnnotationChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -44,24 +45,24 @@ class LineLineAnnotationChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory LineLineAnnotationChart.withRandomData() {
return new LineLineAnnotationChart(_createRandomData());
return LineLineAnnotationChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
final data = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
// Fix one of the points to 100 so that the annotations are consistently
// placed.
new LinearSales(3, 100),
LinearSales(3, 100),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
@@ -73,21 +74,17 @@ class LineLineAnnotationChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList, animate: animate, behaviors: [
new charts.RangeAnnotation([
new charts.LineAnnotationSegment(
1.0, charts.RangeAnnotationAxisType.domain,
return charts.LineChart(seriesList, animate: animate, behaviors: [
charts.RangeAnnotation([
charts.LineAnnotationSegment(1.0, charts.RangeAnnotationAxisType.domain,
startLabel: 'Domain 1'),
new charts.LineAnnotationSegment(
4, charts.RangeAnnotationAxisType.domain,
charts.LineAnnotationSegment(4, charts.RangeAnnotationAxisType.domain,
endLabel: 'Domain 2', color: charts.MaterialPalette.gray.shade200),
new charts.LineAnnotationSegment(
20, charts.RangeAnnotationAxisType.measure,
charts.LineAnnotationSegment(20, charts.RangeAnnotationAxisType.measure,
startLabel: 'Measure 1 Start',
endLabel: 'Measure 1 End',
color: charts.MaterialPalette.gray.shade300),
new charts.LineAnnotationSegment(
65, charts.RangeAnnotationAxisType.measure,
charts.LineAnnotationSegment(65, charts.RangeAnnotationAxisType.measure,
startLabel: 'Measure 2 Start',
endLabel: 'Measure 2 End',
color: charts.MaterialPalette.gray.shade400),
@@ -98,14 +95,14 @@ class LineLineAnnotationChart extends StatelessWidget {
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final data = [
new LinearSales(0, 5),
new LinearSales(1, 25),
new LinearSales(2, 100),
new LinearSales(3, 75),
LinearSales(0, 5),
LinearSales(1, 25),
LinearSales(2, 100),
LinearSales(3, 75),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,

View File

@@ -31,83 +31,83 @@ import 'stacked_area_nulls.dart';
List<GalleryScaffold> buildGallery() {
return [
new GalleryScaffold(
listTileIcon: new Icon(Icons.show_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.show_chart),
title: 'Simple Line Chart',
subtitle: 'With a single series and default line point highlighter',
childBuilder: () => new SimpleLineChart.withRandomData(),
childBuilder: () => SimpleLineChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.show_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.show_chart),
title: 'Stacked Area Chart',
subtitle: 'Stacked area chart with three series',
childBuilder: () => new StackedAreaLineChart.withRandomData(),
childBuilder: () => StackedAreaLineChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.show_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.show_chart),
title: 'Stacked Area Custom Color Chart',
subtitle: 'Stacked area chart with custom area skirt color',
childBuilder: () => new StackedAreaCustomColorLineChart.withRandomData(),
childBuilder: () => StackedAreaCustomColorLineChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.show_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.show_chart),
title: 'Area and Line Combo Chart',
subtitle: 'Combo chart with one line series and one area series',
childBuilder: () => new AreaAndLineChart.withRandomData(),
childBuilder: () => AreaAndLineChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.show_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.show_chart),
title: 'Points Line Chart',
subtitle: 'Line chart with points on a single series',
childBuilder: () => new PointsLineChart.withRandomData(),
childBuilder: () => PointsLineChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.show_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.show_chart),
title: 'Null Data Line Chart',
subtitle: 'With a single series and null measure values',
childBuilder: () => new SimpleNullsLineChart.withRandomData(),
childBuilder: () => SimpleNullsLineChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.show_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.show_chart),
title: 'Stacked Area with Nulls Chart',
subtitle: 'Stacked area chart with three series and null measure values',
childBuilder: () => new StackedAreaNullsLineChart.withRandomData(),
childBuilder: () => StackedAreaNullsLineChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.show_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.show_chart),
title: 'Dash Pattern Line Chart',
subtitle: 'Line chart with dash patterns',
childBuilder: () => new DashPatternLineChart.withRandomData(),
childBuilder: () => DashPatternLineChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.show_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.show_chart),
title: 'Segments Line Chart',
subtitle: 'Line chart with changes of style for each line',
childBuilder: () => new SegmentsLineChart.withRandomData(),
childBuilder: () => SegmentsLineChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.show_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.show_chart),
title: 'Line Annotation Line Chart',
subtitle: 'Line chart with line annotations',
childBuilder: () => new LineLineAnnotationChart.withRandomData(),
childBuilder: () => LineLineAnnotationChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.show_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.show_chart),
title: 'Range Annotation Line Chart',
subtitle: 'Line chart with range annotations',
childBuilder: () => new LineRangeAnnotationChart.withRandomData(),
childBuilder: () => LineRangeAnnotationChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.show_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.show_chart),
title: 'Range Annotation Margin Labels Line Chart',
subtitle: 'Line chart with range annotations with labels in margins',
childBuilder: () => new LineRangeAnnotationMarginChart.withRandomData(),
childBuilder: () => LineRangeAnnotationMarginChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.show_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.show_chart),
title: 'Pan and Zoom Line Chart',
subtitle: 'Simple line chart pan and zoom behaviors enabled',
childBuilder: () => new LineAnimationZoomChart.withRandomData(),
childBuilder: () => LineAnimationZoomChart.withRandomData(),
),
];
}

View File

@@ -24,11 +24,12 @@ class PointsLineChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
PointsLineChart(this.seriesList, {this.animate});
const PointsLineChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and no transition.
factory PointsLineChart.withSampleData() {
return new PointsLineChart(
return PointsLineChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -40,22 +41,22 @@ class PointsLineChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory PointsLineChart.withRandomData() {
return new PointsLineChart(_createRandomData());
return PointsLineChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
final data = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
@@ -68,22 +69,22 @@ class PointsLineChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList,
return charts.LineChart(seriesList,
animate: animate,
defaultRenderer: new charts.LineRendererConfig(includePoints: true));
defaultRenderer: charts.LineRendererConfig(includePoints: true));
}
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final data = [
new LinearSales(0, 5),
new LinearSales(1, 25),
new LinearSales(2, 100),
new LinearSales(3, 75),
LinearSales(0, 5),
LinearSales(1, 25),
LinearSales(2, 100),
LinearSales(3, 75),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,

View File

@@ -24,7 +24,8 @@ class LineRangeAnnotationChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
LineRangeAnnotationChart(this.seriesList, {this.animate});
const LineRangeAnnotationChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and range annotations.
///
@@ -32,7 +33,7 @@ class LineRangeAnnotationChart extends StatelessWidget {
/// demonstrating the effect of the [Charts.RangeAnnotation.extendAxis] flag.
/// This can be set to false to disable range extension.
factory LineRangeAnnotationChart.withSampleData() {
return new LineRangeAnnotationChart(
return LineRangeAnnotationChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -44,24 +45,24 @@ class LineRangeAnnotationChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory LineRangeAnnotationChart.withRandomData() {
return new LineRangeAnnotationChart(_createRandomData());
return LineRangeAnnotationChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
final data = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
// Fix one of the points to 100 so that the annotations are consistently
// placed.
new LinearSales(3, 100),
LinearSales(3, 100),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
@@ -73,20 +74,20 @@ class LineRangeAnnotationChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList, animate: animate, behaviors: [
new charts.RangeAnnotation([
new charts.RangeAnnotationSegment(
return charts.LineChart(seriesList, animate: animate, behaviors: [
charts.RangeAnnotation([
charts.RangeAnnotationSegment(
0.5, 1.0, charts.RangeAnnotationAxisType.domain,
startLabel: 'Domain 1'),
new charts.RangeAnnotationSegment(
charts.RangeAnnotationSegment(
2, 4, charts.RangeAnnotationAxisType.domain,
endLabel: 'Domain 2', color: charts.MaterialPalette.gray.shade200),
new charts.RangeAnnotationSegment(
charts.RangeAnnotationSegment(
15, 20, charts.RangeAnnotationAxisType.measure,
startLabel: 'Measure 1 Start',
endLabel: 'Measure 1 End',
color: charts.MaterialPalette.gray.shade300),
new charts.RangeAnnotationSegment(
charts.RangeAnnotationSegment(
35, 65, charts.RangeAnnotationAxisType.measure,
startLabel: 'Measure 2 Start',
endLabel: 'Measure 2 End',
@@ -98,14 +99,14 @@ class LineRangeAnnotationChart extends StatelessWidget {
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final data = [
new LinearSales(0, 5),
new LinearSales(1, 25),
new LinearSales(2, 100),
new LinearSales(3, 75),
LinearSales(0, 5),
LinearSales(1, 25),
LinearSales(2, 100),
LinearSales(3, 75),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,

View File

@@ -25,7 +25,8 @@ class LineRangeAnnotationMarginChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
LineRangeAnnotationMarginChart(this.seriesList, {this.animate});
const LineRangeAnnotationMarginChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and range annotations.
///
@@ -33,7 +34,7 @@ class LineRangeAnnotationMarginChart extends StatelessWidget {
/// demonstrating the effect of the [Charts.RangeAnnotation.extendAxis] flag.
/// This can be set to false to disable range extension.
factory LineRangeAnnotationMarginChart.withSampleData() {
return new LineRangeAnnotationMarginChart(
return LineRangeAnnotationMarginChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -45,24 +46,24 @@ class LineRangeAnnotationMarginChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory LineRangeAnnotationMarginChart.withRandomData() {
return new LineRangeAnnotationMarginChart(_createRandomData());
return LineRangeAnnotationMarginChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
final data = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
// Fix one of the points to 100 so that the annotations are consistently
// placed.
new LinearSales(3, 100),
LinearSales(3, 100),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
@@ -74,21 +75,21 @@ class LineRangeAnnotationMarginChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList,
return charts.LineChart(seriesList,
animate: animate,
// Allow enough space in the left and right chart margins for the
// annotations.
layoutConfig: new charts.LayoutConfig(
leftMarginSpec: new charts.MarginSpec.fixedPixel(60),
topMarginSpec: new charts.MarginSpec.fixedPixel(20),
rightMarginSpec: new charts.MarginSpec.fixedPixel(60),
bottomMarginSpec: new charts.MarginSpec.fixedPixel(20)),
layoutConfig: charts.LayoutConfig(
leftMarginSpec: charts.MarginSpec.fixedPixel(60),
topMarginSpec: charts.MarginSpec.fixedPixel(20),
rightMarginSpec: charts.MarginSpec.fixedPixel(60),
bottomMarginSpec: charts.MarginSpec.fixedPixel(20)),
behaviors: [
// Define one domain and two measure annotations configured to render
// labels in the chart margins.
new charts.RangeAnnotation([
new charts.RangeAnnotationSegment(
charts.RangeAnnotation([
charts.RangeAnnotationSegment(
0.5, 1.0, charts.RangeAnnotationAxisType.domain,
startLabel: 'D1 Start',
endLabel: 'D1 End',
@@ -96,13 +97,13 @@ class LineRangeAnnotationMarginChart extends StatelessWidget {
color: charts.MaterialPalette.gray.shade200,
// Override the default vertical direction for domain labels.
labelDirection: charts.AnnotationLabelDirection.horizontal),
new charts.RangeAnnotationSegment(
charts.RangeAnnotationSegment(
15, 20, charts.RangeAnnotationAxisType.measure,
startLabel: 'M1 Start',
endLabel: 'M1 End',
labelAnchor: charts.AnnotationLabelAnchor.end,
color: charts.MaterialPalette.gray.shade300),
new charts.RangeAnnotationSegment(
charts.RangeAnnotationSegment(
35, 65, charts.RangeAnnotationAxisType.measure,
startLabel: 'M2 Start',
endLabel: 'M2 End',
@@ -115,14 +116,14 @@ class LineRangeAnnotationMarginChart extends StatelessWidget {
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final data = [
new LinearSales(0, 5),
new LinearSales(1, 25),
new LinearSales(2, 100),
new LinearSales(3, 75),
LinearSales(0, 5),
LinearSales(1, 25),
LinearSales(2, 100),
LinearSales(3, 75),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,

View File

@@ -35,11 +35,12 @@ class SegmentsLineChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
SegmentsLineChart(this.seriesList, {this.animate});
const SegmentsLineChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and no transition.
factory SegmentsLineChart.withSampleData() {
return new SegmentsLineChart(
return SegmentsLineChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -51,45 +52,45 @@ class SegmentsLineChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory SegmentsLineChart.withRandomData() {
return new SegmentsLineChart(_createRandomData());
return SegmentsLineChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
// Series of data with static dash pattern and stroke width. The colorFn
// accessor will colorize each datum (for all three series).
final colorChangeData = [
new LinearSales(0, random.nextInt(100), null, 2.0),
new LinearSales(1, random.nextInt(100), null, 2.0),
new LinearSales(2, random.nextInt(100), null, 2.0),
new LinearSales(3, random.nextInt(100), null, 2.0),
new LinearSales(4, random.nextInt(100), null, 2.0),
new LinearSales(5, random.nextInt(100), null, 2.0),
new LinearSales(6, random.nextInt(100), null, 2.0),
LinearSales(0, random.nextInt(100), null, 2.0),
LinearSales(1, random.nextInt(100), null, 2.0),
LinearSales(2, random.nextInt(100), null, 2.0),
LinearSales(3, random.nextInt(100), null, 2.0),
LinearSales(4, random.nextInt(100), null, 2.0),
LinearSales(5, random.nextInt(100), null, 2.0),
LinearSales(6, random.nextInt(100), null, 2.0),
];
// Series of data with changing color and dash pattern.
final dashPatternChangeData = [
new LinearSales(0, random.nextInt(100), [2, 2], 2.0),
new LinearSales(1, random.nextInt(100), [2, 2], 2.0),
new LinearSales(2, random.nextInt(100), [4, 4], 2.0),
new LinearSales(3, random.nextInt(100), [4, 4], 2.0),
new LinearSales(4, random.nextInt(100), [4, 4], 2.0),
new LinearSales(5, random.nextInt(100), [8, 3, 2, 3], 2.0),
new LinearSales(6, random.nextInt(100), [8, 3, 2, 3], 2.0),
LinearSales(0, random.nextInt(100), [2, 2], 2.0),
LinearSales(1, random.nextInt(100), [2, 2], 2.0),
LinearSales(2, random.nextInt(100), [4, 4], 2.0),
LinearSales(3, random.nextInt(100), [4, 4], 2.0),
LinearSales(4, random.nextInt(100), [4, 4], 2.0),
LinearSales(5, random.nextInt(100), [8, 3, 2, 3], 2.0),
LinearSales(6, random.nextInt(100), [8, 3, 2, 3], 2.0),
];
// Series of data with changing color and stroke width.
final strokeWidthChangeData = [
new LinearSales(0, random.nextInt(100), null, 2.0),
new LinearSales(1, random.nextInt(100), null, 2.0),
new LinearSales(2, random.nextInt(100), null, 4.0),
new LinearSales(3, random.nextInt(100), null, 4.0),
new LinearSales(4, random.nextInt(100), null, 4.0),
new LinearSales(5, random.nextInt(100), null, 6.0),
new LinearSales(6, random.nextInt(100), null, 6.0),
LinearSales(0, random.nextInt(100), null, 2.0),
LinearSales(1, random.nextInt(100), null, 2.0),
LinearSales(2, random.nextInt(100), null, 4.0),
LinearSales(3, random.nextInt(100), null, 4.0),
LinearSales(4, random.nextInt(100), null, 4.0),
LinearSales(5, random.nextInt(100), null, 6.0),
LinearSales(6, random.nextInt(100), null, 6.0),
];
// Generate 2 shades of each color so that we can style the line segments.
@@ -98,7 +99,7 @@ class SegmentsLineChart extends StatelessWidget {
final green = charts.MaterialPalette.green.makeShades(2);
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Color Change',
// Light shade for even years, dark shade for odd.
colorFn: (LinearSales sales, _) =>
@@ -109,7 +110,7 @@ class SegmentsLineChart extends StatelessWidget {
measureFn: (LinearSales sales, _) => sales.sales,
data: colorChangeData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Dash Pattern Change',
// Light shade for even years, dark shade for odd.
colorFn: (LinearSales sales, _) =>
@@ -120,7 +121,7 @@ class SegmentsLineChart extends StatelessWidget {
measureFn: (LinearSales sales, _) => sales.sales,
data: dashPatternChangeData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Stroke Width Change',
// Light shade for even years, dark shade for odd.
colorFn: (LinearSales sales, _) =>
@@ -137,9 +138,9 @@ class SegmentsLineChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList,
return charts.LineChart(seriesList,
defaultRenderer:
new charts.LineRendererConfig(includeArea: true, stacked: true),
charts.LineRendererConfig(includeArea: true, stacked: true),
animate: animate);
}
@@ -148,35 +149,35 @@ class SegmentsLineChart extends StatelessWidget {
// Series of data with static dash pattern and stroke width. The colorFn
// accessor will colorize each datum (for all three series).
final colorChangeData = [
new LinearSales(0, 5, null, 2.0),
new LinearSales(1, 15, null, 2.0),
new LinearSales(2, 25, null, 2.0),
new LinearSales(3, 75, null, 2.0),
new LinearSales(4, 100, null, 2.0),
new LinearSales(5, 90, null, 2.0),
new LinearSales(6, 75, null, 2.0),
LinearSales(0, 5, null, 2.0),
LinearSales(1, 15, null, 2.0),
LinearSales(2, 25, null, 2.0),
LinearSales(3, 75, null, 2.0),
LinearSales(4, 100, null, 2.0),
LinearSales(5, 90, null, 2.0),
LinearSales(6, 75, null, 2.0),
];
// Series of data with changing color and dash pattern.
final dashPatternChangeData = [
new LinearSales(0, 5, [2, 2], 2.0),
new LinearSales(1, 15, [2, 2], 2.0),
new LinearSales(2, 25, [4, 4], 2.0),
new LinearSales(3, 75, [4, 4], 2.0),
new LinearSales(4, 100, [4, 4], 2.0),
new LinearSales(5, 90, [8, 3, 2, 3], 2.0),
new LinearSales(6, 75, [8, 3, 2, 3], 2.0),
LinearSales(0, 5, [2, 2], 2.0),
LinearSales(1, 15, [2, 2], 2.0),
LinearSales(2, 25, [4, 4], 2.0),
LinearSales(3, 75, [4, 4], 2.0),
LinearSales(4, 100, [4, 4], 2.0),
LinearSales(5, 90, [8, 3, 2, 3], 2.0),
LinearSales(6, 75, [8, 3, 2, 3], 2.0),
];
// Series of data with changing color and stroke width.
final strokeWidthChangeData = [
new LinearSales(0, 5, null, 2.0),
new LinearSales(1, 15, null, 2.0),
new LinearSales(2, 25, null, 4.0),
new LinearSales(3, 75, null, 4.0),
new LinearSales(4, 100, null, 4.0),
new LinearSales(5, 90, null, 6.0),
new LinearSales(6, 75, null, 6.0),
LinearSales(0, 5, null, 2.0),
LinearSales(1, 15, null, 2.0),
LinearSales(2, 25, null, 4.0),
LinearSales(3, 75, null, 4.0),
LinearSales(4, 100, null, 4.0),
LinearSales(5, 90, null, 6.0),
LinearSales(6, 75, null, 6.0),
];
// Generate 2 shades of each color so that we can style the line segments.
@@ -185,7 +186,7 @@ class SegmentsLineChart extends StatelessWidget {
final green = charts.MaterialPalette.green.makeShades(2);
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Color Change',
// Light shade for even years, dark shade for odd.
colorFn: (LinearSales sales, _) =>
@@ -196,7 +197,7 @@ class SegmentsLineChart extends StatelessWidget {
measureFn: (LinearSales sales, _) => sales.sales,
data: colorChangeData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Dash Pattern Change',
// Light shade for even years, dark shade for odd.
colorFn: (LinearSales sales, _) =>
@@ -207,7 +208,7 @@ class SegmentsLineChart extends StatelessWidget {
measureFn: (LinearSales sales, _) => sales.sales,
data: dashPatternChangeData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Stroke Width Change',
// Light shade for even years, dark shade for odd.
colorFn: (LinearSales sales, _) =>

View File

@@ -24,11 +24,12 @@ class SimpleLineChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
SimpleLineChart(this.seriesList, {this.animate});
const SimpleLineChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and no transition.
factory SimpleLineChart.withSampleData() {
return new SimpleLineChart(
return SimpleLineChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -40,22 +41,22 @@ class SimpleLineChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory SimpleLineChart.withRandomData() {
return new SimpleLineChart(_createRandomData());
return SimpleLineChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
final data = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
@@ -68,20 +69,20 @@ class SimpleLineChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList, animate: animate);
return charts.LineChart(seriesList, animate: animate);
}
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final data = [
new LinearSales(0, 5),
new LinearSales(1, 25),
new LinearSales(2, 100),
new LinearSales(3, 75),
LinearSales(0, 5),
LinearSales(1, 25),
LinearSales(2, 100),
LinearSales(3, 75),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Sales',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,

View File

@@ -28,11 +28,12 @@ class SimpleNullsLineChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
SimpleNullsLineChart(this.seriesList, {this.animate});
const SimpleNullsLineChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and no transition.
factory SimpleNullsLineChart.withSampleData() {
return new SimpleNullsLineChart(
return SimpleNullsLineChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -44,59 +45,59 @@ class SimpleNullsLineChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory SimpleNullsLineChart.withRandomData() {
return new SimpleNullsLineChart(_createRandomData());
return SimpleNullsLineChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
final myFakeDesktopData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, null),
new LinearSales(3, random.nextInt(100)),
new LinearSales(4, random.nextInt(100)),
new LinearSales(5, random.nextInt(100)),
new LinearSales(6, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, null),
LinearSales(3, random.nextInt(100)),
LinearSales(4, random.nextInt(100)),
LinearSales(5, random.nextInt(100)),
LinearSales(6, random.nextInt(100)),
];
var myFakeTabletData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
new LinearSales(4, random.nextInt(100)),
new LinearSales(5, random.nextInt(100)),
new LinearSales(6, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
LinearSales(4, random.nextInt(100)),
LinearSales(5, random.nextInt(100)),
LinearSales(6, random.nextInt(100)),
];
var myFakeMobileData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, null),
new LinearSales(3, random.nextInt(100)),
new LinearSales(4, null),
new LinearSales(5, random.nextInt(100)),
new LinearSales(6, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, null),
LinearSales(3, random.nextInt(100)),
LinearSales(4, null),
LinearSales(5, random.nextInt(100)),
LinearSales(6, random.nextInt(100)),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Desktop',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeDesktopData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Tablet',
colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeTabletData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Mobile',
colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
@@ -109,57 +110,57 @@ class SimpleNullsLineChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList, animate: animate);
return charts.LineChart(seriesList, animate: animate);
}
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final myFakeDesktopData = [
new LinearSales(0, 5),
new LinearSales(1, 15),
new LinearSales(2, null),
new LinearSales(3, 75),
new LinearSales(4, 100),
new LinearSales(5, 90),
new LinearSales(6, 75),
LinearSales(0, 5),
LinearSales(1, 15),
LinearSales(2, null),
LinearSales(3, 75),
LinearSales(4, 100),
LinearSales(5, 90),
LinearSales(6, 75),
];
final myFakeTabletData = [
new LinearSales(0, 10),
new LinearSales(1, 30),
new LinearSales(2, 50),
new LinearSales(3, 150),
new LinearSales(4, 200),
new LinearSales(5, 180),
new LinearSales(6, 150),
LinearSales(0, 10),
LinearSales(1, 30),
LinearSales(2, 50),
LinearSales(3, 150),
LinearSales(4, 200),
LinearSales(5, 180),
LinearSales(6, 150),
];
final myFakeMobileData = [
new LinearSales(0, 15),
new LinearSales(1, 45),
new LinearSales(2, null),
new LinearSales(3, 225),
new LinearSales(4, null),
new LinearSales(5, 270),
new LinearSales(6, 225),
LinearSales(0, 15),
LinearSales(1, 45),
LinearSales(2, null),
LinearSales(3, 225),
LinearSales(4, null),
LinearSales(5, 270),
LinearSales(6, 225),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Desktop',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeDesktopData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Tablet',
colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeTabletData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Mobile',
colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,

View File

@@ -24,11 +24,12 @@ class StackedAreaLineChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
StackedAreaLineChart(this.seriesList, {this.animate});
const StackedAreaLineChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and no transition.
factory StackedAreaLineChart.withSampleData() {
return new StackedAreaLineChart(
return StackedAreaLineChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -40,50 +41,50 @@ class StackedAreaLineChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory StackedAreaLineChart.withRandomData() {
return new StackedAreaLineChart(_createRandomData());
return StackedAreaLineChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
final myFakeDesktopData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
];
var myFakeTabletData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
];
var myFakeMobileData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Desktop',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeDesktopData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Tablet',
colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeTabletData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Mobile',
colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
@@ -96,51 +97,51 @@ class StackedAreaLineChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList,
return charts.LineChart(seriesList,
defaultRenderer:
new charts.LineRendererConfig(includeArea: true, stacked: true),
charts.LineRendererConfig(includeArea: true, stacked: true),
animate: animate);
}
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final myFakeDesktopData = [
new LinearSales(0, 5),
new LinearSales(1, 25),
new LinearSales(2, 100),
new LinearSales(3, 75),
LinearSales(0, 5),
LinearSales(1, 25),
LinearSales(2, 100),
LinearSales(3, 75),
];
var myFakeTabletData = [
new LinearSales(0, 10),
new LinearSales(1, 50),
new LinearSales(2, 200),
new LinearSales(3, 150),
LinearSales(0, 10),
LinearSales(1, 50),
LinearSales(2, 200),
LinearSales(3, 150),
];
var myFakeMobileData = [
new LinearSales(0, 15),
new LinearSales(1, 75),
new LinearSales(2, 300),
new LinearSales(3, 225),
LinearSales(0, 15),
LinearSales(1, 75),
LinearSales(2, 300),
LinearSales(3, 225),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Desktop',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeDesktopData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Tablet',
colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeTabletData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Mobile',
colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,

View File

@@ -28,11 +28,13 @@ class StackedAreaCustomColorLineChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
StackedAreaCustomColorLineChart(this.seriesList, {this.animate});
const StackedAreaCustomColorLineChart(this.seriesList,
{this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and no transition.
factory StackedAreaCustomColorLineChart.withSampleData() {
return new StackedAreaCustomColorLineChart(
return StackedAreaCustomColorLineChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -44,50 +46,50 @@ class StackedAreaCustomColorLineChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory StackedAreaCustomColorLineChart.withRandomData() {
return new StackedAreaCustomColorLineChart(_createRandomData());
return StackedAreaCustomColorLineChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
final myFakeDesktopData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
];
var myFakeTabletData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
];
var myFakeMobileData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Desktop',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeDesktopData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Tablet',
colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeTabletData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Mobile',
colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
@@ -100,37 +102,37 @@ class StackedAreaCustomColorLineChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList,
return charts.LineChart(seriesList,
defaultRenderer:
new charts.LineRendererConfig(includeArea: true, stacked: true),
charts.LineRendererConfig(includeArea: true, stacked: true),
animate: animate);
}
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final myFakeDesktopData = [
new LinearSales(0, 5),
new LinearSales(1, 25),
new LinearSales(2, 100),
new LinearSales(3, 75),
LinearSales(0, 5),
LinearSales(1, 25),
LinearSales(2, 100),
LinearSales(3, 75),
];
var myFakeTabletData = [
new LinearSales(0, 10),
new LinearSales(1, 50),
new LinearSales(2, 200),
new LinearSales(3, 150),
LinearSales(0, 10),
LinearSales(1, 50),
LinearSales(2, 200),
LinearSales(3, 150),
];
var myFakeMobileData = [
new LinearSales(0, 15),
new LinearSales(1, 75),
new LinearSales(2, 300),
new LinearSales(3, 225),
LinearSales(0, 15),
LinearSales(1, 75),
LinearSales(2, 300),
LinearSales(3, 225),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Desktop',
// colorFn specifies that the line will be blue.
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
@@ -141,7 +143,7 @@ class StackedAreaCustomColorLineChart extends StatelessWidget {
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeDesktopData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Tablet',
// colorFn specifies that the line will be red.
colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault,
@@ -151,7 +153,7 @@ class StackedAreaCustomColorLineChart extends StatelessWidget {
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeTabletData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Mobile',
// colorFn specifies that the line will be green.
colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault,

View File

@@ -37,11 +37,12 @@ class StackedAreaNullsLineChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
StackedAreaNullsLineChart(this.seriesList, {this.animate});
const StackedAreaNullsLineChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [LineChart] with sample data and no transition.
factory StackedAreaNullsLineChart.withSampleData() {
return new StackedAreaNullsLineChart(
return StackedAreaNullsLineChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -53,59 +54,59 @@ class StackedAreaNullsLineChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory StackedAreaNullsLineChart.withRandomData() {
return new StackedAreaNullsLineChart(_createRandomData());
return StackedAreaNullsLineChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, num>> _createRandomData() {
final random = new Random();
final random = Random();
final myFakeDesktopData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, null),
new LinearSales(3, random.nextInt(100)),
new LinearSales(4, random.nextInt(100)),
new LinearSales(5, random.nextInt(100)),
new LinearSales(6, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, null),
LinearSales(3, random.nextInt(100)),
LinearSales(4, random.nextInt(100)),
LinearSales(5, random.nextInt(100)),
LinearSales(6, random.nextInt(100)),
];
var myFakeTabletData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
new LinearSales(4, random.nextInt(100)),
new LinearSales(5, random.nextInt(100)),
new LinearSales(6, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
LinearSales(4, random.nextInt(100)),
LinearSales(5, random.nextInt(100)),
LinearSales(6, random.nextInt(100)),
];
var myFakeMobileData = [
new LinearSales(0, random.nextInt(100)),
new LinearSales(1, random.nextInt(100)),
new LinearSales(2, random.nextInt(100)),
new LinearSales(3, random.nextInt(100)),
new LinearSales(4, null),
new LinearSales(5, random.nextInt(100)),
new LinearSales(6, random.nextInt(100)),
LinearSales(0, random.nextInt(100)),
LinearSales(1, random.nextInt(100)),
LinearSales(2, random.nextInt(100)),
LinearSales(3, random.nextInt(100)),
LinearSales(4, null),
LinearSales(5, random.nextInt(100)),
LinearSales(6, random.nextInt(100)),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Desktop',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeDesktopData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Tablet',
colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeTabletData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Mobile',
colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
@@ -118,60 +119,60 @@ class StackedAreaNullsLineChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.LineChart(seriesList,
return charts.LineChart(seriesList,
defaultRenderer:
new charts.LineRendererConfig(includeArea: true, stacked: true),
charts.LineRendererConfig(includeArea: true, stacked: true),
animate: animate);
}
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final myFakeDesktopData = [
new LinearSales(0, 5),
new LinearSales(1, 15),
new LinearSales(2, null),
new LinearSales(3, 75),
new LinearSales(4, 100),
new LinearSales(5, 90),
new LinearSales(6, 75),
LinearSales(0, 5),
LinearSales(1, 15),
LinearSales(2, null),
LinearSales(3, 75),
LinearSales(4, 100),
LinearSales(5, 90),
LinearSales(6, 75),
];
final myFakeTabletData = [
new LinearSales(0, 5),
new LinearSales(1, 15),
new LinearSales(2, 25),
new LinearSales(3, 75),
new LinearSales(4, 100),
new LinearSales(5, 90),
new LinearSales(6, 75),
LinearSales(0, 5),
LinearSales(1, 15),
LinearSales(2, 25),
LinearSales(3, 75),
LinearSales(4, 100),
LinearSales(5, 90),
LinearSales(6, 75),
];
final myFakeMobileData = [
new LinearSales(0, 5),
new LinearSales(1, 15),
new LinearSales(2, 25),
new LinearSales(3, 75),
new LinearSales(4, null),
new LinearSales(5, 90),
new LinearSales(6, 75),
LinearSales(0, 5),
LinearSales(1, 15),
LinearSales(2, 25),
LinearSales(3, 75),
LinearSales(4, null),
LinearSales(5, 90),
LinearSales(6, 75),
];
return [
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Desktop',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeDesktopData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Tablet',
colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
data: myFakeTabletData,
),
new charts.Series<LinearSales, int>(
charts.Series<LinearSales, int>(
id: 'Mobile',
colorFn: (_, __) => charts.MaterialPalette.green.shadeDefault,
domainFn: (LinearSales sales, _) => sales.year,