@wonderflow/charts 12.11.0 → 14.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.
- package/dist/components/bar-chart/bar-chart.d.ts +35 -7
- package/dist/components/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/components/bar-chart/bar-chart.js +21 -46
- package/dist/components/bar-chart/bar-chart.test.js +7 -1
- package/dist/components/cartesian-base/cartesian-base-axis.d.ts.map +1 -1
- package/dist/components/cartesian-base/cartesian-base-axis.js +10 -11
- package/dist/components/cartesian-base/cartesian-base-legend.d.ts.map +1 -1
- package/dist/components/cartesian-base/cartesian-base-legend.js +3 -3
- package/dist/components/cartesian-base/cartesian-base.d.ts +32 -0
- package/dist/components/cartesian-base/cartesian-base.d.ts.map +1 -1
- package/dist/components/cartesian-base/cartesian-base.js +8 -3
- package/dist/components/cartesian-base/cartesian-base.module.css +1 -1
- package/dist/components/headings/headings.d.ts +19 -2
- package/dist/components/headings/headings.d.ts.map +1 -1
- package/dist/components/headings/headings.js +72 -6
- package/dist/components/headings/headings.module.css +1 -0
- package/dist/components/headings/headings.test.d.ts +1 -1
- package/dist/components/headings/headings.test.d.ts.map +1 -1
- package/dist/components/headings/headings.test.js +37 -3
- package/dist/components/line-chart/line-chart.d.ts +31 -15
- package/dist/components/line-chart/line-chart.d.ts.map +1 -1
- package/dist/components/line-chart/line-chart.js +5 -3
- package/dist/components/line-chart/line-chart.test.js +2 -2
- package/dist/components/loader/bar-chart-loader.d.ts.map +1 -1
- package/dist/components/loader/bar-chart-loader.js +1 -1
- package/dist/components/loader/loader.js +2 -2
- package/dist/components/loader/loader.test.js +4 -2
- package/dist/components/shapes/bars/bars-average.d.ts +3 -0
- package/dist/components/shapes/bars/bars-average.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-average.js +30 -0
- package/dist/components/shapes/bars/bars-label.d.ts +22 -0
- package/dist/components/shapes/bars/bars-label.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-label.js +35 -0
- package/dist/components/shapes/bars/bars-layout.d.ts +3 -0
- package/dist/components/shapes/bars/bars-layout.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-layout.js +36 -0
- package/dist/components/shapes/bars/bars-overlay-labels.d.ts +6 -0
- package/dist/components/shapes/bars/bars-overlay-labels.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-overlay-labels.js +62 -0
- package/dist/components/shapes/bars/bars-overlay.d.ts +6 -0
- package/dist/components/shapes/bars/bars-overlay.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-overlay.js +59 -0
- package/dist/components/shapes/bars/bars-series-labels.d.ts +6 -0
- package/dist/components/shapes/bars/bars-series-labels.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-series-labels.js +62 -0
- package/dist/components/shapes/bars/bars-series.d.ts +6 -0
- package/dist/components/shapes/bars/bars-series.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-series.js +56 -0
- package/dist/components/shapes/bars/bars-stack-overlay-labels.d.ts +6 -0
- package/dist/components/shapes/bars/bars-stack-overlay-labels.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-stack-overlay-labels.js +50 -0
- package/dist/components/shapes/bars/bars-stack-overlay.d.ts +6 -0
- package/dist/components/shapes/bars/bars-stack-overlay.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-stack-overlay.js +50 -0
- package/dist/components/shapes/bars/bars-stack-series-labels.d.ts +6 -0
- package/dist/components/shapes/bars/bars-stack-series-labels.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-stack-series-labels.js +50 -0
- package/dist/components/shapes/bars/bars-stack-series.d.ts +6 -0
- package/dist/components/shapes/bars/bars-stack-series.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-stack-series.js +48 -0
- package/dist/components/shapes/bars/bars-tooltip.d.ts +3 -0
- package/dist/components/shapes/bars/bars-tooltip.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-tooltip.js +96 -0
- package/dist/components/shapes/bars/bars-trendline.d.ts +3 -0
- package/dist/components/shapes/bars/bars-trendline.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-trendline.js +43 -0
- package/dist/components/shapes/bars/bars.d.ts.map +1 -1
- package/dist/components/shapes/bars/bars.js +27 -18
- package/dist/components/shapes/bars/bars.module.css +1 -1
- package/dist/components/shapes/bars/bars.test.js +132 -8
- package/dist/components/shapes/bars/index.d.ts +13 -0
- package/dist/components/shapes/bars/index.d.ts.map +1 -1
- package/dist/components/shapes/bars/index.js +14 -1
- package/dist/components/shapes/lines/lines-average.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-average.js +8 -46
- package/dist/components/shapes/lines/lines-marker-labels.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-marker-labels.js +16 -12
- package/dist/components/shapes/lines/lines-overlay.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-overlay.js +21 -26
- package/dist/components/shapes/lines/lines-series.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-series.js +6 -19
- package/dist/components/shapes/lines/lines-tooltip.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-tooltip.js +21 -28
- package/dist/components/shapes/lines/lines-trendline.d.ts +3 -0
- package/dist/components/shapes/lines/lines-trendline.d.ts.map +1 -0
- package/dist/components/shapes/lines/lines-trendline.js +43 -0
- package/dist/components/shapes/lines/lines.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines.js +2 -1
- package/dist/components/shapes/lines/lines.test.js +29 -8
- package/dist/hooks/hooks.test.d.ts.map +1 -1
- package/dist/hooks/hooks.test.js +162 -5
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/useAverage.d.ts +82 -0
- package/dist/hooks/useAverage.d.ts.map +1 -0
- package/dist/hooks/useAverage.js +83 -0
- package/dist/hooks/useBarChart.d.ts +17 -0
- package/dist/hooks/useBarChart.d.ts.map +1 -0
- package/dist/hooks/useBarChart.js +110 -0
- package/dist/hooks/useBars.d.ts +66 -0
- package/dist/hooks/useBars.d.ts.map +1 -0
- package/dist/hooks/useBars.js +121 -0
- package/dist/hooks/useCartesian.d.ts +12 -2
- package/dist/hooks/useCartesian.d.ts.map +1 -1
- package/dist/hooks/useCartesian.js +19 -7
- package/dist/hooks/useLineChart.d.ts +3 -27
- package/dist/hooks/useLineChart.d.ts.map +1 -1
- package/dist/hooks/useLineChart.js +27 -16
- package/dist/hooks/useLines.d.ts +51 -0
- package/dist/hooks/useLines.d.ts.map +1 -0
- package/dist/hooks/useLines.js +70 -0
- package/dist/hooks/useTrendline.d.ts +60 -0
- package/dist/hooks/useTrendline.d.ts.map +1 -0
- package/dist/hooks/useTrendline.js +84 -0
- package/dist/providers/cartesian.d.ts +5 -1
- package/dist/providers/cartesian.d.ts.map +1 -1
- package/dist/providers/cartesian.js +19 -3
- package/dist/providers/data.d.ts +6 -7
- package/dist/providers/data.d.ts.map +1 -1
- package/dist/providers/data.js +4 -3
- package/dist/style-config/axis.js +3 -3
- package/dist/style-config/bars.d.ts +3 -0
- package/dist/style-config/bars.d.ts.map +1 -0
- package/dist/style-config/bars.js +43 -0
- package/dist/style-config/cartesian.d.ts.map +1 -1
- package/dist/style-config/cartesian.js +2 -0
- package/dist/style-config/colors.d.ts +1 -4
- package/dist/style-config/colors.d.ts.map +1 -1
- package/dist/style-config/colors.js +30 -36
- package/dist/style-config/headings.d.ts.map +1 -1
- package/dist/style-config/headings.js +16 -1
- package/dist/style-config/lines.d.ts.map +1 -1
- package/dist/style-config/lines.js +6 -0
- package/dist/style-config/themes.d.ts.map +1 -1
- package/dist/style-config/themes.js +18 -0
- package/dist/types/bar-chart.d.ts +26 -22
- package/dist/types/bar-chart.d.ts.map +1 -1
- package/dist/types/bar-chart.js +1 -39
- package/dist/types/bars.d.ts +68 -0
- package/dist/types/bars.d.ts.map +1 -0
- package/dist/types/bars.js +16 -0
- package/dist/types/cartesian.d.ts +7 -0
- package/dist/types/cartesian.d.ts.map +1 -1
- package/dist/types/headings.d.ts +15 -0
- package/dist/types/headings.d.ts.map +1 -1
- package/dist/types/headings.js +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +4 -1
- package/dist/types/line-chart.d.ts +17 -19
- package/dist/types/line-chart.d.ts.map +1 -1
- package/dist/types/lines.d.ts +6 -0
- package/dist/types/lines.d.ts.map +1 -1
- package/dist/types/main.d.ts +15 -2
- package/dist/types/main.d.ts.map +1 -1
- package/dist/types/themes.d.ts +9 -0
- package/dist/types/themes.d.ts.map +1 -1
- package/dist/utils/axis.d.ts +12 -2
- package/dist/utils/axis.d.ts.map +1 -1
- package/dist/utils/axis.js +52 -15
- package/dist/utils/axis.test.js +72 -8
- package/dist/utils/bars.d.ts +63 -0
- package/dist/utils/bars.d.ts.map +1 -0
- package/dist/utils/bars.js +316 -0
- package/dist/utils/bars.test.d.ts +2 -0
- package/dist/utils/bars.test.d.ts.map +1 -0
- package/dist/utils/bars.test.js +388 -0
- package/dist/utils/data.d.ts +14 -6
- package/dist/utils/data.d.ts.map +1 -1
- package/dist/utils/data.js +128 -21
- package/dist/utils/data.test.js +195 -86
- package/dist/utils/format.d.ts +1 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +2 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/lines.d.ts +3 -3
- package/dist/utils/lines.d.ts.map +1 -1
- package/dist/utils/lines.js +3 -1
- package/dist/utils/lines.test.js +26 -1
- package/dist/utils/metadata.d.ts +5 -8
- package/dist/utils/metadata.d.ts.map +1 -1
- package/dist/utils/metadata.js +8 -20
- package/dist/utils/metadata.test.js +5 -58
- package/dist/utils/viewport.test.js +8 -0
- package/package.json +13 -11
package/dist/utils/axis.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cartesianStyleConfig, viewportStyleConfig } from '../style-config';
|
|
2
|
-
import { computeAxisOffset, computeAxisProperties, computeAxisStyleConfig, computeAxisSystemOffset, computeAxisSystemProperties, getAxisOffset, getLabelOffset, getTickLabelSize, handleChartAxisLayout, handleNumberOfTicks, handleTickFormat, handleVerticalTickLabelOffset, handleVerticalTickLabelTransform, hasVerticalTickLabel, inferScaleTypeFromDomain, scaleDomainToAxis, } from './axis';
|
|
2
|
+
import { clampLinearDomain, computeAxisOffset, computeAxisProperties, computeAxisStyleConfig, computeAxisSystemOffset, computeAxisSystemProperties, getAxisOffset, getLabelOffset, getTickLabelSize, handleChartAxisLayout, handleNumberOfTicks, handleTickFormat, handleVerticalTickLabelOffset, handleVerticalTickLabelTransform, hasVerticalTickLabel, inferScaleTypeFromDomain, scaleDomainToAxis, } from './axis';
|
|
3
3
|
describe('getAxisOffset()', () => {
|
|
4
4
|
it('should return offset for top axis', () => {
|
|
5
5
|
const res = getAxisOffset({
|
|
@@ -391,7 +391,7 @@ describe('computeAxisStyleConfig()', () => {
|
|
|
391
391
|
};
|
|
392
392
|
const res = computeAxisStyleConfig(system);
|
|
393
393
|
const exp = {
|
|
394
|
-
bottom: { labelOffset: 28, labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: '
|
|
394
|
+
bottom: { labelOffset: 28, labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'middle', dy: 4 } },
|
|
395
395
|
left: { labelOffset: 28, labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'middle', dx: -4, textAnchor: 'end' } },
|
|
396
396
|
offset: {
|
|
397
397
|
bottomAxisOffset: 63,
|
|
@@ -404,7 +404,7 @@ describe('computeAxisStyleConfig()', () => {
|
|
|
404
404
|
right: { labelOffset: 28, labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'middle', dx: 4, textAnchor: 'start' } },
|
|
405
405
|
style: {
|
|
406
406
|
axisLineProps: { strokeDasharray: '', strokeWidth: 1 },
|
|
407
|
-
bottom: { labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: '
|
|
407
|
+
bottom: { labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'middle', dy: 4 } },
|
|
408
408
|
formatting: { maxCharactersLength: 20, omission: '...' },
|
|
409
409
|
labelProps: {
|
|
410
410
|
fontFamily: 'system-ui, sans-serif', fontSize: 12, fontWeight: 600, textAnchor: 'middle',
|
|
@@ -416,9 +416,9 @@ describe('computeAxisStyleConfig()', () => {
|
|
|
416
416
|
},
|
|
417
417
|
tickLabelProps: { fontFamily: 'system-ui, sans-serif', fontSize: 14, fontWeight: 400 },
|
|
418
418
|
tickLineProps: { length: 4, strokeLinecap: 'round', strokeWidth: 1 },
|
|
419
|
-
top: { labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: '
|
|
419
|
+
top: { labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'middle', dy: -12 } },
|
|
420
420
|
},
|
|
421
|
-
top: { labelOffset: 28, labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: '
|
|
421
|
+
top: { labelOffset: 28, labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'middle', dy: -12 } },
|
|
422
422
|
};
|
|
423
423
|
expect(res).toStrictEqual(exp);
|
|
424
424
|
});
|
|
@@ -500,6 +500,11 @@ describe('scaleDomainToAxis()', () => {
|
|
|
500
500
|
});
|
|
501
501
|
});
|
|
502
502
|
describe('handleTickFormat()', () => {
|
|
503
|
+
const config = {
|
|
504
|
+
hasReversedIndex: false,
|
|
505
|
+
hasMirroredDomainsHorizontal: false,
|
|
506
|
+
hasMirroredDomainsVertical: false,
|
|
507
|
+
};
|
|
503
508
|
it('should return the same value w/o tickFormat', () => {
|
|
504
509
|
const axis = {
|
|
505
510
|
domain: [0, 1],
|
|
@@ -515,6 +520,7 @@ describe('handleTickFormat()', () => {
|
|
|
515
520
|
positionRight: 0,
|
|
516
521
|
positionBottom: 0,
|
|
517
522
|
positionLeft: 0,
|
|
523
|
+
config,
|
|
518
524
|
});
|
|
519
525
|
const func = handleTickFormat(computed);
|
|
520
526
|
const res = func(1, 1);
|
|
@@ -536,6 +542,7 @@ describe('handleTickFormat()', () => {
|
|
|
536
542
|
positionRight: 0,
|
|
537
543
|
positionBottom: 0,
|
|
538
544
|
positionLeft: 0,
|
|
545
|
+
config,
|
|
539
546
|
});
|
|
540
547
|
const func = handleTickFormat(computed);
|
|
541
548
|
const res = func(1, 1);
|
|
@@ -558,6 +565,7 @@ describe('handleTickFormat()', () => {
|
|
|
558
565
|
positionRight: 0,
|
|
559
566
|
positionBottom: 0,
|
|
560
567
|
positionLeft: 0,
|
|
568
|
+
config,
|
|
561
569
|
});
|
|
562
570
|
const func = handleTickFormat(computed);
|
|
563
571
|
const res = func(1, 1);
|
|
@@ -580,6 +588,7 @@ describe('handleTickFormat()', () => {
|
|
|
580
588
|
positionRight: 0,
|
|
581
589
|
positionBottom: 0,
|
|
582
590
|
positionLeft: 0,
|
|
591
|
+
config,
|
|
583
592
|
});
|
|
584
593
|
const func = handleTickFormat(computed);
|
|
585
594
|
const res = func('1234567890123456789012345', 1);
|
|
@@ -602,6 +611,7 @@ describe('handleTickFormat()', () => {
|
|
|
602
611
|
positionRight: 0,
|
|
603
612
|
positionBottom: 0,
|
|
604
613
|
positionLeft: 0,
|
|
614
|
+
config,
|
|
605
615
|
});
|
|
606
616
|
const func = handleTickFormat(computed);
|
|
607
617
|
const res = func('1234567890123456789012345', 1);
|
|
@@ -624,6 +634,7 @@ describe('handleTickFormat()', () => {
|
|
|
624
634
|
positionRight: 0,
|
|
625
635
|
positionBottom: 0,
|
|
626
636
|
positionLeft: 0,
|
|
637
|
+
config,
|
|
627
638
|
});
|
|
628
639
|
const func = handleTickFormat(computed);
|
|
629
640
|
const res = func('01-01-2023', 1);
|
|
@@ -632,6 +643,11 @@ describe('handleTickFormat()', () => {
|
|
|
632
643
|
});
|
|
633
644
|
});
|
|
634
645
|
describe('handleNumberOfTicks()', () => {
|
|
646
|
+
const config = {
|
|
647
|
+
hasReversedIndex: false,
|
|
648
|
+
hasMirroredDomainsHorizontal: false,
|
|
649
|
+
hasMirroredDomainsVertical: false,
|
|
650
|
+
};
|
|
635
651
|
it('should return 10 fro large size', () => {
|
|
636
652
|
const axis = {
|
|
637
653
|
domain: [0, 1],
|
|
@@ -647,6 +663,7 @@ describe('handleNumberOfTicks()', () => {
|
|
|
647
663
|
positionRight: 0,
|
|
648
664
|
positionBottom: 0,
|
|
649
665
|
positionLeft: 0,
|
|
666
|
+
config,
|
|
650
667
|
});
|
|
651
668
|
const res = handleNumberOfTicks(800, 600, computed, viewportStyleConfig);
|
|
652
669
|
const exp = 10;
|
|
@@ -667,6 +684,7 @@ describe('handleNumberOfTicks()', () => {
|
|
|
667
684
|
positionRight: 0,
|
|
668
685
|
positionBottom: 0,
|
|
669
686
|
positionLeft: 0,
|
|
687
|
+
config,
|
|
670
688
|
});
|
|
671
689
|
const res = handleNumberOfTicks(400, 400, computed, viewportStyleConfig);
|
|
672
690
|
const exp = 5;
|
|
@@ -687,6 +705,7 @@ describe('handleNumberOfTicks()', () => {
|
|
|
687
705
|
positionRight: 0,
|
|
688
706
|
positionBottom: 0,
|
|
689
707
|
positionLeft: 0,
|
|
708
|
+
config,
|
|
690
709
|
});
|
|
691
710
|
const res = handleNumberOfTicks(200, 200, computed, viewportStyleConfig);
|
|
692
711
|
const exp = 3;
|
|
@@ -768,6 +787,11 @@ describe('hasVerticalTickLabel()', () => {
|
|
|
768
787
|
});
|
|
769
788
|
});
|
|
770
789
|
describe('handleVerticalTickLabelTransform()', () => {
|
|
790
|
+
const config = {
|
|
791
|
+
hasReversedIndex: false,
|
|
792
|
+
hasMirroredDomainsHorizontal: false,
|
|
793
|
+
hasMirroredDomainsVertical: false,
|
|
794
|
+
};
|
|
771
795
|
it('should return style for top axis', () => {
|
|
772
796
|
const axis = {
|
|
773
797
|
domain: [0, 1],
|
|
@@ -783,9 +807,10 @@ describe('handleVerticalTickLabelTransform()', () => {
|
|
|
783
807
|
positionRight: 0,
|
|
784
808
|
positionBottom: 0,
|
|
785
809
|
positionLeft: 0,
|
|
810
|
+
config,
|
|
786
811
|
});
|
|
787
812
|
const res = handleVerticalTickLabelTransform(1, true, computed);
|
|
788
|
-
const exp = {
|
|
813
|
+
const exp = { textAnchor: 'end' };
|
|
789
814
|
expect(res).toStrictEqual(exp);
|
|
790
815
|
});
|
|
791
816
|
it('should return style for top axis - horizontal label', () => {
|
|
@@ -803,6 +828,7 @@ describe('handleVerticalTickLabelTransform()', () => {
|
|
|
803
828
|
positionRight: 0,
|
|
804
829
|
positionBottom: 0,
|
|
805
830
|
positionLeft: 0,
|
|
831
|
+
config,
|
|
806
832
|
});
|
|
807
833
|
const res = handleVerticalTickLabelTransform(1, false, computed);
|
|
808
834
|
const exp = { transform: '', textAnchor: 'middle' };
|
|
@@ -823,9 +849,13 @@ describe('handleVerticalTickLabelTransform()', () => {
|
|
|
823
849
|
positionRight: 0,
|
|
824
850
|
positionBottom: 0,
|
|
825
851
|
positionLeft: 0,
|
|
852
|
+
config,
|
|
826
853
|
});
|
|
827
854
|
const res = handleVerticalTickLabelTransform(1, true, computed);
|
|
828
|
-
const exp = {
|
|
855
|
+
const exp = {
|
|
856
|
+
dy: '-6',
|
|
857
|
+
textAnchor: 'start',
|
|
858
|
+
};
|
|
829
859
|
expect(res).toStrictEqual(exp);
|
|
830
860
|
});
|
|
831
861
|
it('should return style for bottom axis - horizontal label', () => {
|
|
@@ -843,6 +873,7 @@ describe('handleVerticalTickLabelTransform()', () => {
|
|
|
843
873
|
positionRight: 0,
|
|
844
874
|
positionBottom: 0,
|
|
845
875
|
positionLeft: 0,
|
|
876
|
+
config,
|
|
846
877
|
});
|
|
847
878
|
const res = handleVerticalTickLabelTransform(1, false, computed);
|
|
848
879
|
const exp = { transform: '', textAnchor: 'middle' };
|
|
@@ -863,6 +894,7 @@ describe('handleVerticalTickLabelTransform()', () => {
|
|
|
863
894
|
positionRight: 0,
|
|
864
895
|
positionBottom: 0,
|
|
865
896
|
positionLeft: 0,
|
|
897
|
+
config,
|
|
866
898
|
});
|
|
867
899
|
const res = handleVerticalTickLabelTransform(1, true, computed);
|
|
868
900
|
const exp = {};
|
|
@@ -908,6 +940,11 @@ describe('handleVerticalTickLabelOffset()', () => {
|
|
|
908
940
|
});
|
|
909
941
|
});
|
|
910
942
|
describe('computeAxisProperties()', () => {
|
|
943
|
+
const config = {
|
|
944
|
+
hasReversedIndex: false,
|
|
945
|
+
hasMirroredDomainsHorizontal: false,
|
|
946
|
+
hasMirroredDomainsVertical: false,
|
|
947
|
+
};
|
|
911
948
|
it('should return properties for top axis', () => {
|
|
912
949
|
const axis = {
|
|
913
950
|
domain: [0, 1],
|
|
@@ -922,6 +959,7 @@ describe('computeAxisProperties()', () => {
|
|
|
922
959
|
positionRight: 2,
|
|
923
960
|
positionBottom: 3,
|
|
924
961
|
positionLeft: 4,
|
|
962
|
+
config,
|
|
925
963
|
});
|
|
926
964
|
expect(res.scale).toBeDefined();
|
|
927
965
|
});
|
|
@@ -939,6 +977,7 @@ describe('computeAxisProperties()', () => {
|
|
|
939
977
|
positionRight: 2,
|
|
940
978
|
positionBottom: 3,
|
|
941
979
|
positionLeft: 4,
|
|
980
|
+
config,
|
|
942
981
|
});
|
|
943
982
|
expect(res.scale).toBeDefined();
|
|
944
983
|
});
|
|
@@ -956,6 +995,7 @@ describe('computeAxisProperties()', () => {
|
|
|
956
995
|
positionRight: 2,
|
|
957
996
|
positionBottom: 3,
|
|
958
997
|
positionLeft: 4,
|
|
998
|
+
config,
|
|
959
999
|
});
|
|
960
1000
|
expect(res.scale).toBeDefined();
|
|
961
1001
|
});
|
|
@@ -973,6 +1013,7 @@ describe('computeAxisProperties()', () => {
|
|
|
973
1013
|
positionRight: 2,
|
|
974
1014
|
positionBottom: 3,
|
|
975
1015
|
positionLeft: 4,
|
|
1016
|
+
config,
|
|
976
1017
|
});
|
|
977
1018
|
expect(res.scale).toBeDefined();
|
|
978
1019
|
});
|
|
@@ -986,11 +1027,17 @@ describe('computeAxisProperties()', () => {
|
|
|
986
1027
|
positionRight: 2,
|
|
987
1028
|
positionBottom: 3,
|
|
988
1029
|
positionLeft: 4,
|
|
1030
|
+
config,
|
|
989
1031
|
});
|
|
990
1032
|
expect(res).toBeUndefined();
|
|
991
1033
|
});
|
|
992
1034
|
});
|
|
993
1035
|
describe('computeAxisSystemProperties()', () => {
|
|
1036
|
+
const config = {
|
|
1037
|
+
hasReversedIndex: false,
|
|
1038
|
+
hasMirroredDomainsHorizontal: false,
|
|
1039
|
+
hasMirroredDomainsVertical: false,
|
|
1040
|
+
};
|
|
994
1041
|
it('should return', () => {
|
|
995
1042
|
const axis = {
|
|
996
1043
|
top: {
|
|
@@ -1016,7 +1063,7 @@ describe('computeAxisSystemProperties()', () => {
|
|
|
1016
1063
|
};
|
|
1017
1064
|
const res = computeAxisSystemProperties(axis, { maxWidth: 800, maxHeight: 600 }, {
|
|
1018
1065
|
top: 1, right: 2, bottom: 3, left: 4,
|
|
1019
|
-
});
|
|
1066
|
+
}, config);
|
|
1020
1067
|
expect(res.top.scale).toBeDefined();
|
|
1021
1068
|
expect(res.right.scale).toBeDefined();
|
|
1022
1069
|
expect(res.bottom.scale).toBeDefined();
|
|
@@ -1069,3 +1116,20 @@ describe('handleChartAxisLayout()', () => {
|
|
|
1069
1116
|
expect(res).toStrictEqual(exp);
|
|
1070
1117
|
});
|
|
1071
1118
|
});
|
|
1119
|
+
describe('clampLinearDomain()', () => {
|
|
1120
|
+
it('should return [0,max] for positive only values', () => {
|
|
1121
|
+
const res = clampLinearDomain([10, 100]);
|
|
1122
|
+
const exp = [0, 100];
|
|
1123
|
+
expect(res).toStrictEqual(exp);
|
|
1124
|
+
});
|
|
1125
|
+
it('should return [0,max] for negative only values', () => {
|
|
1126
|
+
const res = clampLinearDomain([-10, -100]);
|
|
1127
|
+
const exp = [-100, 0];
|
|
1128
|
+
expect(res).toStrictEqual(exp);
|
|
1129
|
+
});
|
|
1130
|
+
it('should return domain for both positive and negative values', () => {
|
|
1131
|
+
const res = clampLinearDomain([-10, 100]);
|
|
1132
|
+
const exp = [-10, 100];
|
|
1133
|
+
expect(res).toStrictEqual(exp);
|
|
1134
|
+
});
|
|
1135
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CartesianAxis } from '../types/axis';
|
|
2
|
+
import { BarChartMetadata, BarChartSeries } from '../types/bar-chart';
|
|
3
|
+
import { Bar, BarChartLabels, BarsStyleConfig, BarStackContent } from '../types/bars';
|
|
4
|
+
import { Data } from '../types/main';
|
|
5
|
+
export declare const getBarSize: (bar: Bar, axis: CartesianAxis, isHorizontal: boolean) => number;
|
|
6
|
+
export declare const getBarPosition: (bar: Bar, axis: CartesianAxis, isHorizontal: boolean) => number;
|
|
7
|
+
export declare const getBarIndexPositionSeries: (bar: Bar, thickness: number, isHorizontal: boolean) => number;
|
|
8
|
+
export declare const getBarSizeAndPosition: (bar: Bar, axis: CartesianAxis, thickness: number, isHorizontal: boolean) => {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
width: number | undefined;
|
|
12
|
+
height: number | undefined;
|
|
13
|
+
};
|
|
14
|
+
export declare const getBarThickness: (thickness: number, maxSize: number, fixedBarSize: boolean) => number;
|
|
15
|
+
export declare const getStackBarIndexPositionSeries: (bar: Bar, thickness: number, hasOverlay: boolean, isHorizontal: boolean) => number;
|
|
16
|
+
export declare const getStackBarIndexPositionOverlay: (bar: Bar, thickness: number, isHorizontal: boolean) => number;
|
|
17
|
+
export declare const getStackBarThickness: (thickness: number, maxSize: number, fixedBarSize: boolean, hasOverlay: boolean) => number;
|
|
18
|
+
export declare const getHeightForVerticalChartWithFixedBarSize: (config: BarsStyleConfig, data: Data, metadata: BarChartMetadata) => number;
|
|
19
|
+
export declare const getLinearDomainStackSeries: (data: Data, dataKeys: string[], currentDomain?: number[]) => number[] | undefined;
|
|
20
|
+
export declare const getBarChartLabels: (data: Data, series: BarChartSeries, overlay?: BarChartSeries) => BarChartLabels;
|
|
21
|
+
export declare const getBarChartLabelsMaxLength: (labels: BarChartLabels) => number | undefined;
|
|
22
|
+
export declare const getBarChartLabelsMaxSize: (length: number) => number;
|
|
23
|
+
export declare const getBarLabelContent: (datum: Record<string, any>, bar: Record<string, any>, dataKey: string, extraData: ((datum: Record<string, any>) => string) | undefined) => {
|
|
24
|
+
value: any;
|
|
25
|
+
separator: string;
|
|
26
|
+
extra: string;
|
|
27
|
+
};
|
|
28
|
+
export declare const getBarLabelMorphology: (bar: Record<string, any>, extraData: ((datum: Record<string, any>) => string) | undefined, content: BarStackContent, barChartLabelsMaxSize: number, thickness: number, position: {
|
|
29
|
+
x: number | undefined;
|
|
30
|
+
y: number | undefined;
|
|
31
|
+
}, dimension: {
|
|
32
|
+
xMax: number;
|
|
33
|
+
yMax: number;
|
|
34
|
+
}, isHorizontal: boolean) => {
|
|
35
|
+
text: {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
};
|
|
39
|
+
rect: {
|
|
40
|
+
x: number | undefined;
|
|
41
|
+
y: number | undefined;
|
|
42
|
+
width: number;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export declare const getStackBarLabelContent: (datum: Record<string, any>, dataKey: string[], extraData: ((datum: Record<string, any>) => string) | undefined, index: number) => BarStackContent;
|
|
46
|
+
export declare const getStackBarLabelMorphology: (bar: Record<string, any>, extraData: ((datum: Record<string, any>) => string) | undefined, content: BarStackContent, thickness: number, position: {
|
|
47
|
+
x: number | undefined;
|
|
48
|
+
y: number | undefined;
|
|
49
|
+
}, dimension: {
|
|
50
|
+
xMax: number;
|
|
51
|
+
yMax: number;
|
|
52
|
+
}, isHorizontal: boolean) => {
|
|
53
|
+
rect: {
|
|
54
|
+
x: number;
|
|
55
|
+
y: number;
|
|
56
|
+
width: number;
|
|
57
|
+
};
|
|
58
|
+
text: {
|
|
59
|
+
x: number;
|
|
60
|
+
y: number;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=bars.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bars.d.ts","sourceRoot":"","sources":["../../src/utils/bars.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EACL,GAAG,EAAiB,cAAc,EAAE,eAAe,EACnD,eAAe,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAIrC,eAAO,MAAM,UAAU,QAAS,GAAG,QAAQ,aAAa,gBAAgB,OAAO,WAmB9E,CAAC;AAEF,eAAO,MAAM,cAAc,QAAS,GAAG,QAAQ,aAAa,gBAAgB,OAAO,WAYlF,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAC/B,GAAG,aACG,MAAM,gBACH,OAAO,WA2BtB,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAC3B,GAAG,QACF,aAAa,aACR,MAAM,gBACH,OAAO;;;;;CAYtB,CAAC;AAEF,eAAO,MAAM,eAAe,cACf,MAAM,WACR,MAAM,gBACD,OAAO,WAOtB,CAAC;AAEF,eAAO,MAAM,8BAA8B,QACpC,GAAG,aACG,MAAM,cACL,OAAO,gBACL,OAAO,WAmCtB,CAAC;AAEF,eAAO,MAAM,+BAA+B,QACrC,GAAG,aACG,MAAM,gBACH,OAAO,WAiCtB,CAAC;AAEF,eAAO,MAAM,oBAAoB,cACpB,MAAM,WACR,MAAM,gBACD,OAAO,cACT,OAAO,WASpB,CAAC;AAEF,eAAO,MAAM,yCAAyC,WAC5C,eAAe,wBAEb,gBAAgB,WAoB3B,CAAC;AAEF,eAAO,MAAM,0BAA0B,yBAA0B,MAAM,EAAE,kBAAkB,MAAM,EAAE,yBAsBlG,CAAC;AAEF,eAAO,MAAM,iBAAiB,uBAEpB,cAAc,YACZ,cAAc,KACvB,cA4BF,CAAC;AAEF,eAAO,MAAM,0BAA0B,WAAY,cAAc,uBAMhE,CAAC;AAEF,eAAO,MAAM,wBAAwB,WAAY,MAAM,WAItD,CAAC;AAEF,eAAO,MAAM,kBAAkB,UACtB,OAAO,MAAM,EAAE,GAAG,CAAC,OACrB,OAAO,MAAM,EAAE,GAAG,CAAC,WACf,MAAM,sBACK,OAAO,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM;;;;CAcnD,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAC3B,OAAO,MAAM,EAAE,GAAG,CAAC,sBACJ,OAAO,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,wBACzC,eAAe,yBACD,MAAM,aAClB,MAAM,YACP;IAAE,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,aAC/C;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,gBAC3B,OAAO;;;;;;;;;;CA6CtB,CAAC;AAEF,eAAO,MAAM,uBAAuB,UAC3B,OAAO,MAAM,EAAE,GAAG,CAAC,WACjB,MAAM,EAAE,sBACG,OAAO,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,sBAC3C,MAAM,KACZ,eASF,CAAC;AAEF,eAAO,MAAM,0BAA0B,QAChC,OAAO,MAAM,EAAE,GAAG,CAAC,sBACJ,OAAO,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,wBACzC,eAAe,aACb,MAAM,YACP;IAAE,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,aAC/C;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,gBAC3B,OAAO;;;;;;;;;;CA+CtB,CAAC"}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Wonderflow Design Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import _ from 'lodash';
|
|
17
|
+
import { axisStyleConfig } from '../style-config/axis';
|
|
18
|
+
import { barsStyleConfig } from '../style-config/bars';
|
|
19
|
+
import { clampLinearDomain } from './axis';
|
|
20
|
+
import { getDataKeyParentObject, getPrimitiveFromObjectByPath } from './data';
|
|
21
|
+
export const getBarSize = (bar, axis, isHorizontal) => {
|
|
22
|
+
const clampedDomain = clampLinearDomain(axis.domain);
|
|
23
|
+
const min = _.min(clampedDomain);
|
|
24
|
+
const scaleZero = axis.scale(0) ?? 0;
|
|
25
|
+
const scaleMin = axis.scale(min) ?? 0;
|
|
26
|
+
const diffNegative = scaleMin - scaleZero;
|
|
27
|
+
let size;
|
|
28
|
+
if (isHorizontal) {
|
|
29
|
+
size = (bar.value >= 0)
|
|
30
|
+
? (bar.height - diffNegative)
|
|
31
|
+
: (diffNegative - bar.height);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
size = (bar.value >= 0)
|
|
35
|
+
? (bar.width + diffNegative)
|
|
36
|
+
: Math.abs(bar.width + diffNegative);
|
|
37
|
+
}
|
|
38
|
+
return _.clamp(size, 0, size);
|
|
39
|
+
};
|
|
40
|
+
export const getBarPosition = (bar, axis, isHorizontal) => {
|
|
41
|
+
const scaleZero = axis.scale(0) ?? 0;
|
|
42
|
+
if (isHorizontal) {
|
|
43
|
+
return (bar.value >= 0)
|
|
44
|
+
? bar.y
|
|
45
|
+
: scaleZero;
|
|
46
|
+
}
|
|
47
|
+
return (bar.value >= 0)
|
|
48
|
+
? scaleZero
|
|
49
|
+
: bar.width;
|
|
50
|
+
};
|
|
51
|
+
export const getBarIndexPositionSeries = (bar, thickness, isHorizontal) => {
|
|
52
|
+
const { width, height, x, y, } = bar;
|
|
53
|
+
if (isHorizontal) {
|
|
54
|
+
const hasCustomWidth = width !== thickness;
|
|
55
|
+
let xPos = x;
|
|
56
|
+
if (hasCustomWidth) {
|
|
57
|
+
const diff = (width - thickness) / 2;
|
|
58
|
+
xPos += diff;
|
|
59
|
+
}
|
|
60
|
+
return xPos;
|
|
61
|
+
}
|
|
62
|
+
const hasCustomHeight = height !== thickness;
|
|
63
|
+
let yPos = y;
|
|
64
|
+
if (hasCustomHeight) {
|
|
65
|
+
const diff = (height - thickness) / 2;
|
|
66
|
+
yPos += diff;
|
|
67
|
+
}
|
|
68
|
+
return yPos;
|
|
69
|
+
};
|
|
70
|
+
export const getBarSizeAndPosition = (bar, axis, thickness, isHorizontal) => {
|
|
71
|
+
const size = getBarSize(bar, axis, isHorizontal);
|
|
72
|
+
const position = getBarPosition(bar, axis, isHorizontal);
|
|
73
|
+
const indexPosition = getBarIndexPositionSeries(bar, thickness, isHorizontal);
|
|
74
|
+
return {
|
|
75
|
+
x: isHorizontal ? indexPosition : position,
|
|
76
|
+
y: isHorizontal ? position : indexPosition,
|
|
77
|
+
width: isHorizontal ? undefined : size,
|
|
78
|
+
height: isHorizontal ? size : undefined,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
export const getBarThickness = (thickness, maxSize, fixedBarSize) => {
|
|
82
|
+
if (fixedBarSize) {
|
|
83
|
+
return _.clamp(thickness, 2, maxSize);
|
|
84
|
+
}
|
|
85
|
+
return thickness;
|
|
86
|
+
};
|
|
87
|
+
export const getStackBarIndexPositionSeries = (bar, thickness, hasOverlay, isHorizontal) => {
|
|
88
|
+
const { width, height, x, y, } = bar;
|
|
89
|
+
if (isHorizontal) {
|
|
90
|
+
const hasCustomWidth = width !== thickness;
|
|
91
|
+
let xPos = x;
|
|
92
|
+
if (hasCustomWidth) {
|
|
93
|
+
const diff = (width - thickness) / 2;
|
|
94
|
+
xPos += diff;
|
|
95
|
+
if (hasOverlay)
|
|
96
|
+
xPos -= (thickness / 2 + 1);
|
|
97
|
+
}
|
|
98
|
+
else if (hasOverlay) {
|
|
99
|
+
xPos -= (width / 2 + 1);
|
|
100
|
+
}
|
|
101
|
+
return xPos;
|
|
102
|
+
}
|
|
103
|
+
const hasCustomHeight = height !== thickness;
|
|
104
|
+
let yPos = y;
|
|
105
|
+
if (hasCustomHeight) {
|
|
106
|
+
const diff = (height - thickness) / 2;
|
|
107
|
+
yPos += diff;
|
|
108
|
+
if (hasOverlay)
|
|
109
|
+
yPos -= (thickness / 2 + 1);
|
|
110
|
+
}
|
|
111
|
+
else if (hasOverlay) {
|
|
112
|
+
yPos -= (height / 2 + 1);
|
|
113
|
+
}
|
|
114
|
+
return yPos;
|
|
115
|
+
};
|
|
116
|
+
export const getStackBarIndexPositionOverlay = (bar, thickness, isHorizontal) => {
|
|
117
|
+
const { width, height, x, y, } = bar;
|
|
118
|
+
if (isHorizontal) {
|
|
119
|
+
const hasCustomWidth = width !== thickness;
|
|
120
|
+
let xPos = x;
|
|
121
|
+
if (hasCustomWidth) {
|
|
122
|
+
const diff = (width - thickness) / 2;
|
|
123
|
+
xPos += diff;
|
|
124
|
+
xPos += thickness / 2 + 1;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
xPos += (width / 2) + 1;
|
|
128
|
+
}
|
|
129
|
+
return xPos;
|
|
130
|
+
}
|
|
131
|
+
const hasCustomHeight = height !== thickness;
|
|
132
|
+
let yPos = y;
|
|
133
|
+
if (hasCustomHeight) {
|
|
134
|
+
const diff = (height - thickness) / 2;
|
|
135
|
+
yPos += diff;
|
|
136
|
+
yPos += (thickness / 2 + 1);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
yPos += (height / 2 + 1);
|
|
140
|
+
}
|
|
141
|
+
return yPos;
|
|
142
|
+
};
|
|
143
|
+
export const getStackBarThickness = (thickness, maxSize, fixedBarSize, hasOverlay) => {
|
|
144
|
+
const t = hasOverlay ? (thickness - 1) / 2 : thickness;
|
|
145
|
+
if (fixedBarSize) {
|
|
146
|
+
return _.clamp(t, 2, maxSize);
|
|
147
|
+
}
|
|
148
|
+
return t;
|
|
149
|
+
};
|
|
150
|
+
export const getHeightForVerticalChartWithFixedBarSize = (config, data, metadata) => {
|
|
151
|
+
const { series, overlay } = metadata;
|
|
152
|
+
const indexLen = data.length;
|
|
153
|
+
const seriesBarsNum = series.dataKey.length;
|
|
154
|
+
const overlayBarsNum = overlay.dataKey?.length ?? 0;
|
|
155
|
+
const totalBarsNum = seriesBarsNum + overlayBarsNum;
|
|
156
|
+
const { maxSize, paddingInnerGroup, paddingOuterGroup, paddingInner, paddingOuter, } = config;
|
|
157
|
+
const barGroup = totalBarsNum * maxSize * (1 + paddingInnerGroup) * (1 + paddingOuterGroup);
|
|
158
|
+
const allGroups = (indexLen + 2) * barGroup * (1 + paddingInner) + barGroup * (2 + paddingOuter);
|
|
159
|
+
const h = _.round(allGroups);
|
|
160
|
+
return h;
|
|
161
|
+
};
|
|
162
|
+
export const getLinearDomainStackSeries = (data, dataKeys, currentDomain) => {
|
|
163
|
+
if (dataKeys.length === 1 && currentDomain)
|
|
164
|
+
return currentDomain;
|
|
165
|
+
const domainStackSum = data.map((datum) => {
|
|
166
|
+
const values = [];
|
|
167
|
+
dataKeys.forEach(k => values.push(_.at(datum, k)[0]));
|
|
168
|
+
return _.sum(values);
|
|
169
|
+
});
|
|
170
|
+
const domainStackSeries = [_.min(domainStackSum), _.max(domainStackSum)];
|
|
171
|
+
const clampedDomain = clampLinearDomain(domainStackSeries);
|
|
172
|
+
const minClamped = _.min(clampedDomain) ?? 0;
|
|
173
|
+
const maxClamped = _.max(clampedDomain) ?? 0;
|
|
174
|
+
const minCurrent = _.min(currentDomain) ?? 0;
|
|
175
|
+
const maxCurrent = _.max(currentDomain) ?? 0;
|
|
176
|
+
const stackDomain = [_.min([minCurrent, minClamped]) ?? 0, _.max([maxCurrent, maxClamped]) ?? 0];
|
|
177
|
+
return clampLinearDomain(stackDomain);
|
|
178
|
+
};
|
|
179
|
+
export const getBarChartLabels = (data, series, overlay) => {
|
|
180
|
+
const seriesLabels = data.map(datum => series.dataKey.map((k) => {
|
|
181
|
+
const value = getPrimitiveFromObjectByPath(datum, k) ?? '';
|
|
182
|
+
const extraData = series.extraData?.(getDataKeyParentObject(datum, k)) ?? '';
|
|
183
|
+
const { length } = (`${value} ${extraData}`);
|
|
184
|
+
return ({
|
|
185
|
+
value,
|
|
186
|
+
extraData,
|
|
187
|
+
length,
|
|
188
|
+
});
|
|
189
|
+
}));
|
|
190
|
+
const overlayLabels = overlay
|
|
191
|
+
? data.map(datum => overlay.dataKey.map((k) => {
|
|
192
|
+
const value = getPrimitiveFromObjectByPath(datum, k) ?? '';
|
|
193
|
+
const extraData = overlay.extraData?.(getDataKeyParentObject(datum, k)) ?? '';
|
|
194
|
+
const { length } = (`${value} ${extraData}`);
|
|
195
|
+
return ({
|
|
196
|
+
value,
|
|
197
|
+
extraData,
|
|
198
|
+
length,
|
|
199
|
+
});
|
|
200
|
+
}))
|
|
201
|
+
: undefined;
|
|
202
|
+
return { series: seriesLabels, overlay: overlayLabels };
|
|
203
|
+
};
|
|
204
|
+
export const getBarChartLabelsMaxLength = (labels) => {
|
|
205
|
+
const { series, overlay } = labels;
|
|
206
|
+
const flatSeries = _.flattenDeep(series);
|
|
207
|
+
const flatOverlay = overlay ? _.flattenDeep(overlay) : [];
|
|
208
|
+
const lengths = flatSeries.concat(flatOverlay).map(el => el.length);
|
|
209
|
+
return _.max(lengths);
|
|
210
|
+
};
|
|
211
|
+
export const getBarChartLabelsMaxSize = (length) => {
|
|
212
|
+
const charSize = axisStyleConfig.spacing.labelCharExtimatedWidth;
|
|
213
|
+
const extraSpace = 1.20;
|
|
214
|
+
return Math.round(length * charSize * extraSpace);
|
|
215
|
+
};
|
|
216
|
+
export const getBarLabelContent = (datum, bar, dataKey, extraData) => {
|
|
217
|
+
const { value } = bar;
|
|
218
|
+
const separator = ' - ';
|
|
219
|
+
const parentObj = getDataKeyParentObject(datum, dataKey);
|
|
220
|
+
const extra = extraData
|
|
221
|
+
? extraData(parentObj)
|
|
222
|
+
: '';
|
|
223
|
+
return {
|
|
224
|
+
value,
|
|
225
|
+
separator,
|
|
226
|
+
extra,
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
export const getBarLabelMorphology = (bar, extraData, content, barChartLabelsMaxSize, thickness, position, dimension, isHorizontal) => {
|
|
230
|
+
const { xMax, yMax } = dimension;
|
|
231
|
+
const { x, y } = position;
|
|
232
|
+
const { value, separator, extra } = content;
|
|
233
|
+
const len = extraData
|
|
234
|
+
? (`${value}${separator}${extra}`).length
|
|
235
|
+
: String(`${value}`).length;
|
|
236
|
+
const labelHeight = barsStyleConfig.label.height;
|
|
237
|
+
const labelWidth = Math.round(len * 1.2 * 8);
|
|
238
|
+
const width = _.clamp(labelWidth, labelHeight, labelWidth);
|
|
239
|
+
let xPosRect;
|
|
240
|
+
let yPosRect;
|
|
241
|
+
let xPosText;
|
|
242
|
+
let yPosText;
|
|
243
|
+
if (isHorizontal) {
|
|
244
|
+
xPosText = Number(x) + Number(thickness) / 2;
|
|
245
|
+
const extraY = Number(value) >= 0 ? -8 : 16;
|
|
246
|
+
const yText = yMax - bar.height + extraY;
|
|
247
|
+
yPosText = _.clamp(yText, labelHeight, yMax);
|
|
248
|
+
xPosRect = xPosText - (width / 2);
|
|
249
|
+
yPosRect = yPosText - 13;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
const padding = 16;
|
|
253
|
+
xPosText = Number(xMax) + padding;
|
|
254
|
+
yPosText = Number(y) + Number(thickness / 2) + 4;
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
text: {
|
|
258
|
+
x: xPosText,
|
|
259
|
+
y: yPosText,
|
|
260
|
+
},
|
|
261
|
+
rect: {
|
|
262
|
+
x: xPosRect,
|
|
263
|
+
y: yPosRect,
|
|
264
|
+
width: isHorizontal ? width : barChartLabelsMaxSize,
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
export const getStackBarLabelContent = (datum, dataKey, extraData, index) => {
|
|
269
|
+
const value = getPrimitiveFromObjectByPath(datum, dataKey[index]) ?? '';
|
|
270
|
+
const separator = ' - ';
|
|
271
|
+
const parentObj = getDataKeyParentObject(datum, dataKey[index]);
|
|
272
|
+
const extra = extraData
|
|
273
|
+
? extraData(parentObj)
|
|
274
|
+
: '';
|
|
275
|
+
return { value, separator, extra };
|
|
276
|
+
};
|
|
277
|
+
export const getStackBarLabelMorphology = (bar, extraData, content, thickness, position, dimension, isHorizontal) => {
|
|
278
|
+
let xPosRect;
|
|
279
|
+
let yPosRect;
|
|
280
|
+
let xPosText;
|
|
281
|
+
let yPosText;
|
|
282
|
+
const { value, separator, extra } = content;
|
|
283
|
+
const { x, y } = position;
|
|
284
|
+
const { xMax, yMax } = dimension;
|
|
285
|
+
const len = extraData
|
|
286
|
+
? (`${value}${separator}${extra}`).length
|
|
287
|
+
: String(`${value}`).length;
|
|
288
|
+
const labelHeight = barsStyleConfig.label.height;
|
|
289
|
+
const labelWidth = Math.round(len * 1.2 * 8);
|
|
290
|
+
const width = _.clamp(labelWidth, labelHeight, labelWidth);
|
|
291
|
+
if (isHorizontal) {
|
|
292
|
+
xPosRect = (Number(x) + (Number(thickness) - width) / 2);
|
|
293
|
+
const yRect = Number(bar.y) + (Number(bar.height) - labelHeight) / 2;
|
|
294
|
+
yPosRect = _.clamp(yRect, labelHeight, yMax - labelHeight);
|
|
295
|
+
xPosText = Number(x) + Number(thickness) / 2;
|
|
296
|
+
yPosText = yPosRect + 13;
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
const xRect = Number(bar.x) + (Number(bar.width) - width) / 2;
|
|
300
|
+
xPosRect = _.clamp(xRect, 0, xMax - labelWidth);
|
|
301
|
+
yPosRect = Number(y) + (thickness - labelHeight) / 2;
|
|
302
|
+
xPosText = xPosRect + width / 2;
|
|
303
|
+
yPosText = yPosRect + 13;
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
rect: {
|
|
307
|
+
x: xPosRect,
|
|
308
|
+
y: yPosRect,
|
|
309
|
+
width,
|
|
310
|
+
},
|
|
311
|
+
text: {
|
|
312
|
+
x: xPosText,
|
|
313
|
+
y: yPosText,
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bars.test.d.ts","sourceRoot":"","sources":["../../src/utils/bars.test.ts"],"names":[],"mappings":""}
|