@xq-labs/data-ui-v2 0.3.0 → 0.5.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/docs/api/overview.md +60 -5
- package/docs/examples/bar-line-chart.md +47 -4
- package/docs/examples/pie-chart.md +9 -3
- package/es/bar-line-chart/index.js +1 -1
- package/es/{index-d01ce220.js → index-1e113c13.js} +374 -41
- package/es/{index-78b6b881.js → index-bf133030.js} +21 -3
- package/es/index.js +2 -2
- package/es/pie-chart/index.js +1 -1
- package/lib/bar-line-chart/index.js +1 -1
- package/lib/{index-cc49894a.js → index-3dcce54f.js} +374 -41
- package/lib/{index-a0ecafa1.js → index-812cae02.js} +21 -3
- package/lib/index.js +2 -2
- package/lib/pie-chart/index.js +1 -1
- package/package.json +1 -1
|
@@ -32,7 +32,8 @@ var DEFAULT_SERIES = {
|
|
|
32
32
|
kind: 'bar',
|
|
33
33
|
stack: '',
|
|
34
34
|
yAxisIndex: 0,
|
|
35
|
-
colors: []
|
|
35
|
+
colors: [],
|
|
36
|
+
cubeGradientColors: []
|
|
36
37
|
};
|
|
37
38
|
|
|
38
39
|
/**
|
|
@@ -83,7 +84,8 @@ function normalizeBarLineInput(_ref) {
|
|
|
83
84
|
kind: normalizeKind(item.kind),
|
|
84
85
|
stack: typeof item.stack === 'string' ? item.stack : '',
|
|
85
86
|
yAxisIndex: normalizeYAxisIndex(item.yAxisIndex),
|
|
86
|
-
colors: normalizeColors(item.colors)
|
|
87
|
+
colors: normalizeColors(item.colors),
|
|
88
|
+
cubeGradientColors: normalizeColors(item.cubeGradientColors)
|
|
87
89
|
});
|
|
88
90
|
}),
|
|
89
91
|
rawData: rawData
|
|
@@ -149,6 +151,19 @@ function resolveSeriesColor$1(item, index) {
|
|
|
149
151
|
}
|
|
150
152
|
return colors.DEFAULT_COLORS[index % colors.DEFAULT_COLORS.length];
|
|
151
153
|
}
|
|
154
|
+
function collectBarSeries(normalizedSeries) {
|
|
155
|
+
return normalizedSeries.map(function (item, originalIndex) {
|
|
156
|
+
return colors._objectSpread2(colors._objectSpread2({}, item), {}, {
|
|
157
|
+
originalIndex: originalIndex
|
|
158
|
+
});
|
|
159
|
+
}).filter(function (item) {
|
|
160
|
+
return item.kind === 'bar';
|
|
161
|
+
}).map(function (item, barSeriesIndex) {
|
|
162
|
+
return colors._objectSpread2(colors._objectSpread2({}, item), {}, {
|
|
163
|
+
barSeriesIndex: barSeriesIndex
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
152
167
|
|
|
153
168
|
/**
|
|
154
169
|
* 归一化颜色入参。
|
|
@@ -499,6 +514,53 @@ function createBarLayout(barSeries, barWidth, barGap) {
|
|
|
499
514
|
barGap: resolvedBarGap
|
|
500
515
|
};
|
|
501
516
|
}
|
|
517
|
+
function pickBackgroundSlotSeries(barSeries) {
|
|
518
|
+
var renderedStacks = new Set();
|
|
519
|
+
return barSeries.filter(function (item) {
|
|
520
|
+
if (!item.stack) {
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
if (renderedStacks.has(item.stack)) {
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
renderedStacks.add(item.stack);
|
|
527
|
+
return true;
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
function createBackgroundSeriesData(rawData) {
|
|
531
|
+
return rawData.map(function (row, rowIndex) {
|
|
532
|
+
return {
|
|
533
|
+
value: [rowIndex]
|
|
534
|
+
};
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
function resolveBackgroundFaceAlpha(key, opacity) {
|
|
538
|
+
var alphaMap = {
|
|
539
|
+
left: 0.82,
|
|
540
|
+
right: 1,
|
|
541
|
+
top: 1.8,
|
|
542
|
+
middle: 0.82,
|
|
543
|
+
bottom: 1.28,
|
|
544
|
+
legend: 1
|
|
545
|
+
};
|
|
546
|
+
var ratio = alphaMap[key] || 1;
|
|
547
|
+
return Math.max(0, Math.min(1, opacity * ratio));
|
|
548
|
+
}
|
|
549
|
+
function applyBackgroundFaceAlphaToColorMap(colorMap, opacity) {
|
|
550
|
+
return Object.keys(colorMap || {}).reduce(function (result, key) {
|
|
551
|
+
result[key] = applyAlphaToColor(colorMap[key], resolveBackgroundFaceAlpha(key, opacity));
|
|
552
|
+
return result;
|
|
553
|
+
}, {});
|
|
554
|
+
}
|
|
555
|
+
function normalizeBackgroundColors(barBackground, item) {
|
|
556
|
+
if (Array.isArray(barBackground && barBackground.colors) && barBackground.colors.length > 0) {
|
|
557
|
+
return barBackground.colors;
|
|
558
|
+
}
|
|
559
|
+
if (Array.isArray(item && item.colors) && item.colors.length > 0) {
|
|
560
|
+
return item.colors;
|
|
561
|
+
}
|
|
562
|
+
return undefined;
|
|
563
|
+
}
|
|
502
564
|
|
|
503
565
|
/**
|
|
504
566
|
* 创建堆叠累加器。
|
|
@@ -627,13 +689,7 @@ function buildCustomBarSeries(_ref) {
|
|
|
627
689
|
barGap = _ref.barGap,
|
|
628
690
|
createRenderItem = _ref.createRenderItem,
|
|
629
691
|
resolveColorMap = _ref.resolveColorMap;
|
|
630
|
-
var barSeries = normalizedSeries
|
|
631
|
-
return colors._objectSpread2(colors._objectSpread2({}, item), {}, {
|
|
632
|
-
originalIndex: originalIndex
|
|
633
|
-
});
|
|
634
|
-
}).filter(function (item) {
|
|
635
|
-
return item.kind === 'bar';
|
|
636
|
-
});
|
|
692
|
+
var barSeries = collectBarSeries(normalizedSeries);
|
|
637
693
|
var layout = createBarLayout(barSeries, barWidth, barGap);
|
|
638
694
|
var barSeriesWithData = buildBarSeriesData(rawData, barSeries);
|
|
639
695
|
return barSeriesWithData.map(function (item, index) {
|
|
@@ -662,6 +718,57 @@ function buildCustomBarSeries(_ref) {
|
|
|
662
718
|
};
|
|
663
719
|
});
|
|
664
720
|
}
|
|
721
|
+
function buildBackgroundCustomBarSeries(_ref2) {
|
|
722
|
+
var rawData = _ref2.rawData,
|
|
723
|
+
normalizedSeries = _ref2.normalizedSeries,
|
|
724
|
+
barWidth = _ref2.barWidth,
|
|
725
|
+
barGap = _ref2.barGap,
|
|
726
|
+
_ref2$barBackground = _ref2.barBackground,
|
|
727
|
+
barBackground = _ref2$barBackground === void 0 ? {} : _ref2$barBackground,
|
|
728
|
+
createRenderItem = _ref2.createRenderItem,
|
|
729
|
+
resolveColorMap = _ref2.resolveColorMap;
|
|
730
|
+
if (!barBackground.show) {
|
|
731
|
+
return [];
|
|
732
|
+
}
|
|
733
|
+
var barSeries = collectBarSeries(normalizedSeries);
|
|
734
|
+
if (!barSeries.length) {
|
|
735
|
+
return [];
|
|
736
|
+
}
|
|
737
|
+
var layout = createBarLayout(barSeries, barWidth, barGap);
|
|
738
|
+
var backgroundSeriesData = createBackgroundSeriesData(rawData);
|
|
739
|
+
return pickBackgroundSlotSeries(barSeries).map(function (item) {
|
|
740
|
+
var slotKey = item.stack || "__slot_".concat(item.barSeriesIndex);
|
|
741
|
+
var slotIndex = layout.slotMap[slotKey];
|
|
742
|
+
var fallbackColor = resolveSeriesColor$1(item, item.originalIndex);
|
|
743
|
+
var palette = normalizeBackgroundColors(barBackground, item);
|
|
744
|
+
var baseColorMap = resolveColorMap ? resolveColorMap(palette, fallbackColor) : {
|
|
745
|
+
legend: fallbackColor
|
|
746
|
+
};
|
|
747
|
+
var backgroundColorMap = applyBackgroundFaceAlphaToColorMap(baseColorMap, barBackground.opacity);
|
|
748
|
+
return {
|
|
749
|
+
name: item.name,
|
|
750
|
+
type: 'custom',
|
|
751
|
+
stack: item.stack,
|
|
752
|
+
yAxisIndex: item.yAxisIndex || 0,
|
|
753
|
+
isBackground: true,
|
|
754
|
+
silent: true,
|
|
755
|
+
tooltip: {
|
|
756
|
+
show: false
|
|
757
|
+
},
|
|
758
|
+
renderItem: createRenderItem(layout, slotIndex, backgroundColorMap, colors._objectSpread2(colors._objectSpread2({}, item), {}, {
|
|
759
|
+
isBackground: true
|
|
760
|
+
})),
|
|
761
|
+
encode: {
|
|
762
|
+
x: 0
|
|
763
|
+
},
|
|
764
|
+
itemStyle: {
|
|
765
|
+
color: backgroundColorMap.legend || applyAlphaToColor(fallbackColor, barBackground.opacity)
|
|
766
|
+
},
|
|
767
|
+
data: backgroundSeriesData,
|
|
768
|
+
z: 0
|
|
769
|
+
};
|
|
770
|
+
});
|
|
771
|
+
}
|
|
665
772
|
|
|
666
773
|
/**
|
|
667
774
|
* 归一化 flat 模式下的 `barGap`。
|
|
@@ -725,6 +832,27 @@ function resolveFlatBarColors(item, index) {
|
|
|
725
832
|
end: darkenColor(fallbackColor, 0.12)
|
|
726
833
|
};
|
|
727
834
|
}
|
|
835
|
+
function resolveFlatBackgroundColors(item, index, barBackground) {
|
|
836
|
+
var paletteSource = Array.isArray(barBackground.colors) && barBackground.colors.length > 0 ? {
|
|
837
|
+
colors: barBackground.colors
|
|
838
|
+
} : item;
|
|
839
|
+
var colorMap = resolveFlatBarColors(paletteSource, index);
|
|
840
|
+
return {
|
|
841
|
+
start: applyAlphaToColor(colorMap.start, barBackground.opacity),
|
|
842
|
+
middle: applyAlphaToColor(colorMap.middle, barBackground.opacity),
|
|
843
|
+
end: applyAlphaToColor(colorMap.end, barBackground.opacity)
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
function shouldEnableBackground(item, renderedStacks) {
|
|
847
|
+
if (!item.stack) {
|
|
848
|
+
return true;
|
|
849
|
+
}
|
|
850
|
+
if (renderedStacks.has(item.stack)) {
|
|
851
|
+
return false;
|
|
852
|
+
}
|
|
853
|
+
renderedStacks.add(item.stack);
|
|
854
|
+
return true;
|
|
855
|
+
}
|
|
728
856
|
|
|
729
857
|
/**
|
|
730
858
|
* 创建柱体纵向渐变。
|
|
@@ -756,9 +884,12 @@ function createFlatBarLineSeries(_ref) {
|
|
|
756
884
|
var normalizedSeries = _ref.normalizedSeries,
|
|
757
885
|
rawData = _ref.rawData,
|
|
758
886
|
barWidth = _ref.barWidth,
|
|
759
|
-
barGap = _ref.barGap
|
|
887
|
+
barGap = _ref.barGap,
|
|
888
|
+
_ref$barBackground = _ref.barBackground,
|
|
889
|
+
barBackground = _ref$barBackground === void 0 ? {} : _ref$barBackground;
|
|
760
890
|
var resolvedBarWidth = Number.isFinite(Number(barWidth)) ? Number(barWidth) : 18;
|
|
761
891
|
var resolvedBarGap = toBarGapValue(barGap);
|
|
892
|
+
var renderedStacks = new Set();
|
|
762
893
|
return normalizedSeries.map(function (item, index) {
|
|
763
894
|
var isLine = item.kind === 'line';
|
|
764
895
|
var color = resolveSeriesColor(item, index);
|
|
@@ -779,11 +910,18 @@ function createFlatBarLineSeries(_ref) {
|
|
|
779
910
|
yAxisIndex: item.yAxisIndex
|
|
780
911
|
});
|
|
781
912
|
}
|
|
913
|
+
var showBackground = barBackground.show && shouldEnableBackground(item, renderedStacks);
|
|
914
|
+
var backgroundColors = resolveFlatBackgroundColors(item, index, barBackground);
|
|
782
915
|
return colors._objectSpread2(colors._objectSpread2({}, baseSeries), {}, {
|
|
783
916
|
stack: item.stack,
|
|
784
917
|
barWidth: resolvedBarWidth,
|
|
785
|
-
barGap: resolvedBarGap
|
|
786
|
-
|
|
918
|
+
barGap: resolvedBarGap,
|
|
919
|
+
showBackground: showBackground
|
|
920
|
+
}, showBackground ? {
|
|
921
|
+
backgroundStyle: {
|
|
922
|
+
color: createBarGradient(backgroundColors)
|
|
923
|
+
}
|
|
924
|
+
} : {});
|
|
787
925
|
});
|
|
788
926
|
}
|
|
789
927
|
|
|
@@ -842,14 +980,80 @@ function createFaceGradient(x0, y0, x1, y1, startColor, endColor) {
|
|
|
842
980
|
color: endColor
|
|
843
981
|
}]);
|
|
844
982
|
}
|
|
983
|
+
function resolveCubeGradientFaceColors(seriesItem, colorMap) {
|
|
984
|
+
var gradientColors = seriesItem && Array.isArray(seriesItem.cubeGradientColors) ? seriesItem.cubeGradientColors : [];
|
|
985
|
+
return {
|
|
986
|
+
left: gradientColors[0] || colorMap.left,
|
|
987
|
+
right: gradientColors[1] || colorMap.right,
|
|
988
|
+
top: gradientColors[2] || colorMap.top
|
|
989
|
+
};
|
|
990
|
+
}
|
|
845
991
|
|
|
846
992
|
/**
|
|
847
993
|
* 创建方柱渲染器。
|
|
848
994
|
* 参考案例使用三块 polygon 拼接成立方体,而不是“正面 rect + 顶面/侧面”。
|
|
849
995
|
*/
|
|
850
|
-
function createCubeRenderItem(layout, slotIndex, colorMap) {
|
|
996
|
+
function createCubeRenderItem(layout, slotIndex, colorMap, seriesItem) {
|
|
851
997
|
return function renderItem(params, api) {
|
|
852
998
|
var rowIndex = api.value(0);
|
|
999
|
+
var offsetX = getBarOffset(layout, slotIndex);
|
|
1000
|
+
var centerPoint = api.coord([rowIndex, 0]);
|
|
1001
|
+
var centerX = centerPoint[0] + offsetX;
|
|
1002
|
+
var halfWidth = layout.barWidth / 2;
|
|
1003
|
+
var offsetY = Math.tan(Math.PI / 9) * halfWidth;
|
|
1004
|
+
if (seriesItem && seriesItem.isBackground === true) {
|
|
1005
|
+
var _leftFaceGradient = createFaceGradient(0, 0, 0, 1, colorMap.left, colorMap.left);
|
|
1006
|
+
var _rightFaceGradient = createFaceGradient(0, 0, 0, 1, colorMap.right, colorMap.right);
|
|
1007
|
+
var _topFaceGradient = createFaceGradient(0, 0, 1, 0, colorMap.top, colorMap.top);
|
|
1008
|
+
var coordSys = params.coordSys || {};
|
|
1009
|
+
var clipX = coordSys.x || 0;
|
|
1010
|
+
var _topY = coordSys.y || 0;
|
|
1011
|
+
var width = coordSys.width || 0;
|
|
1012
|
+
var _baseY = _topY + (coordSys.height || 0);
|
|
1013
|
+
var _topSurfaceY = _topY + Math.abs(offsetY - 1);
|
|
1014
|
+
return {
|
|
1015
|
+
type: 'group',
|
|
1016
|
+
clipPath: {
|
|
1017
|
+
type: 'rect',
|
|
1018
|
+
shape: {
|
|
1019
|
+
x: clipX,
|
|
1020
|
+
y: _topY,
|
|
1021
|
+
width: width,
|
|
1022
|
+
height: coordSys.height || 0
|
|
1023
|
+
}
|
|
1024
|
+
},
|
|
1025
|
+
children: [{
|
|
1026
|
+
type: 'polygon',
|
|
1027
|
+
shape: {
|
|
1028
|
+
points: [[centerX, _topSurfaceY + offsetY - 1], [centerX - halfWidth, _topSurfaceY], [centerX - halfWidth, _baseY - offsetY], [centerX, _baseY - 1]]
|
|
1029
|
+
},
|
|
1030
|
+
style: {
|
|
1031
|
+
fill: _leftFaceGradient
|
|
1032
|
+
}
|
|
1033
|
+
}, {
|
|
1034
|
+
type: 'polygon',
|
|
1035
|
+
shape: {
|
|
1036
|
+
points: [[centerX, _topSurfaceY + offsetY - 1], [centerX + halfWidth, _topSurfaceY], [centerX + halfWidth, _baseY - offsetY], [centerX, _baseY - 1]]
|
|
1037
|
+
},
|
|
1038
|
+
style: {
|
|
1039
|
+
fill: _rightFaceGradient
|
|
1040
|
+
}
|
|
1041
|
+
}, {
|
|
1042
|
+
type: 'polygon',
|
|
1043
|
+
shape: {
|
|
1044
|
+
points: [[centerX, _topSurfaceY + offsetY - 1], [centerX + halfWidth, _topSurfaceY], [centerX, _topSurfaceY - offsetY + 1], [centerX - halfWidth, _topSurfaceY]]
|
|
1045
|
+
},
|
|
1046
|
+
style: {
|
|
1047
|
+
fill: _topFaceGradient
|
|
1048
|
+
},
|
|
1049
|
+
z2: 2
|
|
1050
|
+
}]
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
var gradientFaceColors = resolveCubeGradientFaceColors(seriesItem, colorMap);
|
|
1054
|
+
var leftFaceGradient = createFaceGradient(0, 0, 0, 1, colorMap.left, gradientFaceColors.left);
|
|
1055
|
+
var rightFaceGradient = createFaceGradient(0, 0, 0, 1, colorMap.right, gradientFaceColors.right);
|
|
1056
|
+
var topFaceGradient = createFaceGradient(0, 0, 1, 0, colorMap.top, gradientFaceColors.top);
|
|
853
1057
|
var endValue = api.value(1);
|
|
854
1058
|
var baseValue = api.value(2);
|
|
855
1059
|
var rawValue = api.value(3);
|
|
@@ -860,20 +1064,13 @@ function createCubeRenderItem(layout, slotIndex, colorMap) {
|
|
|
860
1064
|
}
|
|
861
1065
|
var endPoint = api.coord([rowIndex, endValue]);
|
|
862
1066
|
var basePoint = api.coord([rowIndex, baseValue]);
|
|
863
|
-
var offsetX = getBarOffset(layout, slotIndex);
|
|
864
|
-
var centerX = endPoint[0] + offsetX;
|
|
865
1067
|
var topY = endPoint[1];
|
|
866
1068
|
var baseY = basePoint[1];
|
|
867
|
-
var halfWidth = layout.barWidth / 2;
|
|
868
|
-
var offsetY = Math.tan(Math.PI / 9) * halfWidth;
|
|
869
1069
|
var isPositive = rawValue >= 0;
|
|
870
1070
|
var connectorOverlap = stackStart ? 0 : Math.max(2, Math.round(offsetY));
|
|
871
1071
|
var connectorCapOffset = stackEnd ? 0 : Math.min(2, offsetY * 0.45);
|
|
872
1072
|
var connectBaseY = isPositive ? baseY + connectorOverlap : baseY - connectorOverlap;
|
|
873
1073
|
var topSurfaceY = topY + connectorCapOffset;
|
|
874
|
-
var leftFaceGradient = createFaceGradient(0, 0, 0, 1, colorMap.left, colorMap.left);
|
|
875
|
-
var rightFaceGradient = createFaceGradient(0, 0, 0, 1, colorMap.right, colorMap.right);
|
|
876
|
-
var topFaceGradient = createFaceGradient(0, 0, 1, 0, colorMap.top, colorMap.top);
|
|
877
1074
|
return {
|
|
878
1075
|
type: 'group',
|
|
879
1076
|
children: [{
|
|
@@ -919,6 +1116,15 @@ function createCubeRenderItem(layout, slotIndex, colorMap) {
|
|
|
919
1116
|
function createCubeBarLineOption(normalizedInput) {
|
|
920
1117
|
var flatOption = createFlatBarLineOption(normalizedInput);
|
|
921
1118
|
var flatSeries = createFlatBarLineSeries(normalizedInput);
|
|
1119
|
+
var backgroundSeries = buildBackgroundCustomBarSeries({
|
|
1120
|
+
rawData: normalizedInput.rawData,
|
|
1121
|
+
normalizedSeries: normalizedInput.normalizedSeries,
|
|
1122
|
+
barWidth: normalizedInput.barWidth,
|
|
1123
|
+
barGap: normalizedInput.barGap,
|
|
1124
|
+
barBackground: normalizedInput.barBackground,
|
|
1125
|
+
createRenderItem: createCubeRenderItem,
|
|
1126
|
+
resolveColorMap: resolveCubeColors
|
|
1127
|
+
});
|
|
922
1128
|
var customBarSeries = buildCustomBarSeries({
|
|
923
1129
|
rawData: normalizedInput.rawData,
|
|
924
1130
|
normalizedSeries: normalizedInput.normalizedSeries,
|
|
@@ -937,7 +1143,7 @@ function createCubeBarLineOption(normalizedInput) {
|
|
|
937
1143
|
return flatSeries[index];
|
|
938
1144
|
});
|
|
939
1145
|
return colors._objectSpread2(colors._objectSpread2({}, flatOption), {}, {
|
|
940
|
-
series: series
|
|
1146
|
+
series: [].concat(colors._toConsumableArray(series), colors._toConsumableArray(backgroundSeries))
|
|
941
1147
|
});
|
|
942
1148
|
}
|
|
943
1149
|
|
|
@@ -961,6 +1167,20 @@ function createEllipsePolygon(cx, cy, rx, ry) {
|
|
|
961
1167
|
}
|
|
962
1168
|
return polygonPoints;
|
|
963
1169
|
}
|
|
1170
|
+
function createEllipseArcPoints(cx, cy, rx, ry, startAngle, endAngle) {
|
|
1171
|
+
var points = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 12;
|
|
1172
|
+
var arcPoints = [];
|
|
1173
|
+
for (var index = 0; index <= points; index += 1) {
|
|
1174
|
+
var angle = startAngle + (endAngle - startAngle) * index / points;
|
|
1175
|
+
arcPoints.push([cx + Math.cos(angle) * rx, cy + Math.sin(angle) * ry]);
|
|
1176
|
+
}
|
|
1177
|
+
return arcPoints;
|
|
1178
|
+
}
|
|
1179
|
+
function createCylinderSidePolygon(cx, topCy, bottomCy, rx, ry) {
|
|
1180
|
+
var topLowerArc = createEllipseArcPoints(cx, topCy, rx, ry, Math.PI, 0);
|
|
1181
|
+
var bottomUpperArc = createEllipseArcPoints(cx, bottomCy, rx, ry, 0, -Math.PI);
|
|
1182
|
+
return [].concat(colors._toConsumableArray(topLowerArc), colors._toConsumableArray(bottomUpperArc));
|
|
1183
|
+
}
|
|
964
1184
|
|
|
965
1185
|
/**
|
|
966
1186
|
* 创建圆柱渲染器。
|
|
@@ -969,9 +1189,76 @@ function createEllipsePolygon(cx, cy, rx, ry) {
|
|
|
969
1189
|
* 2. 主体用纵向渐变矩形模拟曲面;
|
|
970
1190
|
* 3. 堆叠连接处保留底片,但不绘制深色描边和弧线,避免形成脏色带。
|
|
971
1191
|
*/
|
|
972
|
-
function createCylinderRenderItem(layout, slotIndex, colorMap) {
|
|
1192
|
+
function createCylinderRenderItem(layout, slotIndex, colorMap, seriesItem) {
|
|
973
1193
|
return function renderItem(params, api) {
|
|
974
1194
|
var rowIndex = api.value(0);
|
|
1195
|
+
var offsetX = getBarOffset(layout, slotIndex);
|
|
1196
|
+
var centerPoint = api.coord([rowIndex, 0]);
|
|
1197
|
+
var centerX = centerPoint[0] + offsetX;
|
|
1198
|
+
var radiusX = layout.barWidth / 2;
|
|
1199
|
+
var radiusY = radiusX * 0.4;
|
|
1200
|
+
var createSideGradient = function createSideGradient(topColor, middleColor, bottomColor) {
|
|
1201
|
+
var opacity = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : CYLINDER_SIDE_OPACITY;
|
|
1202
|
+
return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
|
|
1203
|
+
offset: 0,
|
|
1204
|
+
color: opacity === null ? topColor : applyAlphaToColor(topColor, opacity)
|
|
1205
|
+
}, {
|
|
1206
|
+
offset: 0.55,
|
|
1207
|
+
color: opacity === null ? middleColor : applyAlphaToColor(middleColor, opacity)
|
|
1208
|
+
}, {
|
|
1209
|
+
offset: 1,
|
|
1210
|
+
color: opacity === null ? bottomColor : applyAlphaToColor(bottomColor, opacity)
|
|
1211
|
+
}]);
|
|
1212
|
+
};
|
|
1213
|
+
if (seriesItem && seriesItem.isBackground === true) {
|
|
1214
|
+
var coordSys = params.coordSys || {};
|
|
1215
|
+
var clipX = coordSys.x || 0;
|
|
1216
|
+
var topY = coordSys.y || 0;
|
|
1217
|
+
var width = coordSys.width || 0;
|
|
1218
|
+
var height = coordSys.height || 0;
|
|
1219
|
+
var _topEllipseY = topY + radiusY;
|
|
1220
|
+
var bottomEllipseY = topY + height - radiusY;
|
|
1221
|
+
return {
|
|
1222
|
+
type: 'group',
|
|
1223
|
+
clipPath: {
|
|
1224
|
+
type: 'rect',
|
|
1225
|
+
shape: {
|
|
1226
|
+
x: clipX,
|
|
1227
|
+
y: topY,
|
|
1228
|
+
width: width,
|
|
1229
|
+
height: height
|
|
1230
|
+
}
|
|
1231
|
+
},
|
|
1232
|
+
children: [{
|
|
1233
|
+
type: 'polygon',
|
|
1234
|
+
shape: {
|
|
1235
|
+
points: createEllipsePolygon(centerX, bottomEllipseY, radiusX, radiusY)
|
|
1236
|
+
},
|
|
1237
|
+
style: {
|
|
1238
|
+
fill: colorMap.bottom
|
|
1239
|
+
},
|
|
1240
|
+
z: 0
|
|
1241
|
+
}, {
|
|
1242
|
+
type: 'polygon',
|
|
1243
|
+
shape: {
|
|
1244
|
+
points: createCylinderSidePolygon(centerX, _topEllipseY, bottomEllipseY, radiusX, radiusY)
|
|
1245
|
+
},
|
|
1246
|
+
style: {
|
|
1247
|
+
fill: createSideGradient(colorMap.middle, colorMap.middle, colorMap.bottom, null)
|
|
1248
|
+
},
|
|
1249
|
+
z: 1
|
|
1250
|
+
}, {
|
|
1251
|
+
type: 'polygon',
|
|
1252
|
+
shape: {
|
|
1253
|
+
points: createEllipsePolygon(centerX, _topEllipseY, radiusX, radiusY)
|
|
1254
|
+
},
|
|
1255
|
+
style: {
|
|
1256
|
+
fill: colorMap.top
|
|
1257
|
+
},
|
|
1258
|
+
z2: 2
|
|
1259
|
+
}]
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
975
1262
|
var endValue = api.value(1);
|
|
976
1263
|
var baseValue = api.value(2);
|
|
977
1264
|
var rawValue = api.value(3);
|
|
@@ -982,10 +1269,6 @@ function createCylinderRenderItem(layout, slotIndex, colorMap) {
|
|
|
982
1269
|
}
|
|
983
1270
|
var endPoint = api.coord([rowIndex, endValue]);
|
|
984
1271
|
var basePoint = api.coord([rowIndex, baseValue]);
|
|
985
|
-
var offsetX = getBarOffset(layout, slotIndex);
|
|
986
|
-
var centerX = endPoint[0] + offsetX;
|
|
987
|
-
var radiusX = layout.barWidth / 2;
|
|
988
|
-
var radiusY = radiusX * 0.4;
|
|
989
1272
|
var isPositive = rawValue >= 0;
|
|
990
1273
|
var barHeight = Math.abs(endPoint[1] - basePoint[1]);
|
|
991
1274
|
var visibleEllipseY = endPoint[1];
|
|
@@ -1000,16 +1283,7 @@ function createCylinderRenderItem(layout, slotIndex, colorMap) {
|
|
|
1000
1283
|
var gradientTopColor = isPositive ? colorMap.middle : darkenColor(colorMap.bottom, 0.05);
|
|
1001
1284
|
var gradientMiddleColor = colorMap.middle;
|
|
1002
1285
|
var gradientBottomColor = isPositive ? colorMap.bottom : colorMap.middle;
|
|
1003
|
-
var sideGradient =
|
|
1004
|
-
offset: 0,
|
|
1005
|
-
color: applyAlphaToColor(gradientTopColor, CYLINDER_SIDE_OPACITY)
|
|
1006
|
-
}, {
|
|
1007
|
-
offset: 0.55,
|
|
1008
|
-
color: applyAlphaToColor(gradientMiddleColor, CYLINDER_SIDE_OPACITY)
|
|
1009
|
-
}, {
|
|
1010
|
-
offset: 1,
|
|
1011
|
-
color: applyAlphaToColor(gradientBottomColor, CYLINDER_SIDE_OPACITY)
|
|
1012
|
-
}]);
|
|
1286
|
+
var sideGradient = createSideGradient(gradientTopColor, gradientMiddleColor, gradientBottomColor);
|
|
1013
1287
|
return {
|
|
1014
1288
|
type: 'group',
|
|
1015
1289
|
children: [].concat(colors._toConsumableArray(showBottomPlate ? [{
|
|
@@ -1056,6 +1330,15 @@ function createCylinderRenderItem(layout, slotIndex, colorMap) {
|
|
|
1056
1330
|
function createCylinderBarLineOption(normalizedInput) {
|
|
1057
1331
|
var flatOption = createFlatBarLineOption(normalizedInput);
|
|
1058
1332
|
var flatSeries = createFlatBarLineSeries(normalizedInput);
|
|
1333
|
+
var backgroundSeries = buildBackgroundCustomBarSeries({
|
|
1334
|
+
rawData: normalizedInput.rawData,
|
|
1335
|
+
normalizedSeries: normalizedInput.normalizedSeries,
|
|
1336
|
+
barWidth: normalizedInput.barWidth,
|
|
1337
|
+
barGap: normalizedInput.barGap,
|
|
1338
|
+
barBackground: normalizedInput.barBackground,
|
|
1339
|
+
createRenderItem: createCylinderRenderItem,
|
|
1340
|
+
resolveColorMap: resolveCylinderColors
|
|
1341
|
+
});
|
|
1059
1342
|
var customBarSeries = buildCustomBarSeries({
|
|
1060
1343
|
rawData: normalizedInput.rawData,
|
|
1061
1344
|
normalizedSeries: normalizedInput.normalizedSeries,
|
|
@@ -1074,13 +1357,18 @@ function createCylinderBarLineOption(normalizedInput) {
|
|
|
1074
1357
|
return flatSeries[index];
|
|
1075
1358
|
});
|
|
1076
1359
|
return colors._objectSpread2(colors._objectSpread2({}, flatOption), {}, {
|
|
1077
|
-
series: series
|
|
1360
|
+
series: [].concat(colors._toConsumableArray(series), colors._toConsumableArray(backgroundSeries))
|
|
1078
1361
|
});
|
|
1079
1362
|
}
|
|
1080
1363
|
|
|
1081
1364
|
var DEFAULT_VARIANT = 'flat';
|
|
1082
1365
|
var DEFAULT_X_AXIS_SCROLL_VISIBLE_COUNT = 8;
|
|
1083
1366
|
var DEFAULT_X_AXIS_SCROLL_GRID_BOTTOM = 56;
|
|
1367
|
+
var DEFAULT_BAR_BACKGROUND = {
|
|
1368
|
+
show: false,
|
|
1369
|
+
colors: [],
|
|
1370
|
+
opacity: 1
|
|
1371
|
+
};
|
|
1084
1372
|
var BAR_LINE_PUBLIC_VARIANTS = ['flat', 'cylinder', 'cube'];
|
|
1085
1373
|
|
|
1086
1374
|
// 公开 variant 能力在此处收口:只允许 flat / cylinder / cube。
|
|
@@ -1164,6 +1452,21 @@ function normalizeXAxisScrollConfig() {
|
|
|
1164
1452
|
};
|
|
1165
1453
|
}
|
|
1166
1454
|
|
|
1455
|
+
/**
|
|
1456
|
+
* 归一化柱形背景配置。
|
|
1457
|
+
* 这里统一收敛开关、颜色数量和透明度范围,避免变体层重复兜底。
|
|
1458
|
+
*/
|
|
1459
|
+
function normalizeBarBackgroundConfig() {
|
|
1460
|
+
var barBackground = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1461
|
+
var config = barBackground && colors._typeof(barBackground) === 'object' ? barBackground : {};
|
|
1462
|
+
var opacity = Number(config.opacity);
|
|
1463
|
+
return colors._objectSpread2(colors._objectSpread2({}, DEFAULT_BAR_BACKGROUND), {}, {
|
|
1464
|
+
show: config.show === true,
|
|
1465
|
+
colors: Array.isArray(config.colors) ? config.colors.filter(Boolean).slice(0, 3) : [],
|
|
1466
|
+
opacity: Number.isFinite(opacity) ? Math.max(0, Math.min(1, opacity)) : 1
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1167
1470
|
/**
|
|
1168
1471
|
* 根据横轴类目数量生成 ECharts dataZoom。
|
|
1169
1472
|
* 默认从末尾向前取 `visibleCount` 个类目,满足“最新数据优先展示”的看板诉求。
|
|
@@ -1234,6 +1537,7 @@ function buildBarLineOption() {
|
|
|
1234
1537
|
variant = _ref$variant === void 0 ? 'flat' : _ref$variant,
|
|
1235
1538
|
barWidth = _ref.barWidth,
|
|
1236
1539
|
barGap = _ref.barGap,
|
|
1540
|
+
barBackground = _ref.barBackground,
|
|
1237
1541
|
xAxisScroll = _ref.xAxisScroll,
|
|
1238
1542
|
customOption = _ref.customOption;
|
|
1239
1543
|
var normalizedInput = normalizeBarLineInput({
|
|
@@ -1245,10 +1549,12 @@ function buildBarLineOption() {
|
|
|
1245
1549
|
var presetOption = getBarLinePreset(preset);
|
|
1246
1550
|
var resolvedVariant = resolveVariantName(variant);
|
|
1247
1551
|
var createVariantOption = variantFactory[resolvedVariant] || variantFactory[DEFAULT_VARIANT];
|
|
1552
|
+
var normalizedBarBackground = normalizeBarBackgroundConfig(barBackground);
|
|
1248
1553
|
var variantOption = createVariantOption(colors._objectSpread2(colors._objectSpread2({}, normalizedInput), {}, {
|
|
1249
1554
|
includeXAxis: false,
|
|
1250
1555
|
barWidth: barWidth,
|
|
1251
|
-
barGap: barGap
|
|
1556
|
+
barGap: barGap,
|
|
1557
|
+
barBackground: normalizedBarBackground
|
|
1252
1558
|
}));
|
|
1253
1559
|
var xAxisScrollOption = createXAxisScrollOption(normalizedInput.categories, xAxisScroll);
|
|
1254
1560
|
return colors.mergeChartOption(colors.mergeChartOption(colors.mergeChartOption(baseOption, presetOption, variantOption), xAxisScrollOption), customOption);
|
|
@@ -1305,6 +1611,7 @@ var script = {
|
|
|
1305
1611
|
* - name: 系列名称
|
|
1306
1612
|
* - kind: bar / line
|
|
1307
1613
|
* - stack / yAxisIndex / colors: 可选增强配置
|
|
1614
|
+
* - cubeGradientColors: 仅在 `variant="cube"` 时用于前景方柱三个面的渐变终点色
|
|
1308
1615
|
*/
|
|
1309
1616
|
series: {
|
|
1310
1617
|
type: Array,
|
|
@@ -1350,6 +1657,17 @@ var script = {
|
|
|
1350
1657
|
type: [Number, String],
|
|
1351
1658
|
"default": 8
|
|
1352
1659
|
},
|
|
1660
|
+
/**
|
|
1661
|
+
* 柱形背景配置。
|
|
1662
|
+
* 仅对支持背景柱的柱系列生效,builder 会负责归一化 `show/colors/opacity`
|
|
1663
|
+
* 并交由具体变体决定最终渲染策略。
|
|
1664
|
+
*/
|
|
1665
|
+
barBackground: {
|
|
1666
|
+
type: Object,
|
|
1667
|
+
"default": function _default() {
|
|
1668
|
+
return {};
|
|
1669
|
+
}
|
|
1670
|
+
},
|
|
1353
1671
|
/**
|
|
1354
1672
|
* 额外透传给 ECharts option 的自定义配置。
|
|
1355
1673
|
* 会在 base / preset / variant option 合并完成后再覆盖。
|
|
@@ -1384,6 +1702,14 @@ var script = {
|
|
|
1384
1702
|
type: Boolean,
|
|
1385
1703
|
"default": false
|
|
1386
1704
|
},
|
|
1705
|
+
/**
|
|
1706
|
+
* 是否在数据为空时展示统一空状态。
|
|
1707
|
+
* 关闭后仍会保留图表容器与坐标系渲染,只是不再替换成 BaseEmpty。
|
|
1708
|
+
*/
|
|
1709
|
+
showEmptyState: {
|
|
1710
|
+
type: Boolean,
|
|
1711
|
+
"default": true
|
|
1712
|
+
},
|
|
1387
1713
|
/**
|
|
1388
1714
|
* 统一状态展示配置。
|
|
1389
1715
|
* 组件层只负责原样透传给 BaseChart,不参与文案计算。
|
|
@@ -1410,6 +1736,12 @@ var script = {
|
|
|
1410
1736
|
isEmpty: function isEmpty() {
|
|
1411
1737
|
return colors.isEmptyData(this.data);
|
|
1412
1738
|
},
|
|
1739
|
+
/**
|
|
1740
|
+
* 对 BaseChart 的空态展示做一层显式开关控制。
|
|
1741
|
+
*/
|
|
1742
|
+
chartEmpty: function chartEmpty() {
|
|
1743
|
+
return this.showEmptyState && this.isEmpty;
|
|
1744
|
+
},
|
|
1413
1745
|
/**
|
|
1414
1746
|
* 将公开 props 汇总为 builder 所需输入。
|
|
1415
1747
|
* 组件层不做类型分发,只负责把标准公开参数交给构建层。
|
|
@@ -1424,6 +1756,7 @@ var script = {
|
|
|
1424
1756
|
preset: this.preset,
|
|
1425
1757
|
barWidth: this.barWidth,
|
|
1426
1758
|
barGap: this.barGap,
|
|
1759
|
+
barBackground: this.barBackground,
|
|
1427
1760
|
xAxisScroll: this.xAxisScroll,
|
|
1428
1761
|
customOption: this.customOption
|
|
1429
1762
|
});
|
|
@@ -1431,7 +1764,7 @@ var script = {
|
|
|
1431
1764
|
}
|
|
1432
1765
|
};
|
|
1433
1766
|
|
|
1434
|
-
var css_248z = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
|
|
1767
|
+
var css_248z = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
|
|
1435
1768
|
withInstall.styleInject(css_248z);
|
|
1436
1769
|
|
|
1437
1770
|
/* script */
|
|
@@ -1445,7 +1778,7 @@ var __vue_render__ = function __vue_render__() {
|
|
|
1445
1778
|
attrs: {
|
|
1446
1779
|
option: _vm.chartOption,
|
|
1447
1780
|
loading: _vm.loading,
|
|
1448
|
-
empty: _vm.
|
|
1781
|
+
empty: _vm.chartEmpty,
|
|
1449
1782
|
"state-config": _vm.stateConfig,
|
|
1450
1783
|
height: _vm.height
|
|
1451
1784
|
},
|
|
@@ -1465,7 +1798,7 @@ __vue_render__._withStripped = true;
|
|
|
1465
1798
|
/* style */
|
|
1466
1799
|
var __vue_inject_styles__ = undefined;
|
|
1467
1800
|
/* scoped */
|
|
1468
|
-
var __vue_scope_id__ = "data-v-
|
|
1801
|
+
var __vue_scope_id__ = "data-v-38c7a21f";
|
|
1469
1802
|
/* module identifier */
|
|
1470
1803
|
var __vue_module_identifier__ = undefined;
|
|
1471
1804
|
/* functional template */
|