Repository navigation
feat(flet-charts): add GaugeChart+ pie/bar/axis/line chart improvements - #7066
Draft
ndonkoHenri wants to merge 4 commits into
Draft
ndonkoHenri wants to merge 4 commits into
ndonkoHenri wants to merge 4 commits into
Conversation
GaugeChart draws progress gauges, activity rings and speedometers from fl_chart 1.3.0's GaugeChartData. Its rings are GaugeProgressRing or GaugeZonesRing (made of GaugeZone), with GaugeLineTicks or GaugeCircleTicks, GaugeMarker, and GaugeNeedlePointer or GaugeCirclePointer. Every part is a control, so Python rejects the values fl_chart asserts on. Tick labels are a list of strings, one per tick, and paint colors default to the theme's on_surface. on_event reports the touched ring, zone, value and angle as GaugeChartEvent. The other charts get the fl_chart features Flet was missing: PieChartSection.corner_radius and segments, BarChartRod.label, label/label_style/gradient on BarChartRodStackItem, ChartAxis.label_alignment, LineChartData.gradient_area, and ChartEventType values for secondary-button events. Docs pages, two examples (speedometer, activity_rings) and the gallery entry come with it.
The rings, zones, ticks, pointers and markers are plain data, so they are now @ft.value types instead of controls. The polymorphic bases carry a _type tag, like ChartPointShape, and the client parses them as maps. Value types aren't validated on their own, so GaugeChart.before_update validates each part. Every part except GaugeZone is keyword-only, so GaugeNeedlePointer(100) no longer sets length instead of value. GaugeChartEvent.on_value is renamed to is_on_value, since on_ is reserved for event handlers. Raises entries now sit on every property a cross-field rule compares, including RadarDataSet.entries. GaugeTicks.label_style and BarChartRodLabel.text_style document their default. On the Dart side, each new enum gets a named parser like parseStrokeCap, and resolveFlTouchEventType is a switch expression. The flet-charts changelog entry is split into one item per chart.
Deploying flet-website-v2 with
|
| Latest commit: |
a761c0b
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://76c78c27.flet-website-v2.pages.dev |
| Branch Preview URL: | https://feat-charts-gauge-chart.flet-website-v2.pages.dev |
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds
GaugeChart, the chart type fl_chart 1.3.0 introduced, and the fl_chart options the other charts were missing. fl_chart goes from^1.2.0to^1.3.0.GaugeChartProgress gauges, activity rings and speedometers, built from:
GaugeProgressRing(filled up tovalue, optionalbgcolortrack),GaugeZonesRingofGaugeZone(start, end, color)GaugeLineTicks,GaugeCircleTicks, with optionallabelsGaugeNeedlePointer,GaugeCirclePointerGaugeMarker, a line with an optional label at one valueThe chart takes the scale (
min_value,max_value), the arc (start_degree_offset,sweep_angle,direction), ring sizing (default_ring_width,rings_space),animation,interactive, andon_event, which sends aGaugeChartEventwith the touched ring, zone, value and angle.Design choices worth a look:
@ft.valuetypes, not controls. The polymorphic bases carry a_typetag, likeChartPointShape, and the client parses them as maps.GaugeChart.before_updatevalidates each part. Python raises aValueErrorfor inputs fl_chart would reject, such as a ring value outside the scale,sweep_angleover 360, a zone ending before it starts, orlabelsnot matching the tickcount. Every rule documents aRaises:entry on each property it compares.GaugeZoneis keyword-only, soGaugeNeedlePointer(100)can't setlengthwhenvaluewas meant.on_surface(a progress ring's toprimary) instead of fl_chart's black, which disappears in dark mode. A marker label without a style gets 12-pixel text in the marker's color, since fl_chart skips labels that have no style.Other charts
PieChart:PieChartSection.corner_radiusand stackedPieChartSection.segments(PieChartSectionSegment).BarChart:BarChartRod.label(a string orBarChartRodLabel), andlabel,label_styleandgradientonBarChartRodStackItem. A stack item now needs acoloror agradient, so a missing one raises aValueErrorinstead of breaking the chart.LineChart:LineChartData.gradient_area.ChartAxis.label_alignment(outside, on the border, or inside the chart).ChartEventTypevalues for secondary-button (right-click) taps and long presses.RadarDataSet.entriesgets theRaises:entry its rule was missing.On the Dart side, each new enum has a named parser like
parseStrokeCap, andresolveFlTouchEventTypeis a switch expression.Examples, docs and tests
gauge_chart/speedometer(a slider moves the needle and the progress ring) andgauge_chart/activity_rings(tapping a ring highlights it), both in the gallery.GaugeChartpage with both examples, type pages for the new classes, and entries in the sidebar, the charts index and the flet-charts README.integration_tests/examples/test_gauge_chart.py: the docs image, a slider drag on the speedometer, and a tap on the outer activity ring. Its three goldens are also the docs images.Testing
dart analyzeand ruff are clean, and the flet-charts unit tests pass.Not in this PR
BarChartcrash on stack items withoutfrom_yand theLineChartanimation fix (flet-charts#8) are in FixBarChartstack items withoutfrom_yandLineChartpoint animation #7064, which targets 1.1.x.Summary by Sourcery
Add GaugeChart support and broaden existing chart capabilities through the fl_chart 1.3.0 upgrade.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests:
Chores: