@oliasoft-open-source/charts-library 2.5.15 → 2.5.16-0

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.
@@ -1,664 +0,0 @@
1
- import React, { useState } from 'react';
2
- import {
3
- Flex,
4
- Menu,
5
- Select,
6
- Slider,
7
- Table,
8
- Text,
9
- Toggle,
10
- } from '@oliasoft-open-source/react-ui-library';
11
- import { LineChart } from './line-chart';
12
- import { getCustomLegendPlugin } from '../../helpers/get-custom-legend-plugin-example';
13
-
14
- const dataset1 = {
15
- label: 'Dataset 1',
16
- data: [
17
- {
18
- x: 0,
19
- y: 0,
20
- },
21
- {
22
- x: 5,
23
- y: 25,
24
- },
25
- {
26
- x: 10,
27
- y: 60,
28
- },
29
- {
30
- x: 15,
31
- y: 90,
32
- },
33
- {
34
- x: 20,
35
- y: 120,
36
- },
37
- {
38
- x: 25,
39
- y: 150,
40
- },
41
- ],
42
- };
43
-
44
- const datasetLabelled1 = {
45
- ...dataset1,
46
- data: dataset1.data.map((item) => ({ ...item, label: ['Label'] })),
47
- };
48
-
49
- const dataset2 = {
50
- label: 'Dataset 2',
51
- data: [
52
- {
53
- x: 0,
54
- y: 0,
55
- },
56
- {
57
- x: 3,
58
- y: 15,
59
- },
60
- {
61
- x: 6,
62
- y: 30,
63
- },
64
- {
65
- x: 9,
66
- y: 60,
67
- },
68
- {
69
- x: 12,
70
- y: 120,
71
- },
72
- {
73
- x: 15,
74
- y: 240,
75
- },
76
- ],
77
- };
78
-
79
- const datasetMissingValues = {
80
- label: 'Dataset with missing (null) values',
81
- data: [
82
- {
83
- x: 0,
84
- y: 0,
85
- },
86
- {
87
- x: 3,
88
- y: 0,
89
- },
90
- null, //reproduce OW-9855
91
- undefined, //reproduce OW-9855
92
- {
93
- x: 3,
94
- y: 30,
95
- },
96
- {
97
- x: null,
98
- y: 60,
99
- },
100
- {
101
- x: 12,
102
- y: 120,
103
- },
104
- {
105
- x: 15,
106
- y: 240,
107
- },
108
- ],
109
- };
110
-
111
- const datasetLabelled2 = {
112
- ...dataset2,
113
- data: dataset2.data.map((item) => ({ ...item, label: ['Label'] })),
114
- };
115
-
116
- const basicChart = {
117
- data: {
118
- datasets: [dataset1, dataset2],
119
- },
120
- options: {
121
- title: 'Chart title',
122
- chartStyling: {
123
- height: 400,
124
- },
125
- },
126
- };
127
-
128
- export default {
129
- title: 'LineChart',
130
- component: LineChart,
131
- args: {
132
- chart: basicChart,
133
- },
134
- };
135
-
136
- const Template = (args) => {
137
- return (
138
- <LineChart
139
- // eslint-disable-next-line react/jsx-props-no-spreading
140
- {...args}
141
- />
142
- );
143
- };
144
-
145
- const customLegendContainerID = 'custom-legend-container';
146
-
147
- const TemplateWithCustomLegendContainer = (args) => {
148
- return (
149
- <>
150
- <LineChart
151
- // eslint-disable-next-line react/jsx-props-no-spreading
152
- {...args}
153
- />
154
- <div id={customLegendContainerID}></div>
155
- </>
156
- );
157
- };
158
-
159
- export const Default = Template.bind({});
160
-
161
- export const FillContainer = Template.bind({});
162
- FillContainer.args = {
163
- chart: {
164
- ...basicChart,
165
- options: {
166
- ...basicChart.options,
167
- chartStyling: {
168
- ...basicChart.options.chartStyling,
169
- height: '100%',
170
- },
171
- },
172
- },
173
- };
174
- FillContainer.decorators = [
175
- (Story) => (
176
- <div style={{ height: 400, width: 500 }}>
177
- <Story />
178
- </div>
179
- ),
180
- ];
181
-
182
- export const NoTitle = Template.bind({});
183
- NoTitle.args = {
184
- chart: {
185
- ...basicChart,
186
- options: {
187
- ...basicChart.options,
188
- title: undefined,
189
- },
190
- },
191
- };
192
-
193
- export const DataGaps = Template.bind({});
194
- DataGaps.args = {
195
- chart: {
196
- ...basicChart,
197
- data: {
198
- datasets: [datasetMissingValues],
199
- },
200
- },
201
- };
202
-
203
- export const MinorGridlines = Template.bind({});
204
- MinorGridlines.args = {
205
- chart: {
206
- ...basicChart,
207
- options: {
208
- ...basicChart.options,
209
- graph: {
210
- showMinorGridlines: true,
211
- },
212
- },
213
- },
214
- };
215
-
216
- export const AxesLabels = Template.bind({});
217
- AxesLabels.args = {
218
- chart: {
219
- ...basicChart,
220
- options: {
221
- ...basicChart.options,
222
- axes: {
223
- x: [
224
- {
225
- label: 'x-axis title here',
226
- },
227
- ],
228
- y: [
229
- {
230
- label: 'y-axis title here',
231
- },
232
- ],
233
- },
234
- },
235
- },
236
- };
237
-
238
- export const MultipleXAxes = Template.bind({});
239
- MultipleXAxes.args = {
240
- chart: {
241
- data: {
242
- datasets: [
243
- dataset1,
244
- {
245
- ...dataset2,
246
- xAxisID: 'x2',
247
- },
248
- ],
249
- },
250
- options: {
251
- title: 'Chart title',
252
- chartStyling: {
253
- height: 400,
254
- },
255
- axes: {
256
- x: [
257
- {
258
- label: 'The X',
259
- position: 'bottom',
260
- },
261
- {
262
- label: 'The X 2',
263
- position: 'top',
264
- },
265
- ],
266
- },
267
- },
268
- },
269
- };
270
-
271
- export const ReversedYAxis = Template.bind({});
272
- ReversedYAxis.args = {
273
- chart: {
274
- ...basicChart,
275
- options: {
276
- ...basicChart.options,
277
- additionalAxesOptions: {
278
- reverse: true,
279
- },
280
- },
281
- },
282
- };
283
-
284
- export const LogarithmicScale = Template.bind({});
285
- LogarithmicScale.args = {
286
- chart: {
287
- ...basicChart,
288
- options: {
289
- ...basicChart.options,
290
- additionalAxesOptions: {
291
- chartScaleType: 'logarithmic',
292
- },
293
- },
294
- },
295
- };
296
-
297
- export const PresetRange = Template.bind({});
298
- PresetRange.args = {
299
- chart: {
300
- ...basicChart,
301
- options: {
302
- ...basicChart.options,
303
- additionalAxesOptions: {
304
- range: {
305
- x: {
306
- min: -10,
307
- max: 40,
308
- },
309
- y: {
310
- min: -10,
311
- max: 180,
312
- },
313
- },
314
- },
315
- },
316
- },
317
- };
318
-
319
- export const DataLabels = Template.bind({});
320
- DataLabels.args = {
321
- chart: {
322
- ...basicChart,
323
- data: {
324
- datasets: [datasetLabelled1, datasetLabelled2],
325
- },
326
- options: {
327
- ...basicChart.options,
328
- graph: {
329
- showDataLabels: true,
330
- },
331
- },
332
- },
333
- };
334
-
335
- export const DataLabelsInTooltips = Template.bind({});
336
- DataLabelsInTooltips.args = {
337
- chart: {
338
- ...basicChart,
339
- data: {
340
- datasets: [datasetLabelled1, datasetLabelled2],
341
- },
342
- options: {
343
- ...basicChart.options,
344
- tooltip: {
345
- showLabelsInTooltips: true,
346
- },
347
- },
348
- },
349
- };
350
-
351
- export const LegendOnRight = Template.bind({});
352
- LegendOnRight.args = {
353
- chart: {
354
- ...basicChart,
355
- options: {
356
- ...basicChart.options,
357
- legend: {
358
- position: 'right',
359
- },
360
- },
361
- },
362
- };
363
-
364
- export const Annotations = Template.bind({});
365
- Annotations.args = {
366
- chart: {
367
- ...basicChart,
368
- options: {
369
- ...basicChart.options,
370
- annotations: {
371
- showAnnotations: true,
372
- labelAnnotation: {
373
- content: ['Annotation label'],
374
- },
375
- annotationsData: [
376
- {
377
- annotationAxis: 'y',
378
- label: 'Annotation on y-axis',
379
- value: 50,
380
- },
381
- {
382
- annotationAxis: 'x',
383
- label: 'Annotation on x-axis',
384
- value: 10,
385
- },
386
- {
387
- annotationAxis: 'y',
388
- label: 'Diagonal annotation',
389
- value: 20,
390
- endValue: 170,
391
- },
392
- ],
393
- },
394
- },
395
- },
396
- };
397
-
398
- export const AnnotationsInLegend = Template.bind({});
399
- AnnotationsInLegend.args = {
400
- chart: {
401
- ...basicChart,
402
- options: {
403
- ...basicChart.options,
404
- annotations: {
405
- controlAnnotation: true,
406
- showAnnotations: true,
407
- annotationsData: [
408
- {
409
- annotationAxis: 'x',
410
- label: 'Annotation',
411
- value: 20,
412
- },
413
- ],
414
- },
415
- },
416
- },
417
- };
418
-
419
- export const CustomLegend = TemplateWithCustomLegendContainer.bind({});
420
- CustomLegend.args = {
421
- chart: {
422
- ...basicChart,
423
- options: {
424
- ...basicChart.options,
425
- title: 'Custom HTML legend',
426
- legend: {
427
- customLegend: {
428
- customLegendPlugin: getCustomLegendPlugin(customLegendContainerID),
429
- customLegendContainerID,
430
- },
431
- },
432
- },
433
- },
434
- };
435
-
436
- export const Animation = Template.bind({});
437
- Animation.args = {
438
- chart: {
439
- ...basicChart,
440
- options: {
441
- ...basicChart.options,
442
- chartStyling: {
443
- ...basicChart.options.chartStyling,
444
- performanceMode: false,
445
- },
446
- },
447
- },
448
- };
449
-
450
- export const SquareAspectRatio = Template.bind({});
451
- SquareAspectRatio.args = {
452
- chart: {
453
- ...basicChart,
454
- options: {
455
- ...basicChart.options,
456
- title: 'Square aspect ratio',
457
- chartStyling: {
458
- squareAspectRatio: true,
459
- maintainAspectRatio: true,
460
- },
461
- },
462
- },
463
- };
464
-
465
- export const HeaderComponentNoTitle = (args) => {
466
- const options = ['Category A', 'Category B', 'Category C'];
467
-
468
- const suboptions = ['Chart 1', 'Chart 2', 'Chart 3'];
469
-
470
- const charts = options.map((option) => ({
471
- label: option,
472
- options: suboptions.map((suboption) => ({
473
- label: suboption,
474
- options: {
475
- label: `${option} - ${suboption}`,
476
- },
477
- })),
478
- }));
479
-
480
- const [selectedChartTitle, setSelectedChartTitle] = useState(
481
- `${options[0]} - ${suboptions[0]}`,
482
- );
483
-
484
- const chart = {
485
- ...basicChart,
486
- options: { ...basicChart.options, title: null },
487
- };
488
-
489
- return (
490
- <LineChart
491
- chart={chart}
492
- headerComponent={
493
- <Flex gap="10px" alignItems="center">
494
- <Text bold>
495
- <Menu
496
- menu={{
497
- label: selectedChartTitle,
498
- sections: charts.map((option) => ({
499
- type: 'Menu',
500
- trigger: 'Text',
501
- menu: {
502
- label: option.label,
503
- trigger: 'Text',
504
- sections: option.options.map((suboption) => ({
505
- label: suboption.label,
506
- type: 'Option',
507
- onClick: () =>
508
- setSelectedChartTitle(
509
- `${option.label} - ${suboption.label}`,
510
- ),
511
- })),
512
- },
513
- })),
514
- trigger: 'Text',
515
- small: true,
516
- }}
517
- />
518
- </Text>
519
- <Toggle label="Toggle" onChange={() => {}} noMargin />
520
- </Flex>
521
- }
522
- />
523
- );
524
- };
525
- HeaderComponentNoTitle.parameters = {
526
- docs: {
527
- description: {
528
- story:
529
- 'If no chart title is set, a `headerComponent` can take its place.',
530
- },
531
- },
532
- };
533
-
534
- const testComponent = (
535
- <div
536
- style={{
537
- flexGrow: 1,
538
- minWidth: 280,
539
- margin: '-9px 0',
540
- display: 'flex',
541
- alignItems: 'center',
542
- }}
543
- >
544
- <Select
545
- options={['Aardvarks', 'Kangaroos']}
546
- value="Aardvarks"
547
- small
548
- width="90px"
549
- autoLayerWidth
550
- />
551
- <Slider max={100} min={0} onChange={() => {}} showArrows value={50} />
552
- <Text>180s</Text>
553
- </div>
554
- );
555
-
556
- export const HeaderComponentWithTitle = Template.bind({});
557
- HeaderComponentWithTitle.args = {
558
- headerComponent: testComponent,
559
- };
560
- HeaderComponentWithTitle.parameters = {
561
- docs: {
562
- description: {
563
- story:
564
- "If a chart title is set, the `headerComponent` will be displayed to the right of it. Setting a `minWidth` on the `headerComponent` will make sure it isn't squashed.",
565
- },
566
- },
567
- };
568
-
569
- export const SubheaderComponent = Template.bind({});
570
- SubheaderComponent.args = {
571
- subheaderComponent: testComponent,
572
- };
573
-
574
- const table = {
575
- headers: [
576
- {
577
- cells: [
578
- { value: 'Name' },
579
- { value: 'Weight' },
580
- { value: 'Energy' },
581
- { value: 'Origin' },
582
- ],
583
- },
584
- ],
585
- rows: [
586
- {
587
- cells: [
588
- { value: 'Brown rice' },
589
- { value: 100 },
590
- { value: 361 },
591
- { value: 'Vietnam' },
592
- ],
593
- },
594
- {
595
- cells: [
596
- { value: 'Buckwheat' },
597
- { value: 50 },
598
- { value: 358 },
599
- { value: 'Poland' },
600
- ],
601
- },
602
- {
603
- cells: [
604
- { value: 'Couscous' },
605
- { value: 10 },
606
- { value: 368 },
607
- { value: 'France' },
608
- ],
609
- },
610
- ],
611
- };
612
- SubheaderComponent.parameters = {
613
- docs: {
614
- description: {
615
- story:
616
- 'This will be displayed between the title/controls and the chart itself.',
617
- },
618
- },
619
- };
620
-
621
- export const WithTable = (args) => {
622
- return <LineChart chart={basicChart} table={<Table table={table} />} />;
623
- };
624
- export const SquareAspectRatioFillContainer = Template.bind({});
625
- SquareAspectRatioFillContainer.args = {
626
- chart: {
627
- ...basicChart,
628
- options: {
629
- ...basicChart.options,
630
- title: 'Square aspect ratio',
631
- chartStyling: {
632
- squareAspectRatio: true,
633
- maintainAspectRatio: true,
634
- height: '100%',
635
- },
636
- },
637
- },
638
- };
639
- SquareAspectRatioFillContainer.decorators = [
640
- (Story) => (
641
- <div style={{ display: 'flex', height: 400, width: 600 }}>
642
- <Story />
643
- </div>
644
- ),
645
- ];
646
-
647
- export const OnPointHover = Template.bind({});
648
- OnPointHover.args = {
649
- chart: {
650
- ...basicChart,
651
- options: {
652
- ...basicChart.options,
653
- interactions: {
654
- onPointHover: (evt, datasetIndex, pointIndex, datasets) => {
655
- console.log({ evt });
656
- console.log(datasets[datasetIndex].data[pointIndex]);
657
- },
658
- onPointUnhover: () => {
659
- console.log('No point hovered');
660
- },
661
- },
662
- },
663
- },
664
- };