1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-10 06:48:26 +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 DonutAutoLabelChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
DonutAutoLabelChart(this.seriesList, {this.animate});
const DonutAutoLabelChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [PieChart] with sample data and no transition.
factory DonutAutoLabelChart.withSampleData() {
return new DonutAutoLabelChart(
return DonutAutoLabelChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -41,22 +42,22 @@ class DonutAutoLabelChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory DonutAutoLabelChart.withRandomData() {
return new DonutAutoLabelChart(_createRandomData());
return DonutAutoLabelChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, int>> _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',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
@@ -70,7 +71,7 @@ class DonutAutoLabelChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.PieChart(seriesList,
return charts.PieChart(seriesList,
animate: animate,
// Configure the width of the pie slices to 60px. The remaining space in
// the chart will be left as a hole in the center.
@@ -87,22 +88,21 @@ class DonutAutoLabelChart extends StatelessWidget {
// new charts.ArcLabelDecorator(
// insideLabelStyleSpec: new charts.TextStyleSpec(...),
// outsideLabelStyleSpec: new charts.TextStyleSpec(...)),
defaultRenderer: new charts.ArcRendererConfig(
arcWidth: 60,
arcRendererDecorators: [new charts.ArcLabelDecorator()]));
defaultRenderer: charts.ArcRendererConfig(
arcWidth: 60, arcRendererDecorators: [charts.ArcLabelDecorator()]));
}
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final data = [
new LinearSales(0, 100),
new LinearSales(1, 75),
new LinearSales(2, 25),
new LinearSales(3, 5),
LinearSales(0, 100),
LinearSales(1, 75),
LinearSales(2, 25),
LinearSales(3, 5),
];
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 DonutPieChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
DonutPieChart(this.seriesList, {this.animate});
const DonutPieChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [PieChart] with sample data and no transition.
factory DonutPieChart.withSampleData() {
return new DonutPieChart(
return DonutPieChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -40,22 +41,22 @@ class DonutPieChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory DonutPieChart.withRandomData() {
return new DonutPieChart(_createRandomData());
return DonutPieChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, int>> _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',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
@@ -67,24 +68,24 @@ class DonutPieChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.PieChart(seriesList,
return charts.PieChart(seriesList,
animate: animate,
// Configure the width of the pie slices to 60px. The remaining space in
// the chart will be left as a hole in the center.
defaultRenderer: new charts.ArcRendererConfig(arcWidth: 60));
defaultRenderer: charts.ArcRendererConfig(arcWidth: 60));
}
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final data = [
new LinearSales(0, 100),
new LinearSales(1, 75),
new LinearSales(2, 25),
new LinearSales(3, 5),
LinearSales(0, 100),
LinearSales(1, 75),
LinearSales(2, 25),
LinearSales(3, 5),
];
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,11 +25,11 @@ class GaugeChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
GaugeChart(this.seriesList, {this.animate});
const GaugeChart(this.seriesList, {this.animate, Key key}) : super(key: key);
/// Creates a [PieChart] with sample data and no transition.
factory GaugeChart.withSampleData() {
return new GaugeChart(
return GaugeChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -41,22 +41,22 @@ class GaugeChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory GaugeChart.withRandomData() {
return new GaugeChart(_createRandomData());
return GaugeChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<GaugeSegment, String>> _createRandomData() {
final random = new Random();
final random = Random();
final data = [
new GaugeSegment('Low', random.nextInt(100)),
new GaugeSegment('Acceptable', random.nextInt(100)),
new GaugeSegment('High', random.nextInt(100)),
new GaugeSegment('Highly Unusual', random.nextInt(100)),
GaugeSegment('Low', random.nextInt(100)),
GaugeSegment('Acceptable', random.nextInt(100)),
GaugeSegment('High', random.nextInt(100)),
GaugeSegment('Highly Unusual', random.nextInt(100)),
];
return [
new charts.Series<GaugeSegment, String>(
charts.Series<GaugeSegment, String>(
id: 'Segments',
domainFn: (GaugeSegment segment, _) => segment.segment,
measureFn: (GaugeSegment segment, _) => segment.size,
@@ -68,26 +68,26 @@ class GaugeChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.PieChart(seriesList,
return charts.PieChart(seriesList,
animate: animate,
// Configure the width of the pie slices to 30px. The remaining space in
// the chart will be left as a hole in the center. Adjust the start
// angle and the arc length of the pie so it resembles a gauge.
defaultRenderer: new charts.ArcRendererConfig(
defaultRenderer: charts.ArcRendererConfig(
arcWidth: 30, startAngle: 4 / 5 * pi, arcLength: 7 / 5 * pi));
}
/// Create one series with sample hard coded data.
static List<charts.Series<GaugeSegment, String>> _createSampleData() {
final data = [
new GaugeSegment('Low', 75),
new GaugeSegment('Acceptable', 100),
new GaugeSegment('High', 50),
new GaugeSegment('Highly Unusual', 5),
GaugeSegment('Low', 75),
GaugeSegment('Acceptable', 100),
GaugeSegment('High', 50),
GaugeSegment('Highly Unusual', 5),
];
return [
new charts.Series<GaugeSegment, String>(
charts.Series<GaugeSegment, String>(
id: 'Segments',
domainFn: (GaugeSegment segment, _) => segment.segment,
measureFn: (GaugeSegment segment, _) => segment.size,

View File

@@ -24,11 +24,12 @@ class PieOutsideLabelChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
PieOutsideLabelChart(this.seriesList, {this.animate});
const PieOutsideLabelChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [PieChart] with sample data and no transition.
factory PieOutsideLabelChart.withSampleData() {
return new PieOutsideLabelChart(
return PieOutsideLabelChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -40,22 +41,22 @@ class PieOutsideLabelChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory PieOutsideLabelChart.withRandomData() {
return new PieOutsideLabelChart(_createRandomData());
return PieOutsideLabelChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, int>> _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',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
@@ -69,7 +70,7 @@ class PieOutsideLabelChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new charts.PieChart(seriesList,
return charts.PieChart(seriesList,
animate: animate,
// Add an [ArcLabelDecorator] configured to render labels outside of the
// arc with a leader line.
@@ -81,8 +82,8 @@ class PieOutsideLabelChart extends StatelessWidget {
// new charts.ArcLabelDecorator(
// insideLabelStyleSpec: new charts.TextStyleSpec(...),
// outsideLabelStyleSpec: new charts.TextStyleSpec(...)),
defaultRenderer: new charts.ArcRendererConfig(arcRendererDecorators: [
new charts.ArcLabelDecorator(
defaultRenderer: charts.ArcRendererConfig(arcRendererDecorators: [
charts.ArcLabelDecorator(
labelPosition: charts.ArcLabelPosition.outside)
]));
}
@@ -90,14 +91,14 @@ class PieOutsideLabelChart extends StatelessWidget {
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final data = [
new LinearSales(0, 100),
new LinearSales(1, 75),
new LinearSales(2, 25),
new LinearSales(3, 5),
LinearSales(0, 100),
LinearSales(1, 75),
LinearSales(2, 25),
LinearSales(3, 5),
];
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,11 +25,12 @@ class PartialPieChart extends StatelessWidget {
final List<charts.Series> seriesList;
final bool animate;
PartialPieChart(this.seriesList, {this.animate});
const PartialPieChart(this.seriesList, {this.animate, Key key})
: super(key: key);
/// Creates a [PieChart] with sample data and no transition.
factory PartialPieChart.withSampleData() {
return new PartialPieChart(
return PartialPieChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
@@ -41,22 +42,22 @@ class PartialPieChart extends StatelessWidget {
// It is used for creating random series data to demonstrate animation in
// the example app only.
factory PartialPieChart.withRandomData() {
return new PartialPieChart(_createRandomData());
return PartialPieChart(_createRandomData());
}
/// Create random data.
static List<charts.Series<LinearSales, int>> _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',
domainFn: (LinearSales sales, _) => sales.year,
measureFn: (LinearSales sales, _) => sales.sales,
@@ -70,22 +71,22 @@ class PartialPieChart extends StatelessWidget {
Widget build(BuildContext context) {
// Configure the pie to display the data across only 3/4 instead of the full
// revolution.
return new charts.PieChart(seriesList,
return charts.PieChart(seriesList,
animate: animate,
defaultRenderer: new charts.ArcRendererConfig(arcLength: 3 / 2 * pi));
defaultRenderer: charts.ArcRendererConfig(arcLength: 3 / 2 * pi));
}
/// Create one series with sample hard coded data.
static List<charts.Series<LinearSales, int>> _createSampleData() {
final data = [
new LinearSales(0, 100),
new LinearSales(1, 75),
new LinearSales(2, 25),
new LinearSales(3, 5),
LinearSales(0, 100),
LinearSales(1, 75),
LinearSales(2, 25),
LinearSales(3, 5),
];
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,42 +24,42 @@ import 'partial_pie.dart';
List<GalleryScaffold> buildGallery() {
return [
new GalleryScaffold(
listTileIcon: new Icon(Icons.pie_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.pie_chart),
title: 'Simple Pie Chart',
subtitle: 'With a single series',
childBuilder: () => new SimplePieChart.withRandomData(),
childBuilder: () => SimplePieChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.pie_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.pie_chart),
title: 'Outside Label Pie Chart',
subtitle: 'With a single series and labels outside the arcs',
childBuilder: () => new PieOutsideLabelChart.withRandomData(),
childBuilder: () => PieOutsideLabelChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.pie_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.pie_chart),
title: 'Partial Pie Chart',
subtitle: 'That doesn\'t cover a full revolution',
childBuilder: () => new PartialPieChart.withRandomData(),
childBuilder: () => PartialPieChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.pie_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.pie_chart),
title: 'Simple Donut Chart',
subtitle: 'With a single series and a hole in the middle',
childBuilder: () => new DonutPieChart.withRandomData(),
childBuilder: () => DonutPieChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.pie_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.pie_chart),
title: 'Auto Label Donut Chart',
subtitle:
'With a single series, a hole in the middle, and auto-positioned labels',
childBuilder: () => new DonutAutoLabelChart.withRandomData(),
childBuilder: () => DonutAutoLabelChart.withRandomData(),
),
new GalleryScaffold(
listTileIcon: new Icon(Icons.pie_chart),
GalleryScaffold(
listTileIcon: const Icon(Icons.pie_chart),
title: 'Gauge Chart',
subtitle: 'That doesn\'t cover a full revolution',
childBuilder: () => new GaugeChart.withRandomData(),
childBuilder: () => GaugeChart.withRandomData(),
),
];
}

View File

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