[squeak-dev] Json dictionary tree accessing
Thiede, Christoph
Christoph.Thiede at student.hpi.uni-potsdam.de
Thu Sep 2 08:32:16 UTC 2021
What about
#(encoding x axis labelAngle) inject: barchart into: [:dict :segment | dict at: segment].
or even shorter
#(encoding x axis labelAngle) inject: barchart into: #at:.
?
Best,
Christoph
________________________________
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von tim Rowledge <tim at rowledge.org>
Gesendet: Donnerstag, 2. September 2021 01:33:31
An: The general-purpose Squeak developers list
Betreff: [squeak-dev] Json dictionary tree accessing
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210902/944b1aa1/attachment-0001.html>
More information about the Squeak-dev
mailing list
|