Skip to content

Commit

Permalink
Run dart format
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaknezic committed Sep 12, 2023
1 parent 62f4874 commit 6efaa19
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 122 deletions.
76 changes: 54 additions & 22 deletions example/lib/charts/scrollable_chart_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class _ScrollableChartScreenState extends State<ScrollableChartScreen> {
final Random _rand = Random();
final double _difference = _rand.nextDouble() * 15;

targetMax = 3 + ((_rand.nextDouble() * _difference * 0.75) - (_difference * 0.25)).roundToDouble();
targetMax = 3 +
((_rand.nextDouble() * _difference * 0.75) - (_difference * 0.25))
.roundToDouble();
_values.addAll(List.generate(minItems, (index) {
return 2 + _rand.nextDouble() * _difference;
}));
Expand All @@ -56,7 +58,10 @@ class _ScrollableChartScreenState extends State<ScrollableChartScreen> {
final targetArea = TargetAreaDecoration(
targetMax: targetMax + 2,
targetMin: targetMax,
colorOverTarget: Theme.of(context).colorScheme.error.withOpacity(_showBars ? 1.0 : 0.0),
colorOverTarget: Theme.of(context)
.colorScheme
.error
.withOpacity(_showBars ? 1.0 : 0.0),
targetAreaFillColor: Theme.of(context).colorScheme.error.withOpacity(0.2),
targetLineColor: Theme.of(context).colorScheme.error,
targetAreaRadius: BorderRadius.circular(12.0),
Expand All @@ -73,15 +78,20 @@ class _ScrollableChartScreenState extends State<ScrollableChartScreen> {
barItemBuilder: (data) {
return BarItem(
color: targetArea.getTargetItemColor(
Theme.of(context).colorScheme.primary.withOpacity(_showBars ? 1.0 : 0.0), data.item),
Theme.of(context)
.colorScheme
.primary
.withOpacity(_showBars ? 1.0 : 0.0),
data.item),
radius: const BorderRadius.vertical(
top: Radius.circular(24.0),
),
);
},
),
behaviour: ChartBehaviour(
scrollSettings: _isScrollable ? ScrollSettings() : ScrollSettings.none(),
scrollSettings:
_isScrollable ? ScrollSettings() : ScrollSettings.none(),
onItemClicked: (item) {
print('Clciked');
setState(() {
Expand All @@ -100,13 +110,15 @@ class _ScrollableChartScreenState extends State<ScrollableChartScreen> {
endWithChart: false,
lineWidth: 2.0,
axisStep: 2,
lineColor: Theme.of(context).colorScheme.primaryContainer.withOpacity(0.2),
lineColor:
Theme.of(context).colorScheme.primaryContainer.withOpacity(0.2),
),
VerticalAxisDecoration(
endWithChart: false,
lineWidth: 2.0,
axisStep: 7,
lineColor: Theme.of(context).colorScheme.primaryContainer.withOpacity(0.8),
lineColor:
Theme.of(context).colorScheme.primaryContainer.withOpacity(0.8),
),
GridDecoration(
showVerticalGrid: true,
Expand All @@ -116,25 +128,32 @@ class _ScrollableChartScreenState extends State<ScrollableChartScreen> {
verticalAxisStep: 1,
horizontalAxisStep: 1,
textStyle: Theme.of(context).textTheme.caption,
gridColor: Theme.of(context).colorScheme.primaryContainer.withOpacity(0.2),
gridColor:
Theme.of(context).colorScheme.primaryContainer.withOpacity(0.2),
),
targetArea,
SparkLineDecoration(
fill: true,
lineColor: Theme.of(context).primaryColor.withOpacity(!_showBars ? 0.2 : 0.0),
lineColor: Theme.of(context)
.primaryColor
.withOpacity(!_showBars ? 0.2 : 0.0),
smoothPoints: _smoothPoints,
),
],
foregroundDecorations: [
ValueDecoration(
alignment: _showBars ? Alignment.bottomCenter : Alignment(0.0, -1.0),
textStyle: Theme.of(context).textTheme.button!.copyWith(
color: (_showBars ? Theme.of(context).colorScheme.onPrimary : Theme.of(context).colorScheme.primary)
color: (_showBars
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.primary)
.withOpacity(_isScrollable ? 1.0 : 0.0)),
),
SparkLineDecoration(
lineWidth: 2.0,
lineColor: Theme.of(context).primaryColor.withOpacity(!_showBars ? 1.0 : 0.0),
lineColor: Theme.of(context)
.primaryColor
.withOpacity(!_showBars ? 1.0 : 0.0),
smoothPoints: _smoothPoints,
),
BorderDecoration(
Expand All @@ -155,10 +174,13 @@ class _ScrollableChartScreenState extends State<ScrollableChartScreen> {
border: Border.all(),
shape: BoxShape.circle,
),
child: Text('${_selected != null ? _values[_selected!].toStringAsPrecision(2) : '...'}'),
child: Text(
'${_selected != null ? _values[_selected!].toStringAsPrecision(2) : '...'}'),
),
),
backgroundColor: Theme.of(context).scaffoldBackgroundColor.withOpacity(_isScrollable ? 0.5 : 0.8),
backgroundColor: Theme.of(context)
.scaffoldBackgroundColor
.withOpacity(_isScrollable ? 0.5 : 0.8),
),
],
);
Expand All @@ -177,7 +199,9 @@ class _ScrollableChartScreenState extends State<ScrollableChartScreen> {
children: [
Expanded(
child: SingleChildScrollView(
physics: _isScrollable ? ScrollPhysics() : NeverScrollableScrollPhysics(),
physics: _isScrollable
? ScrollPhysics()
: NeverScrollableScrollPhysics(),
controller: _controller,
scrollDirection: Axis.horizontal,
child: AnimatedChart(
Expand All @@ -191,13 +215,17 @@ class _ScrollableChartScreenState extends State<ScrollableChartScreen> {
AnimatedContainer(
duration: Duration(milliseconds: 350),
decoration: BoxDecoration(
gradient: LinearGradient(begin: Alignment.centerRight, end: Alignment.centerLeft, colors: [
Colors.white,
Colors.white.withOpacity(0.0),
], stops: [
0.5,
1.0
]),
gradient: LinearGradient(
begin: Alignment.centerRight,
end: Alignment.centerLeft,
colors: [
Colors.white,
Colors.white.withOpacity(0.0),
],
stops: [
0.5,
1.0
]),
),
width: _fixedAxis ? 34.0 : 0.0,
height: MediaQuery.of(context).size.height * 0.4,
Expand All @@ -211,10 +239,14 @@ class _ScrollableChartScreenState extends State<ScrollableChartScreen> {
showValues: true,
endWithChart: false,
axisValue: (value) => '$value E',
legendFontStyle: Theme.of(context).textTheme.caption,
legendFontStyle:
Theme.of(context).textTheme.caption,
valuesAlign: TextAlign.center,
valuesPadding: const EdgeInsets.only(right: 8.0),
lineColor: Theme.of(context).colorScheme.primaryContainer.withOpacity(0.8),
lineColor: Theme.of(context)
.colorScheme
.primaryContainer
.withOpacity(0.8),
)
]
: [],
Expand Down
52 changes: 40 additions & 12 deletions example/lib/issue_repro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ class LineChart extends StatelessWidget {
LineChart({Key? key, this.useAxis = true}) : super(key: key);

final List<List<ChartItem<double>>> _mappedValues = [
[ChartItem(2.0), ChartItem(5.0), ChartItem(8.0), ChartItem(3.0), ChartItem(6.0)]
[
ChartItem(2.0),
ChartItem(5.0),
ChartItem(8.0),
ChartItem(3.0),
ChartItem(6.0)
]
];

@override
Expand All @@ -43,7 +49,8 @@ class LineChart extends StatelessWidget {
axisValue: (value) => '$value',
legendFontStyle: Theme.of(context).textTheme.bodyMedium,
valuesAlign: TextAlign.center,
valuesPadding: const EdgeInsets.only(left: -axisWidth, bottom: -10),
valuesPadding:
const EdgeInsets.only(left: -axisWidth, bottom: -10),
showLines: false,
showTopValue: true,
)
Expand All @@ -53,7 +60,8 @@ class LineChart extends StatelessWidget {
_mappedValues,
axisMin: useAxis ? 2 : null,
axisMax: useAxis ? 8 : null,
dataStrategy: const DefaultDataStrategy(stackMultipleValues: true),
dataStrategy:
const DefaultDataStrategy(stackMultipleValues: true),
),
itemOptions: WidgetItemOptions(widgetItemBuilder: (data) {
return const SizedBox();
Expand Down Expand Up @@ -83,7 +91,8 @@ class LineChart extends StatelessWidget {
_mappedValues,
axisMin: useAxis ? 2 : null,
axisMax: useAxis ? 8 : null,
dataStrategy: const DefaultDataStrategy(stackMultipleValues: true),
dataStrategy:
const DefaultDataStrategy(stackMultipleValues: true),
),
itemOptions: WidgetItemOptions(widgetItemBuilder: (data) {
return Stack(
Expand All @@ -96,7 +105,11 @@ class LineChart extends StatelessWidget {
right: 0,
child: Column(
children: [
Center(child: Text(_mappedValues[data.listIndex][data.itemIndex].max.toString()))
Center(
child: Text(_mappedValues[data.listIndex]
[data.itemIndex]
.max
.toString()))
],
),
),
Expand All @@ -111,9 +124,16 @@ class LineChart extends StatelessWidget {
width: 10,
height: 10,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary,
borderRadius: const BorderRadius.all(Radius.circular(8)),
border: Border.all(width: 1.4, color: Theme.of(context).colorScheme.surface)),
color: Theme.of(context)
.colorScheme
.primary,
borderRadius: const BorderRadius.all(
Radius.circular(8)),
border: Border.all(
width: 1.4,
color: Theme.of(context)
.colorScheme
.surface)),
),
)
],
Expand All @@ -131,13 +151,17 @@ class LineChart extends StatelessWidget {
verticalLegendPosition: VerticalLegendPosition.bottom,
verticalValuesPadding: const EdgeInsets.only(top: 8.0),
verticalAxisStep: 1,
gridColor: Theme.of(context).colorScheme.outline.withOpacity(0.3),
gridColor: Theme.of(context)
.colorScheme
.outline
.withOpacity(0.3),
dashArray: [8, 8],
gridWidth: 1,
textStyle: Theme.of(context).textTheme.labelSmall,
),
WidgetDecoration(
widgetDecorationBuilder: (context, chartState, itemWidth, verticalMultiplier) {
widgetDecorationBuilder: (context, chartState,
itemWidth, verticalMultiplier) {
return Padding(
padding: chartState.defaultMargin,
child: Stack(
Expand All @@ -146,15 +170,19 @@ class LineChart extends StatelessWidget {
right: 0,
left: 0,
bottom: verticalMultiplier * 3.6,
child: CustomPaint(painter: DashedLinePainter()),
child:
CustomPaint(painter: DashedLinePainter()),
),
],
),
);
},
),
TargetAreaDecoration(
targetAreaFillColor: Theme.of(context).colorScheme.error.withOpacity(0.6),
targetAreaFillColor: Theme.of(context)
.colorScheme
.error
.withOpacity(0.6),
targetLineColor: Colors.transparent,
lineWidth: 0,
targetMax: 2,
Expand Down
12 changes: 8 additions & 4 deletions lib/chart/model/theme/item_theme/widget/widget_item_options.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
part of charts_painter;

// Hidden because it's only used if chart item is a widget.
GeometryPainter<T> _emptyPainter<T>(
ChartItem<T> item, ChartData<T> data, ItemOptions itemOptions, DrawDataItem drawDataItem) =>
GeometryPainter<T> _emptyPainter<T>(ChartItem<T> item, ChartData<T> data,
ItemOptions itemOptions, DrawDataItem drawDataItem) =>
_EmptyGeometryPainter<T>(item, data, itemOptions);

typedef WidgetItemBuilder<T> = Widget Function(ItemBuilderData<T>);
Expand Down Expand Up @@ -68,8 +68,12 @@ class WidgetItemOptions extends ItemOptions {
@override
ItemOptions animateTo(ItemOptions endValue, double t) {
return WidgetItemOptions._lerp(
widgetItemBuilder: endValue is WidgetItemOptions ? endValue.widgetItemBuilder : widgetItemBuilder,
multiValuePadding: EdgeInsets.lerp(multiValuePadding, endValue.multiValuePadding, t) ?? EdgeInsets.zero,
widgetItemBuilder: endValue is WidgetItemOptions
? endValue.widgetItemBuilder
: widgetItemBuilder,
multiValuePadding:
EdgeInsets.lerp(multiValuePadding, endValue.multiValuePadding, t) ??
EdgeInsets.zero,
);
}
}
Loading

0 comments on commit 6efaa19

Please sign in to comment.