pict-section-form 1.0.138 → 1.0.140

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,209 @@
1
+ # Chart Input Type
2
+
3
+ Chart input types wrap one of a few charting libraries. This means the tech is
4
+ compatible with chart.js, c3 and d3 natively and more can be easily added.
5
+
6
+ ## Defaults
7
+
8
+ By default charts use `chart.js` and are `bar` charts. They will try to cast
9
+ an array or object into a meaningful data set.
10
+
11
+ This means minimum viable config is something like the following:
12
+
13
+ ```json
14
+ {
15
+ "Scope": "ChartDemo",
16
+
17
+ "Descriptors":
18
+ {
19
+ "Chart.Display":
20
+ {
21
+ "Name": "MVP Chart",
22
+ "Hash": "MVPChart",
23
+ "DataType": "Object",
24
+ "PictForm":
25
+ {
26
+ "InputType": "Chart",
27
+ "ChartDataAddress": "City.Populations"
28
+ }
29
+ }
30
+ }
31
+ }
32
+ ```
33
+
34
+ And AppData has something like this:
35
+
36
+ ```json
37
+ {
38
+ "City":
39
+ {
40
+ "Populations":
41
+ {
42
+ "Seattle": 324230,
43
+ "Lynnwood": 2349,
44
+ "Burien": 1500,
45
+ "Tacoma": 23498,
46
+ "Olympia": 17984,
47
+ "Redmond": 8700,
48
+ "Kirkland": 9723,
49
+ "Bellevue": 11001
50
+ }
51
+ }
52
+ }
53
+ ```
54
+
55
+ You will end up with a bar graph that has the X axis as cities, y axis as
56
+ populations and the series will be named "City.Populations" as such:
57
+
58
+
59
+
60
+ ## Data Addresses, Raw Objects and Configurable Programmability _(oh my!)_
61
+
62
+ There is a three tiered system to how the chart configuration is generated.
63
+ Because modern charting libraries rely almost entirely on configuration to
64
+ define behavior these days, we can manage the displays this way and only
65
+ rely on the pict-section-form library to broker data back-and-forth.
66
+
67
+ Chaining by default does the following:
68
+
69
+ 1. If there is a `Raw` use that as the base
70
+ 2. If there as an `Address` use that instead of `Raw` as the base (this lets you override config if you want)
71
+ 3. If there is a configuration, merge that with the base
72
+
73
+ So if there is a `ChartLabelsRaw` you can have a set of hard-coded values, and
74
+ then if there is a `ChartLabelsAddress` the input provider will look at that
75
+ address and see if there is an object at that address; if there is it will be
76
+ used instead (as opposed to merging).
77
+
78
+ Lastly, if there is a configuration, it will merge the configuration into
79
+ whatever came from these.
80
+
81
+ You can control this though! It's controlled by configuration.
82
+
83
+
84
+
85
+ ### Purely Raw Data
86
+
87
+ You can hard code any chart right into the form. There are three places
88
+ for raw form config:
89
+
90
+ * `ChartLabelsRaw` - the "labels" object for the chart
91
+ * `ChartDatasetsRaw` - the "data" object for the chart
92
+ * `ChartJSOptionsCorePrototype` - the chart.js config base
93
+
94
+ The input provider will use the `ChartJSOptionsCorePrototype` and then
95
+ decorate in the `labels` and `data` objects from their raw entries.
96
+
97
+
98
+ ### Purely Raw, Hard-coded Data and Labels
99
+
100
+ This is hard-coded config. It takes whatever is in the "Raw" configuration and
101
+ puts it into the chart config.
102
+
103
+ ```json
104
+ {
105
+ "SimpleGraphExampleRawDataOne":
106
+ {
107
+ Name: "SimpleGraphExampleOne",
108
+ Hash: "SimpleGraphExampleOne",
109
+
110
+ DataType: "Object",
111
+ PictForm:
112
+ {
113
+ Section: "Chart",
114
+ Group: "SimpleChart",
115
+
116
+ Row: 1,
117
+ Width: 3,
118
+
119
+ InputType: "Chart",
120
+
121
+ ChartLabelsRaw: ['Red', 'Green', 'Yellow', 'Grey', 'Blue'],
122
+
123
+ ChartDatasetsRaw: [{
124
+ label: 'My First Dataset',
125
+ data: [11, 16, 7, 3, 14],
126
+ backgroundColor:
127
+ [
128
+ 'rgb(255, 99, 132)',
129
+ 'rgb(75, 192, 192)',
130
+ 'rgb(255, 205, 86)',
131
+ 'rgb(201, 203, 207)',
132
+ 'rgb(54, 162, 235)'
133
+ ]
134
+ }],
135
+
136
+ ChartJSOptionsCorePrototype:
137
+ {
138
+ type: 'polarArea'
139
+ }
140
+ }
141
+ }
142
+ }
143
+ ```
144
+
145
+ ### Configurability via Solvers
146
+
147
+ This is configuration based on solvers.
148
+
149
+ ```json
150
+ {
151
+ "SimpleGraphExampleRawDataTwo":
152
+ {
153
+ Name: "SimpleGraphExampleTwo",
154
+ Hash: "SimpleGraphExampleTwo",
155
+
156
+ DataType: "Object",
157
+ PictForm:
158
+ {
159
+ Section: "Chart",
160
+ Group: "SimpleChart",
161
+
162
+ Row: 2,
163
+ Width: 6,
164
+
165
+ InputType: "Chart",
166
+
167
+ ChartType: "bar",
168
+ ChartLabelsSolver: `objectkeystoarray(aggregationhistogrambyobject(FruitGrid, "name", "nutritions.calories"))`,
169
+ ChartDatasetsSolvers:
170
+ [
171
+ {
172
+ Label: 'Calories',
173
+ DataSolver: `objectvaluestoarray(aggregationhistogrambyobject(FruitGrid, "name", "nutritions.calories"))`
174
+ }
175
+ ]
176
+ }
177
+ }
178
+ }
179
+ ```
180
+
181
+ ### Configurability via Address
182
+
183
+ This is configuration based on solvers.
184
+
185
+ ```json
186
+ {
187
+ "SimpleGraphExampleRawDataTwo":
188
+ {
189
+ Name: "SimpleGraphExampleTwo",
190
+ Hash: "SimpleGraphExampleTwo",
191
+
192
+ DataType: "Object",
193
+ PictForm:
194
+ {
195
+ Section: "Chart",
196
+ Group: "SimpleChart",
197
+
198
+ Row: 2,
199
+ Width: 6,
200
+
201
+ InputType: "Chart",
202
+
203
+ ChartType: "bar",
204
+ ChartLabelsAddress: `AppData.Chart.LabelsArray`,
205
+ ChartDatasetsAddress: `AppData.Chart.Datasets`
206
+ }
207
+ }
208
+ }
209
+ ```