More control over series formatting #31
Replies: 2 comments 2 replies
-
|
On further thought, the second syntax is more flexible, as it would allow for: CristalyseChart()
.data(data)
.mapping(x: 'time', y: 'amount', color: 'series')
.geomLine(strokeWidth: 1.0)
.geomArea(data: subset(key: 'trend'), style: LineStyle.dashed, strokeWidth: 3.0, color: Colors.green)
.geomRange(data: subset(keys: ['min', 'max']), barWidth: 3.0) // EDIT: this won't work, at least not as presented
// ...
.build();Which would draw an area for 'trend', a new type I just invented called 'range' for the 'min' and 'max' series, and lines for all other series. This shares some features of the secondary axis, but would offer the ability to use more representations, and free the secondary axis for having a different scaling than the primary (I'll assume the user has good reason for doing so). EDIT: The |
Beta Was this translation helpful? Give feedback.
-
|
I made some progress:
I still need to verify backwards compatibility (should be, but must verify), add test coverage, create examples, and documentation. I'll work on those and get a PR cleared to submit, hopefully later this week. Here's the code: return CristalyseChart()
.data(data)
.theme(getChartTheme(context, showAxis, showGridLines))
.mapping(x: 'time', y: 'amount', color: 'series', size: 'amount')
.scaleXContinuous(
labels: (val) => DateFormat(DateFormat.ABBR_MONTH_DAY,).format(DateTime.fromMillisecondsSinceEpoch(val.toInt())),
min: minDate.millisecondsSinceEpoch.toDouble(),
max: DateTime.now().millisecondsSinceEpoch.toDouble(),
)
.scaleYContinuous(min: 0, max: maxValue)
.animate(duration: Duration(milliseconds: 0))
.geomLine(key: 'current', color: Colors.green, style: LineStyle.solid, strokeWidth: 3.0, dotSpacing: 3.0)
.geomLine(key: 'trend', color: Colors.blueGrey, style: LineStyle.dashed, strokeWidth: 3.0, dashPattern: [12.0, 8.0])
.geomRange(key: 'current', lower: 'min', upper: 'max', color: Colors.lightBlueAccent, alpha: 0.25)
.build();Here's a better view of the dashed lines. I'm particularly happy about the way they are continuous around the points: But dotted lines are still giving me grief at the ends of segments: |
Beta Was this translation helpful? Give feedback.



Uh oh!
There was an error while loading. Please reload this page.
-
While automated assignment of colors makes for a quick and easy initial setup, sometimes it would be nice to have more control, e.g. where you have multiple charts showing a mix of shared and unique series, you might want to be able to have the shared series show up with the same style and color across all charts.
e.g. in this example, the short trend line (green in top, red in bottom chart) should be the same color in both charts, and ideally it would be dashed, while all others are solid.
One possible implementation, keeping in mind I'm not an expert in the grammar of graphics:
Where
seriesLineoverrides the auto-selected color/style that is set from the theme andgeomLinesettings for the line identified by the value of the 'series' property. Any values in 'series' that do not have an override will use existing behavior for color and line style, e.g. for series = current since there is no override for color, it will use thecolorPaletteof the theme. For simplicity of implementation, if a color should not be used for any series other than the override, it should not be included in the theme'scolorPalette. i.e. if we did not want to allow green solid lines for any other series, we would exclude green from the palette; if instead we wanted to allow other series to appear as a green solid line, we would include green in the palette. There would be similarseriesArea,seriesPoint, etc. to allow override of other representations.An alternative syntax could be (
shamelessly stolenadapted from Google's LLM summary ofggplot2):Beta Was this translation helpful? Give feedback.
All reactions