You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by su...@apache.org on 2019/05/29 16:23:21 UTC
[incubator-echarts] 01/01: Fix commit 244d0b9 . See #10481 .
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch fix/symbol-function
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit c7da80ac651d325bd184167facb2a8109d3ca340
Author: sushuang <su...@gmail.com>
AuthorDate: Thu May 30 00:22:14 2019 +0800
Fix commit 244d0b9 . See #10481 .
---
src/component/marker/MarkPointView.js | 26 ++++++++++++++++----------
src/util/symbol.js | 6 +-----
src/visual/symbol.js | 30 +++++++++++++++++-------------
test/symbol2.html | 29 ++++++++++++++++++++++++++---
4 files changed, 60 insertions(+), 31 deletions(-)
diff --git a/src/component/marker/MarkPointView.js b/src/component/marker/MarkPointView.js
index d95b6f2..2edd302 100644
--- a/src/component/marker/MarkPointView.js
+++ b/src/component/marker/MarkPointView.js
@@ -103,21 +103,27 @@ export default MarkerView.extend({
mpData.each(function (idx) {
var itemModel = mpData.getItemModel(idx);
var symbol = itemModel.getShallow('symbol');
- if (typeof symbol === 'function') {
- symbol = symbol(mpModel.getRawValue(idx), mpModel.getDataParams(idx));
- }
var symbolSize = itemModel.getShallow('symbolSize');
- if (typeof symbolSize === 'function') {
- // FIXME 这里不兼容 ECharts 2.x,2.x 貌似参数是整个数据?
- symbolSize = symbolSize(
- mpModel.getRawValue(idx), mpModel.getDataParams(idx)
- );
+ var isFnSymbol = zrUtil.isFunction(symbol);
+ var isFnSymbolSize = zrUtil.isFunction(symbolSize);
+
+ if (isFnSymbol || isFnSymbolSize) {
+ var rawIdx = mpModel.getRawValue(idx);
+ var dataParams = mpModel.getDataParams(idx);
+ if (isFnSymbol) {
+ symbol = symbol(rawIdx, dataParams);
+ }
+ if (isFnSymbolSize) {
+ // FIXME 这里不兼容 ECharts 2.x,2.x 貌似参数是整个数据?
+ symbolSize = symbolSize(rawIdx, dataParams);
+ }
}
+
mpData.setItemVisual(idx, {
+ symbol: symbol,
symbolSize: symbolSize,
color: itemModel.get('itemStyle.color')
- || seriesData.getVisual('color'),
- symbol: symbol
+ || seriesData.getVisual('color')
});
});
diff --git a/src/util/symbol.js b/src/util/symbol.js
index 54c4e7e..0df28c2 100644
--- a/src/util/symbol.js
+++ b/src/util/symbol.js
@@ -332,15 +332,11 @@ function symbolPathSetColor(color, innerColor) {
export function createSymbol(symbolType, x, y, w, h, color, keepAspect) {
// TODO Support image object, DynamicImage.
- var isFunction = typeof symbolType === 'function'
- if (isFunction) {
- symbolType = symbolType();
- }
- var symbolPath;
var isEmpty = symbolType.indexOf('empty') === 0;
if (isEmpty) {
symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
}
+ var symbolPath;
if (symbolType.indexOf('image://') === 0) {
symbolPath = graphic.makeImage(
diff --git a/src/visual/symbol.js b/src/visual/symbol.js
index f868baf..8cd7e06 100644
--- a/src/visual/symbol.js
+++ b/src/visual/symbol.js
@@ -17,6 +17,7 @@
* under the License.
*/
+import {isFunction} from 'zrender/src/core/util';
export default function (seriesType, defaultSymbolType, legendSymbol) {
// Encoding visual for all series include which is filtered for legend drawing
@@ -33,10 +34,20 @@ export default function (seriesType, defaultSymbolType, legendSymbol) {
var symbolSize = seriesModel.get('symbolSize');
var keepAspect = seriesModel.get('symbolKeepAspect');
+ var hasSymbolTypeCallback = isFunction(symbolType);
+ var hasSymbolSizeCallback = isFunction(symbolSize);
+ var hasCallback = hasSymbolTypeCallback || hasSymbolSizeCallback;
+ var seriesSymbol = (!hasSymbolTypeCallback && symbolType) ? symbolType : defaultSymbolType;
+ var seriesSymbolSize = !hasSymbolSizeCallback ? symbolSize : null;
+
data.setVisual({
- legendSymbol: legendSymbol || symbolType || defaultSymbolType,
- symbol: symbolType || defaultSymbolType,
- symbolSize: symbolSize,
+ legendSymbol: legendSymbol || seriesSymbol,
+ // If seting callback functions on `symbol` or `symbolSize`, for simplicity and avoiding
+ // to bring trouble, we do not pick a reuslt from one of its calling on data item here,
+ // but just use the default value. Callback on `symbol` or `symbolSize` is convenient in
+ // some cases but generally it is not recommanded.
+ symbol: seriesSymbol,
+ symbolSize: seriesSymbolSize,
symbolKeepAspect: keepAspect
});
@@ -45,10 +56,6 @@ export default function (seriesType, defaultSymbolType, legendSymbol) {
return;
}
- var hasSymbolTypeCallback = typeof symbolType === 'function';
- var hasSymbolSizeCallback = typeof symbolSize === 'function';
- var hasCallback = hasSymbolTypeCallback || hasSymbolSizeCallback;
-
function dataEach(data, idx) {
if (hasCallback) {
var rawValue = seriesModel.getRawValue(idx);
@@ -60,10 +67,8 @@ export default function (seriesType, defaultSymbolType, legendSymbol) {
if (data.hasItemOption) {
var itemModel = data.getItemModel(idx);
var itemSymbolType = itemModel.getShallow('symbol', true);
- var itemSymbolSize = itemModel.getShallow('symbolSize',
- true);
- var itemSymbolKeepAspect =
- itemModel.getShallow('symbolKeepAspect', true);
+ var itemSymbolSize = itemModel.getShallow('symbolSize', true);
+ var itemSymbolKeepAspect = itemModel.getShallow('symbolKeepAspect', true);
// If has item symbol
if (itemSymbolType != null) {
@@ -74,8 +79,7 @@ export default function (seriesType, defaultSymbolType, legendSymbol) {
data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
}
if (itemSymbolKeepAspect != null) {
- data.setItemVisual(idx, 'symbolKeepAspect',
- itemSymbolKeepAspect);
+ data.setItemVisual(idx, 'symbolKeepAspect', itemSymbolKeepAspect);
}
}
}
diff --git a/test/symbol2.html b/test/symbol2.html
index 2f545e4..f55a9f1 100644
--- a/test/symbol2.html
+++ b/test/symbol2.html
@@ -101,7 +101,10 @@ under the License.
var option = {
xAxis: {},
yAxis: {},
+ legend: {},
series: [{
+ name: 'aa',
+ type: 'scatter',
symbolSize: 30,
symbol: function (rawValue, params) {
return ['rect', 'diamond', 'circle'][params.dataIndex];
@@ -116,13 +119,33 @@ under the License.
[10.0, 8.04],
[8.0, 6.95],
[13.0, 7.58]
- ],
- type: 'scatter'
+ ]
+ }, {
+ name: 'bb',
+ type: 'scatter',
+ markPoint: {
+ data: [{
+ type: 'min',
+ symbol: function () {
+ return 'diamond';
+ },
+ symbolSize: function () {
+ return 50;
+ }
+ }]
+ },
+ data: [
+ [10, 3]
+ ]
}]
};
var chart = testHelper.create(echarts, 'main1', {
- title: 'symbol function make it display 0: "rect", 1: "diamond", 2: "circle"',
+ title: [
+ 'symbol function make it display 0: "rect", 1: "diamond", 2: "circle"',
+ 'legend should be displayed',
+ 'diamond markPoint should be displayed'
+ ],
option: option
});
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org