@oliasoft-open-source/charts-library 2.0.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.
Files changed (79) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.js +129 -0
  3. package/.gitlab-ci.yml +77 -0
  4. package/.husky/pre-commit +4 -0
  5. package/.prettierignore +3 -0
  6. package/.prettierrc +4 -0
  7. package/.storybook/main.js +40 -0
  8. package/LICENSE +21 -0
  9. package/README.md +5 -0
  10. package/babel.config.js +29 -0
  11. package/index.js +9 -0
  12. package/jest.config.js +9 -0
  13. package/package.json +96 -0
  14. package/src/components/bar-chart/bar-chart-prop-types.js +181 -0
  15. package/src/components/bar-chart/bar-chart.interface.ts +83 -0
  16. package/src/components/bar-chart/bar-chart.jsx +247 -0
  17. package/src/components/bar-chart/bar-chart.module.less +56 -0
  18. package/src/components/bar-chart/basic.stories.jsx +752 -0
  19. package/src/components/bar-chart/charts.stories.jsx +119 -0
  20. package/src/components/bar-chart/get-bar-chart-data-labels.js +45 -0
  21. package/src/components/bar-chart/get-bar-chart-scales.js +147 -0
  22. package/src/components/bar-chart/get-bar-chart-tooltips.js +100 -0
  23. package/src/components/line-chart/Controls/Controls.jsx +59 -0
  24. package/src/components/line-chart/Controls/Controls.module.less +21 -0
  25. package/src/components/line-chart/Controls/Layer.jsx +169 -0
  26. package/src/components/line-chart/basic.stories.jsx +735 -0
  27. package/src/components/line-chart/charts.stories.jsx +264 -0
  28. package/src/components/line-chart/get-line-chart-data-labels.js +24 -0
  29. package/src/components/line-chart/get-line-chart-scales.js +131 -0
  30. package/src/components/line-chart/get-line-chart-tooltips.js +91 -0
  31. package/src/components/line-chart/line-chart-consts.js +6 -0
  32. package/src/components/line-chart/line-chart-prop-types.js +187 -0
  33. package/src/components/line-chart/line-chart-utils.js +163 -0
  34. package/src/components/line-chart/line-chart.interface.ts +103 -0
  35. package/src/components/line-chart/line-chart.jsx +423 -0
  36. package/src/components/line-chart/line-chart.minor-gridlines-plugin.js +78 -0
  37. package/src/components/line-chart/line-chart.minor-gridlines-plugin.test.js +34 -0
  38. package/src/components/line-chart/line-chart.module.less +56 -0
  39. package/src/components/line-chart/state/action-types.js +9 -0
  40. package/src/components/line-chart/state/initial-state.js +51 -0
  41. package/src/components/line-chart/state/line-chart-reducer.js +115 -0
  42. package/src/components/line-chart/stories/shapes/cubes.stories.jsx +326 -0
  43. package/src/components/line-chart/stories/shapes/pyramid.stories.jsx +189 -0
  44. package/src/components/line-chart/stories/shapes/round.stories.jsx +339 -0
  45. package/src/components/line-chart/stories/shapes/triangle.stories.jsx +166 -0
  46. package/src/components/pie-chart/basic.stories.jsx +390 -0
  47. package/src/components/pie-chart/charts.stories.jsx +66 -0
  48. package/src/components/pie-chart/pie-chart-prop-types.js +111 -0
  49. package/src/components/pie-chart/pie-chart-utils.js +55 -0
  50. package/src/components/pie-chart/pie-chart.interface.ts +61 -0
  51. package/src/components/pie-chart/pie-chart.jsx +477 -0
  52. package/src/components/pie-chart/pie-chart.module.less +56 -0
  53. package/src/components/scatter-chart/scatter-chart.intefrace.ts +32 -0
  54. package/src/components/scatter-chart/scatter-chart.jsx +13 -0
  55. package/src/components/scatter-chart/scatter.stories.jsx +196 -0
  56. package/src/helpers/chart-consts.js +82 -0
  57. package/src/helpers/chart-interface.ts +54 -0
  58. package/src/helpers/chart-utils.js +178 -0
  59. package/src/helpers/container.jsx +60 -0
  60. package/src/helpers/disabled-context.js +8 -0
  61. package/src/helpers/enums.js +84 -0
  62. package/src/helpers/get-chart-annotation.js +91 -0
  63. package/src/helpers/styles.js +68 -0
  64. package/src/helpers/text.js +6 -0
  65. package/src/style/external.less +4 -0
  66. package/src/style/fonts/lato/Lato-Bold.woff2 +0 -0
  67. package/src/style/fonts/lato/Lato-BoldItalic.woff2 +0 -0
  68. package/src/style/fonts/lato/Lato-Italic.woff2 +0 -0
  69. package/src/style/fonts/lato/Lato-Regular.woff2 +0 -0
  70. package/src/style/fonts.less +27 -0
  71. package/src/style/global.less +43 -0
  72. package/src/style/reset/reset.less +28 -0
  73. package/src/style/shared.less +24 -0
  74. package/src/style/variables.less +91 -0
  75. package/webpack/webpack.common.js +39 -0
  76. package/webpack/webpack.common.rules.js +107 -0
  77. package/webpack/webpack.dev.js +22 -0
  78. package/webpack/webpack.prod.js +23 -0
  79. package/webpack/webpack.resolve.js +22 -0
@@ -0,0 +1,735 @@
1
+ import React from 'react';
2
+ import { LineChart } from './line-chart';
3
+ import { Container } from '../../helpers/container';
4
+
5
+ const style = {
6
+ height: '1000px',
7
+ width: '1000px',
8
+ };
9
+
10
+ const darkmodeStyle = {
11
+ backgroundColor: '#232628',
12
+ };
13
+
14
+ const dataset1 = {
15
+ label: 'Curve 1',
16
+ borderColor: '#a30125',
17
+ pointBackgroundColor: '#a30125',
18
+ backgroundColor: '#e5f013',
19
+ pointRadius: 2,
20
+ pointHoverRadius: 5,
21
+ pointHitRadius: 20,
22
+ borderWidth: 2,
23
+ fill: false,
24
+ data: [
25
+ {
26
+ x: 0,
27
+ y: 0,
28
+ label: ['Label'],
29
+ },
30
+ {
31
+ x: 5,
32
+ y: 25,
33
+ label: ['Label'],
34
+ },
35
+ {
36
+ x: 10,
37
+ y: 60,
38
+ label: ['Label'],
39
+ },
40
+ {
41
+ x: 15,
42
+ y: 90,
43
+ label: ['Label'],
44
+ },
45
+ {
46
+ x: 20,
47
+ y: 120,
48
+ label: ['Label'],
49
+ },
50
+ {
51
+ x: 25,
52
+ y: 150,
53
+ label: ['Label'],
54
+ },
55
+ ],
56
+ };
57
+
58
+ const dataset2 = {
59
+ label: 'Curve 2',
60
+ borderColor: '#017aa3',
61
+ pointBackgroundColor: '#e5f013',
62
+ pointRadius: 4,
63
+ pointHoverRadius: 5,
64
+ pointHitRadius: 20,
65
+ borderWidth: 1,
66
+ fill: true,
67
+ data: [
68
+ {
69
+ x: 0,
70
+ y: 0,
71
+ },
72
+ {
73
+ x: 3,
74
+ y: 15,
75
+ },
76
+ {
77
+ x: 6,
78
+ y: 30,
79
+ },
80
+ {
81
+ x: 9,
82
+ y: 60,
83
+ },
84
+ {
85
+ x: 12,
86
+ y: 120,
87
+ },
88
+ {
89
+ x: 15,
90
+ y: 240,
91
+ },
92
+ ],
93
+ };
94
+
95
+ const dataset3 = {
96
+ label: 'Curve 3',
97
+ borderColor: '#011fa3',
98
+ pointBackgroundColor: '#011fa3',
99
+ pointRadius: 3,
100
+ pointHoverRadius: 5,
101
+ pointHitRadius: 20,
102
+ borderWidth: 2,
103
+ lineTension: 0.5,
104
+ fill: false,
105
+ yAxisID: 'y2',
106
+ borderDash: [10, 5],
107
+ data: [
108
+ {
109
+ x: 0,
110
+ y: 0,
111
+ },
112
+ {
113
+ x: 7,
114
+ y: 25,
115
+ },
116
+ {
117
+ x: 14,
118
+ y: 12,
119
+ },
120
+ {
121
+ x: 21,
122
+ y: 50,
123
+ },
124
+ {
125
+ x: 28,
126
+ y: 25,
127
+ },
128
+ {
129
+ x: 30,
130
+ y: 100,
131
+ },
132
+ ],
133
+ };
134
+
135
+ const testChartData = {
136
+ datasets: [dataset1, dataset2, dataset3],
137
+ };
138
+
139
+ const multiplelinesKitchensink = {
140
+ data: testChartData,
141
+ options: {
142
+ title: 'Multiple lines Kitchen sink',
143
+ axes: {
144
+ x: [
145
+ {
146
+ label: 'The X',
147
+ position: 'bottom',
148
+ color: 'rgba(128, 32, 196, 0.5)',
149
+ gridLines: {
150
+ drawOnChartArea: false,
151
+ },
152
+ },
153
+ {
154
+ label: 'The X 2',
155
+ position: 'top',
156
+ },
157
+ ],
158
+ y: [
159
+ {
160
+ label: 'The Y',
161
+ position: 'left',
162
+ color: '#a30125',
163
+ },
164
+ {
165
+ label: 'The Y 2',
166
+ position: 'right',
167
+ gridLines: {
168
+ drawOnChartArea: false,
169
+ },
170
+ },
171
+ ],
172
+ },
173
+ },
174
+ };
175
+
176
+ const simpleMultipleLines = {
177
+ data: {
178
+ datasets: [dataset1, dataset2],
179
+ },
180
+ options: {
181
+ title: 'Simple multiple lines',
182
+ axes: {
183
+ y: [
184
+ {
185
+ label: 'The Y',
186
+ position: 'left',
187
+ color: '#a30125',
188
+ },
189
+ ],
190
+ },
191
+ },
192
+ };
193
+
194
+ const withMinorGridlines = {
195
+ data: {
196
+ datasets: [dataset1],
197
+ },
198
+ options: {
199
+ title: 'Minor gridlines',
200
+ graph: {
201
+ showMinorGridlines: true,
202
+ },
203
+ },
204
+ };
205
+
206
+ const multiXAxes = {
207
+ data: {
208
+ datasets: [dataset1],
209
+ },
210
+ options: {
211
+ title: 'Multiple X Axes',
212
+ axes: {
213
+ x: [
214
+ {
215
+ label: 'The X',
216
+ position: 'bottom',
217
+ color: 'rgba(128, 32, 196, 0.5)',
218
+ },
219
+ {
220
+ label: 'The X 2',
221
+ position: 'top',
222
+ },
223
+ ],
224
+ },
225
+ },
226
+ };
227
+
228
+ const reversedYAxis = {
229
+ data: {
230
+ datasets: [dataset1],
231
+ },
232
+ options: {
233
+ title: 'Reversed Y Axis',
234
+ axes: {
235
+ x: [
236
+ {
237
+ label: 'The X',
238
+ position: 'bottom',
239
+ color: 'rgba(128, 32, 196, 0.5)',
240
+ },
241
+ ],
242
+ },
243
+ additionalAxesOptions: {
244
+ reverse: true,
245
+ },
246
+ },
247
+ };
248
+
249
+ const logarithmicScale = {
250
+ data: {
251
+ datasets: [dataset2],
252
+ },
253
+ options: {
254
+ title: 'Logarithmic scale',
255
+ axes: {
256
+ y: [
257
+ {
258
+ label: 'The Y',
259
+ position: 'right',
260
+ color: '#a30125',
261
+ },
262
+ {
263
+ label: 'The Y 2',
264
+ position: 'left',
265
+ color: '#011fa3',
266
+ gridLines: {
267
+ drawOnChartArea: false,
268
+ },
269
+ },
270
+ ],
271
+ },
272
+ additionalAxesOptions: {
273
+ chartScaleType: 'logarithmic',
274
+ },
275
+ },
276
+ };
277
+ const presetRange = {
278
+ data: {
279
+ datasets: [dataset1],
280
+ },
281
+ options: {
282
+ title: 'Preset range',
283
+ additionalAxesOptions: {
284
+ range: {
285
+ x: {
286
+ min: -10,
287
+ max: 40,
288
+ },
289
+ y: {
290
+ min: -10,
291
+ max: 180,
292
+ },
293
+ },
294
+ },
295
+ },
296
+ };
297
+
298
+ const withDatalabels = {
299
+ data: {
300
+ datasets: [dataset1],
301
+ },
302
+ options: {
303
+ title: 'With datalabels',
304
+ graph: {
305
+ showDataLabels: true,
306
+ },
307
+ },
308
+ };
309
+
310
+ const datalabelsTooltips = {
311
+ data: {
312
+ datasets: [dataset1],
313
+ },
314
+ options: {
315
+ title: 'With datalabels in tooltips',
316
+ tooltip: {
317
+ showLabelsInTooltips: true,
318
+ },
319
+ },
320
+ };
321
+
322
+ const legendPosition = {
323
+ data: {
324
+ datasets: [dataset1],
325
+ },
326
+ options: {
327
+ title: 'Legend to the right',
328
+ legend: {
329
+ position: 'right',
330
+ },
331
+ },
332
+ };
333
+
334
+ const legendAlign = {
335
+ data: {
336
+ datasets: [dataset1],
337
+ },
338
+ options: {
339
+ title: 'Legend aligned to start',
340
+ legend: {
341
+ align: 'start',
342
+ },
343
+ },
344
+ };
345
+
346
+ const annotationKitchensink = {
347
+ data: {
348
+ datasets: [dataset1],
349
+ },
350
+ options: {
351
+ title: 'Annotations Kitchen Sink',
352
+ annotations: {
353
+ borderWidth: 10,
354
+ controlAnnotation: true,
355
+ annotationsData: [
356
+ {
357
+ label: 'Annotation 1',
358
+ value: 40,
359
+ },
360
+ {
361
+ label: 'Annotation 2',
362
+ value: 120,
363
+ },
364
+ {
365
+ annotationAxis: 'x',
366
+ label: 'Annotation 3',
367
+ value: 7,
368
+ },
369
+ {
370
+ annotationAxis: 'x',
371
+ label: 'Annotation 4',
372
+ value: 20,
373
+ },
374
+ {
375
+ label: 'Annotation 5',
376
+ value: 20,
377
+ endValue: 170,
378
+ },
379
+ ],
380
+ },
381
+ },
382
+ };
383
+
384
+ const annotationsYAxis = {
385
+ data: {
386
+ datasets: [dataset1],
387
+ },
388
+ options: {
389
+ title: 'Annotations Y Axis',
390
+ annotations: {
391
+ annotationsData: [
392
+ {
393
+ label: 'Annotation',
394
+ value: 40,
395
+ },
396
+ ],
397
+ },
398
+ },
399
+ };
400
+
401
+ const annotationsXAxis = {
402
+ data: {
403
+ datasets: [dataset1],
404
+ },
405
+ options: {
406
+ title: 'Annotations X Axis',
407
+ annotations: {
408
+ annotationsData: [
409
+ {
410
+ annotationAxis: 'x',
411
+ label: 'Annotation',
412
+ value: 20,
413
+ },
414
+ ],
415
+ },
416
+ },
417
+ };
418
+
419
+ const diagonalAnnotation = {
420
+ data: {
421
+ datasets: [dataset1],
422
+ },
423
+ options: {
424
+ title: 'Diagonal annotation',
425
+ annotations: {
426
+ annotationsData: [
427
+ {
428
+ annotationAxis: 'y',
429
+ label: 'Annotation',
430
+ value: 20,
431
+ endValue: 170,
432
+ },
433
+ ],
434
+ },
435
+ },
436
+ };
437
+
438
+ const controlAnnotation = {
439
+ data: {
440
+ datasets: [dataset1],
441
+ },
442
+ options: {
443
+ title: 'Control annotations in legend',
444
+ annotations: {
445
+ controlAnnotation: true,
446
+ annotationsData: [
447
+ {
448
+ annotationAxis: 'x',
449
+ label: 'Annotation',
450
+ value: 20,
451
+ },
452
+ ],
453
+ },
454
+ },
455
+ };
456
+
457
+ const multipleAnnotations = {
458
+ data: {
459
+ datasets: [dataset1],
460
+ },
461
+ options: {
462
+ title: 'Multiple annotations',
463
+ annotations: {
464
+ controlAnnotation: true,
465
+ annotationsData: [
466
+ {
467
+ annotationAxis: 'y',
468
+ label: 'Annotation 1',
469
+ value: 50,
470
+ },
471
+ {
472
+ annotationAxis: 'x',
473
+ label: 'Annotation 2',
474
+ value: 10,
475
+ },
476
+ {
477
+ annotationAxis: 'y',
478
+ label: 'Annotation 3',
479
+ value: 20,
480
+ },
481
+ ],
482
+ },
483
+ },
484
+ };
485
+
486
+ const widthHeight = {
487
+ data: {
488
+ datasets: [dataset1],
489
+ },
490
+ options: {
491
+ title: 'Custom width and height',
492
+ chartStyling: {
493
+ width: 400,
494
+ height: 800,
495
+ },
496
+ },
497
+ };
498
+
499
+ const noAnimation = {
500
+ data: {
501
+ datasets: [dataset1],
502
+ },
503
+ options: {
504
+ title: 'No animations',
505
+ },
506
+ };
507
+
508
+ const withAnimation = {
509
+ data: {
510
+ datasets: [dataset1],
511
+ },
512
+ options: {
513
+ title: 'With animations',
514
+ chartStyling: {
515
+ performanceMode: false,
516
+ },
517
+ },
518
+ };
519
+
520
+ const withAnimationMultiple = {
521
+ data: {
522
+ datasets: [dataset1, dataset2],
523
+ },
524
+ options: {
525
+ title: 'Animations with multiple lines and annotations',
526
+ chartStyling: {
527
+ performanceMode: false,
528
+ },
529
+ annotations: {
530
+ annotationsData: [
531
+ {
532
+ annotationAxis: 'y',
533
+ value: 200,
534
+ },
535
+ {
536
+ annotationAxis: 'x',
537
+ value: 10,
538
+ },
539
+ ],
540
+ },
541
+ },
542
+ };
543
+
544
+ const lightMode = {
545
+ data: {
546
+ datasets: [dataset1, dataset2],
547
+ },
548
+ options: {
549
+ title: 'Light mode',
550
+ axes: {
551
+ x: [
552
+ {
553
+ label: 'The X',
554
+ position: 'bottom',
555
+ },
556
+ {
557
+ label: 'The X 2',
558
+ position: 'top',
559
+ },
560
+ ],
561
+ y: [{}],
562
+ },
563
+ graph: {
564
+ showDataLabels: true,
565
+ showMinorGridlines: true,
566
+ },
567
+ annotations: {
568
+ controlAnnotation: true,
569
+ annotationsData: [
570
+ {
571
+ label: 'Annotation 1',
572
+ annotationAxis: 'y',
573
+ value: 100,
574
+ },
575
+ ],
576
+ },
577
+ },
578
+ };
579
+ const darkMode = {
580
+ data: {
581
+ datasets: [dataset1, dataset2],
582
+ },
583
+ options: {
584
+ title: 'Dark mode',
585
+ axes: {
586
+ x: [
587
+ {
588
+ label: 'The X',
589
+ position: 'bottom',
590
+ },
591
+ {
592
+ label: 'The X 2',
593
+ position: 'top',
594
+ },
595
+ ],
596
+ },
597
+ chartStyling: {
598
+ darkMode: true,
599
+ },
600
+ graph: {
601
+ showDataLabels: true,
602
+ showMinorGridlines: true,
603
+ },
604
+ annotations: {
605
+ controlAnnotation: true,
606
+ annotationsData: [
607
+ {
608
+ label: 'Annotation 1',
609
+ annotationAxis: 'y',
610
+ value: 100,
611
+ },
612
+ ],
613
+ },
614
+ },
615
+ };
616
+
617
+ export default {
618
+ title: 'Basic Line Chart',
619
+ component: LineChart,
620
+ };
621
+
622
+ export const SingleLine = () => {
623
+ const singleChart = {
624
+ data: {
625
+ datasets: [dataset1],
626
+ },
627
+ };
628
+
629
+ return (
630
+ <Container style={style}>
631
+ <LineChart chart={singleChart} />
632
+ </Container>
633
+ );
634
+ };
635
+
636
+ export const MultipleLines = () => (
637
+ <Container style={style}>
638
+ <LineChart chart={multiplelinesKitchensink} />
639
+ <LineChart chart={simpleMultipleLines} />
640
+ </Container>
641
+ );
642
+
643
+ export const WithMinorGridlines = () => (
644
+ <Container style={style}>
645
+ <LineChart chart={withMinorGridlines} />
646
+ </Container>
647
+ );
648
+
649
+ export const AxesOptions = () => (
650
+ <Container style={style}>
651
+ <LineChart chart={multiXAxes} />
652
+ <LineChart chart={reversedYAxis} />
653
+ <LineChart chart={logarithmicScale} />
654
+ <LineChart chart={presetRange} />
655
+ </Container>
656
+ );
657
+
658
+ export const GraphOptions = () => (
659
+ <Container style={style}>
660
+ <LineChart chart={withDatalabels} />
661
+ <LineChart chart={datalabelsTooltips} />
662
+ </Container>
663
+ );
664
+
665
+ export const LegendOptions = () => (
666
+ <Container style={style}>
667
+ <LineChart chart={legendPosition} />
668
+ <LineChart chart={legendAlign} />
669
+ </Container>
670
+ );
671
+
672
+ export const Annotations = () => (
673
+ <Container style={style}>
674
+ <LineChart chart={annotationKitchensink} />
675
+ <LineChart chart={annotationsYAxis} />
676
+ <LineChart chart={annotationsXAxis} />
677
+ <LineChart chart={diagonalAnnotation} />
678
+ <LineChart chart={controlAnnotation} />
679
+ <LineChart chart={multipleAnnotations} />
680
+ </Container>
681
+ );
682
+
683
+ export const Styling = () => (
684
+ <Container style={style}>
685
+ <LineChart chart={widthHeight} />
686
+ </Container>
687
+ );
688
+
689
+ export const Animations = () => (
690
+ <Container style={style}>
691
+ <LineChart chart={noAnimation} />
692
+ <LineChart chart={withAnimation} />
693
+ <LineChart chart={withAnimationMultiple} />
694
+ </Container>
695
+ );
696
+
697
+ export const DarkMode = () => (
698
+ <Container style={style}>
699
+ <Container>
700
+ <LineChart chart={lightMode} />
701
+ </Container>
702
+ <Container style={darkmodeStyle}>
703
+ <LineChart chart={darkMode} />
704
+ </Container>
705
+ </Container>
706
+ );
707
+
708
+ export const ControlsPopup = () => {
709
+ const closeOnCross = {
710
+ data: {
711
+ datasets: [dataset1],
712
+ },
713
+ options: {
714
+ title: 'Close controls popup on cross (default)',
715
+ },
716
+ };
717
+ const closeOnOutsideClick = {
718
+ data: {
719
+ datasets: [dataset1],
720
+ },
721
+ options: {
722
+ title: 'Close controls popup on outside click',
723
+ chartOptions: {
724
+ closeOnOutsideClick: true,
725
+ },
726
+ },
727
+ };
728
+
729
+ return (
730
+ <Container style={style}>
731
+ <LineChart chart={closeOnCross} />
732
+ <LineChart chart={closeOnOutsideClick} />
733
+ </Container>
734
+ );
735
+ };