Skip to content
Open
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/presentation/samples/bar/bar_chart_sample6.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,19 @@ class BarChartSample6 extends StatelessWidget {
y: 3.3,
color: pilateColor,
strokeWidth: 1,
dashArray: [20, 4],
pathData: const FlPathData(dashArray: [20, 4]),
),
HorizontalLine(
y: 8,
color: quickWorkoutColor,
strokeWidth: 1,
dashArray: [20, 4],
pathData: const FlPathData(dashArray: [20, 4]),
),
HorizontalLine(
y: 11,
color: cyclingColor,
strokeWidth: 1,
dashArray: [20, 4],
pathData: const FlPathData(dashArray: [20, 4]),
),
],
),
Expand Down
7 changes: 6 additions & 1 deletion example/lib/presentation/samples/bar/bar_chart_sample8.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ class BarChartSample1State extends State<BarChartSample8> {
toYErrorRange: errorRange,
color: x >= 4 ? Colors.transparent : widget.barColor,
borderRadius: BorderRadius.zero,
borderDashArray: x >= 4 ? [4, 4] : null,
pathData: x >= 4
? const FlPathData(
dashArray: [4, 4],
strokeCap: StrokeCap.round,
)
: null,
width: 22,
borderSide: BorderSide(color: widget.barColor, width: 2.0),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CandlestickChartSample1State extends State<CandlestickChartSample1> {
_gridLine = FlLine(
color: Colors.blueGrey.withValues(alpha: 0.4),
strokeWidth: 0.4,
dashArray: [8, 4],
pathData: const FlPathData(dashArray: [8, 4]),
);
super.initState();
}
Expand Down
12 changes: 6 additions & 6 deletions example/lib/presentation/samples/line/line_chart_sample1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class _LineChart extends StatelessWidget {
isCurved: true,
color: AppColors.contentColorGreen,
barWidth: 8,
isStrokeCapRound: true,
pathData: const FlPathData(strokeCap: StrokeCap.round),
dotData: const FlDotData(show: false),
belowBarData: BarAreaData(show: false),
spots: const [
Expand All @@ -184,7 +184,7 @@ class _LineChart extends StatelessWidget {
isCurved: true,
color: AppColors.contentColorPink,
barWidth: 8,
isStrokeCapRound: true,
pathData: const FlPathData(strokeCap: StrokeCap.round),
dotData: const FlDotData(show: false),
belowBarData: BarAreaData(
show: false,
Expand All @@ -204,7 +204,7 @@ class _LineChart extends StatelessWidget {
isCurved: true,
color: AppColors.contentColorCyan,
barWidth: 8,
isStrokeCapRound: true,
pathData: const FlPathData(strokeCap: StrokeCap.round),
dotData: const FlDotData(show: false),
belowBarData: BarAreaData(show: false),
spots: const [
Expand All @@ -221,7 +221,7 @@ class _LineChart extends StatelessWidget {
curveSmoothness: 0,
color: AppColors.contentColorGreen.withValues(alpha: 0.5),
barWidth: 4,
isStrokeCapRound: true,
pathData: const FlPathData(strokeCap: StrokeCap.round),
dotData: const FlDotData(show: false),
belowBarData: BarAreaData(show: false),
spots: const [
Expand All @@ -239,7 +239,7 @@ class _LineChart extends StatelessWidget {
isCurved: true,
color: AppColors.contentColorPink.withValues(alpha: 0.5),
barWidth: 4,
isStrokeCapRound: true,
pathData: const FlPathData(strokeCap: StrokeCap.round),
dotData: const FlDotData(show: false),
belowBarData: BarAreaData(
show: true,
Expand All @@ -260,7 +260,7 @@ class _LineChart extends StatelessWidget {
curveSmoothness: 0,
color: AppColors.contentColorCyan.withValues(alpha: 0.5),
barWidth: 2,
isStrokeCapRound: true,
pathData: const FlPathData(strokeCap: StrokeCap.round),
dotData: const FlDotData(show: true),
belowBarData: BarAreaData(show: false),
spots: const [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ class _Chart extends StatelessWidget {
return const FlLine(
color: Colors.white70,
strokeWidth: 1,
dashArray: [8, 4],
pathData: FlPathData(dashArray: [8, 4]),
);
} else {
return const FlLine(
color: Colors.blueGrey,
strokeWidth: 0.4,
dashArray: [8, 4],
pathData: FlPathData(dashArray: [8, 4]),
);
}
}
Expand All @@ -134,13 +134,13 @@ class _Chart extends StatelessWidget {
return const FlLine(
color: Colors.white70,
strokeWidth: 1,
dashArray: [8, 4],
pathData: FlPathData(dashArray: [8, 4]),
);
} else {
return const FlLine(
color: Colors.blueGrey,
strokeWidth: 0.4,
dashArray: [8, 4],
pathData: FlPathData(dashArray: [8, 4]),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class _LineChartSample12State extends State<LineChartSample12> {
const FlLine(
color: AppColors.contentColorRed,
strokeWidth: 1.5,
dashArray: [8, 2],
pathData: FlPathData(dashArray: [8, 2]),
),
FlDotData(
show: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class _LineChartSample13State extends State<LineChartSample13> {
return FlLine(
color: isZero ? Colors.white38 : Colors.blueGrey,
strokeWidth: isZero ? 0.8 : 0.4,
dashArray: isZero ? null : [8, 4],
pathData: isZero ? null : const FlPathData(dashArray: [8, 4]),
);
}

Expand Down
4 changes: 2 additions & 2 deletions example/lib/presentation/samples/line/line_chart_sample2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class _LineChartSample2State extends State<LineChartSample2> {
colors: gradientColors,
),
barWidth: 5,
isStrokeCapRound: true,
pathData: const FlPathData(strokeCap: StrokeCap.round),
dotData: const FlDotData(
show: false,
),
Expand Down Expand Up @@ -252,7 +252,7 @@ class _LineChartSample2State extends State<LineChartSample2> {
],
),
barWidth: 5,
isStrokeCapRound: true,
pathData: const FlPathData(strokeCap: StrokeCap.round),
dotData: const FlDotData(
show: false,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class _LineChartSample3State extends State<LineChartSample3> {
y: 1.8,
color: widget.averageLineColor,
strokeWidth: 3,
dashArray: [20, 10],
pathData: const FlPathData(dashArray: [20, 10]),
),
],
),
Expand Down
4 changes: 2 additions & 2 deletions example/lib/presentation/samples/line/line_chart_sample6.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class LineChartSample6 extends StatelessWidget {
),
spots: reverseSpots(spots, minSpotY, maxSpotY),
isCurved: true,
isStrokeCapRound: true,
pathData: const FlPathData(strokeCap: StrokeCap.round),
barWidth: 10,
belowBarData: BarAreaData(
show: false,
Expand Down Expand Up @@ -196,7 +196,7 @@ class LineChartSample6 extends StatelessWidget {
),
spots: reverseSpots(spots2, minSpotY, maxSpotY),
isCurved: true,
isStrokeCapRound: true,
pathData: const FlPathData(strokeCap: StrokeCap.round),
barWidth: 10,
belowBarData: BarAreaData(
show: false,
Expand Down
10 changes: 6 additions & 4 deletions example/lib/presentation/samples/line/line_chart_sample8.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class _LineChartSample8State extends State<LineChartSample8> {
y: 5,
color: AppColors.contentColorGreen,
strokeWidth: 2,
dashArray: [5, 10],
pathData: const FlPathData(dashArray: [5, 10]),
label: HorizontalLineLabel(
show: true,
alignment: Alignment.topRight,
Expand All @@ -164,7 +164,7 @@ class _LineChartSample8State extends State<LineChartSample8> {
x: 5.7,
color: AppColors.contentColorBlue,
strokeWidth: 2,
dashArray: [5, 10],
pathData: const FlPathData(dashArray: [5, 10]),
label: VerticalLineLabel(
show: true,
alignment: Alignment.bottomRight,
Expand Down Expand Up @@ -276,11 +276,13 @@ class _LineChartSample8State extends State<LineChartSample8> {
FlSpot(10, 2),
FlSpot(11, 2.5),
],
dashArray: [10, 6],
pathData: const FlPathData(
dashArray: [10, 6],
strokeCap: StrokeCap.round,
),
isCurved: true,
color: AppColors.contentColorRed,
barWidth: 4,
isStrokeCapRound: true,
dotData: const FlDotData(
show: false,
),
Expand Down
6 changes: 3 additions & 3 deletions example/lib/presentation/samples/line/line_chart_sample9.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class LineChartSample9 extends StatelessWidget {
color: AppColors.contentColorPink,
spots: spots,
isCurved: true,
isStrokeCapRound: true,
pathData: const FlPathData(strokeCap: StrokeCap.round),
barWidth: 3,
belowBarData: BarAreaData(
show: false,
Expand Down Expand Up @@ -131,12 +131,12 @@ class LineChartSample9 extends StatelessWidget {
},
getDrawingHorizontalLine: (_) => FlLine(
color: AppColors.contentColorBlue.withValues(alpha: 1),
dashArray: [8, 2],
pathData: const FlPathData(dashArray: [8, 2]),
strokeWidth: 0.8,
),
getDrawingVerticalLine: (_) => FlLine(
color: AppColors.contentColorYellow.withValues(alpha: 1),
dashArray: [8, 2],
pathData: const FlPathData(dashArray: [8, 2]),
strokeWidth: 0.8,
),
checkToShowVerticalLine: (value) {
Expand Down
1 change: 1 addition & 0 deletions lib/fl_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export 'src/chart/base/axis_chart/axis_chart_widgets.dart';
export 'src/chart/base/axis_chart/scale_axis.dart';
export 'src/chart/base/axis_chart/transformation_config.dart';
export 'src/chart/base/base_chart/base_chart_data.dart';
export 'src/chart/base/base_chart/fl_path_data.dart';
export 'src/chart/base/base_chart/fl_touch_event.dart';
export 'src/chart/candlestick_chart/candlestick_chart.dart';
export 'src/chart/candlestick_chart/candlestick_chart_data.dart';
Expand Down
22 changes: 14 additions & 8 deletions lib/src/chart/bar_chart/bar_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ class BarChartRodData with EquatableMixin {
/// and the x is equivalent to the [BarChartGroupData.x] value.
///
/// It renders each rod using [color], [width], and [borderRadius] for rounding corners and also [borderSide] for stroke border.
/// Optionally you can use [borderDashArray] if you want your borders to have dashed lines.
/// Optionally you can use [pathData] if you want your borders to have dashed
/// lines and configure their stroke cap and join.
///
/// This bar draws with provided [color] or [gradient].
/// You must provide one of them.
Expand Down Expand Up @@ -336,7 +337,8 @@ class BarChartRodData with EquatableMixin {
this.gradient,
double? width,
BorderRadius? borderRadius,
this.borderDashArray,
FlPathData? pathData,
@Deprecated('Use pathData.dashArray instead.') List<int>? borderDashArray,
BorderSide? borderSide,
BackgroundBarChartRodData? backDrawRodData,
List<BarChartRodStackItem>? rodStackItems,
Expand All @@ -346,6 +348,10 @@ class BarChartRodData with EquatableMixin {
color ?? ((color == null && gradient == null) ? Colors.cyan : null),
width = width ?? 8,
borderRadius = Utils().normalizeBorderRadius(borderRadius, width ?? 8),
pathData = pathData ??
(borderDashArray == null
? null
: FlPathData(dashArray: borderDashArray)),
borderSide = Utils().normalizeBorderSide(borderSide, width ?? 8),
backDrawRodData = backDrawRodData ?? BackgroundBarChartRodData(),
rodStackItems = rodStackItems ?? const [];
Expand Down Expand Up @@ -381,8 +387,8 @@ class BarChartRodData with EquatableMixin {
/// If you want to have a rounded rod, set this value.
final BorderRadius? borderRadius;

/// If you want to have dashed border, set this value.
final List<int>? borderDashArray;
/// Holds dash configuration for the rod border.
final FlPathData? pathData;

/// If you want to have a border for rod, set this value.
final BorderSide borderSide;
Expand Down Expand Up @@ -412,7 +418,7 @@ class BarChartRodData with EquatableMixin {
Gradient? gradient,
double? width,
BorderRadius? borderRadius,
List<int>? dashArray,
FlPathData? pathData,
BorderSide? borderSide,
BackgroundBarChartRodData? backDrawRodData,
List<BarChartRodStackItem>? rodStackItems,
Expand All @@ -426,7 +432,7 @@ class BarChartRodData with EquatableMixin {
gradient: gradient ?? this.gradient,
width: width ?? this.width,
borderRadius: borderRadius ?? this.borderRadius,
borderDashArray: borderDashArray,
pathData: pathData ?? this.pathData,
borderSide: borderSide ?? this.borderSide,
backDrawRodData: backDrawRodData ?? this.backDrawRodData,
rodStackItems: rodStackItems ?? this.rodStackItems,
Expand All @@ -440,7 +446,7 @@ class BarChartRodData with EquatableMixin {
color: Color.lerp(a.color, b.color, t),
width: lerpDouble(a.width, b.width, t),
borderRadius: BorderRadius.lerp(a.borderRadius, b.borderRadius, t),
borderDashArray: lerpIntList(a.borderDashArray, b.borderDashArray, t),
pathData: FlPathData.lerp(a.pathData, b.pathData, t),
borderSide: BorderSide.lerp(a.borderSide, b.borderSide, t),
fromY: lerpDouble(a.fromY, b.fromY, t),
toY: lerpDouble(a.toY, b.toY, t)!,
Expand All @@ -463,7 +469,7 @@ class BarChartRodData with EquatableMixin {
toYErrorRange,
width,
borderRadius,
borderDashArray,
pathData,
borderSide,
backDrawRodData,
rodStackItems,
Expand Down
9 changes: 7 additions & 2 deletions lib/src/chart/bar_chart/bar_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,20 @@ class BarChartPainter extends AxisChartPainter<BarChartData> {

// draw border stroke
if (borderSide.width > 0 && borderSide.color.a > 0) {
final pathData = barRod.pathData ?? const FlPathData();

_barStrokePaint
..color = borderSide.color
..strokeWidth = borderSide.width;
..strokeWidth = borderSide.width
..strokeCap = pathData.strokeCap
..strokeJoin = pathData.strokeJoin
..strokeMiterLimit = pathData.strokeMiterLimit;

final borderPath = Path()..addRRect(barRRect);

canvasWrapper.drawPath(
borderPath.toDashedPath(
barRod.borderDashArray,
pathData.dashArray,
),
_barStrokePaint,
);
Expand Down
Loading
Loading