-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Gauge Chart #1424
Open
FlorianArnould
wants to merge
8
commits into
imaNNeo:main
Choose a base branch
from
FlorianArnould:feature/gauge-chart-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Gauge Chart #1424
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
37f21b1
feat: gauge diagram
FlorianArnould 185812b
chore: refactors and cleanups
FlorianArnould e31db9a
feat: implemented the gauge touch support
FlorianArnould 5fc9b8b
chore: reformat
FlorianArnould 7724755
chore: added gauge tests
FlorianArnould 7f3ddc6
chore: format
FlorianArnould 5037e80
chore: added the gauge icon
FlorianArnould c4d5647
chore: reformat
FlorianArnould File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
example/lib/presentation/samples/gauge/gauge_chart_sample1.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:fl_chart_app/presentation/resources/app_resources.dart'; | ||
import 'package:fl_chart/fl_chart.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class GaugeChartSample1 extends StatefulWidget { | ||
const GaugeChartSample1({super.key}); | ||
|
||
@override | ||
State<StatefulWidget> createState() => GaugeChartSample1State(); | ||
} | ||
|
||
class GaugeChartSample1State extends State { | ||
double _value = 0.7; | ||
bool _isSelected = false; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: const EdgeInsets.all(28), | ||
child: Column( | ||
children: [ | ||
SizedBox( | ||
width: 250, | ||
height: 250, | ||
child: GaugeChart( | ||
GaugeChartData( | ||
value: _value, | ||
valueColor: VariableGaugeColor( | ||
colors: [ | ||
AppColors.contentColorYellow, | ||
AppColors.contentColorBlue, | ||
AppColors.contentColorRed | ||
], | ||
limits: [0.35, 0.5], | ||
), | ||
backgroundColor: AppColors.contentColorPurple | ||
.withOpacity(_isSelected ? 0.2 : 1), | ||
strokeWidth: 30, | ||
startAngle: 45, | ||
endAngle: -225, | ||
strokeCap: StrokeCap.round, | ||
ticks: const GaugeTicks( | ||
count: 11, | ||
color: AppColors.contentColorCyan, | ||
radius: 5, | ||
position: GaugeTickPosition.inner, | ||
margin: 5, | ||
), | ||
touchData: GaugeTouchData( | ||
enabled: true, | ||
touchCallback: (_, value) => setState(() { | ||
_isSelected = value?.spot != null; | ||
}), | ||
), | ||
), | ||
), | ||
), | ||
Slider(value: _value, onChanged: (v) => setState(() => _value = v)), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'package:fl_chart/src/chart/gauge_chart/gauge_chart_data.dart'; | ||
import 'package:fl_chart/src/chart/gauge_chart/gauge_chart_renderer.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
|
||
class GaugeChart extends ImplicitlyAnimatedWidget { | ||
/// [data] determines how the [GaugeChart] should be look like, | ||
/// when you make any change in the [GaugeChartData], it updates | ||
/// new values with animation, and duration is [swapAnimationDuration]. | ||
/// also you can change the [swapAnimationCurve] | ||
/// which default is [Curves.linear]. | ||
const GaugeChart( | ||
this.data, { | ||
this.chartRendererKey, | ||
super.key, | ||
Duration swapAnimationDuration = const Duration(milliseconds: 150), | ||
Curve swapAnimationCurve = Curves.linear, | ||
}) : super( | ||
duration: swapAnimationDuration, | ||
curve: swapAnimationCurve, | ||
); | ||
|
||
/// Determines how the [GaugeChartData] should be look like. | ||
final GaugeChartData data; | ||
|
||
/// We pass this key to our renderers which are supposed to | ||
/// render the chart itself (without anything around the chart). | ||
final Key? chartRendererKey; | ||
|
||
/// Creates a [_GaugeChartState] | ||
@override | ||
_GaugeChartState createState() => _GaugeChartState(); | ||
} | ||
|
||
class _GaugeChartState extends AnimatedWidgetBaseState<GaugeChart> { | ||
/// we handle under the hood animations (implicit animations) via this tween, | ||
/// it lerps between the old [GaugeChartData] to the new one. | ||
GaugeChartDataTween? _gaugeChartDataTween; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final showingData = _getData(); | ||
|
||
return GaugeChartLeaf( | ||
data: _gaugeChartDataTween!.evaluate(animation), | ||
targetData: showingData, | ||
); | ||
} | ||
|
||
GaugeChartData _getData() { | ||
return widget.data; | ||
} | ||
|
||
@override | ||
void forEachTween(TweenVisitor<dynamic> visitor) { | ||
_gaugeChartDataTween = visitor( | ||
_gaugeChartDataTween, | ||
widget.data, | ||
(dynamic value) => | ||
GaugeChartDataTween(begin: value as GaugeChartData, end: widget.data), | ||
) as GaugeChartDataTween?; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can have a list of values (each value can have startAngle and endAngle).
Then we can draw them on top of each other.
This way, it is more customizable.
Look at these samples: