Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
27 changes: 15 additions & 12 deletions example/lib/presentation/samples/bar/bar_chart_sample1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ class BarChartSample1State extends State<BarChartSample1> {
x: x,
barRods: [
BarChartRodData(
borderRadius: BorderRadius.circular(0),
border: Border(
top: BorderSide(color: Colors.red, width: 6),
),
toY: isTouched ? y + 1 : y,
color: isTouched ? widget.touchedBarColor : barColor,
width: width,
Expand All @@ -138,18 +142,17 @@ class BarChartSample1State extends State<BarChartSample1> {
}

List<BarChartGroupData> showingGroups() => List.generate(
7,
(i) => switch (i) {
0 => makeGroupData(0, 5, isTouched: i == touchedIndex),
1 => makeGroupData(1, 6.5, isTouched: i == touchedIndex),
2 => makeGroupData(2, 5, isTouched: i == touchedIndex),
3 => makeGroupData(3, 7.5, isTouched: i == touchedIndex),
4 => makeGroupData(4, 9, isTouched: i == touchedIndex),
5 => makeGroupData(5, 11.5, isTouched: i == touchedIndex),
6 => makeGroupData(6, 6.5, isTouched: i == touchedIndex),
_ => throw Error(),
}
);
7,
(i) => switch (i) {
0 => makeGroupData(0, 5, isTouched: i == touchedIndex),
1 => makeGroupData(1, 6.5, isTouched: i == touchedIndex),
2 => makeGroupData(2, 5, isTouched: i == touchedIndex),
3 => makeGroupData(3, 7.5, isTouched: i == touchedIndex),
4 => makeGroupData(4, 9, isTouched: i == touchedIndex),
5 => makeGroupData(5, 11.5, isTouched: i == touchedIndex),
6 => makeGroupData(6, 6.5, isTouched: i == touchedIndex),
_ => throw Error(),
});

BarChartData mainBarData() {
return BarChartData(
Expand Down
30 changes: 29 additions & 1 deletion lib/src/chart/bar_chart/bar_chart_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,28 @@ class BarChartGroupData with EquatableMixin {
];
}

Border? _normalizeBorder(Border? border, double width) {
Comment thread
haashem marked this conversation as resolved.
Outdated
if (border == null) {
return null;
}

final utils = Utils();
return Border(
top: utils.normalizeBorderSide(border.top, width),
right: utils.normalizeBorderSide(border.right, width),
bottom: utils.normalizeBorderSide(border.bottom, width),
left: utils.normalizeBorderSide(border.left, width),
);
}

/// Holds data about rendering each rod (or bar) in the [BarChart].
class BarChartRodData with EquatableMixin {
/// [BarChart] renders rods vertically from zero to [toY],
/// 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.
/// It renders each rod using [color], [width], and [borderRadius] for
/// rounding corners and also [borderSide] or [border] for stroke
/// border.
/// Optionally you can use [borderDashArray] if you want your borders to have dashed lines.
///
/// This bar draws with provided [color] or [gradient].
Expand Down Expand Up @@ -338,6 +354,7 @@ class BarChartRodData with EquatableMixin {
BorderRadius? borderRadius,
this.borderDashArray,
BorderSide? borderSide,
Border? border,
BackgroundBarChartRodData? backDrawRodData,
List<BarChartRodStackItem>? rodStackItems,
this.label = const BarChartRodLabel(show: false),
Expand All @@ -347,6 +364,7 @@ class BarChartRodData with EquatableMixin {
width = width ?? 8,
borderRadius = Utils().normalizeBorderRadius(borderRadius, width ?? 8),
borderSide = Utils().normalizeBorderSide(borderSide, width ?? 8),
Comment thread
haashem marked this conversation as resolved.
border = _normalizeBorder(border, width ?? 8),
backDrawRodData = backDrawRodData ?? BackgroundBarChartRodData(),
rodStackItems = rodStackItems ?? const [];

Expand Down Expand Up @@ -387,6 +405,12 @@ class BarChartRodData with EquatableMixin {
/// If you want to have a border for rod, set this value.
final BorderSide borderSide;

/// If you want different borders for each side of rod, set this value.
///
/// If both [border] and [borderSide] are provided, [border]
/// takes precedence in rendering.
final Border? border;

/// If you want to have a bar drawn in rear of this rod, use [backDrawRodData],
/// it uses to have a bar with a passive color in rear of the rod,
/// for example you can use it as the maximum value place holder.
Expand Down Expand Up @@ -414,6 +438,7 @@ class BarChartRodData with EquatableMixin {
BorderRadius? borderRadius,
List<int>? dashArray,
BorderSide? borderSide,
Border? border,
BackgroundBarChartRodData? backDrawRodData,
List<BarChartRodStackItem>? rodStackItems,
BarChartRodLabel? label,
Expand All @@ -428,6 +453,7 @@ class BarChartRodData with EquatableMixin {
borderRadius: borderRadius ?? this.borderRadius,
borderDashArray: borderDashArray,
borderSide: borderSide ?? this.borderSide,
border: border ?? this.border,
backDrawRodData: backDrawRodData ?? this.backDrawRodData,
rodStackItems: rodStackItems ?? this.rodStackItems,
label: label ?? this.label,
Expand All @@ -442,6 +468,7 @@ class BarChartRodData with EquatableMixin {
borderRadius: BorderRadius.lerp(a.borderRadius, b.borderRadius, t),
borderDashArray: lerpIntList(a.borderDashArray, b.borderDashArray, t),
borderSide: BorderSide.lerp(a.borderSide, b.borderSide, t),
border: Border.lerp(a.border, b.border, t),
fromY: lerpDouble(a.fromY, b.fromY, t),
toY: lerpDouble(a.toY, b.toY, t)!,
toYErrorRange: FlErrorRange.lerp(a.toYErrorRange, b.toYErrorRange, t),
Expand All @@ -465,6 +492,7 @@ class BarChartRodData with EquatableMixin {
borderRadius,
borderDashArray,
borderSide,
border,
backDrawRodData,
rodStackItems,
color,
Expand Down
Loading
Loading