-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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: Add draggable spots functionality for LineChart #1428
Open
G33kFreak
wants to merge
152
commits into
imaNNeo:main
Choose a base branch
from
G33kFreak:master
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
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
Changes from 8 commits
Commits
Show all changes
152 commits
Select commit
Hold shift + click to select a range
10673fa
Add draggable logic for LineChart
G33kFreak b0d0ced
Remake logic of updating spot's position and adjust tests
G33kFreak 773cabf
Add dragSpotUpdatedCallback functionality
G33kFreak 8430ec3
Update changelog
G33kFreak 99d2484
Add sample of draggable line chart
G33kFreak c96551a
minor fixes
G33kFreak 4eeeb77
Change the comparing logic in didUpdateWidget
G33kFreak ffe2237
Removed unnecessary logic
G33kFreak 4c6d2b3
chore: bump actions/checkout from 2 to 4
dependabot[bot] ce49b92
Fix donation link in README.md file
imaNNeo e074877
Add draggable callbacks
G33kFreak f883446
Add draggable logic for LineChart
G33kFreak 0bfef57
Remake logic of updating spot's position and adjust tests
G33kFreak 5e9a68e
Add dragSpotUpdatedCallback functionality
G33kFreak 1e9a832
Update changelog
G33kFreak 2a47fc4
Add sample of draggable line chart
G33kFreak b1703f7
minor fixes
G33kFreak 32b7162
Change the comparing logic in didUpdateWidget
G33kFreak 60e9e4a
Removed unnecessary logic
G33kFreak f42ba99
Add draggable callbacks
G33kFreak e9b9046
Merge branch 'master' of https://github.com/G33kFreak/fl_chart
G33kFreak 77646e4
Add initializations for drag feature callbacks
G33kFreak 8f8a851
Add draggable logic for LineChart
G33kFreak 76348e3
Remake logic of updating spot's position and adjust tests
G33kFreak 539cca8
Add initializations for drag feature callbacks
G33kFreak 7875962
Merge branch 'master' of https://github.com/G33kFreak/fl_chart
G33kFreak cb51189
Consider fraction digits when formatting chart side titles, #1267
imaNNeo 621b79e
Update CHANGELOG.md
imaNNeo e3910de
Bump version to 0.64.0
imaNNeo 7918942
Fix macOS debug network issue
imaNNeo b99169b
Fix radar chart sample 1 overflow
imaNNeo 396b2e1
Upgrade example/ dependencies
imaNNeo 79e6ec7
Open flchart.dev when user clicks on the fl_chart logo
imaNNeo ab88658
Added gradient to FlLine
Dartek12 696bb2d
Updated docs
Dartek12 c8dc3c0
Mention the issue id in the CHANGELOG.md file
imaNNeo 07c3d85
Fix iOS, macOS build issues
imaNNeo ba68c76
Fix bar line shadow crash when we have only one (or zero) spot, #1466
imaNNeo 3c30cc3
Fix having negative `toY` (or positive `fromY`) in BarChart's `minY` …
imaNNeo b3529d3
Remove the changelog section from CONTRIBUTING. Because it is a file …
imaNNeo f0b387d
Fix bargraph overflow
356b722
Fix documentation
bobatsar 1334eb7
Add golden widget tests for bargraph overflow
24d0fc5
Update CHANGELOG.md
cd14e6d
Open fl_chart web page only when we're on the web, otherwise open the…
imaNNeo fb672b5
Add appVersion and fl_chart version on the bottom of app menu
imaNNeo dcb1188
Add flutter version veriable in the gh-pages.yml
imaNNeo 0aaf7ee
Fix format
imaNNeo 87f0444
Add tryToLaunchUrl function in the app_utils to have a single place t…
imaNNeo 0ae88cf
Remove flaky golden tests, I need to learn more about them later
imaNNeo 4a2924a
Use TextScaler textScaler insted of double textScale to get rid of th…
imaNNeo d173cc0
Add dashArray parameter to BarChartRodData
k0psutin 98d10e5
Make border draw last and use toDashedPath to draw the border
k0psutin 1f1834a
Add new sample to show the dashed border
k0psutin d9a0efb
Update BarChartRodData documentation
k0psutin 5151fc2
Create two tests to test borders
k0psutin 4424452
Fix @kopsutin -> @k0psutin
k0psutin 2955cef
Rename dashArray to borderDashArray
k0psutin 0d4faea
Fix tests
k0psutin c911024
chore(handle_animations.md):replace = with :
polonski 2b7be70
Allow to show single point line in LineChart, #1438
imaNNeo 4a9bd3f
Fix flutter version issue in gh-pages.yml
imaNNeo 40caf90
Change the drawer header logic to always open the landing page
imaNNeo df87e97
Open flutter release page when user clicks on the fl_chart version on…
imaNNeo 9877450
Remove buy me a coffe button in the app
imaNNeo 803409c
Bump version to 0.65.0
imaNNeo 6b52a4e
Add pubspec constraints for newer version of flutter/dart, #1509
imaNNeo 22b02c3
Use FlDotPainter to draw scatter spots
imaNNeo bb7b885
Update CHANGELOG.md
imaNNeo a99a3dd
Fix some test issues
imaNNeo 256e2cc
Implement lerp method for FlDotPainter
imaNNeo ae7432f
Define customized hitTest for different FlDotPainters
imaNNeo 9e133f1
Move FlDotPainter from line_chart_data to axis_chart_data
imaNNeo c1a5189
Generate new mock files
imaNNeo 2f6a0e1
Update CHANGELOG.md to add migration guide
imaNNeo 2bb9c81
Add a feature to allow user to select a painterType in ScatterChartSa…
imaNNeo e9ab493
Fix barChart tooltip for values below or above the 0 point, #1462
imaNNeo 68cf161
Fix pieChart drawing single section on iPhone, #1515
imaNNeo 08107bf
Fix test fail issue
imaNNeo bcd4aef
Add gradient property to the HorizontalLine and VerticalLine, #1525
imaNNeo bee1cf3
Update CHANGELOG.md
imaNNeo 6f9c859
Fix format issue
imaNNeo 950ac7f
Update base_chart.md docs
imaNNeo 2482719
Rename all /master to /main
imaNNeo 4c1c27a
Update handle_animations.md
LIZA1608 944bef4
Add gradient for PieChart
RAldhafeeri d3d06d1
update docs for pie chart
RAldhafeeri 494a51f
Update pie_chart.md with gradient usage clarification
RAldhafeeri 00c1cd6
Update CHANGELOG.md
imaNNeo 001fd68
Update CHANGELOG.md
imaNNeo 5f92d72
Update flutter version to remove the upper bound (to fix the flutter …
imaNNeo c0ca436
Bump version to 0.66.0
imaNNeo d116601
Upgrade Kotlin version from 1.6.10 to 1.7.10
4838f8b
Fix PieChart blackout issue, #1538
imaNNeo ba2f03f
Add some new brandings in README.md
imaNNeo 5f31d52
Fix readme issue
imaNNeo 3858b0b
Decrease thumbnail video size
imaNNeo 50def3d
Fix memory leak in LineChart and BarChart, #1106
imaNNeo 122a9e3
Update CHANGELOG.md
imaNNeo 294f250
Minor change on .codecov.yml
imaNNeo 90b615e
Bump version to 0.66.1
imaNNeo c75c6ea
Minor fix on README.md
imaNNeo 0c75173
Fix README [ issue
imaNNeo 4b144a0
Use <a> tag for link in README
imaNNeo 2ff658b
Update README.md
r3za13 46dd5ad
Fix unsupported environment access on web
julianscheel 75a3b98
Update bar_chart.md
adamsocrat 2d21444
Update pie_chart.md
adamsocrat c2e634d
Update radar_chart.md
adamsocrat eb82f1c
- removed dependency to dart:io
stwarwas 09d1944
Update README.md
imaNNeo 5a01893
Bump version to 0.66.2
imaNNeo fb7cf1b
Add sponsors section
imaNNeo 16d92d7
add the option to display the text vertically for a FLineLabel
julien4215 9c28a8a
edit changelog
julien4215 dbaa832
edit test for coverage
julien4215 288852a
WIP test
julien4215 1d1e137
end unit tests
julien4215 2c7295b
make code more understandable
julien4215 bf36544
fix : label always inside chart
julien4215 a540582
add direction in lerp method
julien4215 34a6af0
Update CHANGELOG.md
imaNNeo cdfdb66
Dynamically changing tooltipBgColor
xvrh 0d486c8
Adrresses review comments
xvrh bba7394
Typo in changelog
xvrh bfdd91b
Add migration guide
xvrh e170af8
Fix scatter_chart_sample2 color contrast
imaNNeo 2d0ce64
Update CHANGELOG.md
imaNNeo f82c496
Bump version to 0.67.0
imaNNeo 930ac12
Update CHANGELOG.md
imaNNeo 033e367
Add draggable logic for LineChart
G33kFreak dd241fb
Remake logic of updating spot's position and adjust tests
G33kFreak b060874
Add dragSpotUpdatedCallback functionality
G33kFreak b481923
Update changelog
G33kFreak 0cd3590
Add sample of draggable line chart
G33kFreak cd3e422
minor fixes
G33kFreak fc35f04
Change the comparing logic in didUpdateWidget
G33kFreak 74f7ed5
Removed unnecessary logic
G33kFreak c298aac
Add draggable callbacks
G33kFreak ba18217
Add draggable logic for LineChart
G33kFreak b476743
Remake logic of updating spot's position and adjust tests
G33kFreak 0d5026c
Add initializations for drag feature callbacks
G33kFreak e4509e0
Add draggable logic for LineChart
G33kFreak a325175
Remake logic of updating spot's position and adjust tests
G33kFreak 916c1e1
Change the comparing logic in didUpdateWidget
G33kFreak 9d283be
Removed unnecessary logic
G33kFreak f664065
Merge branch 'master' of https://github.com/G33kFreak/fl_chart
G33kFreak 6870cd4
fix example
G33kFreak 04f18f2
Fix after rebase logic
G33kFreak 9357bf2
Fix tests
G33kFreak b60e4fe
Adjust data tests
G33kFreak 2ae1234
Update CHANGELOG
G33kFreak File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
132 changes: 132 additions & 0 deletions
132
example/lib/presentation/samples/line/line_chart_sample12.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,132 @@ | ||
import 'package:fl_chart/fl_chart.dart'; | ||
import 'package:fl_chart_app/presentation/resources/app_colors.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class LineChartSample12 extends StatefulWidget { | ||
const LineChartSample12({super.key}); | ||
|
||
@override | ||
State<LineChartSample12> createState() => _LineChartSample12State(); | ||
} | ||
|
||
class _LineChartSample12State extends State<LineChartSample12> { | ||
List<FlSpot> get spots1 => [ | ||
const FlSpot(1, 3), | ||
const FlSpot(2, 2), | ||
const FlSpot(4, 5), | ||
const FlSpot(6, 4), | ||
]; | ||
List<FlSpot> get spots2 => [ | ||
const FlSpot(1, 1), | ||
const FlSpot(2, 4), | ||
const FlSpot(3, 6), | ||
const FlSpot(5, 3), | ||
]; | ||
|
||
UpdatedDragSpotsData? _lastUpdate; | ||
|
||
void _onUpdated(UpdatedDragSpotsData newUpdate) { | ||
setState(() { | ||
_lastUpdate = newUpdate; | ||
}); | ||
} | ||
|
||
String get _formattedLastSpotValue { | ||
if (_lastUpdate == null) { | ||
return 'Updated spot: None'; | ||
} | ||
|
||
final flSpot = _lastUpdate!.newSpots[_lastUpdate!.updatedSpotIndex]; | ||
|
||
return 'new X: ${flSpot.x.toStringAsFixed(2)}, new Y: ${flSpot.y.toStringAsFixed(2)}'; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
const SizedBox(height: 12), | ||
Text( | ||
'Last updated bar index: ${_lastUpdate?.updatedBarIndex ?? 'none'}', | ||
style: const TextStyle( | ||
color: AppColors.mainTextColor2, | ||
fontSize: 12, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
const SizedBox(height: 12), | ||
Text( | ||
'Last updated spot index: ${_lastUpdate?.updatedSpotIndex ?? 'none'}', | ||
style: const TextStyle( | ||
color: AppColors.mainTextColor2, | ||
fontSize: 12, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
const SizedBox(height: 12), | ||
Text( | ||
_formattedLastSpotValue, | ||
style: const TextStyle( | ||
color: AppColors.mainTextColor2, | ||
fontSize: 12, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
AspectRatio( | ||
aspectRatio: 1, | ||
child: Padding( | ||
padding: const EdgeInsets.symmetric( | ||
horizontal: 24.0, | ||
vertical: 10, | ||
), | ||
child: LayoutBuilder(builder: (context, constraints) { | ||
return LineChart( | ||
LineChartData( | ||
minY: 0, | ||
minX: 0, | ||
maxX: 8, | ||
maxY: 8, | ||
lineTouchData: LineTouchData( | ||
enabled: true, | ||
handleBuiltInTouches: true, | ||
dragSpotUpdateFinishedCallback: _onUpdated, | ||
getTouchedSpotIndicator: | ||
(LineChartBarData barData, List<int> spotIndexes) { | ||
return spotIndexes.map((index) {}).toList(); | ||
}, | ||
touchTooltipData: LineTouchTooltipData( | ||
tooltipBgColor: Colors.transparent, | ||
getTooltipItems: (List<LineBarSpot> lineBarsSpot) { | ||
return lineBarsSpot.map((lineBarSpot) {}).toList(); | ||
}, | ||
), | ||
), | ||
lineBarsData: [ | ||
LineChartBarData( | ||
spots: spots1, | ||
isCurved: true, | ||
isDraggable: true, | ||
), | ||
LineChartBarData( | ||
spots: spots2, | ||
isCurved: true, | ||
isDraggable: false, | ||
color: Colors.red, | ||
), | ||
], | ||
gridData: const FlGridData(show: false), | ||
borderData: FlBorderData( | ||
show: true, | ||
border: Border.all( | ||
color: AppColors.borderColor, | ||
), | ||
), | ||
), | ||
); | ||
}), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
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
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'm a bit confused about the design, we have an
isDraggable
flag in our LineChartBarData class, also we haveDragSpotUpdateFinishedCallback? dragSpotUpdateFinishedCallback;
in our LineTouchData.(I know we might have something similar in other places, and I admit that is a bad design)
But for now, what if we keep these two variables beside each other in the LineTouchData class?
What do you think?
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.
Also, we can add other kinds of callbacks for example
dragSpotStartedCallback
,dragSpotMovedCallback
, anddragSpodFinishedCallback
.The other (perfect) solution is to touch the RenderBaseChart to add a DragGestureRecognizer to detect the gesture events using this predefined, then we can pass down the gesture events to the touchCallback event as a
FlTouchEvent
. This way, we can use thedrag-drop
feature in all kinds of charts with the same logic.For example in LineChart, we can have a flag to do the spot drag-drop (that you already implemented) as an under-the-hood magic. Also, users can implement any other kind of interaction with the
drag-drop
feature.What do you think?
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.
Thanks for the comments! I like the 2nd idea and will research and play a little bit with it.
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.
So, after some checks about the additional gesture recognizer, I realized, that it's already done :D
See, the DragGestureRecognizer is an abstract class.
However, the package already implements PanGestureRecognizer in the RenderBaseChart which extends DragGestureRecognizer and has everything we need to implement some kind of similar features in other charts as well.
Based on that, we already have the needed gesture recognizer and this PR just creates the wanted
under-the-hood magic
for theLineChart
, if I got you right.To be honest, I don't really know what would be better here. My intention was to allow users to implement a draggable feature for particular
LineChartBarData
. For example, we can have a few bars, but only one of them is going to be draggable. It's similar toisCurved
flag to me.So that's why I put this flag there.
Definitely! Added it in the commit f42ba99.
Anyway, we have to pay users' attention to be careful with using
setState
in thedragSpotUpdateCallback
. Would be good to have some notes in the docs :)