From c1b67759765e420e09412dc0193ce06d471d626a Mon Sep 17 00:00:00 2001 From: plainheart Date: Sat, 28 May 2022 15:17:06 +0800 Subject: [PATCH 1/2] feat(pie): support specifying coordinate system for pie series. --- src/chart/pie/pieLayout.ts | 17 +- test/pie-coordinate-system.html | 376 ++++++++++++++++++++++++++++++++ 2 files changed, 391 insertions(+), 2 deletions(-) create mode 100644 test/pie-coordinate-system.html diff --git a/src/chart/pie/pieLayout.ts b/src/chart/pie/pieLayout.ts index 0598a779aa..0a6998c70c 100644 --- a/src/chart/pie/pieLayout.ts +++ b/src/chart/pie/pieLayout.ts @@ -53,10 +53,23 @@ export function getBasicPieLayout(seriesModel: PieSeriesModel, api: ExtensionAPI const width = parsePercent(viewRect.width, api.getWidth()); const height = parsePercent(viewRect.height, api.getHeight()); const size = Math.min(width, height); - const cx = parsePercent(center[0], width) + viewRect.x; - const cy = parsePercent(center[1], height) + viewRect.y; const r0 = parsePercent(radius[0], size / 2); const r = parsePercent(radius[1], size / 2); + + let cx: number; + let cy: number; + const coordSys = seriesModel.coordinateSystem; + if (coordSys) { + // percentage is not allowed when coordinate system is specified + const point = coordSys.dataToPoint(center); + cx = point[0] || 0; + cy = point[1] || 0; + } + else { + cx = parsePercent(center[0], width) + viewRect.x; + cy = parsePercent(center[1], height) + viewRect.y; + } + return { cx, cy, diff --git a/test/pie-coordinate-system.html b/test/pie-coordinate-system.html new file mode 100644 index 0000000000..95221bc4d1 --- /dev/null +++ b/test/pie-coordinate-system.html @@ -0,0 +1,376 @@ + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + From a6307826cfc17862c9ef533283c80dc06de0969f Mon Sep 17 00:00:00 2001 From: plainheart Date: Sat, 28 May 2022 16:16:15 +0800 Subject: [PATCH 2/2] feat(bmap): support `convertToPixel` & `convertFromPixel` API. --- extension-src/bmap/BMapCoordSys.ts | 14 ++++++++++++++ test/pie-coordinate-system.html | 13 +++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/extension-src/bmap/BMapCoordSys.ts b/extension-src/bmap/BMapCoordSys.ts index 79ec79f0f2..96f24de386 100644 --- a/extension-src/bmap/BMapCoordSys.ts +++ b/extension-src/bmap/BMapCoordSys.ts @@ -36,6 +36,8 @@ function BMapCoordSys(bmap, api) { this._projection = new BMap.MercatorProjection(); } +BMapCoordSys.prototype.type = 'bmap'; + BMapCoordSys.prototype.dimensions = ['lng', 'lat']; BMapCoordSys.prototype.setZoom = function (zoom) { @@ -107,6 +109,15 @@ BMapCoordSys.prototype.prepareCustoms = function () { }; }; +BMapCoordSys.prototype.convertToPixel = function (ecModel, finder, value) { + // here we ignore finder as only one bmap component is allowed + return this.dataToPoint(value); +}; + +BMapCoordSys.prototype.convertFromPixel = function (ecModel, finder, value) { + return this.pointToData(value); +}; + function dataToCoordSize(dataSize, dataItem) { dataItem = dataItem || [0, 0]; return zrUtil.map([0, 1], function (dimIdx) { @@ -229,6 +240,9 @@ BMapCoordSys.create = function (ecModel, api) { seriesModel.coordinateSystem = bmapCoordSys; } }); + + // return created coordinate systems + return bmapCoordSys && [bmapCoordSys]; }; export default BMapCoordSys; diff --git a/test/pie-coordinate-system.html b/test/pie-coordinate-system.html index 95221bc4d1..ad0703eddf 100644 --- a/test/pie-coordinate-system.html +++ b/test/pie-coordinate-system.html @@ -85,11 +85,16 @@ ] }; - testHelper.create(echarts, 'main0', { + var chart = testHelper.create(echarts, 'main0', { title: ['Pie series on BMap'], - option: option - }) - + option: option, + buttons: [{ + text: 'Convert point [120, 30] to pixel', + onclick: function () { + alert(chart.convertToPixel('bmap', [120, 30])); + } + }] + }); });