Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/refactor class names #7

Merged
merged 2 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

## 0.0.2
* fixed `minX`, `maxX` functionality on LineChart
* restricted to access private classes of the library
* restricted to access private classes of the library

## 0.0.3
* renamed `FlChartWidget` to `FlChart` (our main widget) and now you have to import `package:fl_chart/fl_chart.dart` instead of `package:fl_chart/fl_chart_widget.dart`
* renamed `FlChart*` to `BaseChart*` (parent class of our charts like `PieChart`)
* renamed `FlAxisChart*` to `AxisChart*`
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Thank you all!

```kotlin
dependencies:
fl_chart: ^0.0.2
fl_chart: ^0.0.3
```


Expand Down
6 changes: 3 additions & 3 deletions example/lib/bar_chart/samples/bar_chart_sample1.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:fl_chart/fl_chart_widget.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

class BarChartSample1 extends StatelessWidget {
Expand Down Expand Up @@ -40,8 +40,8 @@ class BarChartSample1 extends StatelessWidget {
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: FlChartWidget(
flChart: BarChart(BarChartData(
child: FlChart(
chart: BarChart(BarChartData(
titlesData: FlTitlesData(
show: true,
showHorizontalTitles: true,
Expand Down
6 changes: 3 additions & 3 deletions example/lib/bar_chart/samples/bar_chart_sample2.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:fl_chart/fl_chart_widget.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

class BarChartSample2 extends StatelessWidget {
Expand Down Expand Up @@ -50,8 +50,8 @@ class BarChartSample2 extends StatelessWidget {
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: FlChartWidget(
flChart: BarChart(BarChartData(
child: FlChart(
chart: BarChart(BarChartData(
titlesData: FlTitlesData(
show: true,
showHorizontalTitles: true,
Expand Down
6 changes: 3 additions & 3 deletions example/lib/line_chart/samples/line_chart_sample1.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:fl_chart/fl_chart_widget.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

class LineChartSample1 extends StatelessWidget {
Expand Down Expand Up @@ -36,8 +36,8 @@ class LineChartSample1 extends StatelessWidget {
Expanded(
child: Padding(
padding: const EdgeInsets.only(right: 16.0, left: 6.0),
child: FlChartWidget(
flChart: LineChart(
child: FlChart(
chart: LineChart(
LineChartData(
gridData: FlGridData(
show: false,
Expand Down
6 changes: 3 additions & 3 deletions example/lib/line_chart/samples/line_chart_sample2.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:fl_chart/fl_chart_widget.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

class LineChartSample2 extends StatelessWidget {
Expand All @@ -18,8 +18,8 @@ class LineChartSample2 extends StatelessWidget {
),
child: Padding(
padding: const EdgeInsets.only(right: 18.0, left: 12.0, top: 24, bottom: 12),
child: FlChartWidget(
flChart: LineChart(
child: FlChart(
chart: LineChart(
LineChartData(
gridData: FlGridData(
show: true,
Expand Down
6 changes: 3 additions & 3 deletions example/lib/line_chart/samples/line_chart_sample3.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:fl_chart/fl_chart_widget.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

class LineChartSample3 extends StatelessWidget {
Expand All @@ -8,8 +8,8 @@ class LineChartSample3 extends StatelessWidget {
return SizedBox(
width: 300,
height: 140,
child: FlChartWidget(
flChart: LineChart(
child: FlChart(
chart: LineChart(
LineChartData(
lineBarsData: [
LineChartBarData(
Expand Down
6 changes: 3 additions & 3 deletions example/lib/line_chart/samples/line_chart_sample4.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:fl_chart/fl_chart_widget.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

class LineChartSample4 extends StatelessWidget {
Expand All @@ -8,8 +8,8 @@ class LineChartSample4 extends StatelessWidget {
return SizedBox(
width: 300,
height: 140,
child: FlChartWidget(
flChart: LineChart(
child: FlChart(
chart: LineChart(
LineChartData(
lineBarsData: [
LineChartBarData(
Expand Down
6 changes: 3 additions & 3 deletions example/lib/line_chart/samples/line_chart_sample5.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:fl_chart/fl_chart_widget.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

class LineChartSample5 extends StatelessWidget {
Expand All @@ -8,8 +8,8 @@ class LineChartSample5 extends StatelessWidget {
return SizedBox(
width: 300,
height: 140,
child: FlChartWidget(
flChart: LineChart(
child: FlChart(
chart: LineChart(
LineChartData(
lineBarsData: [
LineChartBarData(
Expand Down
6 changes: 3 additions & 3 deletions example/lib/pie_chart/samples/pie_chart_sample1.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:fl_chart/fl_chart_widget.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

import 'indicator.dart';
Expand Down Expand Up @@ -67,8 +67,8 @@ class PieChartSample1 extends StatelessWidget {
Expanded(
child: AspectRatio(
aspectRatio: 1,
child: FlChartWidget(
flChart: PieChart(
child: FlChart(
chart: PieChart(
PieChartData(
startDegreeOffset: 180,
borderData: FlBorderData(
Expand Down
6 changes: 3 additions & 3 deletions example/lib/pie_chart/samples/pie_chart_sample2.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:fl_chart/fl_chart_widget.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

import 'indicator.dart';
Expand Down Expand Up @@ -50,8 +50,8 @@ class PieChartSample2 extends StatelessWidget {
Expanded(
child: AspectRatio(
aspectRatio: 1,
child: FlChartWidget(
flChart: PieChart(
child: FlChart(
chart: PieChart(
PieChartData(
borderData: FlBorderData(
show: false,
Expand Down
49 changes: 49 additions & 0 deletions lib/fl_chart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
library fl_chart;

import 'package:flutter/material.dart';

import 'src/chart/bar_chart/bar_chart.dart';
import 'src/chart/base/base_chart/base_chart.dart';
import 'src/chart/base/base_chart/base_chart_painter.dart';
import 'src/chart/line_chart/line_chart.dart';
import 'src/chart/pie_chart/pie_chart.dart';

export 'src/chart/bar_chart/bar_chart.dart';
export 'src/chart/bar_chart/bar_chart_data.dart';
export 'src/chart/base/axis_chart/axis_chart_data.dart';
export 'src/chart/base/base_chart/base_chart_data.dart';
export 'src/chart/line_chart/line_chart.dart';
export 'src/chart/line_chart/line_chart_data.dart';
export 'src/chart/pie_chart/pie_chart.dart';
export 'src/chart/pie_chart/pie_chart_data.dart';


/// A base widget that holds a [BaseChart] class
/// that contains [BaseChartPainter] extends from [CustomPainter]
/// to paint the relative content on our [CustomPaint] class
/// [BaseChart] is an abstract class and we should use a concrete class
/// such as [LineChart], [BarChart], [PieChart].
class FlChart extends StatefulWidget {
final BaseChart chart;

FlChart({
Key key,
@required this.chart,
}) : super(key: key) {
if (chart == null) {
throw Exception('chart might not be null');
}
}

@override
State<StatefulWidget> createState() => _FlChartState();
}

class _FlChartState extends State<FlChart> {
@override
Widget build(BuildContext context) {
return CustomPaint(
painter: widget.chart.painter(),
);
}
}
45 changes: 0 additions & 45 deletions lib/fl_chart_widget.dart

This file was deleted.

11 changes: 6 additions & 5 deletions lib/src/chart/bar_chart/bar_chart.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import '../base/fl_axis_chart/fl_axis_chart.dart';
import '../base/fl_chart/fl_chart_data.dart';
import '../base/fl_chart/fl_chart_painter.dart';
import 'package:fl_chart/src/chart/base/axis_chart/axis_chart.dart';
import 'package:fl_chart/src/chart/base/base_chart/base_chart_data.dart';
import 'package:fl_chart/src/chart/base/base_chart/base_chart_painter.dart';

import 'bar_chart_data.dart';
import 'bar_chart_painter.dart';

class BarChart extends FlAxisChart {
class BarChart extends AxisChart {
final BarChartData barChartData;

BarChart(
this.barChartData,
);

@override
FlChartPainter<FlChartData> painter() => BarChartPainter(barChartData);
BaseChartPainter<BaseChartData> painter() => BarChartPainter(barChartData);
}
9 changes: 4 additions & 5 deletions lib/src/chart/bar_chart/bar_chart_data.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import 'dart:ui';

import 'package:fl_chart/src/chart/base/axis_chart/axis_chart_data.dart';
import 'package:fl_chart/src/chart/base/base_chart/base_chart_data.dart';
import 'package:flutter/material.dart';

import '../base/fl_axis_chart/fl_axis_chart_data.dart';
import '../base/fl_chart/fl_chart_data.dart';

/// This class is responsible to holds data to draw Bar Chart
/// [barGroups] holds list of bar groups to show together,
/// [alignment] is the alignment of showing groups,
/// [titlesData] holds data about drawing left and bottom titles.
class BarChartData extends FlAxisChartData {
class BarChartData extends AxisChartData {
final List<BarChartGroupData> barGroups;
final BarChartAlignment alignment;
final FlTitlesData titlesData;
Expand All @@ -33,7 +32,7 @@ class BarChartData extends FlAxisChartData {
initSuperMinMaxValues(minX, maxX, minY, maxY);
}

/// we have to tell [FlAxisChartData] how much is our
/// we have to tell [AxisChartData] how much is our
/// minX, maxX, minY, maxY, values.
/// here we get them in our constructor, but if each of them was null,
/// we calculate it with the barGroups, and barRods data.
Expand Down
7 changes: 3 additions & 4 deletions lib/src/chart/bar_chart/bar_chart_painter.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:fl_chart/src/chart/bar_chart/bar_chart_data.dart';
import 'package:fl_chart/src/chart/base/axis_chart/axis_chart_painter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import '../bar_chart/bar_chart_data.dart';
import '../base/fl_axis_chart/fl_axis_chart_painter.dart';

class BarChartPainter extends FlAxisChartPainter {
class BarChartPainter extends AxisChartPainter {
final BarChartData data;

Paint barPaint;
Expand Down
8 changes: 8 additions & 0 deletions lib/src/chart/base/axis_chart/axis_chart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:fl_chart/src/chart/bar_chart/bar_chart.dart';
import 'package:fl_chart/src/chart/base/base_chart/base_chart.dart';
import 'package:fl_chart/src/chart/line_chart/line_chart.dart';

/// This class is suitable for axis base charts
/// in the axis base charts we have a grid behind the charts
/// the direct subclasses are [LineChart], [BarChart]
abstract class AxisChart extends BaseChart {}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import 'package:fl_chart/src/chart/base/base_chart/base_chart_data.dart';
import 'package:flutter/material.dart';

import '../fl_chart/fl_chart_data.dart';

/// This is the base class for axis base charts data
/// that contains a [FlGridData] that holds data for showing grid lines,
/// also we have [minX], [maxX], [minY], [maxY] values
/// we use them to determine how much is the scale of chart,
/// and calculate x and y according to the scale.
/// each child have to set it in their constructor.
class FlAxisChartData extends FlChartData {
class AxisChartData extends BaseChartData {
final FlGridData gridData;

double minX, maxX;
double minY, maxY;

FlAxisChartData({
AxisChartData({
this.gridData = const FlGridData(),
FlBorderData borderData,
this.minX, this.maxX,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import 'package:fl_chart/src/chart/bar_chart/bar_chart_painter.dart';
import 'package:fl_chart/src/chart/base/base_chart/base_chart_painter.dart';
import 'package:flutter/material.dart';

import '../../bar_chart/bar_chart_painter.dart';
import '../../base/fl_chart/fl_chart_painter.dart';
import 'fl_axis_chart_data.dart';
import 'axis_chart_data.dart';

/// This class is responsible to draw the grid behind all axis base charts.
/// also we have two useful function [getPixelX] and [getPixelY] that used
/// in child classes -> [BarChartPainter], [LineChartPainter]
abstract class FlAxisChartPainter<D extends FlAxisChartData> extends FlChartPainter<D> {
abstract class AxisChartPainter<D extends AxisChartData> extends BaseChartPainter<D> {
final D data;

Paint gridPaint;

FlAxisChartPainter(this.data) : super(data) {
AxisChartPainter(this.data) : super(data) {
gridPaint = Paint()..style = PaintingStyle.fill;
}

Expand Down
Loading