@visactor/vchart-extension 2.1.0-alpha.9 → 2.1.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/build/index.js +124 -29
- package/build/index.min.js +2 -2
- package/cjs/charts/3d/layout.d.ts +2 -1
- package/cjs/charts/3d/layout.js.map +1 -1
- package/cjs/charts/image-cloud/series/image-cloud.d.ts +1 -1
- package/cjs/charts/pictogram/series/pictogram.d.ts +9 -2
- package/cjs/charts/pictogram/series/pictogram.js +55 -15
- package/cjs/charts/pictogram/series/pictogram.js.map +1 -1
- package/cjs/charts/pictogram/series/svg-source.d.ts +12 -2
- package/cjs/charts/pictogram/series/svg-source.js +27 -3
- package/cjs/charts/pictogram/series/svg-source.js.map +1 -1
- package/cjs/components/bar-regression-line/index.js +6 -3
- package/cjs/components/bar-regression-line/index.js.map +1 -1
- package/cjs/components/histogram-regression-line/index.js +6 -3
- package/cjs/components/histogram-regression-line/index.js.map +1 -1
- package/cjs/components/map-label/layout.d.ts +2 -1
- package/cjs/components/map-label/layout.js.map +1 -1
- package/cjs/components/map-label/map-label.d.ts +5 -4
- package/cjs/components/map-label/map-label.js.map +1 -1
- package/cjs/components/scatter-regression-line/index.js +6 -3
- package/cjs/components/scatter-regression-line/index.js.map +1 -1
- package/esm/charts/3d/layout.d.ts +2 -1
- package/esm/charts/3d/layout.js.map +1 -1
- package/esm/charts/image-cloud/series/image-cloud.d.ts +1 -1
- package/esm/charts/pictogram/series/pictogram.d.ts +9 -2
- package/esm/charts/pictogram/series/pictogram.js +57 -17
- package/esm/charts/pictogram/series/pictogram.js.map +1 -1
- package/esm/charts/pictogram/series/svg-source.d.ts +12 -2
- package/esm/charts/pictogram/series/svg-source.js +25 -1
- package/esm/charts/pictogram/series/svg-source.js.map +1 -1
- package/esm/components/bar-regression-line/index.js +5 -2
- package/esm/components/bar-regression-line/index.js.map +1 -1
- package/esm/components/histogram-regression-line/index.js +5 -2
- package/esm/components/histogram-regression-line/index.js.map +1 -1
- package/esm/components/map-label/layout.d.ts +2 -1
- package/esm/components/map-label/layout.js.map +1 -1
- package/esm/components/map-label/map-label.d.ts +5 -4
- package/esm/components/map-label/map-label.js.map +1 -1
- package/esm/components/scatter-regression-line/index.js +5 -2
- package/esm/components/scatter-regression-line/index.js.map +1 -1
- package/package.json +7 -7
package/build/index.js
CHANGED
|
@@ -4167,7 +4167,9 @@
|
|
|
4167
4167
|
}
|
|
4168
4168
|
|
|
4169
4169
|
const svgSourceMap = new Map();
|
|
4170
|
+
const SVG_VIEWPORT_RECT_KEY = '_vchartViewportRect';
|
|
4170
4171
|
let svgDataSet;
|
|
4172
|
+
const numberReg = /-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/gi;
|
|
4171
4173
|
function initSVGDataSet() {
|
|
4172
4174
|
if (svgDataSet) {
|
|
4173
4175
|
return;
|
|
@@ -4175,6 +4177,28 @@
|
|
|
4175
4177
|
svgDataSet = new vchart.DataSet();
|
|
4176
4178
|
vchart.registerDataSetInstanceParser(svgDataSet, 'svg', vchart.svgParser);
|
|
4177
4179
|
}
|
|
4180
|
+
function parseEnableBackgroundViewport(source) {
|
|
4181
|
+
var _a, _b, _c, _d;
|
|
4182
|
+
const svgStartTag = (_a = source.match(/<svg\b[\s\S]*?>/i)) === null || _a === void 0 ? void 0 : _a[0];
|
|
4183
|
+
const enableBackground = (_b = svgStartTag === null || svgStartTag === void 0 ? void 0 : svgStartTag.match(/\benable-background\s*=\s*(['"])(.*?)\1/i)) === null || _b === void 0 ? void 0 : _b[2];
|
|
4184
|
+
if (!enableBackground || !/^\s*new\b/i.test(enableBackground)) {
|
|
4185
|
+
return null;
|
|
4186
|
+
}
|
|
4187
|
+
const values = (_d = (_c = enableBackground.match(numberReg)) === null || _c === void 0 ? void 0 : _c.map(Number)) !== null && _d !== void 0 ? _d : [];
|
|
4188
|
+
const [x, y, width, height] = values;
|
|
4189
|
+
if (!Number.isFinite(x) ||
|
|
4190
|
+
!Number.isFinite(y) ||
|
|
4191
|
+
!Number.isFinite(width) ||
|
|
4192
|
+
!Number.isFinite(height) ||
|
|
4193
|
+
width <= 0 ||
|
|
4194
|
+
height <= 0) {
|
|
4195
|
+
return null;
|
|
4196
|
+
}
|
|
4197
|
+
return { x, y, width, height };
|
|
4198
|
+
}
|
|
4199
|
+
function hasValidSize(parsedSvg) {
|
|
4200
|
+
return (Number.isFinite(parsedSvg.width) && Number.isFinite(parsedSvg.height) && parsedSvg.width > 0 && parsedSvg.height > 0);
|
|
4201
|
+
}
|
|
4178
4202
|
function registerSVGSource(key, source) {
|
|
4179
4203
|
if (svgSourceMap.has(key)) {
|
|
4180
4204
|
vchart.warn(`svg source key of '${key}' already exists, will be overwritten.`);
|
|
@@ -4184,6 +4208,11 @@
|
|
|
4184
4208
|
dataView.parse(source, {
|
|
4185
4209
|
type: 'svg'
|
|
4186
4210
|
});
|
|
4211
|
+
const parsedSvg = dataView.latestData;
|
|
4212
|
+
const viewportRect = parseEnableBackgroundViewport(source);
|
|
4213
|
+
if (parsedSvg && viewportRect && !parsedSvg.viewBoxRect && !hasValidSize(parsedSvg)) {
|
|
4214
|
+
parsedSvg[SVG_VIEWPORT_RECT_KEY] = viewportRect;
|
|
4215
|
+
}
|
|
4187
4216
|
svgSourceMap.set(key, dataView);
|
|
4188
4217
|
}
|
|
4189
4218
|
function unregisterSVGSource(key) {
|
|
@@ -4595,19 +4624,18 @@
|
|
|
4595
4624
|
}, vchart.STATE_VALUE_ENUM.STATE_NORMAL, vchart.AttributeLevel.Series);
|
|
4596
4625
|
}
|
|
4597
4626
|
initMarkStyle() {
|
|
4598
|
-
const { root
|
|
4627
|
+
const { root } = this._parsedSvgResult;
|
|
4628
|
+
const svgViewportRect = this._getSvgViewportRect();
|
|
4599
4629
|
const elements = this._mapViewData.getDataView().latestData;
|
|
4600
4630
|
if (root) {
|
|
4601
4631
|
this.setMarkStyle(this._pictogramMark, graphicAttributeTransform.group(root.attributes), 'normal', vchart.AttributeLevel.Built_In);
|
|
4602
|
-
|
|
4603
|
-
this.
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
}
|
|
4607
|
-
if (viewBoxRect) {
|
|
4632
|
+
this.setMarkStyle(this._pictogramMark, {
|
|
4633
|
+
postMatrix: () => this._getFittedSvgRootMatrix()
|
|
4634
|
+
}, 'normal', vchart.AttributeLevel.Built_In);
|
|
4635
|
+
if (svgViewportRect) {
|
|
4608
4636
|
this._pictogramMark.setMarkConfig({
|
|
4609
4637
|
clip: true,
|
|
4610
|
-
clipPath: [vchart.createRect(Object.assign(Object.assign({},
|
|
4638
|
+
clipPath: [vchart.createRect(Object.assign(Object.assign({}, svgViewportRect), { fill: true }))]
|
|
4611
4639
|
});
|
|
4612
4640
|
}
|
|
4613
4641
|
}
|
|
@@ -4694,6 +4722,71 @@
|
|
|
4694
4722
|
getPictogramRootGraphic() {
|
|
4695
4723
|
return this._pictogramMark.getProduct();
|
|
4696
4724
|
}
|
|
4725
|
+
_getSvgRootMatrix() {
|
|
4726
|
+
var _a, _b;
|
|
4727
|
+
const transform = (_b = (_a = this._parsedSvgResult) === null || _a === void 0 ? void 0 : _a.root) === null || _b === void 0 ? void 0 : _b.transform;
|
|
4728
|
+
return transform
|
|
4729
|
+
? new vchart.Matrix(transform.a, transform.b, transform.c, transform.d, transform.e, transform.f)
|
|
4730
|
+
: new vchart.Matrix();
|
|
4731
|
+
}
|
|
4732
|
+
_getSvgViewportRect() {
|
|
4733
|
+
var _a, _b, _c, _d;
|
|
4734
|
+
const viewBoxRect = (_a = this._parsedSvgResult) === null || _a === void 0 ? void 0 : _a.viewBoxRect;
|
|
4735
|
+
if (viewBoxRect) {
|
|
4736
|
+
return viewBoxRect;
|
|
4737
|
+
}
|
|
4738
|
+
const { width, height } = (_b = this._parsedSvgResult) !== null && _b !== void 0 ? _b : {};
|
|
4739
|
+
if (Number.isFinite(width) && Number.isFinite(height) && width > 0 && height > 0) {
|
|
4740
|
+
return {
|
|
4741
|
+
x: 0,
|
|
4742
|
+
y: 0,
|
|
4743
|
+
width,
|
|
4744
|
+
height
|
|
4745
|
+
};
|
|
4746
|
+
}
|
|
4747
|
+
return (_d = (_c = this._parsedSvgResult) === null || _c === void 0 ? void 0 : _c[SVG_VIEWPORT_RECT_KEY]) !== null && _d !== void 0 ? _d : null;
|
|
4748
|
+
}
|
|
4749
|
+
_getSvgRootBounds(rootMatrix) {
|
|
4750
|
+
const viewBoxRect = this._getSvgViewportRect();
|
|
4751
|
+
if (!viewBoxRect) {
|
|
4752
|
+
return null;
|
|
4753
|
+
}
|
|
4754
|
+
const bounds = new vchart.Bounds().setValue(viewBoxRect.x, viewBoxRect.y, viewBoxRect.x + viewBoxRect.width, viewBoxRect.y + viewBoxRect.height);
|
|
4755
|
+
bounds.transformWithMatrix(rootMatrix);
|
|
4756
|
+
return bounds;
|
|
4757
|
+
}
|
|
4758
|
+
_appendMatrixScale(matrix, scale, center) {
|
|
4759
|
+
const nextMatrix = new vchart.Matrix();
|
|
4760
|
+
nextMatrix.translate(center.x, center.y);
|
|
4761
|
+
nextMatrix.scale(scale, scale);
|
|
4762
|
+
nextMatrix.translate(-center.x, -center.y);
|
|
4763
|
+
nextMatrix.multiply(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f);
|
|
4764
|
+
return nextMatrix;
|
|
4765
|
+
}
|
|
4766
|
+
_appendMatrixTranslate(matrix, dx, dy) {
|
|
4767
|
+
const nextMatrix = new vchart.Matrix();
|
|
4768
|
+
nextMatrix.translate(dx, dy);
|
|
4769
|
+
nextMatrix.multiply(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f);
|
|
4770
|
+
return nextMatrix;
|
|
4771
|
+
}
|
|
4772
|
+
_getFittedSvgRootMatrix() {
|
|
4773
|
+
const rootMatrix = this._getSvgRootMatrix();
|
|
4774
|
+
const bounds = this._getSvgRootBounds(rootMatrix);
|
|
4775
|
+
if (!bounds) {
|
|
4776
|
+
return rootMatrix;
|
|
4777
|
+
}
|
|
4778
|
+
const width = bounds.width();
|
|
4779
|
+
const height = bounds.height();
|
|
4780
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) {
|
|
4781
|
+
return rootMatrix;
|
|
4782
|
+
}
|
|
4783
|
+
const { width: regionWidth, height: regionHeight } = this.getLayoutRect();
|
|
4784
|
+
const rootCenterX = (bounds.x1 + bounds.x2) / 2;
|
|
4785
|
+
const rootCenterY = (bounds.y1 + bounds.y2) / 2;
|
|
4786
|
+
const scale = Math.min(regionWidth / width, regionHeight / height);
|
|
4787
|
+
const scaledMatrix = this._appendMatrixScale(rootMatrix, scale, { x: rootCenterX, y: rootCenterY });
|
|
4788
|
+
return this._appendMatrixTranslate(scaledMatrix, regionWidth / 2 - rootCenterX, regionHeight / 2 - rootCenterY);
|
|
4789
|
+
}
|
|
4697
4790
|
initData() {
|
|
4698
4791
|
var _a, _b;
|
|
4699
4792
|
super.initData();
|
|
@@ -4747,29 +4840,15 @@
|
|
|
4747
4840
|
(_a = this._mapViewData) === null || _a === void 0 ? void 0 : _a.getDataView().reRunAllTransform();
|
|
4748
4841
|
}
|
|
4749
4842
|
updateSVGSize() {
|
|
4750
|
-
const { width: regionWidth, height: regionHeight } = this.getLayoutRect();
|
|
4751
|
-
const regionCenterX = regionWidth / 2;
|
|
4752
|
-
const regionCenterY = regionHeight / 2;
|
|
4753
4843
|
const root = this.getPictogramRootGraphic();
|
|
4754
4844
|
if (root) {
|
|
4755
|
-
|
|
4756
|
-
const { x1, x2, y1, y2 } = root.AABBBounds;
|
|
4757
|
-
const width = bounds.width();
|
|
4758
|
-
const height = bounds.height();
|
|
4759
|
-
const rootCenterX = (x1 + x2) / 2;
|
|
4760
|
-
const rootCenterY = (y1 + y2) / 2;
|
|
4761
|
-
const scaleX = regionWidth / width;
|
|
4762
|
-
const scaleY = regionHeight / height;
|
|
4763
|
-
const scale = Math.min(scaleX, scaleY);
|
|
4764
|
-
root.scale(scale, scale, { x: rootCenterX, y: rootCenterY });
|
|
4765
|
-
root.translate(regionCenterX - rootCenterX, regionCenterY - rootCenterY);
|
|
4845
|
+
root.setAttributes({ postMatrix: this._getFittedSvgRootMatrix() });
|
|
4766
4846
|
}
|
|
4767
4847
|
}
|
|
4768
4848
|
initEvent() {
|
|
4769
4849
|
var _a;
|
|
4770
4850
|
super.initEvent();
|
|
4771
4851
|
(_a = this._mapViewData.getDataView()) === null || _a === void 0 ? void 0 : _a.target.addListener('change', this.mapViewDataUpdate.bind(this));
|
|
4772
|
-
this.event.on(vchart.ChartEvent.afterMarkLayoutEnd, this.updateSVGSize.bind(this));
|
|
4773
4852
|
}
|
|
4774
4853
|
handleZoom(e) {
|
|
4775
4854
|
const { scale, scaleCenter } = e;
|
|
@@ -7627,10 +7706,15 @@
|
|
|
7627
7706
|
};
|
|
7628
7707
|
}
|
|
7629
7708
|
function appendScatterRegressionLineConfig(chartSpec, spec) {
|
|
7630
|
-
var _a
|
|
7709
|
+
var _a;
|
|
7631
7710
|
if (!spec) {
|
|
7711
|
+
const seriesSpecs = Array.isArray(chartSpec.series)
|
|
7712
|
+
? chartSpec.series
|
|
7713
|
+
: chartSpec.series
|
|
7714
|
+
? [chartSpec.series]
|
|
7715
|
+
: [];
|
|
7632
7716
|
spec =
|
|
7633
|
-
(_a = vchart.get(chartSpec, REGRESSION_LINE)) !== null && _a !== void 0 ? _a : vchart.get(
|
|
7717
|
+
(_a = vchart.get(chartSpec, REGRESSION_LINE)) !== null && _a !== void 0 ? _a : vchart.get(seriesSpecs.find((s) => s.type === vchart.SeriesTypeEnum.scatter), REGRESSION_LINE);
|
|
7634
7718
|
}
|
|
7635
7719
|
const specs = vchart.array(spec);
|
|
7636
7720
|
specs.forEach((s) => {
|
|
@@ -7706,10 +7790,15 @@
|
|
|
7706
7790
|
};
|
|
7707
7791
|
}
|
|
7708
7792
|
function appendBarRegressionLineConfig(chartSpec, spec) {
|
|
7709
|
-
var _a
|
|
7793
|
+
var _a;
|
|
7710
7794
|
if (!spec) {
|
|
7795
|
+
const seriesSpecs = Array.isArray(chartSpec.series)
|
|
7796
|
+
? chartSpec.series
|
|
7797
|
+
: chartSpec.series
|
|
7798
|
+
? [chartSpec.series]
|
|
7799
|
+
: [];
|
|
7711
7800
|
spec =
|
|
7712
|
-
(_a = vchart.get(chartSpec, REGRESSION_LINE)) !== null && _a !== void 0 ? _a : vchart.get(
|
|
7801
|
+
(_a = vchart.get(chartSpec, REGRESSION_LINE)) !== null && _a !== void 0 ? _a : vchart.get(seriesSpecs.find((s) => s.type === vchart.SeriesTypeEnum.bar), REGRESSION_LINE);
|
|
7713
7802
|
}
|
|
7714
7803
|
const specs = vchart.array(spec);
|
|
7715
7804
|
specs.forEach((s) => {
|
|
@@ -7796,10 +7885,15 @@
|
|
|
7796
7885
|
};
|
|
7797
7886
|
}
|
|
7798
7887
|
function appendHistogramRegressionLineConfig(chartSpec, spec) {
|
|
7799
|
-
var _a
|
|
7888
|
+
var _a;
|
|
7800
7889
|
if (!spec) {
|
|
7890
|
+
const seriesSpecs = Array.isArray(chartSpec.series)
|
|
7891
|
+
? chartSpec.series
|
|
7892
|
+
: chartSpec.series
|
|
7893
|
+
? [chartSpec.series]
|
|
7894
|
+
: [];
|
|
7801
7895
|
spec =
|
|
7802
|
-
(_a = vchart.get(chartSpec, REGRESSION_LINE)) !== null && _a !== void 0 ? _a : vchart.get(
|
|
7896
|
+
(_a = vchart.get(chartSpec, REGRESSION_LINE)) !== null && _a !== void 0 ? _a : vchart.get(seriesSpecs.find((s) => s.type === vchart.SeriesTypeEnum.bar), REGRESSION_LINE);
|
|
7803
7897
|
}
|
|
7804
7898
|
const specs = vchart.array(spec);
|
|
7805
7899
|
specs.forEach((s) => {
|
|
@@ -7956,6 +8050,7 @@
|
|
|
7956
8050
|
exports.RankingList = RankingList;
|
|
7957
8051
|
exports.RegressionLine = RegressionLine;
|
|
7958
8052
|
exports.SERIES_BREAK = SERIES_BREAK;
|
|
8053
|
+
exports.SVG_VIEWPORT_RECT_KEY = SVG_VIEWPORT_RECT_KEY;
|
|
7959
8054
|
exports.SequenceScatterKDE = SequenceScatterKDE;
|
|
7960
8055
|
exports.SequenceScatterLink = SequenceScatterLink;
|
|
7961
8056
|
exports.SequenceScatterPixel = SequenceScatterPixel;
|