Skip to content

Commit

Permalink
Merge branch 'remove-data'
Browse files Browse the repository at this point in the history
  • Loading branch information
thekeenant committed Apr 24, 2018
2 parents 4978441 + 1d378a8 commit 62f0e58
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 49 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.0.8

* Added more examples
* Wrapped up automatic span calculation

# 0.0.7

* New API for creating a line chart widget
Expand Down
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,37 @@ library) you will find the high level API to be somewhat familiar.

## Demo

![Bar chart demo](https://i.imgur.com/D1Rd7jk.gif) ![Touch demo](https://i.imgur.com/pvHhenr.gif)
![Bar chart demo](https://i.imgur.com/D1Rd7jk.gif) ![Touch demo](https://i.imgur.com/pvHhenr.gif)

## Example Usage



```dart
class SimpleLineChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
// X value -> Y value
final data = [
["A", "✔"],
["B", "❓"],
["C", "✖"],
["D", "❓"],
["E", "✖"],
["F", "✖"],
["G", "✔"],
];
return new LineChart(
lines: [
new Line<List<String>, String, String>(
data: data,
xFn: (datum) => datum[0],
yFn: (datum) => datum[1],
),
],
chartPadding: new EdgeInsets.fromLTRB(30.0, 10.0, 10.0, 30.0),
);
}
}
```
4 changes: 3 additions & 1 deletion example/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# fcharts_example

Demonstrates how to use the fcharts plugin.
Demonstrates how to use the fcharts plugin.

See `lib/line` for example charts.
2 changes: 0 additions & 2 deletions example/lib/data.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


/// 4-tiered level system.
enum Level {
Very,
Expand Down
45 changes: 45 additions & 0 deletions example/lib/line/city_coolness.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:fcharts/fcharts.dart';
import 'package:fcharts_example/data.dart';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';

/// A city in the world.
@immutable
class City {
const City(this.name, this.coolness);

/// The name of the city.
final String name;

/// How cool this city is, this is how we measure the city in the chart.
final Level coolness;
}

/// Our city data.
final cities = [
new City("District X", Level.Not),
new City("Gotham", Level.Kinda),
new City("Mos Eisley", Level.Quite),
new City("Palo Alto", Level.Very),
];

class CityCoolnessChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new LineChart.single(
chartPadding: new EdgeInsets.fromLTRB(60.0, 10.0, 10.0, 20.0),
line: new Line<City, String, Level>(
data: cities,
xFn: (city) => city.name,
yFn: (city) => city.coolness,
yAxis: new ChartAxis(
tickLabelFn: (coolness) =>
coolness.toString().replaceFirst("Level\.", ""),
),
marker:
const MarkerOptions(paint: const PaintOptions(color: Colors.blue)),
stroke: const PaintOptions.stroke(color: Colors.blue),
),
);
}
}
53 changes: 19 additions & 34 deletions example/lib/line/simple.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,29 @@ import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
import 'package:fcharts/fcharts.dart';

/// A city in the world.
@immutable
class City {
const City(this.name, this.coolness);

/// The name of the city.
final String name;

/// How cool this city is, this is how we measure the city in the chart.
final Level coolness;
}

/// Our city data.
final cities = [
new City("District X", Level.Not),
new City("Gotham", Level.Kinda),
new City("Mos Eisley", Level.Quite),
new City("Palo Alto", Level.Very),
];

class SimpleLineChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new LineChart.single(
chartPadding: new EdgeInsets.fromLTRB(60.0, 10.0, 10.0, 20.0),
line: new Line<City, String, Level>(
data: cities,
xFn: (city) => city.name,
yFn: (city) => city.coolness,
yAxis: new ChartAxis(
tickLabelFn: (coolness) =>
coolness.toString().replaceFirst("Level\.", ""),
),
marker: const MarkerOptions(
paint: const PaintOptions(color: Colors.blue)
// X value -> Y value
final data = [
["A", "✔"],
["B", "❓"],
["C", "✖"],
["D", "❓"],
["E", "✖"],
["F", "✖"],
["G", "✔"],
];

return new LineChart(
lines: [
new Line<List<String>, String, String>(
data: data,
xFn: (datum) => datum[0],
yFn: (datum) => datum[1],
),
stroke: const PaintOptions.stroke(color: Colors.blue),
),
],
chartPadding: new EdgeInsets.fromLTRB(30.0, 10.0, 10.0, 30.0),
);
}
}
42 changes: 34 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import 'package:fcharts_example/line/city_coolness.dart';
import 'package:fcharts_example/line/simple.dart';
import 'package:flutter/material.dart';

void main() => runApp(new FChartsExampleApp());

class ChartExample {
ChartExample(this.name, this.widget);
ChartExample(
this.name,
this.widget,
this.description,
);

final String name;
final Widget widget;
final String description;
}

final charts = [
new ChartExample('City Coolness', new SimpleLineChart()),
new ChartExample(
'Simple',
new SimpleLineChart(),
'Strings on the X-Axis and their index in the list on the Y-Axis.',
),
new ChartExample(
'City Coolness',
new CityCoolnessChart(),
'Cities on the X-Axis and coolness on the Y-Axis with a painted line.',
),
];

class FChartsExampleApp extends StatefulWidget {
Expand All @@ -35,12 +50,23 @@ class _MyAppState extends State<FChartsExampleApp> {
decoration: new BoxDecoration(
color: Colors.white,
),
child: new Padding(
padding: new EdgeInsets.all(20.0),
child: new AspectRatio(
aspectRatio: 4/3,
child: chart.widget,
),
child: new Column(
children: [
new Padding(
padding: new EdgeInsets.all(30.0),
child: new Text(
chart.description,
textAlign: TextAlign.center,
),
),
new Padding(
padding: new EdgeInsets.all(20.0),
child: new AspectRatio(
aspectRatio: 4 / 3,
child: chart.widget,
),
),
],
),
),
floatingActionButton: new FloatingActionButton(
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.0
fcharts:
path: ../
dev_dependencies:
flutter_test:
sdk: flutter
fcharts:
path: ../
flutter:
uses-material-design: true
6 changes: 6 additions & 0 deletions lib/src/widgets/chart_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ class _ChartViewState extends State<ChartView> with TickerProviderStateMixin {
Animation<double> _curve;
_ChartPainter _painter;

@override
void dispose() {
_controller.dispose();
super.dispose();
}

_ChartPainter _createPainter() {
final charts = widget.charts;
final decor = widget.decor == null ? ChartDecor.none : widget.decor;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: fcharts
description: >
A composable chart library for Flutter. Create beautiful,
animated, responsive charts using a simple and intuitive API.
version: 0.0.7
version: 0.0.8
author: Keenan Thompson <keenan@keenant.com>
homepage: https://github.com/thekeenant/fcharts

Expand Down

0 comments on commit 62f0e58

Please sign in to comment.