@xq-labs/data-ui-v2 0.2.1 → 0.4.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/README.md +38 -12
- package/docs/api/overview.md +242 -29
- package/docs/examples/bar-line-chart.md +43 -3
- package/docs/examples/local-development.md +191 -0
- package/docs/examples/pie-chart.md +19 -8
- package/docs/examples/radar-chart.md +97 -0
- package/es/bar-line-chart/index.js +2 -2
- package/es/{colors-ca059479.js → colors-ec0ad9ce.js} +10 -1
- package/es/index-788e473f.js +471 -0
- package/es/{index-d151eeca.js → index-78b6b881.js} +97 -58
- package/es/{index-017ccf86.js → index-914fbae3.js} +456 -43
- package/es/index.js +7 -5
- package/es/pie-chart/3d-runtime.js +6 -0
- package/es/pie-chart/index.js +2 -2
- package/es/radar-chart/index.js +13 -0
- package/lib/bar-line-chart/index.js +2 -2
- package/lib/{colors-55265c91.js → colors-19a7242d.js} +10 -0
- package/lib/{index-b9e0c40b.js → index-3d9f6fe7.js} +455 -42
- package/lib/index-6039f724.js +492 -0
- package/lib/{index-7abf647e.js → index-a0ecafa1.js} +96 -58
- package/lib/index.js +7 -4
- package/lib/pie-chart/3d-runtime.js +27 -0
- package/lib/pie-chart/index.js +2 -2
- package/lib/radar-chart/index.js +19 -0
- package/package.json +12 -2
- package/pie-chart/3d-runtime.js +1 -0
|
@@ -5,7 +5,7 @@ var charts = require('echarts/charts');
|
|
|
5
5
|
var components = require('echarts/components');
|
|
6
6
|
var renderers = require('echarts/renderers');
|
|
7
7
|
var withInstall = require('./with-install-4304a8ea.js');
|
|
8
|
-
var colors = require('./colors-
|
|
8
|
+
var colors = require('./colors-19a7242d.js');
|
|
9
9
|
|
|
10
10
|
function _interopNamespaceDefault(e) {
|
|
11
11
|
var n = Object.create(null);
|
|
@@ -149,6 +149,19 @@ function resolveSeriesColor$1(item, index) {
|
|
|
149
149
|
}
|
|
150
150
|
return colors.DEFAULT_COLORS[index % colors.DEFAULT_COLORS.length];
|
|
151
151
|
}
|
|
152
|
+
function collectBarSeries(normalizedSeries) {
|
|
153
|
+
return normalizedSeries.map(function (item, originalIndex) {
|
|
154
|
+
return colors._objectSpread2(colors._objectSpread2({}, item), {}, {
|
|
155
|
+
originalIndex: originalIndex
|
|
156
|
+
});
|
|
157
|
+
}).filter(function (item) {
|
|
158
|
+
return item.kind === 'bar';
|
|
159
|
+
}).map(function (item, barSeriesIndex) {
|
|
160
|
+
return colors._objectSpread2(colors._objectSpread2({}, item), {}, {
|
|
161
|
+
barSeriesIndex: barSeriesIndex
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
152
165
|
|
|
153
166
|
/**
|
|
154
167
|
* 归一化颜色入参。
|
|
@@ -499,6 +512,53 @@ function createBarLayout(barSeries, barWidth, barGap) {
|
|
|
499
512
|
barGap: resolvedBarGap
|
|
500
513
|
};
|
|
501
514
|
}
|
|
515
|
+
function pickBackgroundSlotSeries(barSeries) {
|
|
516
|
+
var renderedStacks = new Set();
|
|
517
|
+
return barSeries.filter(function (item) {
|
|
518
|
+
if (!item.stack) {
|
|
519
|
+
return true;
|
|
520
|
+
}
|
|
521
|
+
if (renderedStacks.has(item.stack)) {
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
renderedStacks.add(item.stack);
|
|
525
|
+
return true;
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
function createBackgroundSeriesData(rawData) {
|
|
529
|
+
return rawData.map(function (row, rowIndex) {
|
|
530
|
+
return {
|
|
531
|
+
value: [rowIndex]
|
|
532
|
+
};
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
function resolveBackgroundFaceAlpha(key, opacity) {
|
|
536
|
+
var alphaMap = {
|
|
537
|
+
left: 0.82,
|
|
538
|
+
right: 1,
|
|
539
|
+
top: 1.8,
|
|
540
|
+
middle: 0.82,
|
|
541
|
+
bottom: 1.28,
|
|
542
|
+
legend: 1
|
|
543
|
+
};
|
|
544
|
+
var ratio = alphaMap[key] || 1;
|
|
545
|
+
return Math.max(0, Math.min(1, opacity * ratio));
|
|
546
|
+
}
|
|
547
|
+
function applyBackgroundFaceAlphaToColorMap(colorMap, opacity) {
|
|
548
|
+
return Object.keys(colorMap || {}).reduce(function (result, key) {
|
|
549
|
+
result[key] = applyAlphaToColor(colorMap[key], resolveBackgroundFaceAlpha(key, opacity));
|
|
550
|
+
return result;
|
|
551
|
+
}, {});
|
|
552
|
+
}
|
|
553
|
+
function normalizeBackgroundColors(barBackground, item) {
|
|
554
|
+
if (Array.isArray(barBackground && barBackground.colors) && barBackground.colors.length > 0) {
|
|
555
|
+
return barBackground.colors;
|
|
556
|
+
}
|
|
557
|
+
if (Array.isArray(item && item.colors) && item.colors.length > 0) {
|
|
558
|
+
return item.colors;
|
|
559
|
+
}
|
|
560
|
+
return undefined;
|
|
561
|
+
}
|
|
502
562
|
|
|
503
563
|
/**
|
|
504
564
|
* 创建堆叠累加器。
|
|
@@ -627,13 +687,7 @@ function buildCustomBarSeries(_ref) {
|
|
|
627
687
|
barGap = _ref.barGap,
|
|
628
688
|
createRenderItem = _ref.createRenderItem,
|
|
629
689
|
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
|
-
});
|
|
690
|
+
var barSeries = collectBarSeries(normalizedSeries);
|
|
637
691
|
var layout = createBarLayout(barSeries, barWidth, barGap);
|
|
638
692
|
var barSeriesWithData = buildBarSeriesData(rawData, barSeries);
|
|
639
693
|
return barSeriesWithData.map(function (item, index) {
|
|
@@ -662,6 +716,57 @@ function buildCustomBarSeries(_ref) {
|
|
|
662
716
|
};
|
|
663
717
|
});
|
|
664
718
|
}
|
|
719
|
+
function buildBackgroundCustomBarSeries(_ref2) {
|
|
720
|
+
var rawData = _ref2.rawData,
|
|
721
|
+
normalizedSeries = _ref2.normalizedSeries,
|
|
722
|
+
barWidth = _ref2.barWidth,
|
|
723
|
+
barGap = _ref2.barGap,
|
|
724
|
+
_ref2$barBackground = _ref2.barBackground,
|
|
725
|
+
barBackground = _ref2$barBackground === void 0 ? {} : _ref2$barBackground,
|
|
726
|
+
createRenderItem = _ref2.createRenderItem,
|
|
727
|
+
resolveColorMap = _ref2.resolveColorMap;
|
|
728
|
+
if (!barBackground.show) {
|
|
729
|
+
return [];
|
|
730
|
+
}
|
|
731
|
+
var barSeries = collectBarSeries(normalizedSeries);
|
|
732
|
+
if (!barSeries.length) {
|
|
733
|
+
return [];
|
|
734
|
+
}
|
|
735
|
+
var layout = createBarLayout(barSeries, barWidth, barGap);
|
|
736
|
+
var backgroundSeriesData = createBackgroundSeriesData(rawData);
|
|
737
|
+
return pickBackgroundSlotSeries(barSeries).map(function (item) {
|
|
738
|
+
var slotKey = item.stack || "__slot_".concat(item.barSeriesIndex);
|
|
739
|
+
var slotIndex = layout.slotMap[slotKey];
|
|
740
|
+
var fallbackColor = resolveSeriesColor$1(item, item.originalIndex);
|
|
741
|
+
var palette = normalizeBackgroundColors(barBackground, item);
|
|
742
|
+
var baseColorMap = resolveColorMap ? resolveColorMap(palette, fallbackColor) : {
|
|
743
|
+
legend: fallbackColor
|
|
744
|
+
};
|
|
745
|
+
var backgroundColorMap = applyBackgroundFaceAlphaToColorMap(baseColorMap, barBackground.opacity);
|
|
746
|
+
return {
|
|
747
|
+
name: item.name,
|
|
748
|
+
type: 'custom',
|
|
749
|
+
stack: item.stack,
|
|
750
|
+
yAxisIndex: item.yAxisIndex || 0,
|
|
751
|
+
isBackground: true,
|
|
752
|
+
silent: true,
|
|
753
|
+
tooltip: {
|
|
754
|
+
show: false
|
|
755
|
+
},
|
|
756
|
+
renderItem: createRenderItem(layout, slotIndex, backgroundColorMap, colors._objectSpread2(colors._objectSpread2({}, item), {}, {
|
|
757
|
+
isBackground: true
|
|
758
|
+
})),
|
|
759
|
+
encode: {
|
|
760
|
+
x: 0
|
|
761
|
+
},
|
|
762
|
+
itemStyle: {
|
|
763
|
+
color: backgroundColorMap.legend || applyAlphaToColor(fallbackColor, barBackground.opacity)
|
|
764
|
+
},
|
|
765
|
+
data: backgroundSeriesData,
|
|
766
|
+
z: 0
|
|
767
|
+
};
|
|
768
|
+
});
|
|
769
|
+
}
|
|
665
770
|
|
|
666
771
|
/**
|
|
667
772
|
* 归一化 flat 模式下的 `barGap`。
|
|
@@ -725,6 +830,27 @@ function resolveFlatBarColors(item, index) {
|
|
|
725
830
|
end: darkenColor(fallbackColor, 0.12)
|
|
726
831
|
};
|
|
727
832
|
}
|
|
833
|
+
function resolveFlatBackgroundColors(item, index, barBackground) {
|
|
834
|
+
var paletteSource = Array.isArray(barBackground.colors) && barBackground.colors.length > 0 ? {
|
|
835
|
+
colors: barBackground.colors
|
|
836
|
+
} : item;
|
|
837
|
+
var colorMap = resolveFlatBarColors(paletteSource, index);
|
|
838
|
+
return {
|
|
839
|
+
start: applyAlphaToColor(colorMap.start, barBackground.opacity),
|
|
840
|
+
middle: applyAlphaToColor(colorMap.middle, barBackground.opacity),
|
|
841
|
+
end: applyAlphaToColor(colorMap.end, barBackground.opacity)
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
function shouldEnableBackground(item, renderedStacks) {
|
|
845
|
+
if (!item.stack) {
|
|
846
|
+
return true;
|
|
847
|
+
}
|
|
848
|
+
if (renderedStacks.has(item.stack)) {
|
|
849
|
+
return false;
|
|
850
|
+
}
|
|
851
|
+
renderedStacks.add(item.stack);
|
|
852
|
+
return true;
|
|
853
|
+
}
|
|
728
854
|
|
|
729
855
|
/**
|
|
730
856
|
* 创建柱体纵向渐变。
|
|
@@ -756,9 +882,12 @@ function createFlatBarLineSeries(_ref) {
|
|
|
756
882
|
var normalizedSeries = _ref.normalizedSeries,
|
|
757
883
|
rawData = _ref.rawData,
|
|
758
884
|
barWidth = _ref.barWidth,
|
|
759
|
-
barGap = _ref.barGap
|
|
885
|
+
barGap = _ref.barGap,
|
|
886
|
+
_ref$barBackground = _ref.barBackground,
|
|
887
|
+
barBackground = _ref$barBackground === void 0 ? {} : _ref$barBackground;
|
|
760
888
|
var resolvedBarWidth = Number.isFinite(Number(barWidth)) ? Number(barWidth) : 18;
|
|
761
889
|
var resolvedBarGap = toBarGapValue(barGap);
|
|
890
|
+
var renderedStacks = new Set();
|
|
762
891
|
return normalizedSeries.map(function (item, index) {
|
|
763
892
|
var isLine = item.kind === 'line';
|
|
764
893
|
var color = resolveSeriesColor(item, index);
|
|
@@ -779,11 +908,18 @@ function createFlatBarLineSeries(_ref) {
|
|
|
779
908
|
yAxisIndex: item.yAxisIndex
|
|
780
909
|
});
|
|
781
910
|
}
|
|
911
|
+
var showBackground = barBackground.show && shouldEnableBackground(item, renderedStacks);
|
|
912
|
+
var backgroundColors = resolveFlatBackgroundColors(item, index, barBackground);
|
|
782
913
|
return colors._objectSpread2(colors._objectSpread2({}, baseSeries), {}, {
|
|
783
914
|
stack: item.stack,
|
|
784
915
|
barWidth: resolvedBarWidth,
|
|
785
|
-
barGap: resolvedBarGap
|
|
786
|
-
|
|
916
|
+
barGap: resolvedBarGap,
|
|
917
|
+
showBackground: showBackground
|
|
918
|
+
}, showBackground ? {
|
|
919
|
+
backgroundStyle: {
|
|
920
|
+
color: createBarGradient(backgroundColors)
|
|
921
|
+
}
|
|
922
|
+
} : {});
|
|
787
923
|
});
|
|
788
924
|
}
|
|
789
925
|
|
|
@@ -847,9 +983,63 @@ function createFaceGradient(x0, y0, x1, y1, startColor, endColor) {
|
|
|
847
983
|
* 创建方柱渲染器。
|
|
848
984
|
* 参考案例使用三块 polygon 拼接成立方体,而不是“正面 rect + 顶面/侧面”。
|
|
849
985
|
*/
|
|
850
|
-
function createCubeRenderItem(layout, slotIndex, colorMap) {
|
|
986
|
+
function createCubeRenderItem(layout, slotIndex, colorMap, seriesItem) {
|
|
851
987
|
return function renderItem(params, api) {
|
|
852
988
|
var rowIndex = api.value(0);
|
|
989
|
+
var offsetX = getBarOffset(layout, slotIndex);
|
|
990
|
+
var centerPoint = api.coord([rowIndex, 0]);
|
|
991
|
+
var centerX = centerPoint[0] + offsetX;
|
|
992
|
+
var halfWidth = layout.barWidth / 2;
|
|
993
|
+
var offsetY = Math.tan(Math.PI / 9) * halfWidth;
|
|
994
|
+
var leftFaceGradient = createFaceGradient(0, 0, 0, 1, colorMap.left, colorMap.left);
|
|
995
|
+
var rightFaceGradient = createFaceGradient(0, 0, 0, 1, colorMap.right, colorMap.right);
|
|
996
|
+
var topFaceGradient = createFaceGradient(0, 0, 1, 0, colorMap.top, colorMap.top);
|
|
997
|
+
if (seriesItem && seriesItem.isBackground === true) {
|
|
998
|
+
var coordSys = params.coordSys || {};
|
|
999
|
+
var clipX = coordSys.x || 0;
|
|
1000
|
+
var _topY = coordSys.y || 0;
|
|
1001
|
+
var width = coordSys.width || 0;
|
|
1002
|
+
var _baseY = _topY + (coordSys.height || 0);
|
|
1003
|
+
var _topSurfaceY = _topY + Math.abs(offsetY - 1);
|
|
1004
|
+
return {
|
|
1005
|
+
type: 'group',
|
|
1006
|
+
clipPath: {
|
|
1007
|
+
type: 'rect',
|
|
1008
|
+
shape: {
|
|
1009
|
+
x: clipX,
|
|
1010
|
+
y: _topY,
|
|
1011
|
+
width: width,
|
|
1012
|
+
height: coordSys.height || 0
|
|
1013
|
+
}
|
|
1014
|
+
},
|
|
1015
|
+
children: [{
|
|
1016
|
+
type: 'polygon',
|
|
1017
|
+
shape: {
|
|
1018
|
+
points: [[centerX, _topSurfaceY + offsetY - 1], [centerX - halfWidth, _topSurfaceY], [centerX - halfWidth, _baseY - offsetY], [centerX, _baseY - 1]]
|
|
1019
|
+
},
|
|
1020
|
+
style: {
|
|
1021
|
+
fill: leftFaceGradient
|
|
1022
|
+
}
|
|
1023
|
+
}, {
|
|
1024
|
+
type: 'polygon',
|
|
1025
|
+
shape: {
|
|
1026
|
+
points: [[centerX, _topSurfaceY + offsetY - 1], [centerX + halfWidth, _topSurfaceY], [centerX + halfWidth, _baseY - offsetY], [centerX, _baseY - 1]]
|
|
1027
|
+
},
|
|
1028
|
+
style: {
|
|
1029
|
+
fill: rightFaceGradient
|
|
1030
|
+
}
|
|
1031
|
+
}, {
|
|
1032
|
+
type: 'polygon',
|
|
1033
|
+
shape: {
|
|
1034
|
+
points: [[centerX, _topSurfaceY + offsetY - 1], [centerX + halfWidth, _topSurfaceY], [centerX, _topSurfaceY - offsetY + 1], [centerX - halfWidth, _topSurfaceY]]
|
|
1035
|
+
},
|
|
1036
|
+
style: {
|
|
1037
|
+
fill: topFaceGradient
|
|
1038
|
+
},
|
|
1039
|
+
z2: 2
|
|
1040
|
+
}]
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
853
1043
|
var endValue = api.value(1);
|
|
854
1044
|
var baseValue = api.value(2);
|
|
855
1045
|
var rawValue = api.value(3);
|
|
@@ -860,20 +1050,13 @@ function createCubeRenderItem(layout, slotIndex, colorMap) {
|
|
|
860
1050
|
}
|
|
861
1051
|
var endPoint = api.coord([rowIndex, endValue]);
|
|
862
1052
|
var basePoint = api.coord([rowIndex, baseValue]);
|
|
863
|
-
var offsetX = getBarOffset(layout, slotIndex);
|
|
864
|
-
var centerX = endPoint[0] + offsetX;
|
|
865
1053
|
var topY = endPoint[1];
|
|
866
1054
|
var baseY = basePoint[1];
|
|
867
|
-
var halfWidth = layout.barWidth / 2;
|
|
868
|
-
var offsetY = Math.tan(Math.PI / 9) * halfWidth;
|
|
869
1055
|
var isPositive = rawValue >= 0;
|
|
870
1056
|
var connectorOverlap = stackStart ? 0 : Math.max(2, Math.round(offsetY));
|
|
871
1057
|
var connectorCapOffset = stackEnd ? 0 : Math.min(2, offsetY * 0.45);
|
|
872
1058
|
var connectBaseY = isPositive ? baseY + connectorOverlap : baseY - connectorOverlap;
|
|
873
1059
|
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
1060
|
return {
|
|
878
1061
|
type: 'group',
|
|
879
1062
|
children: [{
|
|
@@ -919,6 +1102,15 @@ function createCubeRenderItem(layout, slotIndex, colorMap) {
|
|
|
919
1102
|
function createCubeBarLineOption(normalizedInput) {
|
|
920
1103
|
var flatOption = createFlatBarLineOption(normalizedInput);
|
|
921
1104
|
var flatSeries = createFlatBarLineSeries(normalizedInput);
|
|
1105
|
+
var backgroundSeries = buildBackgroundCustomBarSeries({
|
|
1106
|
+
rawData: normalizedInput.rawData,
|
|
1107
|
+
normalizedSeries: normalizedInput.normalizedSeries,
|
|
1108
|
+
barWidth: normalizedInput.barWidth,
|
|
1109
|
+
barGap: normalizedInput.barGap,
|
|
1110
|
+
barBackground: normalizedInput.barBackground,
|
|
1111
|
+
createRenderItem: createCubeRenderItem,
|
|
1112
|
+
resolveColorMap: resolveCubeColors
|
|
1113
|
+
});
|
|
922
1114
|
var customBarSeries = buildCustomBarSeries({
|
|
923
1115
|
rawData: normalizedInput.rawData,
|
|
924
1116
|
normalizedSeries: normalizedInput.normalizedSeries,
|
|
@@ -937,7 +1129,7 @@ function createCubeBarLineOption(normalizedInput) {
|
|
|
937
1129
|
return flatSeries[index];
|
|
938
1130
|
});
|
|
939
1131
|
return colors._objectSpread2(colors._objectSpread2({}, flatOption), {}, {
|
|
940
|
-
series: series
|
|
1132
|
+
series: [].concat(colors._toConsumableArray(series), colors._toConsumableArray(backgroundSeries))
|
|
941
1133
|
});
|
|
942
1134
|
}
|
|
943
1135
|
|
|
@@ -961,6 +1153,20 @@ function createEllipsePolygon(cx, cy, rx, ry) {
|
|
|
961
1153
|
}
|
|
962
1154
|
return polygonPoints;
|
|
963
1155
|
}
|
|
1156
|
+
function createEllipseArcPoints(cx, cy, rx, ry, startAngle, endAngle) {
|
|
1157
|
+
var points = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 12;
|
|
1158
|
+
var arcPoints = [];
|
|
1159
|
+
for (var index = 0; index <= points; index += 1) {
|
|
1160
|
+
var angle = startAngle + (endAngle - startAngle) * index / points;
|
|
1161
|
+
arcPoints.push([cx + Math.cos(angle) * rx, cy + Math.sin(angle) * ry]);
|
|
1162
|
+
}
|
|
1163
|
+
return arcPoints;
|
|
1164
|
+
}
|
|
1165
|
+
function createCylinderSidePolygon(cx, topCy, bottomCy, rx, ry) {
|
|
1166
|
+
var topLowerArc = createEllipseArcPoints(cx, topCy, rx, ry, Math.PI, 0);
|
|
1167
|
+
var bottomUpperArc = createEllipseArcPoints(cx, bottomCy, rx, ry, 0, -Math.PI);
|
|
1168
|
+
return [].concat(colors._toConsumableArray(topLowerArc), colors._toConsumableArray(bottomUpperArc));
|
|
1169
|
+
}
|
|
964
1170
|
|
|
965
1171
|
/**
|
|
966
1172
|
* 创建圆柱渲染器。
|
|
@@ -969,9 +1175,76 @@ function createEllipsePolygon(cx, cy, rx, ry) {
|
|
|
969
1175
|
* 2. 主体用纵向渐变矩形模拟曲面;
|
|
970
1176
|
* 3. 堆叠连接处保留底片,但不绘制深色描边和弧线,避免形成脏色带。
|
|
971
1177
|
*/
|
|
972
|
-
function createCylinderRenderItem(layout, slotIndex, colorMap) {
|
|
1178
|
+
function createCylinderRenderItem(layout, slotIndex, colorMap, seriesItem) {
|
|
973
1179
|
return function renderItem(params, api) {
|
|
974
1180
|
var rowIndex = api.value(0);
|
|
1181
|
+
var offsetX = getBarOffset(layout, slotIndex);
|
|
1182
|
+
var centerPoint = api.coord([rowIndex, 0]);
|
|
1183
|
+
var centerX = centerPoint[0] + offsetX;
|
|
1184
|
+
var radiusX = layout.barWidth / 2;
|
|
1185
|
+
var radiusY = radiusX * 0.4;
|
|
1186
|
+
var createSideGradient = function createSideGradient(topColor, middleColor, bottomColor) {
|
|
1187
|
+
var opacity = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : CYLINDER_SIDE_OPACITY;
|
|
1188
|
+
return new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
|
|
1189
|
+
offset: 0,
|
|
1190
|
+
color: opacity === null ? topColor : applyAlphaToColor(topColor, opacity)
|
|
1191
|
+
}, {
|
|
1192
|
+
offset: 0.55,
|
|
1193
|
+
color: opacity === null ? middleColor : applyAlphaToColor(middleColor, opacity)
|
|
1194
|
+
}, {
|
|
1195
|
+
offset: 1,
|
|
1196
|
+
color: opacity === null ? bottomColor : applyAlphaToColor(bottomColor, opacity)
|
|
1197
|
+
}]);
|
|
1198
|
+
};
|
|
1199
|
+
if (seriesItem && seriesItem.isBackground === true) {
|
|
1200
|
+
var coordSys = params.coordSys || {};
|
|
1201
|
+
var clipX = coordSys.x || 0;
|
|
1202
|
+
var topY = coordSys.y || 0;
|
|
1203
|
+
var width = coordSys.width || 0;
|
|
1204
|
+
var height = coordSys.height || 0;
|
|
1205
|
+
var _topEllipseY = topY + radiusY;
|
|
1206
|
+
var bottomEllipseY = topY + height - radiusY;
|
|
1207
|
+
return {
|
|
1208
|
+
type: 'group',
|
|
1209
|
+
clipPath: {
|
|
1210
|
+
type: 'rect',
|
|
1211
|
+
shape: {
|
|
1212
|
+
x: clipX,
|
|
1213
|
+
y: topY,
|
|
1214
|
+
width: width,
|
|
1215
|
+
height: height
|
|
1216
|
+
}
|
|
1217
|
+
},
|
|
1218
|
+
children: [{
|
|
1219
|
+
type: 'polygon',
|
|
1220
|
+
shape: {
|
|
1221
|
+
points: createEllipsePolygon(centerX, bottomEllipseY, radiusX, radiusY)
|
|
1222
|
+
},
|
|
1223
|
+
style: {
|
|
1224
|
+
fill: colorMap.bottom
|
|
1225
|
+
},
|
|
1226
|
+
z: 0
|
|
1227
|
+
}, {
|
|
1228
|
+
type: 'polygon',
|
|
1229
|
+
shape: {
|
|
1230
|
+
points: createCylinderSidePolygon(centerX, _topEllipseY, bottomEllipseY, radiusX, radiusY)
|
|
1231
|
+
},
|
|
1232
|
+
style: {
|
|
1233
|
+
fill: createSideGradient(colorMap.middle, colorMap.middle, colorMap.bottom, null)
|
|
1234
|
+
},
|
|
1235
|
+
z: 1
|
|
1236
|
+
}, {
|
|
1237
|
+
type: 'polygon',
|
|
1238
|
+
shape: {
|
|
1239
|
+
points: createEllipsePolygon(centerX, _topEllipseY, radiusX, radiusY)
|
|
1240
|
+
},
|
|
1241
|
+
style: {
|
|
1242
|
+
fill: colorMap.top
|
|
1243
|
+
},
|
|
1244
|
+
z2: 2
|
|
1245
|
+
}]
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
975
1248
|
var endValue = api.value(1);
|
|
976
1249
|
var baseValue = api.value(2);
|
|
977
1250
|
var rawValue = api.value(3);
|
|
@@ -982,10 +1255,6 @@ function createCylinderRenderItem(layout, slotIndex, colorMap) {
|
|
|
982
1255
|
}
|
|
983
1256
|
var endPoint = api.coord([rowIndex, endValue]);
|
|
984
1257
|
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
1258
|
var isPositive = rawValue >= 0;
|
|
990
1259
|
var barHeight = Math.abs(endPoint[1] - basePoint[1]);
|
|
991
1260
|
var visibleEllipseY = endPoint[1];
|
|
@@ -1000,16 +1269,7 @@ function createCylinderRenderItem(layout, slotIndex, colorMap) {
|
|
|
1000
1269
|
var gradientTopColor = isPositive ? colorMap.middle : darkenColor(colorMap.bottom, 0.05);
|
|
1001
1270
|
var gradientMiddleColor = colorMap.middle;
|
|
1002
1271
|
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
|
-
}]);
|
|
1272
|
+
var sideGradient = createSideGradient(gradientTopColor, gradientMiddleColor, gradientBottomColor);
|
|
1013
1273
|
return {
|
|
1014
1274
|
type: 'group',
|
|
1015
1275
|
children: [].concat(colors._toConsumableArray(showBottomPlate ? [{
|
|
@@ -1056,6 +1316,15 @@ function createCylinderRenderItem(layout, slotIndex, colorMap) {
|
|
|
1056
1316
|
function createCylinderBarLineOption(normalizedInput) {
|
|
1057
1317
|
var flatOption = createFlatBarLineOption(normalizedInput);
|
|
1058
1318
|
var flatSeries = createFlatBarLineSeries(normalizedInput);
|
|
1319
|
+
var backgroundSeries = buildBackgroundCustomBarSeries({
|
|
1320
|
+
rawData: normalizedInput.rawData,
|
|
1321
|
+
normalizedSeries: normalizedInput.normalizedSeries,
|
|
1322
|
+
barWidth: normalizedInput.barWidth,
|
|
1323
|
+
barGap: normalizedInput.barGap,
|
|
1324
|
+
barBackground: normalizedInput.barBackground,
|
|
1325
|
+
createRenderItem: createCylinderRenderItem,
|
|
1326
|
+
resolveColorMap: resolveCylinderColors
|
|
1327
|
+
});
|
|
1059
1328
|
var customBarSeries = buildCustomBarSeries({
|
|
1060
1329
|
rawData: normalizedInput.rawData,
|
|
1061
1330
|
normalizedSeries: normalizedInput.normalizedSeries,
|
|
@@ -1074,11 +1343,18 @@ function createCylinderBarLineOption(normalizedInput) {
|
|
|
1074
1343
|
return flatSeries[index];
|
|
1075
1344
|
});
|
|
1076
1345
|
return colors._objectSpread2(colors._objectSpread2({}, flatOption), {}, {
|
|
1077
|
-
series: series
|
|
1346
|
+
series: [].concat(colors._toConsumableArray(series), colors._toConsumableArray(backgroundSeries))
|
|
1078
1347
|
});
|
|
1079
1348
|
}
|
|
1080
1349
|
|
|
1081
1350
|
var DEFAULT_VARIANT = 'flat';
|
|
1351
|
+
var DEFAULT_X_AXIS_SCROLL_VISIBLE_COUNT = 8;
|
|
1352
|
+
var DEFAULT_X_AXIS_SCROLL_GRID_BOTTOM = 56;
|
|
1353
|
+
var DEFAULT_BAR_BACKGROUND = {
|
|
1354
|
+
show: false,
|
|
1355
|
+
colors: [],
|
|
1356
|
+
opacity: 1
|
|
1357
|
+
};
|
|
1082
1358
|
var BAR_LINE_PUBLIC_VARIANTS = ['flat', 'cylinder', 'cube'];
|
|
1083
1359
|
|
|
1084
1360
|
// 公开 variant 能力在此处收口:只允许 flat / cylinder / cube。
|
|
@@ -1124,6 +1400,108 @@ function createBaseOption(normalizedInput) {
|
|
|
1124
1400
|
}
|
|
1125
1401
|
};
|
|
1126
1402
|
}
|
|
1403
|
+
function isValidNumber(value) {
|
|
1404
|
+
return Number.isFinite(Number(value));
|
|
1405
|
+
}
|
|
1406
|
+
function normalizePositiveInteger(value, fallback) {
|
|
1407
|
+
var normalizedValue = Number(value);
|
|
1408
|
+
if (!Number.isFinite(normalizedValue) || normalizedValue <= 0) {
|
|
1409
|
+
return fallback;
|
|
1410
|
+
}
|
|
1411
|
+
return Math.floor(normalizedValue);
|
|
1412
|
+
}
|
|
1413
|
+
function normalizeStartIndex(startIndex) {
|
|
1414
|
+
if (!isValidNumber(startIndex)) {
|
|
1415
|
+
return null;
|
|
1416
|
+
}
|
|
1417
|
+
var normalizedStartIndex = Math.floor(Number(startIndex));
|
|
1418
|
+
return normalizedStartIndex >= 0 ? normalizedStartIndex : null;
|
|
1419
|
+
}
|
|
1420
|
+
function toPercent(value, total) {
|
|
1421
|
+
return Number((value / total * 100).toFixed(2));
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
/**
|
|
1425
|
+
* 归一化横轴滚动配置。
|
|
1426
|
+
* 该配置只服务 X 轴类目过多的场景,不扩展 Y 轴滚动,避免 API 语义变复杂。
|
|
1427
|
+
*/
|
|
1428
|
+
function normalizeXAxisScrollConfig() {
|
|
1429
|
+
var xAxisScroll = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1430
|
+
var scrollConfig = xAxisScroll && colors._typeof(xAxisScroll) === 'object' ? xAxisScroll : {};
|
|
1431
|
+
return {
|
|
1432
|
+
enabled: scrollConfig.enabled === true,
|
|
1433
|
+
visibleCount: normalizePositiveInteger(scrollConfig.visibleCount, DEFAULT_X_AXIS_SCROLL_VISIBLE_COUNT),
|
|
1434
|
+
startPosition: scrollConfig.startPosition === 'start' ? 'start' : 'end',
|
|
1435
|
+
startIndex: normalizeStartIndex(scrollConfig.startIndex),
|
|
1436
|
+
showSlider: scrollConfig.showSlider !== false,
|
|
1437
|
+
inside: scrollConfig.inside !== false
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
/**
|
|
1442
|
+
* 归一化柱形背景配置。
|
|
1443
|
+
* 这里统一收敛开关、颜色数量和透明度范围,避免变体层重复兜底。
|
|
1444
|
+
*/
|
|
1445
|
+
function normalizeBarBackgroundConfig() {
|
|
1446
|
+
var barBackground = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1447
|
+
var config = barBackground && colors._typeof(barBackground) === 'object' ? barBackground : {};
|
|
1448
|
+
var opacity = Number(config.opacity);
|
|
1449
|
+
return colors._objectSpread2(colors._objectSpread2({}, DEFAULT_BAR_BACKGROUND), {}, {
|
|
1450
|
+
show: config.show === true,
|
|
1451
|
+
colors: Array.isArray(config.colors) ? config.colors.filter(Boolean).slice(0, 3) : [],
|
|
1452
|
+
opacity: Number.isFinite(opacity) ? Math.max(0, Math.min(1, opacity)) : 1
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
/**
|
|
1457
|
+
* 根据横轴类目数量生成 ECharts dataZoom。
|
|
1458
|
+
* 默认从末尾向前取 `visibleCount` 个类目,满足“最新数据优先展示”的看板诉求。
|
|
1459
|
+
*/
|
|
1460
|
+
function createXAxisScrollOption() {
|
|
1461
|
+
var categories = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1462
|
+
var xAxisScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1463
|
+
var scrollConfig = normalizeXAxisScrollConfig(xAxisScroll);
|
|
1464
|
+
var totalCount = Array.isArray(categories) ? categories.length : 0;
|
|
1465
|
+
if (!scrollConfig.enabled || totalCount <= scrollConfig.visibleCount) {
|
|
1466
|
+
return {};
|
|
1467
|
+
}
|
|
1468
|
+
var windowSize = Math.min(scrollConfig.visibleCount, totalCount);
|
|
1469
|
+
var maxStartIndex = totalCount - windowSize;
|
|
1470
|
+
var resolvedStartIndex = scrollConfig.startIndex !== null ? Math.min(scrollConfig.startIndex, maxStartIndex) : scrollConfig.startPosition === 'start' ? 0 : maxStartIndex;
|
|
1471
|
+
var start = toPercent(resolvedStartIndex, totalCount);
|
|
1472
|
+
var end = toPercent(resolvedStartIndex + windowSize, totalCount);
|
|
1473
|
+
var dataZoom = [];
|
|
1474
|
+
if (scrollConfig.showSlider) {
|
|
1475
|
+
dataZoom.push({
|
|
1476
|
+
type: 'slider',
|
|
1477
|
+
xAxisIndex: 0,
|
|
1478
|
+
start: start,
|
|
1479
|
+
end: end,
|
|
1480
|
+
height: 14,
|
|
1481
|
+
bottom: 8,
|
|
1482
|
+
brushSelect: false
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
if (scrollConfig.inside) {
|
|
1486
|
+
dataZoom.push({
|
|
1487
|
+
type: 'inside',
|
|
1488
|
+
xAxisIndex: 0,
|
|
1489
|
+
start: start,
|
|
1490
|
+
end: end,
|
|
1491
|
+
zoomLock: true
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
if (dataZoom.length === 0) {
|
|
1495
|
+
return {};
|
|
1496
|
+
}
|
|
1497
|
+
return colors._objectSpread2(colors._objectSpread2({}, scrollConfig.showSlider ? {
|
|
1498
|
+
grid: {
|
|
1499
|
+
bottom: DEFAULT_X_AXIS_SCROLL_GRID_BOTTOM
|
|
1500
|
+
}
|
|
1501
|
+
} : {}), {}, {
|
|
1502
|
+
dataZoom: dataZoom
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1127
1505
|
|
|
1128
1506
|
/**
|
|
1129
1507
|
* 构建 `BarLineChart` 最终 option。
|
|
@@ -1131,7 +1509,8 @@ function createBaseOption(normalizedInput) {
|
|
|
1131
1509
|
* 1. 输入归一化
|
|
1132
1510
|
* 2. preset 合并
|
|
1133
1511
|
* 3. 变体分发
|
|
1134
|
-
* 4.
|
|
1512
|
+
* 4. X 轴滚动配置合并
|
|
1513
|
+
* 5. customOption 覆盖
|
|
1135
1514
|
*/
|
|
1136
1515
|
function buildBarLineOption() {
|
|
1137
1516
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
@@ -1144,6 +1523,8 @@ function buildBarLineOption() {
|
|
|
1144
1523
|
variant = _ref$variant === void 0 ? 'flat' : _ref$variant,
|
|
1145
1524
|
barWidth = _ref.barWidth,
|
|
1146
1525
|
barGap = _ref.barGap,
|
|
1526
|
+
barBackground = _ref.barBackground,
|
|
1527
|
+
xAxisScroll = _ref.xAxisScroll,
|
|
1147
1528
|
customOption = _ref.customOption;
|
|
1148
1529
|
var normalizedInput = normalizeBarLineInput({
|
|
1149
1530
|
data: data,
|
|
@@ -1154,12 +1535,15 @@ function buildBarLineOption() {
|
|
|
1154
1535
|
var presetOption = getBarLinePreset(preset);
|
|
1155
1536
|
var resolvedVariant = resolveVariantName(variant);
|
|
1156
1537
|
var createVariantOption = variantFactory[resolvedVariant] || variantFactory[DEFAULT_VARIANT];
|
|
1538
|
+
var normalizedBarBackground = normalizeBarBackgroundConfig(barBackground);
|
|
1157
1539
|
var variantOption = createVariantOption(colors._objectSpread2(colors._objectSpread2({}, normalizedInput), {}, {
|
|
1158
1540
|
includeXAxis: false,
|
|
1159
1541
|
barWidth: barWidth,
|
|
1160
|
-
barGap: barGap
|
|
1542
|
+
barGap: barGap,
|
|
1543
|
+
barBackground: normalizedBarBackground
|
|
1161
1544
|
}));
|
|
1162
|
-
|
|
1545
|
+
var xAxisScrollOption = createXAxisScrollOption(normalizedInput.categories, xAxisScroll);
|
|
1546
|
+
return colors.mergeChartOption(colors.mergeChartOption(colors.mergeChartOption(baseOption, presetOption, variantOption), xAxisScrollOption), customOption);
|
|
1163
1547
|
}
|
|
1164
1548
|
|
|
1165
1549
|
//
|
|
@@ -1181,7 +1565,7 @@ function buildBarLineOption() {
|
|
|
1181
1565
|
* 这里显式注册柱图、折线图、自定义系列以及笛卡尔坐标系常用组件,
|
|
1182
1566
|
* 否则运行时虽然能生成 option,但对应主类型不会真正参与渲染。
|
|
1183
1567
|
*/
|
|
1184
|
-
echarts__namespace.use([charts.BarChart, charts.LineChart, charts.CustomChart, components.TooltipComponent, components.LegendComponent, components.GridComponent, components.TitleComponent, renderers.CanvasRenderer]);
|
|
1568
|
+
echarts__namespace.use([charts.BarChart, charts.LineChart, charts.CustomChart, components.TooltipComponent, components.LegendComponent, components.GridComponent, components.TitleComponent, components.DataZoomComponent, renderers.CanvasRenderer]);
|
|
1185
1569
|
var script = {
|
|
1186
1570
|
name: 'BarLineChart',
|
|
1187
1571
|
components: {
|
|
@@ -1258,6 +1642,17 @@ var script = {
|
|
|
1258
1642
|
type: [Number, String],
|
|
1259
1643
|
"default": 8
|
|
1260
1644
|
},
|
|
1645
|
+
/**
|
|
1646
|
+
* 柱形背景配置。
|
|
1647
|
+
* 仅对支持背景柱的柱系列生效,builder 会负责归一化 `show/colors/opacity`
|
|
1648
|
+
* 并交由具体变体决定最终渲染策略。
|
|
1649
|
+
*/
|
|
1650
|
+
barBackground: {
|
|
1651
|
+
type: Object,
|
|
1652
|
+
"default": function _default() {
|
|
1653
|
+
return {};
|
|
1654
|
+
}
|
|
1655
|
+
},
|
|
1261
1656
|
/**
|
|
1262
1657
|
* 额外透传给 ECharts option 的自定义配置。
|
|
1263
1658
|
* 会在 base / preset / variant option 合并完成后再覆盖。
|
|
@@ -1268,6 +1663,22 @@ var script = {
|
|
|
1268
1663
|
return {};
|
|
1269
1664
|
}
|
|
1270
1665
|
},
|
|
1666
|
+
/**
|
|
1667
|
+
* X 轴类目滚动配置。
|
|
1668
|
+
* 仅控制横轴,不扩展 Y 轴;适合月份、日期、地区等类目数量较多的看板场景。
|
|
1669
|
+
* 常用字段:
|
|
1670
|
+
* - enabled: 是否开启 X 轴滚动
|
|
1671
|
+
* - visibleCount: 初始窗口内展示的类目数量,默认按 8 个处理
|
|
1672
|
+
* - startPosition: 初始窗口位置,默认 end,即展示最新一段数据
|
|
1673
|
+
* - startIndex: 指定窗口起始索引;传入合法数字时优先级高于 startPosition
|
|
1674
|
+
* - showSlider / inside: 分别控制底部滚动条与图表内部滚轮/触控滚动
|
|
1675
|
+
*/
|
|
1676
|
+
xAxisScroll: {
|
|
1677
|
+
type: Object,
|
|
1678
|
+
"default": function _default() {
|
|
1679
|
+
return {};
|
|
1680
|
+
}
|
|
1681
|
+
},
|
|
1271
1682
|
/**
|
|
1272
1683
|
* 图表 loading 状态。
|
|
1273
1684
|
* 由 BaseChart 统一接管组件层遮罩式 loading UI。
|
|
@@ -1316,13 +1727,15 @@ var script = {
|
|
|
1316
1727
|
preset: this.preset,
|
|
1317
1728
|
barWidth: this.barWidth,
|
|
1318
1729
|
barGap: this.barGap,
|
|
1730
|
+
barBackground: this.barBackground,
|
|
1731
|
+
xAxisScroll: this.xAxisScroll,
|
|
1319
1732
|
customOption: this.customOption
|
|
1320
1733
|
});
|
|
1321
1734
|
}
|
|
1322
1735
|
}
|
|
1323
1736
|
};
|
|
1324
1737
|
|
|
1325
|
-
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";
|
|
1738
|
+
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";
|
|
1326
1739
|
withInstall.styleInject(css_248z);
|
|
1327
1740
|
|
|
1328
1741
|
/* script */
|
|
@@ -1356,7 +1769,7 @@ __vue_render__._withStripped = true;
|
|
|
1356
1769
|
/* style */
|
|
1357
1770
|
var __vue_inject_styles__ = undefined;
|
|
1358
1771
|
/* scoped */
|
|
1359
|
-
var __vue_scope_id__ = "data-v-
|
|
1772
|
+
var __vue_scope_id__ = "data-v-4e3be95d";
|
|
1360
1773
|
/* module identifier */
|
|
1361
1774
|
var __vue_module_identifier__ = undefined;
|
|
1362
1775
|
/* functional template */
|