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

Feature/dashed lines and cut off value #63

Closed
wants to merge 5 commits into from
Closed
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
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
Expand Up @@ -152,7 +152,7 @@ class LineChartSample1State extends State<LineChartSample1> {
dotData: FlDotData(
show: false,
),
belowBarData: BelowBarData(
barAreaData: BarAreaData(
show: false,
),
),
Expand All @@ -174,7 +174,7 @@ class LineChartSample1State extends State<LineChartSample1> {
dotData: FlDotData(
show: false,
),
belowBarData: BelowBarData(
barAreaData: BarAreaData(
show: false,
),
),
Expand All @@ -195,7 +195,7 @@ class LineChartSample1State extends State<LineChartSample1> {
dotData: FlDotData(
show: false,
),
belowBarData: BelowBarData(
barAreaData: BarAreaData(
show: false,
),
),
Expand Down
9 changes: 7 additions & 2 deletions example/lib/line_chart/samples/line_chart_sample2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class LineChartSample2 extends StatelessWidget {
Color(0xff23b6e6),
Color(0xff02d39a),
];
List<Color> otherGradientColors = [
Colors.red, Colors.redAccent
];
return AspectRatio(
aspectRatio: 1.70,
child: Container(
Expand Down Expand Up @@ -103,9 +106,11 @@ class LineChartSample2 extends StatelessWidget {
dotData: FlDotData(
show: false,
),
belowBarData: BelowBarData(
barAreaData: BarAreaData(
show: true,
colors: gradientColors.map((color) => color.withOpacity(0.3)).toList(),
yCutOff: 3.05,
belowColors: gradientColors.map((color) => color.withOpacity(0.3)).toList(),
aboveColors: otherGradientColors.map((color) => color.withOpacity(0.3)).toList()
),
),
],
Expand Down
8 changes: 4 additions & 4 deletions example/lib/line_chart/samples/line_chart_sample3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ class LineChartSample3 extends StatelessWidget {
colors: [
Colors.orange,
],
belowBarData: BelowBarData(
barAreaData: BarAreaData(
show: true,
colors: [
belowColors: [
Colors.orange.withOpacity(0.5),
Colors.orange.withOpacity(0.0),
],
gradientColorStops: [0.5, 1.0],
gradientFrom: Offset(0, 0),
gradientTo: Offset(0, 1),
belowGradientFrom: Offset(0, 0),
belowGradientTo: Offset(0, 1),
belowSpotsLine: BelowSpotsLine(
show: true,
flLineStyle: const FlLine(
Expand Down
4 changes: 2 additions & 2 deletions example/lib/line_chart/samples/line_chart_sample4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class LineChartSample4 extends StatelessWidget {
colors: [
Colors.purpleAccent,
],
belowBarData: BelowBarData(
barAreaData: BarAreaData(
show: true,
colors: [Colors.deepPurple.withOpacity(0.2)],
belowColors: [Colors.deepPurple.withOpacity(0.2)],
),
dotData: FlDotData(
show: false,
Expand Down
2 changes: 1 addition & 1 deletion example/lib/line_chart/samples/line_chart_sample5.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LineChartSample5 extends StatelessWidget {
],
isCurved: true,
barWidth: 4,
belowBarData: BelowBarData(
barAreaData: BarAreaData(
show: true,
),
dotData: FlDotData(show: false),
Expand Down
4 changes: 2 additions & 2 deletions example/lib/line_chart/samples/line_chart_sample6.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class LineChartSample6 extends StatelessWidget {
isCurved: true,
isStrokeCapRound: true,
barWidth: 10,
belowBarData: const BelowBarData(
barAreaData: const BarAreaData(
show: false,
),
dotData: FlDotData(
Expand All @@ -103,7 +103,7 @@ class LineChartSample6 extends StatelessWidget {
isCurved: true,
isStrokeCapRound: true,
barWidth: 10,
belowBarData: const BelowBarData(
barAreaData: const BarAreaData(
show: false,
),
dotData: FlDotData(
Expand Down
4 changes: 4 additions & 0 deletions lib/src/chart/base/axis_chart/axis_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,14 @@ class FlGridData {
class FlLine {
final Color color;
final double strokeWidth;
final bool isDashed;
final double dashLength;

const FlLine({
this.color = Colors.black,
this.strokeWidth = 2,
this.isDashed,
this.dashLength
});
}

Expand Down
42 changes: 30 additions & 12 deletions lib/src/chart/line_chart/line_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class LineChartBarData {
final bool isStrokeCapRound;

/// to fill space below the bar line,
final BelowBarData belowBarData;
final BarAreaData barAreaData;

/// to show dot spots upon the line chart
final FlDotData dotData;
Expand All @@ -157,29 +157,32 @@ class LineChartBarData {
this.curveSmoothness = 0.35,
this.preventCurveOverShooting = false,
this.isStrokeCapRound = false,
this.belowBarData = const BelowBarData(),
this.barAreaData = const BarAreaData(),
this.dotData = const FlDotData(),
});
}

/***** BelowBarData *****/
/// This class holds data about draw on below space of the bar line,
class BelowBarData {
class BarAreaData {
final bool show;

/// if you pass just one color, the solid color will be used,
/// or if you pass more than one color, we use gradient mode to draw.
/// then the [gradientFrom], [gradientTo] and [gradientColorStops] is important,
final List<Color> colors;
final List<Color> belowColors;
final List<Color> aboveColors;

/// if the gradient mode is enabled (if you have more than one color)
/// [gradientFrom] and [gradientTo] is important otherwise they will be skipped.
/// you can determine where the gradient should start and end,
/// values are available between 0 to 1,
/// Offset(0, 0) represent the top / left
/// Offset(1, 1) represent the bottom / right
final Offset gradientFrom;
final Offset gradientTo;
final Offset belowGradientFrom;
final Offset belowGradientTo;
final Offset aboveGradientFrom;
final Offset aboveGradientTo;

/// if more than one color provided gradientColorStops will hold
/// stop points of the gradient.
Expand All @@ -189,13 +192,20 @@ class BelowBarData {
/// holds data for drawing a line from each spot the the bottom of the chart
final BelowSpotsLine belowSpotsLine;

const BelowBarData({
// y value line to draw under graph area color around
final double yCutOff;

const BarAreaData({
this.show = true,
this.colors = const [Colors.blueGrey],
this.gradientFrom = const Offset(0, 0),
this.gradientTo = const Offset(1, 0),
this.belowColors = const [Colors.blueGrey],
this.aboveColors = const [Colors.redAccent],
this.belowGradientFrom = const Offset(0, 0),
this.belowGradientTo = const Offset(1, 0),
this.aboveGradientFrom = const Offset(0, 0),
this.aboveGradientTo = const Offset(0, 1),
this.gradientColorStops,
this.belowSpotsLine = const BelowSpotsLine(),
this.yCutOff = 0,
});
}

Expand Down Expand Up @@ -252,22 +262,30 @@ class FlDotData {
/// and the x is dynamic
class HorizontalLine extends FlLine {
final double x;
final bool isDashed;
final double dashLength;
HorizontalLine({
this.x,
Color color = Colors.black,
double strokeWidth = 2,
}) : super(color: color, strokeWidth: strokeWidth);
this.isDashed = false,
this.dashLength = 5.0
}) : super(color: color, strokeWidth: strokeWidth, );
}

/// vertical lines draw from left to right of the chart
/// and the y is dynamic
class VerticalLine extends FlLine {
final double y;
final bool isDashed;
final double dashLength;
VerticalLine({
this.y,
Color color = Colors.black,
double strokeWidth = 2,
}) : super(color: color, strokeWidth: strokeWidth);
this.isDashed = false,
this.dashLength = 5.0
}) : super(color: color, strokeWidth: strokeWidth, isDashed: isDashed, dashLength: dashLength);
}

/// we use ExtraLinesData to draw straight horizontal and vertical lines,
Expand Down
Loading