Repository navigation
Move the trend charts to MudBlazor - #117
Merged
Merged
Conversation
Blazor-ApexCharts is a JS chart library behind a wrapper, and it has to boot a chart instance per category before anything shows up. MudBlazor's line chart builds the SVG in C# and renders it with the rest of the page, so there's no interop round trip and no second rendering engine to ship. It also drops the only non-MIT dependency in the app. The charts changed shape a bit along the way: Values are drawn as straight segments between days instead of a smooth curve. Readings are one per day, not samples of a continuous signal, and a spline implies values between them that were never recorded. Every point gets a marker. A day whose neighbours are both missing has no line segment to draw, so without a marker it just isn't there. This also works around a MudBlazor quirk where markers are only built when tooltips are enabled. The series legend is gone. Every chart plots one series and the category name is already the header above it, so the legend was a wasted row that only ever repeated what was written above. The scale hint it used to carry moved to the y axis: mood is labelled with its own emoji, bools read No/Yes, and sleep is labelled in hours. Y axis steps are picked from the data with a 1/2/5/10 ramp, which is nicer than what we had: mood used to be scaled 0-10 for 1-7 data, and a category with a constant value drew 1999/2000/2001 around it. A constant series now stretches the axis to zero so the line sits inside the chart. MudBlazor goes to 9.12.0 for the nullable chart data that makes the gaps work. That added two IDialogService overloads, so the test fake grows two more passthroughs, and global.json moves to the 10.0.400 band since the 300 band no longer resolves.
The port moved real decisions into the component, so pin them down: the emoji mood axis, the zero-stretched axis a constant series gets, how many date labels survive a 31 day month, and that a gap breaks the line while a lone day still draws a marker. The chart builds its viewBox from a measured element, so the tests have to hand it a size or it renders nothing at all to assert on.
The days are always one unbroken run, so the query can ask for a range instead of listing all 31 dates. Nothing on the page is edited, so change tracking is wasted work; identity resolution stays on because the grouping needs one Category instance per category. Grouping now walks the points once instead of scanning them again for every day. A month of sample data went from 19ms to 12ms.
The gridline colour and the black data markers are the library's job now, so those overrides come out of the stylesheet, and the chart box no longer needs a max-height to convince the parent-height probe it is constrained. XAxisLabelInterval thins the axis without touching the tooltips, so every point can keep its own date and hovering an unlabelled day names it again. Needs 9.13.0; the branch does not build until that is on NuGet.
YAxisTicks = 0 picks a 1/2/5 step that fits the values, so the hand-rolled NiceStep comes out. MaxNumYAxisTicks = 5 keeps it near the four gaps it aimed for. A flat series now sits between zero and the next round step instead of on the top gridline. Gridlines take the theme's line colour at 1px from the library now, so that override comes out of the stylesheet too. Needs MudBlazor #14179 and #14180 in 9.13.0. Drop this commit if they miss it.
{{Y_AXIS_VALUE}} (MudBlazor #14183) replaces the TooltipTemplate that parsed the label back into a number. Charts without an axis formatter keep {{Y_VALUE}}, since the axis format rounds off decimals a reading needs.
9.12.0-nightly.1046 is MudBlazor dev at a1094eef3, with every chart fix this branch needs from 9.13.0. Nightlies are only on GitHub Packages, so CI can't restore it. Switch this to 9.13.0 before merging.
ShowToolTipsOnTouch (MudBlazor #14196) does what chart-touch.js did, so the script, its attach call and the pan-y rule come out. MudBlazor leaves pinch-zoom alone and stops the page scrolling only once a drag is a scrub. 9.12.0-nightly.1056 is MudBlazor dev at 964e54243, which has #14196 and the chart perf work (#14197 to #14201). Switch this to 9.13.0 before merging.
9.13.0 is out on NuGet with every chart change this branch uses, touch tooltips (#14196) included, so the nightly pin comes out.
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.
The trends page now draws its charts with MudBlazor's line chart instead of Blazor-ApexCharts. The charts are plain SVG built in C# and rendered with the rest of the page, so there's no JS chart engine to boot per category, and it drops the only non-MIT dependency in the app. Drawing a month of seven charts went from about 156ms to 40ms on the same machine and data.
The charts changed a bit along the way. Days are joined by straight lines instead of a curve, since a reading is one value per day and a spline makes up values in between. Every day gets a marker, so a day with nothing either side of it still shows up, and a missing day breaks the line. The legend is gone because each chart has one series and its name is already the header above it. The y axis says what the scale is instead: mood is labelled with its emoji, yes/no categories read No and Yes, and sleep is in hours. Axis steps are round numbers MudBlazor picks from the data, the date labels are thinned so they don't collide at phone width, and the tooltip still names every day along with the value written the way the axis writes it.
On a phone you can drag sideways across a chart to walk the tooltip from day to day, or press and hold and then go in any direction, and lifting your finger puts it away. A tap opens the nearest day until you touch somewhere else. That's MudBlazor's
ShowToolTipsOnTouch, which went upstream from this branch as MudBlazor/MudBlazor#14196.Loading the month got quicker too: the query asks for a date range instead of 31 dates, skips change tracking, and groups the points in one pass, which took it from 19ms to 12ms.
It builds against MudBlazor 9.13.0, which has the chart changes this needs (MudBlazor/MudBlazor#14150, MudBlazor/MudBlazor#14151, MudBlazor/MudBlazor#14152, MudBlazor/MudBlazor#14154, MudBlazor/MudBlazor#14156, MudBlazor/MudBlazor#14177, MudBlazor/MudBlazor#14178, MudBlazor/MudBlazor#14179, MudBlazor/MudBlazor#14180, MudBlazor/MudBlazor#14181, MudBlazor/MudBlazor#14183, MudBlazor/MudBlazor#14184 and MudBlazor/MudBlazor#14196, plus the rendering work in MudBlazor/MudBlazor#14197 to MudBlazor/MudBlazor#14201). Tested on Windows and the Android emulator, in light and dark.