[squeak-dev] Json dictionary tree accessing
tim Rowledge
tim at rowledge.org
Wed Sep 1 23:33:31 UTC 2021
When driving JS libraries from Seaside it is often necessary to build a tree of dictionaries to encode settings - for example, using vega-lite to display charts & graphs.
I currently have a very simple case that ends up rather verbose -
|barchart|
barchart := Dictionary new.
barchart
at: #'$schema' put: 'https://vega.github.io/schema/vega-lite/v5.json';
at: #description put: 'A simple bar chart';
at: #width put: 'container';
at: #usermeta put:
(Dictionary new
at: #embedOptions put:
(Dictionary new
at: #export put: true;
at: #compiled put: false;
at: #editor put: false;
yourself);
yourself);
at: #mark put:
(Dictionary new
at: #type put: #bar;
at: #tooltip put: true;
yourself);
at: #encoding put:
(Dictionary new
at: #x
put: (Dictionary new
at: #field put: 'label';
at: #type put: #nominal;
at: #axis put:
(Dictionary new
at: #labelAngle put: -45;
yourself);
at: #title put: #Group;
yourself);
at: #y
put: (Dictionary new
at: #field put: 'value';
at: #type put: #quantitative;
at: #title put: #Value;
yourself);
yourself);
at: #height put:'container'.
^barchart
... and that's without any actual data!
If I want to do something like change the label angle I end up with ugliness like
(((chartSpec at: #encoding)
at: #x)
at: #axis)
at:#labelAngle put: axisLabellingAngle.
I feel sure I've seen this done better but I can't find anything with my current searches. It wouldn't be too hard to implement a method to do #atPath: #(encoding x axis labelAngle) put: thingy but if it's been done cleanly by somebody I'd much rather just load it.
Somebody please point me to the ludicrously obvious answer any idiot should have spotted immediately...
tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
Strange OpCodes: AG: Add Gibberish
More information about the Squeak-dev
mailing list
|