Skip to content

Commit

Permalink
Merge pull request #86 from imaNNeoFighT/bugfix/grid-lines-direction
Browse files Browse the repository at this point in the history
Bugfix/grid lines direction
  • Loading branch information
imaNNeo committed Oct 13, 2019
2 parents bbc743b + 5a488b4 commit 9423b71
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 0.3.4
* BREAKING CHANGES
* swapped horizontal and vertical semantics in [FlGridData](https://github.com/imaNNeoFighT/fl_chart/blob/master/repo_files/documentations/base_chart.md#FlGridData), fixed this [issue](https://github.com/imaNNeoFighT/fl_chart/issues/85).

## 0.3.3
* BREAKING CHANGES
* added support for drawing below and above areas separately in LineChart
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -36,7 +36,7 @@ Thank you all!

```kotlin
dependencies:
fl_chart: ^0.3.3
fl_chart: ^0.3.4
```


Expand Down
6 changes: 3 additions & 3 deletions example/lib/line_chart/samples/line_chart_sample2.dart
Expand Up @@ -63,14 +63,14 @@ class _LineChartSample2State extends State<LineChartSample2> {
return LineChartData(
gridData: FlGridData(
show: true,
drawHorizontalGrid: true,
getDrawingVerticalGridLine: (value) {
drawVerticalGrid: true,
getDrawingHorizontalGridLine: (value) {
return const FlLine(
color: Color(0xff37434d),
strokeWidth: 1,
);
},
getDrawingHorizontalGridLine: (value) {
getDrawingVerticalGridLine: (value) {
return const FlLine(
color: Color(0xff37434d),
strokeWidth: 1,
Expand Down
28 changes: 8 additions & 20 deletions example/lib/line_chart/samples/line_chart_sample3.dart
Expand Up @@ -23,24 +23,15 @@ class LineChartSample3 extends StatelessWidget {
children: const <Widget>[
Text(
'Average Line',
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.bold,
fontSize: 16),
style: TextStyle(color: Colors.green, fontWeight: FontWeight.bold, fontSize: 16),
),
Text(
' and ',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 16),
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 16),
),
Text(
'Indicators',
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
fontSize: 16),
style: TextStyle(color: Colors.blue, fontWeight: FontWeight.bold, fontSize: 16),
),
],
),
Expand All @@ -61,8 +52,7 @@ class LineChartSample3 extends StatelessWidget {
}
return TouchedSpotIndicatorData(
const FlLine(color: Colors.blue, strokeWidth: 4),
const FlDotData(
dotSize: 8, dotColor: Colors.deepOrange),
const FlDotData(dotSize: 8, dotColor: Colors.deepOrange),
);
}).toList();
},
Expand All @@ -81,8 +71,7 @@ class LineChartSample3 extends StatelessWidget {
);
}).toList();
})),
extraLinesData:
ExtraLinesData(showVerticalLines: true, verticalLines: [
extraLinesData: ExtraLinesData(showVerticalLines: true, verticalLines: [
VerticalLine(
y: 1.8,
color: Colors.green.withOpacity(0.7),
Expand Down Expand Up @@ -141,7 +130,7 @@ class LineChartSample3 extends StatelessWidget {
show: true,
drawHorizontalGrid: true,
drawVerticalGrid: true,
getDrawingVerticalGridLine: (value) {
getDrawingHorizontalGridLine: (value) {
if (value == 0) {
return const FlLine(
color: Colors.deepOrange,
Expand All @@ -154,7 +143,7 @@ class LineChartSample3 extends StatelessWidget {
);
}
},
getDrawingHorizontalGridLine: (value) {
getDrawingVerticalGridLine: (value) {
if (value == 0) {
return const FlLine(
color: Colors.black,
Expand Down Expand Up @@ -186,8 +175,7 @@ class LineChartSample3 extends StatelessWidget {

return '';
},
textStyle:
const TextStyle(color: Colors.black, fontSize: 10),
textStyle: const TextStyle(color: Colors.black, fontSize: 10),
),
bottomTitles: SideTitles(
showTitles: true,
Expand Down
2 changes: 1 addition & 1 deletion example/lib/line_chart/samples/line_chart_sample4.dart
Expand Up @@ -98,7 +98,7 @@ class LineChartSample4 extends StatelessWidget {
),
gridData: FlGridData(
show: true,
checkToShowVerticalGrid: (double value) {
checkToShowHorizontalGrid: (double value) {
return value == 1 || value == 6 || value == 4 || value == 5;
}),
),
Expand Down
4 changes: 2 additions & 2 deletions example/lib/line_chart/samples/line_chart_sample6.dart
Expand Up @@ -165,8 +165,8 @@ class LineChartSample6 extends StatelessWidget {
),
gridData: FlGridData(
show: true,
drawHorizontalGrid: true,
checkToShowVerticalGrid: (value) {
drawVerticalGrid: true,
checkToShowHorizontalGrid: (value) {
final intValue =
reverseY(value, minSpotY, maxSpotY).toInt();

Expand Down
4 changes: 2 additions & 2 deletions lib/src/chart/base/axis_chart/axis_chart_data.dart
Expand Up @@ -104,13 +104,13 @@ class FlGridData {
const FlGridData({
this.show = true,
// Horizontal
this.drawHorizontalGrid = false,
this.drawHorizontalGrid = true,
this.horizontalInterval = 1.0,
this.getDrawingHorizontalGridLine = defaultGridLine,
this.checkToShowHorizontalGrid = showAllGrids,

//Vertical
this.drawVerticalGrid = true,
this.drawVerticalGrid = false,
this.verticalInterval = 1.0,
this.getDrawingVerticalGridLine = defaultGridLine,
this.checkToShowVerticalGrid = showAllGrids,
Expand Down
28 changes: 14 additions & 14 deletions lib/src/chart/base/axis_chart/axis_chart_painter.dart
Expand Up @@ -51,19 +51,19 @@ abstract class AxisChartPainter<D extends AxisChartData>
final Size usableViewSize = getChartUsableDrawSize(viewSize);
// Show Vertical Grid
if (data.gridData.drawVerticalGrid) {
double verticalSeek = data.minY;
while (verticalSeek < data.maxY) {
double verticalSeek = data.minX;
while (verticalSeek < data.maxX) {
if (data.gridData.checkToShowVerticalGrid(verticalSeek)) {
final FlLine flLineStyle =
data.gridData.getDrawingVerticalGridLine(verticalSeek);
gridPaint.color = flLineStyle.color;
gridPaint.strokeWidth = flLineStyle.strokeWidth;

final double bothY = getPixelY(verticalSeek, usableViewSize);
final double x1 = 0 + getLeftOffsetDrawSize();
final double y1 = bothY;
final double x2 = usableViewSize.width + getLeftOffsetDrawSize();
final double y2 = bothY;
final double bothX = getPixelX(verticalSeek, usableViewSize);
final double x1 = bothX;
final double y1 = 0 + getTopOffsetDrawSize();
final double x2 = bothX;
final double y2 = usableViewSize.height + getTopOffsetDrawSize();
canvas.drawLine(
Offset(x1, y1),
Offset(x2, y2),
Expand All @@ -76,19 +76,19 @@ abstract class AxisChartPainter<D extends AxisChartData>

// Show Horizontal Grid
if (data.gridData.drawHorizontalGrid) {
double horizontalSeek = data.minX;
while (horizontalSeek < data.maxX) {
double horizontalSeek = data.minY;
while (horizontalSeek < data.maxY) {
if (data.gridData.checkToShowHorizontalGrid(horizontalSeek)) {
final FlLine flLine =
data.gridData.getDrawingHorizontalGridLine(horizontalSeek);
gridPaint.color = flLine.color;
gridPaint.strokeWidth = flLine.strokeWidth;

final double bothX = getPixelX(horizontalSeek, usableViewSize);
final double x1 = bothX;
final double y1 = 0 + getTopOffsetDrawSize();
final double x2 = bothX;
final double y2 = usableViewSize.height + getTopOffsetDrawSize();
final double bothY = getPixelY(horizontalSeek, usableViewSize);
final double x1 = 0 + getLeftOffsetDrawSize();
final double y1 = bothY;
final double x2 = usableViewSize.width + getLeftOffsetDrawSize();
final double y2 = bothY;
canvas.drawLine(
Offset(x1, y1),
Offset(x2, y2),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,6 +1,6 @@
name: fl_chart
description: A powerful Flutter chart library, currently supporting Line Chart, Bar Chart and Pie Chart.
version: 0.3.3
version: 0.3.4
author: Iman Khoshabi <iman.neofight@gmail.com>
homepage: https://github.com/imaNNeoFighT/fl_chart

Expand Down

0 comments on commit 9423b71

Please sign in to comment.