summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/luametafun/luametafun-chart.tex
blob: 1bd89d3505fe628eb7fdd32dbb84fbfe5e37d82b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
% language=us

\environment luametafun-style

\startcomponent luametafun-chart

\startchapter[title={Chart}]

This is another example implementation but it might be handy for simple cases of
presenting results. Of course one can debate the usefulness of certain ways of
presenting but here we avoid that discussion. Let's start with a simple pie
chart (\in {figure} [chart:1]).

\startbuffer[1]
\startMPcode
    draw lmt_chart_circle [
        samples    = { { 1, 4, 3, 2, 5, 7, 6 } },
        percentage = true,
        trace      = true,
    ] ;
\stopMPcode
\stopbuffer

\typebuffer[1][option=TEX]

\startplacefigure[reference=chart:1]
    \getbuffer[1]
\stopplacefigure

As with all these \LMTX\ extensions, you're invited to play with the parameters.
in \in {figure} [chart:2] we see a variant that adds labels as well as one that
has a legend.

\startbuffer[2a]
\startMPcode
draw lmt_chart_circle [
    height      = 4cm,
    samples     = { { 1, 4, 3, 2, 5, 7, 6 } },
    percentage  = true,
    trace       = true,
    labelcolor  = "white",
    labelformat = "@0.1f",
    labelstyle  = "ttxx"
] ;
\stopMPcode
\stopbuffer

The styling of labels and legends can be influenced independently.

\typebuffer[2a][option=TEX]

\startbuffer[2b]
\startMPcode
draw lmt_chart_circle [
    height      = 4cm,
    samples     =  { { 1, 4, 3, 2, 5, 7, 6 } },
    percentage  = false,
    trace       = true,
    linewidth   = .125mm,
    originsize  = 0,
    labeloffset = 3cm,
    labelstyle  = "bfxx",
    legendstyle = "tfxx",
    legend      = {
        "first", "second", "third", "fourth",
        "fifth", "sixths", "sevenths"
    }
] ;

\stopMPcode
\stopbuffer

\typebuffer[2b][option=TEX]

\startplacefigure[reference=chart:2]
    \startcombination
        {\getbuffer[2a]} {}
        {\getbuffer[2b]} {}
    \stopcombination
\stopplacefigure

A second way of rendering are histograms, and the interface is mostly the same.
In \in {figure} [chart:3] we see two variants

\startbuffer[3a]
\startMPcode
    draw lmt_chart_histogram [
        samples    = { { 1, 4, 3, 2, 5, 7, 6 } },
        percentage = true,
        cumulative = true,
        trace      = true,
    ] ;
\stopMPcode
\stopbuffer

\startbuffer[3b]
\startMPcode
    draw lmt_chart_histogram [
        samples    = {
            { 1, 4, 3, 2, 5, 7, 6 },
            { 1, 2, 3, 4, 5, 6, 7 }
        },
        background = "lightgray",
        trace      = true,
    ] ;
\stopMPcode
\stopbuffer

\typebuffer[3a][option=TEX]

and one with two datasets:

\typebuffer[3b][option=TEX]

\startplacefigure[reference=chart:3]
    \startcombination
        {\getbuffer[3a]} {}
        {\getbuffer[3b]} {}
    \stopcombination
\stopplacefigure

\startbuffer[4]
\startMPpage[offset=5mm]
    draw lmt_chart_histogram [
        samples         = {
            { 1, 4, 3, 2, 5, 7, 6 },
            { 1, 2, 3, 4, 5, 6, 7 }
        },
        percentage      = true,
        cumulative      = true,
        showlabels      = false,
        backgroundcolor = "lightgray",
    ] ;
\stopMPpage
\stopbuffer

A cumulative variant is shown in \in {figure} [chart:4] where we also add a
background (color).

\typebuffer[4][option=TEX]

\startplacefigure[reference=chart:4]
    \getbuffer[4]
\stopplacefigure

A different way of using colors is shown in \in {figure} [chart:5] where each
sample gets its own (same) color.

\startbuffer[5]
\startMPcode
    draw lmt_chart_histogram [
        samples    = {
            { 1, 4, 3, 2, 5, 7, 6 },
            { 1, 2, 3, 4, 5, 6, 7 }
        },
        percentage = true,
        cumulative = true,
        showlabels = false,
        background = "lightgray",
        colormode  = "local",
    ] ;
\stopMPcode
\stopbuffer

\typebuffer[5][option=TEX]

\startplacefigure[reference=chart:5]
    \getbuffer[5]
\stopplacefigure

As with pie charts you can add labels and a legend:

\startbuffer[6a]
\startMPcode
    draw lmt_chart_histogram [
        height          = 6cm,
        samples         = { { 1, 4, 3, 2, 5, 7, 6 } },
        percentage      = true,
        cumulative      = true,
        trace           = true,
        labelstyle      = "ttxx",
        labelanchor     = "top",
        labelcolor      = "white",
        backgroundcolor = "middlegray",
    ] ;
\stopMPcode
\stopbuffer

\typebuffer[6a][option=TEX]

The previous and next examples are shown in \in {figure} [chart:6]. The height
specified here concerns the graphic and excludes the labels,

\startbuffer[6b]
\startMPcode
    draw lmt_chart_histogram [
        height      = 6cm,
        width       = 10mm,
        samples     = { { 1, 4, 3, 2, 5, 7, 6 } },
        trace       = true,
        maximum     = 7.5,
        linewidth   = 1mm,
        originsize  = 0,
        labelanchor = "bot",
        labelcolor  = "black"
        labelstyle  = "bfxx"
        legendstyle = "tfxx",
        labelstrut  = "yes",
        legend      = {
            "first", "second", "third", "fourth",
            "fifth", "sixths", "sevenths"
        }
    ] ;
\stopMPcode
\stopbuffer

\typebuffer[6b][option=TEX]

\startplacefigure[reference=chart:6]
    \startcombination
        {\getbuffer[6a]} {}
        {\getbuffer[6b]} {}
    \stopcombination
\stopplacefigure

The third category concerns bar charts that run horizontal. Again we see similar
options driving the rendering (\in {figure} [chart:7]).

\startbuffer[7a]
\startMPcode
    draw lmt_chart_bar [
        samples    = { { 1, 4, 3, 2, 5, 7, 6 } },
        percentage = true,
        cumulative = true,
        trace      = true,
    ] ;
\stopMPcode
\stopbuffer

\typebuffer[7a][option=TEX]

\startbuffer[7b]
\startMPcode
    draw lmt_chart_bar [
        samples         = { { 1, 4, 3, 2, 5, 7, 6 } },
        percentage      = true,
        cumulative      = true,
        showlabels      = false,
        backgroundcolor = "lightgray",
    ] ;
\stopMPcode
\stopbuffer

\typebuffer[7b][option=TEX]

Determining the offset of labels is manual work:

\startbuffer[7c]
\startMPcode
draw lmt_chart_bar [
    width           = 4cm,
    height          = 5mm,
    samples         = { { 1, 4, 3, 2, 5, 7, 6 } },
    percentage      = true,
    cumulative      = true,
    trace           = true,
    labelcolor      = "white",
    labelstyle      = "ttxx",
    labelanchor     = "rt",
    labeloffset     = .25EmWidth,
    backgroundcolor = "middlegray",
] ;
\stopMPcode
\stopbuffer

\typebuffer[7c][option=TEX]

\startplacefigure[reference=chart:7]
    \startcombination[3*1]
        {\getbuffer[7a]} {}
        {\getbuffer[7b]} {}
        {\getbuffer[7c]} {}
    \stopcombination
\stopplacefigure

Here is one with a legend (rendered in \in {figure} [chart:8]):

\startbuffer[8]
\startMPcode
draw lmt_chart_bar [
    width       = 8cm,
    height      = 10mm,
    samples     = { { 1, 4, 3, 2, 5, 7, 6 } },
    trace       = true,
    maximum     = 7.5,
    linewidth   = 1mm,
    originsize  = 0,
    labelanchor = "lft",
    labelcolor  = "black"
    labelstyle  = "bfxx"
    legendstyle = "tfxx",
    labelstrut  = "yes",
    legend      = {
        "first", "second", "third", "fourth",
        "fifth", "sixths", "sevenths"
    }
] ;
\stopMPcode
\stopbuffer

\typebuffer[8][option=TEX]

\startplacefigure[reference=chart:8]
    \getbuffer[8]
\stopplacefigure

You can have labels per dataset as well as draw multiple datasets in
one image, see \in {figure} [chart:9]:

\startbuffer[9]
\startMPcode
    draw lmt_chart_bar [
        samples = {
            { 1, 4, 3, 2, 5, 7, 6 },
            { 3, 2, 5, 7, 5, 6, 1 }
        },
        labels      = {
            { "a1", "b1", "c1", "d1", "e1", "f1", "g1" },
            { "a2", "b2", "c2", "d2", "e2", "f2", "g2" }
        },
        labeloffset = -EmWidth,
        labelanchor = "center",
        labelstyle  = "ttxx",
        trace       = true,
        center      = true,
    ] ;

    draw lmt_chart_bar [
        samples     = {
            { 1, 4, 3, 2, 5, 7, 6 }
        },
        labels      = {
            { "a", "b", "c", "d", "e", "f", "g" }
        },
        labeloffset = -EmWidth,
        labelanchor = "center",
        trace       = true,
        center      = true,
    ] shifted (10cm,0) ;
\stopMPcode
\stopbuffer

\typebuffer[9][option=TEX]

\startplacefigure[reference=chart:9]
    \getbuffer[9]
\stopplacefigure

\starttabulate[|T|T|T|p|]
\FL
\BC name            \BC type    \BC default \BC comment \NC \NR
\ML
\NC originsize      \NC numeric \NC 1mm     \NC \NC \NR
\NC trace           \NC boolean \NC false   \NC \NC \NR
\NC showlabels      \NC boolean \NC true    \NC \NC \NR
\NC center          \NC boolean \NC false   \NC \NC \NR
\ML
\NC samples         \NC list    \NC         \NC \NC \NR
\NC
\NC cumulative      \NC boolean \NC false   \NC \NC \NR
\NC percentage      \NC boolean \NC false   \NC \NC \NR
\NC maximum         \NC numeric \NC 0       \NC \NC \NR
\NC distance        \NC numeric \NC 1mm     \NC \NC \NR
\ML
\NC labels          \NC list    \NC         \NC \NC \NR
\NC labelstyle      \NC string  \NC         \NC \NC \NR
\NC labelformat     \NC string  \NC         \NC \NC \NR
\NC labelstrut      \NC string  \NC auto    \NC \NC \NR
\NC labelanchor     \NC string  \NC         \NC \NC \NR
\NC labeloffset     \NC numeric \NC 0       \NC \NC \NR
\NC labelfraction   \NC numeric \NC 0.8     \NC \NC \NR
\NC labelcolor      \NC string  \NC         \NC \NC \NR
\ML
\NC backgroundcolor \NC string  \NC         \NC \NC \NR
\NC drawcolor       \NC string  \NC white   \NC \NC \NR
\NC fillcolors      \NC list    \NC         \NC primary (dark) colors \NC \NR
\NC colormode       \NC string  \NC global  \NC \NC or \type {local} \NC \NR
\ML
\NC linewidth       \NC numeric \NC .25mm   \NC \NC \NR
\ML
\NC legendcolor     \NC string  \NC         \NC \NC \NR
\NC legendstyle     \NC string  \NC         \NC \NC \NR
\NC legend          \NC list    \NC         \NC \NC \NR
\LL
\stoptabulate

Pie charts have:

\starttabulate[|T|T|]
\FL
\BC name        \BC default \NC \NR
\ML
\NC height      \NC 5cm     \NC \NR
\NC width       \NC 5mm     \NC \NR
\NC labelanchor \NC         \NC \NR
\NC labeloffset \NC 0       \NC \NR
\NC labelstrut  \NC no      \NC \NR
\LL
\stoptabulate

Histograms come with:

\starttabulate[|T|T|]
\FL
\BC name        \BC default \NC \NR
\ML
\NC height      \NC 5cm     \NC \NR
\NC width       \NC 5mm     \NC \NR
\NC labelanchor \NC bot     \NC \NR
\NC labeloffset \NC 1mm     \NC \NR
\NC labelstrut  \NC auto    \NC \NR
\LL
\stoptabulate

Bar charts use:

\starttabulate[|T|T|]
\FL
\BC name        \BC default \NC \NR
\ML
\NC height      \NC 5cm     \NC \NR
\NC width       \NC 5mm     \NC \NR
\NC labelanchor \NC lft     \NC \NR
\NC labeloffset \NC 1mm     \NC \NR
\NC labelstrut  \NC no      \NC \NR
\LL
\stoptabulate

\stopchapter

\stopcomponent