first commit

This commit is contained in:
jefferyzhao
2025-07-31 17:44:12 +08:00
commit b9bdc8598b
42390 changed files with 4467935 additions and 0 deletions

View File

@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var MarkerModel = require("./MarkerModel");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _default = MarkerModel.extend({
type: 'markArea',
defaultOption: {
zlevel: 0,
// PENDING
z: 1,
tooltip: {
trigger: 'item'
},
// markArea should fixed on the coordinate system
animation: false,
label: {
show: true,
position: 'top'
},
itemStyle: {
// color and borderColor default to use color from series
// color: 'auto'
// borderColor: 'auto'
borderWidth: 0
},
emphasis: {
label: {
show: true,
position: 'top'
}
}
}
});
module.exports = _default;

View File

@ -0,0 +1,357 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var zrUtil = require("zrender/lib/core/util");
var colorUtil = require("zrender/lib/tool/color");
var List = require("../../data/List");
var numberUtil = require("../../util/number");
var graphic = require("../../util/graphic");
var markerHelper = require("./markerHelper");
var MarkerView = require("./MarkerView");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// TODO Better on polar
var markAreaTransform = function (seriesModel, coordSys, maModel, item) {
var lt = markerHelper.dataTransform(seriesModel, item[0]);
var rb = markerHelper.dataTransform(seriesModel, item[1]);
var retrieve = zrUtil.retrieve; // FIXME make sure lt is less than rb
var ltCoord = lt.coord;
var rbCoord = rb.coord;
ltCoord[0] = retrieve(ltCoord[0], -Infinity);
ltCoord[1] = retrieve(ltCoord[1], -Infinity);
rbCoord[0] = retrieve(rbCoord[0], Infinity);
rbCoord[1] = retrieve(rbCoord[1], Infinity); // Merge option into one
var result = zrUtil.mergeAll([{}, lt, rb]);
result.coord = [lt.coord, rb.coord];
result.x0 = lt.x;
result.y0 = lt.y;
result.x1 = rb.x;
result.y1 = rb.y;
return result;
};
function isInifinity(val) {
return !isNaN(val) && !isFinite(val);
} // If a markArea has one dim
function ifMarkLineHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
var otherDimIndex = 1 - dimIndex;
return isInifinity(fromCoord[otherDimIndex]) && isInifinity(toCoord[otherDimIndex]);
}
function markAreaFilter(coordSys, item) {
var fromCoord = item.coord[0];
var toCoord = item.coord[1];
if (coordSys.type === 'cartesian2d') {
// In case
// {
// markArea: {
// data: [{ yAxis: 2 }]
// }
// }
if (fromCoord && toCoord && (ifMarkLineHasOnlyDim(1, fromCoord, toCoord, coordSys) || ifMarkLineHasOnlyDim(0, fromCoord, toCoord, coordSys))) {
return true;
}
}
return markerHelper.dataFilter(coordSys, {
coord: fromCoord,
x: item.x0,
y: item.y0
}) || markerHelper.dataFilter(coordSys, {
coord: toCoord,
x: item.x1,
y: item.y1
});
} // dims can be ['x0', 'y0'], ['x1', 'y1'], ['x0', 'y1'], ['x1', 'y0']
function getSingleMarkerEndPoint(data, idx, dims, seriesModel, api) {
var coordSys = seriesModel.coordinateSystem;
var itemModel = data.getItemModel(idx);
var point;
var xPx = numberUtil.parsePercent(itemModel.get(dims[0]), api.getWidth());
var yPx = numberUtil.parsePercent(itemModel.get(dims[1]), api.getHeight());
if (!isNaN(xPx) && !isNaN(yPx)) {
point = [xPx, yPx];
} else {
// Chart like bar may have there own marker positioning logic
if (seriesModel.getMarkerPosition) {
// Use the getMarkerPoisition
point = seriesModel.getMarkerPosition(data.getValues(dims, idx));
} else {
var x = data.get(dims[0], idx);
var y = data.get(dims[1], idx);
var pt = [x, y];
coordSys.clampData && coordSys.clampData(pt, pt);
point = coordSys.dataToPoint(pt, true);
}
if (coordSys.type === 'cartesian2d') {
var xAxis = coordSys.getAxis('x');
var yAxis = coordSys.getAxis('y');
var x = data.get(dims[0], idx);
var y = data.get(dims[1], idx);
if (isInifinity(x)) {
point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[dims[0] === 'x0' ? 0 : 1]);
} else if (isInifinity(y)) {
point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[dims[1] === 'y0' ? 0 : 1]);
}
} // Use x, y if has any
if (!isNaN(xPx)) {
point[0] = xPx;
}
if (!isNaN(yPx)) {
point[1] = yPx;
}
}
return point;
}
var dimPermutations = [['x0', 'y0'], ['x1', 'y0'], ['x1', 'y1'], ['x0', 'y1']];
MarkerView.extend({
type: 'markArea',
// updateLayout: function (markAreaModel, ecModel, api) {
// ecModel.eachSeries(function (seriesModel) {
// var maModel = seriesModel.markAreaModel;
// if (maModel) {
// var areaData = maModel.getData();
// areaData.each(function (idx) {
// var points = zrUtil.map(dimPermutations, function (dim) {
// return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
// });
// // Layout
// areaData.setItemLayout(idx, points);
// var el = areaData.getItemGraphicEl(idx);
// el.setShape('points', points);
// });
// }
// }, this);
// },
updateTransform: function (markAreaModel, ecModel, api) {
ecModel.eachSeries(function (seriesModel) {
var maModel = seriesModel.markAreaModel;
if (maModel) {
var areaData = maModel.getData();
areaData.each(function (idx) {
var points = zrUtil.map(dimPermutations, function (dim) {
return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
}); // Layout
areaData.setItemLayout(idx, points);
var el = areaData.getItemGraphicEl(idx);
el.setShape('points', points);
});
}
}, this);
},
renderSeries: function (seriesModel, maModel, ecModel, api) {
var coordSys = seriesModel.coordinateSystem;
var seriesId = seriesModel.id;
var seriesData = seriesModel.getData();
var areaGroupMap = this.markerGroupMap;
var polygonGroup = areaGroupMap.get(seriesId) || areaGroupMap.set(seriesId, {
group: new graphic.Group()
});
this.group.add(polygonGroup.group);
polygonGroup.__keep = true;
var areaData = createList(coordSys, seriesModel, maModel); // Line data for tooltip and formatter
maModel.setData(areaData); // Update visual and layout of line
areaData.each(function (idx) {
// Layout
var points = zrUtil.map(dimPermutations, function (dim) {
return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
}); // If none of the area is inside coordSys, allClipped is set to be true
// in layout so that label will not be displayed. See #12591
var allClipped = true;
zrUtil.each(dimPermutations, function (dim) {
if (!allClipped) {
return;
}
var xValue = areaData.get(dim[0], idx);
var yValue = areaData.get(dim[1], idx); // If is infinity, the axis should be considered not clipped
if ((isInifinity(xValue) || coordSys.getAxis('x').containData(xValue)) && (isInifinity(yValue) || coordSys.getAxis('y').containData(yValue))) {
allClipped = false;
}
});
areaData.setItemLayout(idx, {
points: points,
allClipped: allClipped
}); // Visual
areaData.setItemVisual(idx, {
color: seriesData.getVisual('color')
});
});
areaData.diff(polygonGroup.__data).add(function (idx) {
var layout = areaData.getItemLayout(idx);
if (!layout.allClipped) {
var polygon = new graphic.Polygon({
shape: {
points: layout.points
}
});
areaData.setItemGraphicEl(idx, polygon);
polygonGroup.group.add(polygon);
}
}).update(function (newIdx, oldIdx) {
var polygon = polygonGroup.__data.getItemGraphicEl(oldIdx);
var layout = areaData.getItemLayout(newIdx);
if (!layout.allClipped) {
if (polygon) {
graphic.updateProps(polygon, {
shape: {
points: layout.points
}
}, maModel, newIdx);
} else {
polygon = new graphic.Polygon({
shape: {
points: layout.points
}
});
}
areaData.setItemGraphicEl(newIdx, polygon);
polygonGroup.group.add(polygon);
} else if (polygon) {
polygonGroup.group.remove(polygon);
}
}).remove(function (idx) {
var polygon = polygonGroup.__data.getItemGraphicEl(idx);
polygonGroup.group.remove(polygon);
}).execute();
areaData.eachItemGraphicEl(function (polygon, idx) {
var itemModel = areaData.getItemModel(idx);
var labelModel = itemModel.getModel('label');
var labelHoverModel = itemModel.getModel('emphasis.label');
var color = areaData.getItemVisual(idx, 'color');
polygon.useStyle(zrUtil.defaults(itemModel.getModel('itemStyle').getItemStyle(), {
fill: colorUtil.modifyAlpha(color, 0.4),
stroke: color
}));
polygon.hoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
graphic.setLabelStyle(polygon.style, polygon.hoverStyle, labelModel, labelHoverModel, {
labelFetcher: maModel,
labelDataIndex: idx,
defaultText: areaData.getName(idx) || '',
isRectText: true,
autoColor: color
});
graphic.setHoverStyle(polygon, {});
polygon.dataModel = maModel;
});
polygonGroup.__data = areaData;
polygonGroup.group.silent = maModel.get('silent') || seriesModel.get('silent');
}
});
/**
* @inner
* @param {module:echarts/coord/*} coordSys
* @param {module:echarts/model/Series} seriesModel
* @param {module:echarts/model/Model} mpModel
*/
function createList(coordSys, seriesModel, maModel) {
var coordDimsInfos;
var areaData;
var dims = ['x0', 'y0', 'x1', 'y1'];
if (coordSys) {
coordDimsInfos = zrUtil.map(coordSys && coordSys.dimensions, function (coordDim) {
var data = seriesModel.getData();
var info = data.getDimensionInfo(data.mapDimension(coordDim)) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
return zrUtil.defaults({
name: coordDim
}, info);
});
areaData = new List(zrUtil.map(dims, function (dim, idx) {
return {
name: dim,
type: coordDimsInfos[idx % 2].type
};
}), maModel);
} else {
coordDimsInfos = [{
name: 'value',
type: 'float'
}];
areaData = new List(coordDimsInfos, maModel);
}
var optData = zrUtil.map(maModel.get('data'), zrUtil.curry(markAreaTransform, seriesModel, coordSys, maModel));
if (coordSys) {
optData = zrUtil.filter(optData, zrUtil.curry(markAreaFilter, coordSys));
}
var dimValueGetter = coordSys ? function (item, dimName, dataIndex, dimIndex) {
return item.coord[Math.floor(dimIndex / 2)][dimIndex % 2];
} : function (item) {
return item.value;
};
areaData.initData(optData, null, dimValueGetter);
areaData.hasItemOption = true;
return areaData;
}

View File

@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var MarkerModel = require("./MarkerModel");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _default = MarkerModel.extend({
type: 'markLine',
defaultOption: {
zlevel: 0,
z: 5,
symbol: ['circle', 'arrow'],
symbolSize: [8, 16],
//symbolRotate: 0,
precision: 2,
tooltip: {
trigger: 'item'
},
label: {
show: true,
position: 'end',
distance: 5
},
lineStyle: {
type: 'dashed'
},
emphasis: {
label: {
show: true
},
lineStyle: {
width: 3
}
},
animationEasing: 'linear'
}
});
module.exports = _default;

View File

@ -0,0 +1,369 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var zrUtil = require("zrender/lib/core/util");
var List = require("../../data/List");
var numberUtil = require("../../util/number");
var markerHelper = require("./markerHelper");
var LineDraw = require("../../chart/helper/LineDraw");
var MarkerView = require("./MarkerView");
var _dataStackHelper = require("../../data/helper/dataStackHelper");
var getStackedDimension = _dataStackHelper.getStackedDimension;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var markLineTransform = function (seriesModel, coordSys, mlModel, item) {
var data = seriesModel.getData(); // Special type markLine like 'min', 'max', 'average', 'median'
var mlType = item.type;
if (!zrUtil.isArray(item) && (mlType === 'min' || mlType === 'max' || mlType === 'average' || mlType === 'median' // In case
// data: [{
// yAxis: 10
// }]
|| item.xAxis != null || item.yAxis != null)) {
var valueAxis;
var value;
if (item.yAxis != null || item.xAxis != null) {
valueAxis = coordSys.getAxis(item.yAxis != null ? 'y' : 'x');
value = zrUtil.retrieve(item.yAxis, item.xAxis);
} else {
var axisInfo = markerHelper.getAxisInfo(item, data, coordSys, seriesModel);
valueAxis = axisInfo.valueAxis;
var valueDataDim = getStackedDimension(data, axisInfo.valueDataDim);
value = markerHelper.numCalculate(data, valueDataDim, mlType);
}
var valueIndex = valueAxis.dim === 'x' ? 0 : 1;
var baseIndex = 1 - valueIndex;
var mlFrom = zrUtil.clone(item);
var mlTo = {};
mlFrom.type = null;
mlFrom.coord = [];
mlTo.coord = [];
mlFrom.coord[baseIndex] = -Infinity;
mlTo.coord[baseIndex] = Infinity;
var precision = mlModel.get('precision');
if (precision >= 0 && typeof value === 'number') {
value = +value.toFixed(Math.min(precision, 20));
}
mlFrom.coord[valueIndex] = mlTo.coord[valueIndex] = value;
item = [mlFrom, mlTo, {
// Extra option for tooltip and label
type: mlType,
valueIndex: item.valueIndex,
// Force to use the value of calculated value.
value: value
}];
}
item = [markerHelper.dataTransform(seriesModel, item[0]), markerHelper.dataTransform(seriesModel, item[1]), zrUtil.extend({}, item[2])]; // Avoid line data type is extended by from(to) data type
item[2].type = item[2].type || ''; // Merge from option and to option into line option
zrUtil.merge(item[2], item[0]);
zrUtil.merge(item[2], item[1]);
return item;
};
function isInifinity(val) {
return !isNaN(val) && !isFinite(val);
} // If a markLine has one dim
function ifMarkLineHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
var otherDimIndex = 1 - dimIndex;
var dimName = coordSys.dimensions[dimIndex];
return isInifinity(fromCoord[otherDimIndex]) && isInifinity(toCoord[otherDimIndex]) && fromCoord[dimIndex] === toCoord[dimIndex] && coordSys.getAxis(dimName).containData(fromCoord[dimIndex]);
}
function markLineFilter(coordSys, item) {
if (coordSys.type === 'cartesian2d') {
var fromCoord = item[0].coord;
var toCoord = item[1].coord; // In case
// {
// markLine: {
// data: [{ yAxis: 2 }]
// }
// }
if (fromCoord && toCoord && (ifMarkLineHasOnlyDim(1, fromCoord, toCoord, coordSys) || ifMarkLineHasOnlyDim(0, fromCoord, toCoord, coordSys))) {
return true;
}
}
return markerHelper.dataFilter(coordSys, item[0]) && markerHelper.dataFilter(coordSys, item[1]);
}
function updateSingleMarkerEndLayout(data, idx, isFrom, seriesModel, api) {
var coordSys = seriesModel.coordinateSystem;
var itemModel = data.getItemModel(idx);
var point;
var xPx = numberUtil.parsePercent(itemModel.get('x'), api.getWidth());
var yPx = numberUtil.parsePercent(itemModel.get('y'), api.getHeight());
if (!isNaN(xPx) && !isNaN(yPx)) {
point = [xPx, yPx];
} else {
// Chart like bar may have there own marker positioning logic
if (seriesModel.getMarkerPosition) {
// Use the getMarkerPoisition
point = seriesModel.getMarkerPosition(data.getValues(data.dimensions, idx));
} else {
var dims = coordSys.dimensions;
var x = data.get(dims[0], idx);
var y = data.get(dims[1], idx);
point = coordSys.dataToPoint([x, y]);
} // Expand line to the edge of grid if value on one axis is Inifnity
// In case
// markLine: {
// data: [{
// yAxis: 2
// // or
// type: 'average'
// }]
// }
if (coordSys.type === 'cartesian2d') {
var xAxis = coordSys.getAxis('x');
var yAxis = coordSys.getAxis('y');
var dims = coordSys.dimensions;
if (isInifinity(data.get(dims[0], idx))) {
point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[isFrom ? 0 : 1]);
} else if (isInifinity(data.get(dims[1], idx))) {
point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[isFrom ? 0 : 1]);
}
} // Use x, y if has any
if (!isNaN(xPx)) {
point[0] = xPx;
}
if (!isNaN(yPx)) {
point[1] = yPx;
}
}
data.setItemLayout(idx, point);
}
var _default = MarkerView.extend({
type: 'markLine',
// updateLayout: function (markLineModel, ecModel, api) {
// ecModel.eachSeries(function (seriesModel) {
// var mlModel = seriesModel.markLineModel;
// if (mlModel) {
// var mlData = mlModel.getData();
// var fromData = mlModel.__from;
// var toData = mlModel.__to;
// // Update visual and layout of from symbol and to symbol
// fromData.each(function (idx) {
// updateSingleMarkerEndLayout(fromData, idx, true, seriesModel, api);
// updateSingleMarkerEndLayout(toData, idx, false, seriesModel, api);
// });
// // Update layout of line
// mlData.each(function (idx) {
// mlData.setItemLayout(idx, [
// fromData.getItemLayout(idx),
// toData.getItemLayout(idx)
// ]);
// });
// this.markerGroupMap.get(seriesModel.id).updateLayout();
// }
// }, this);
// },
updateTransform: function (markLineModel, ecModel, api) {
ecModel.eachSeries(function (seriesModel) {
var mlModel = seriesModel.markLineModel;
if (mlModel) {
var mlData = mlModel.getData();
var fromData = mlModel.__from;
var toData = mlModel.__to; // Update visual and layout of from symbol and to symbol
fromData.each(function (idx) {
updateSingleMarkerEndLayout(fromData, idx, true, seriesModel, api);
updateSingleMarkerEndLayout(toData, idx, false, seriesModel, api);
}); // Update layout of line
mlData.each(function (idx) {
mlData.setItemLayout(idx, [fromData.getItemLayout(idx), toData.getItemLayout(idx)]);
});
this.markerGroupMap.get(seriesModel.id).updateLayout();
}
}, this);
},
renderSeries: function (seriesModel, mlModel, ecModel, api) {
var coordSys = seriesModel.coordinateSystem;
var seriesId = seriesModel.id;
var seriesData = seriesModel.getData();
var lineDrawMap = this.markerGroupMap;
var lineDraw = lineDrawMap.get(seriesId) || lineDrawMap.set(seriesId, new LineDraw());
this.group.add(lineDraw.group);
var mlData = createList(coordSys, seriesModel, mlModel);
var fromData = mlData.from;
var toData = mlData.to;
var lineData = mlData.line;
mlModel.__from = fromData;
mlModel.__to = toData; // Line data for tooltip and formatter
mlModel.setData(lineData);
var symbolType = mlModel.get('symbol');
var symbolSize = mlModel.get('symbolSize');
if (!zrUtil.isArray(symbolType)) {
symbolType = [symbolType, symbolType];
}
if (typeof symbolSize === 'number') {
symbolSize = [symbolSize, symbolSize];
} // Update visual and layout of from symbol and to symbol
mlData.from.each(function (idx) {
updateDataVisualAndLayout(fromData, idx, true);
updateDataVisualAndLayout(toData, idx, false);
}); // Update visual and layout of line
lineData.each(function (idx) {
var lineColor = lineData.getItemModel(idx).get('lineStyle.color');
lineData.setItemVisual(idx, {
color: lineColor || fromData.getItemVisual(idx, 'color')
});
lineData.setItemLayout(idx, [fromData.getItemLayout(idx), toData.getItemLayout(idx)]);
lineData.setItemVisual(idx, {
'fromSymbolRotate': fromData.getItemVisual(idx, 'symbolRotate'),
'fromSymbolSize': fromData.getItemVisual(idx, 'symbolSize'),
'fromSymbol': fromData.getItemVisual(idx, 'symbol'),
'toSymbolRotate': toData.getItemVisual(idx, 'symbolRotate'),
'toSymbolSize': toData.getItemVisual(idx, 'symbolSize'),
'toSymbol': toData.getItemVisual(idx, 'symbol')
});
});
lineDraw.updateData(lineData); // Set host model for tooltip
// FIXME
mlData.line.eachItemGraphicEl(function (el, idx) {
el.traverse(function (child) {
child.dataModel = mlModel;
});
});
function updateDataVisualAndLayout(data, idx, isFrom) {
var itemModel = data.getItemModel(idx);
updateSingleMarkerEndLayout(data, idx, isFrom, seriesModel, api);
data.setItemVisual(idx, {
symbolRotate: itemModel.get('symbolRotate'),
symbolSize: itemModel.get('symbolSize') || symbolSize[isFrom ? 0 : 1],
symbol: itemModel.get('symbol', true) || symbolType[isFrom ? 0 : 1],
color: itemModel.get('itemStyle.color') || seriesData.getVisual('color')
});
}
lineDraw.__keep = true;
lineDraw.group.silent = mlModel.get('silent') || seriesModel.get('silent');
}
});
/**
* @inner
* @param {module:echarts/coord/*} coordSys
* @param {module:echarts/model/Series} seriesModel
* @param {module:echarts/model/Model} mpModel
*/
function createList(coordSys, seriesModel, mlModel) {
var coordDimsInfos;
if (coordSys) {
coordDimsInfos = zrUtil.map(coordSys && coordSys.dimensions, function (coordDim) {
var info = seriesModel.getData().getDimensionInfo(seriesModel.getData().mapDimension(coordDim)) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
return zrUtil.defaults({
name: coordDim
}, info);
});
} else {
coordDimsInfos = [{
name: 'value',
type: 'float'
}];
}
var fromData = new List(coordDimsInfos, mlModel);
var toData = new List(coordDimsInfos, mlModel); // No dimensions
var lineData = new List([], mlModel);
var optData = zrUtil.map(mlModel.get('data'), zrUtil.curry(markLineTransform, seriesModel, coordSys, mlModel));
if (coordSys) {
optData = zrUtil.filter(optData, zrUtil.curry(markLineFilter, coordSys));
}
var dimValueGetter = coordSys ? markerHelper.dimValueGetter : function (item) {
return item.value;
};
fromData.initData(zrUtil.map(optData, function (item) {
return item[0];
}), null, dimValueGetter);
toData.initData(zrUtil.map(optData, function (item) {
return item[1];
}), null, dimValueGetter);
lineData.initData(zrUtil.map(optData, function (item) {
return item[2];
}));
lineData.hasItemOption = true;
return {
from: fromData,
to: toData,
line: lineData
};
}
module.exports = _default;

View File

@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var MarkerModel = require("./MarkerModel");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _default = MarkerModel.extend({
type: 'markPoint',
defaultOption: {
zlevel: 0,
z: 5,
symbol: 'pin',
symbolSize: 50,
//symbolRotate: 0,
//symbolOffset: [0, 0]
tooltip: {
trigger: 'item'
},
label: {
show: true,
position: 'inside'
},
itemStyle: {
borderWidth: 2
},
emphasis: {
label: {
show: true
}
}
}
});
module.exports = _default;

View File

@ -0,0 +1,202 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var zrUtil = require("zrender/lib/core/util");
var SymbolDraw = require("../../chart/helper/SymbolDraw");
var numberUtil = require("../../util/number");
var List = require("../../data/List");
var markerHelper = require("./markerHelper");
var MarkerView = require("./MarkerView");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
function updateMarkerLayout(mpData, seriesModel, api) {
var coordSys = seriesModel.coordinateSystem;
mpData.each(function (idx) {
var itemModel = mpData.getItemModel(idx);
var point;
var xPx = numberUtil.parsePercent(itemModel.get('x'), api.getWidth());
var yPx = numberUtil.parsePercent(itemModel.get('y'), api.getHeight());
if (!isNaN(xPx) && !isNaN(yPx)) {
point = [xPx, yPx];
} // Chart like bar may have there own marker positioning logic
else if (seriesModel.getMarkerPosition) {
// Use the getMarkerPoisition
point = seriesModel.getMarkerPosition(mpData.getValues(mpData.dimensions, idx));
} else if (coordSys) {
var x = mpData.get(coordSys.dimensions[0], idx);
var y = mpData.get(coordSys.dimensions[1], idx);
point = coordSys.dataToPoint([x, y]);
} // Use x, y if has any
if (!isNaN(xPx)) {
point[0] = xPx;
}
if (!isNaN(yPx)) {
point[1] = yPx;
}
mpData.setItemLayout(idx, point);
});
}
var _default = MarkerView.extend({
type: 'markPoint',
// updateLayout: function (markPointModel, ecModel, api) {
// ecModel.eachSeries(function (seriesModel) {
// var mpModel = seriesModel.markPointModel;
// if (mpModel) {
// updateMarkerLayout(mpModel.getData(), seriesModel, api);
// this.markerGroupMap.get(seriesModel.id).updateLayout(mpModel);
// }
// }, this);
// },
updateTransform: function (markPointModel, ecModel, api) {
ecModel.eachSeries(function (seriesModel) {
var mpModel = seriesModel.markPointModel;
if (mpModel) {
updateMarkerLayout(mpModel.getData(), seriesModel, api);
this.markerGroupMap.get(seriesModel.id).updateLayout(mpModel);
}
}, this);
},
renderSeries: function (seriesModel, mpModel, ecModel, api) {
var coordSys = seriesModel.coordinateSystem;
var seriesId = seriesModel.id;
var seriesData = seriesModel.getData();
var symbolDrawMap = this.markerGroupMap;
var symbolDraw = symbolDrawMap.get(seriesId) || symbolDrawMap.set(seriesId, new SymbolDraw());
var mpData = createList(coordSys, seriesModel, mpModel); // FIXME
mpModel.setData(mpData);
updateMarkerLayout(mpModel.getData(), seriesModel, api);
mpData.each(function (idx) {
var itemModel = mpData.getItemModel(idx);
var symbol = itemModel.getShallow('symbol');
var symbolSize = itemModel.getShallow('symbolSize');
var symbolRotate = itemModel.getShallow('symbolRotate');
var isFnSymbol = zrUtil.isFunction(symbol);
var isFnSymbolSize = zrUtil.isFunction(symbolSize);
var isFnSymbolRotate = zrUtil.isFunction(symbolRotate);
if (isFnSymbol || isFnSymbolSize || isFnSymbolRotate) {
var rawIdx = mpModel.getRawValue(idx);
var dataParams = mpModel.getDataParams(idx);
if (isFnSymbol) {
symbol = symbol(rawIdx, dataParams);
}
if (isFnSymbolSize) {
// FIXME 这里不兼容 ECharts 2.x2.x 貌似参数是整个数据?
symbolSize = symbolSize(rawIdx, dataParams);
}
if (isFnSymbolRotate) {
symbolRotate = symbolRotate(rawIdx, dataParams);
}
}
mpData.setItemVisual(idx, {
symbol: symbol,
symbolSize: symbolSize,
symbolRotate: symbolRotate,
color: itemModel.get('itemStyle.color') || seriesData.getVisual('color')
});
}); // TODO Text are wrong
symbolDraw.updateData(mpData);
this.group.add(symbolDraw.group); // Set host model for tooltip
// FIXME
mpData.eachItemGraphicEl(function (el) {
el.traverse(function (child) {
child.dataModel = mpModel;
});
});
symbolDraw.__keep = true;
symbolDraw.group.silent = mpModel.get('silent') || seriesModel.get('silent');
}
});
/**
* @inner
* @param {module:echarts/coord/*} [coordSys]
* @param {module:echarts/model/Series} seriesModel
* @param {module:echarts/model/Model} mpModel
*/
function createList(coordSys, seriesModel, mpModel) {
var coordDimsInfos;
if (coordSys) {
coordDimsInfos = zrUtil.map(coordSys && coordSys.dimensions, function (coordDim) {
var info = seriesModel.getData().getDimensionInfo(seriesModel.getData().mapDimension(coordDim)) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
return zrUtil.defaults({
name: coordDim
}, info);
});
} else {
coordDimsInfos = [{
name: 'value',
type: 'float'
}];
}
var mpData = new List(coordDimsInfos, mpModel);
var dataOpt = zrUtil.map(mpModel.get('data'), zrUtil.curry(markerHelper.dataTransform, seriesModel));
if (coordSys) {
dataOpt = zrUtil.filter(dataOpt, zrUtil.curry(markerHelper.dataFilter, coordSys));
}
mpData.initData(dataOpt, null, coordSys ? markerHelper.dimValueGetter : function (item) {
return item.value;
});
return mpData;
}
module.exports = _default;

View File

@ -0,0 +1,174 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _config = require("../../config");
var __DEV__ = _config.__DEV__;
var echarts = require("../../echarts");
var zrUtil = require("zrender/lib/core/util");
var env = require("zrender/lib/core/env");
var modelUtil = require("../../util/model");
var formatUtil = require("../../util/format");
var dataFormatMixin = require("../../model/mixin/dataFormat");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var addCommas = formatUtil.addCommas;
var encodeHTML = formatUtil.encodeHTML;
function fillLabel(opt) {
modelUtil.defaultEmphasis(opt, 'label', ['show']);
}
var MarkerModel = echarts.extendComponentModel({
type: 'marker',
dependencies: ['series', 'grid', 'polar', 'geo'],
/**
* @overrite
*/
init: function (option, parentModel, ecModel) {
this.mergeDefaultAndTheme(option, ecModel);
this._mergeOption(option, ecModel, false, true);
},
/**
* @return {boolean}
*/
isAnimationEnabled: function () {
if (env.node) {
return false;
}
var hostSeries = this.__hostSeries;
return this.getShallow('animation') && hostSeries && hostSeries.isAnimationEnabled();
},
/**
* @overrite
*/
mergeOption: function (newOpt, ecModel) {
this._mergeOption(newOpt, ecModel, false, false);
},
_mergeOption: function (newOpt, ecModel, createdBySelf, isInit) {
var MarkerModel = this.constructor;
var modelPropName = this.mainType + 'Model';
if (!createdBySelf) {
ecModel.eachSeries(function (seriesModel) {
var markerOpt = seriesModel.get(this.mainType, true);
var markerModel = seriesModel[modelPropName];
if (!markerOpt || !markerOpt.data) {
seriesModel[modelPropName] = null;
return;
}
if (!markerModel) {
if (isInit) {
// Default label emphasis `position` and `show`
fillLabel(markerOpt);
}
zrUtil.each(markerOpt.data, function (item) {
// FIXME Overwrite fillLabel method ?
if (item instanceof Array) {
fillLabel(item[0]);
fillLabel(item[1]);
} else {
fillLabel(item);
}
});
markerModel = new MarkerModel(markerOpt, this, ecModel);
zrUtil.extend(markerModel, {
mainType: this.mainType,
// Use the same series index and name
seriesIndex: seriesModel.seriesIndex,
name: seriesModel.name,
createdBySelf: true
});
markerModel.__hostSeries = seriesModel;
} else {
markerModel._mergeOption(markerOpt, ecModel, true);
}
seriesModel[modelPropName] = markerModel;
}, this);
}
},
formatTooltip: function (dataIndex, multipleSeries, dataType, renderMode) {
var data = this.getData();
var value = this.getRawValue(dataIndex);
var formattedValue = zrUtil.isArray(value) ? zrUtil.map(value, addCommas).join(', ') : addCommas(value);
var name = data.getName(dataIndex);
var html = encodeHTML(this.name);
var newLine = renderMode === 'html' ? '<br/>' : '\n';
if (value != null || name) {
html += newLine;
}
if (name) {
html += encodeHTML(name);
if (value != null) {
html += ' : ';
}
}
if (value != null) {
html += encodeHTML(formattedValue);
}
return html;
},
getData: function () {
return this._data;
},
setData: function (data) {
this._data = data;
}
});
zrUtil.mixin(MarkerModel, dataFormatMixin);
var _default = MarkerModel;
module.exports = _default;

View File

@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var echarts = require("../../echarts");
var zrUtil = require("zrender/lib/core/util");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _default = echarts.extendComponentView({
type: 'marker',
init: function () {
/**
* Markline grouped by series
* @private
* @type {module:zrender/core/util.HashMap}
*/
this.markerGroupMap = zrUtil.createHashMap();
},
render: function (markerModel, ecModel, api) {
var markerGroupMap = this.markerGroupMap;
markerGroupMap.each(function (item) {
item.__keep = false;
});
var markerModelKey = this.type + 'Model';
ecModel.eachSeries(function (seriesModel) {
var markerModel = seriesModel[markerModelKey];
markerModel && this.renderSeries(seriesModel, markerModel, ecModel, api);
}, this);
markerGroupMap.each(function (item) {
!item.__keep && this.group.remove(item.group);
}, this);
},
renderSeries: function () {}
});
module.exports = _default;

View File

@ -0,0 +1,254 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var zrUtil = require("zrender/lib/core/util");
var numberUtil = require("../../util/number");
var _dataStackHelper = require("../../data/helper/dataStackHelper");
var isDimensionStacked = _dataStackHelper.isDimensionStacked;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var indexOf = zrUtil.indexOf;
function hasXOrY(item) {
return !(isNaN(parseFloat(item.x)) && isNaN(parseFloat(item.y)));
}
function hasXAndY(item) {
return !isNaN(parseFloat(item.x)) && !isNaN(parseFloat(item.y));
} // Make it simple, do not visit all stacked value to count precision.
// function getPrecision(data, valueAxisDim, dataIndex) {
// var precision = -1;
// var stackedDim = data.mapDimension(valueAxisDim);
// do {
// precision = Math.max(
// numberUtil.getPrecision(data.get(stackedDim, dataIndex)),
// precision
// );
// var stackedOnSeries = data.getCalculationInfo('stackedOnSeries');
// if (stackedOnSeries) {
// var byValue = data.get(data.getCalculationInfo('stackedByDimension'), dataIndex);
// data = stackedOnSeries.getData();
// dataIndex = data.indexOf(data.getCalculationInfo('stackedByDimension'), byValue);
// stackedDim = data.getCalculationInfo('stackedDimension');
// }
// else {
// data = null;
// }
// } while (data);
// return precision;
// }
function markerTypeCalculatorWithExtent(mlType, data, otherDataDim, targetDataDim, otherCoordIndex, targetCoordIndex) {
var coordArr = [];
var stacked = isDimensionStacked(data, targetDataDim
/*, otherDataDim*/
);
var calcDataDim = stacked ? data.getCalculationInfo('stackResultDimension') : targetDataDim;
var value = numCalculate(data, calcDataDim, mlType);
var dataIndex = data.indicesOfNearest(calcDataDim, value)[0];
coordArr[otherCoordIndex] = data.get(otherDataDim, dataIndex);
coordArr[targetCoordIndex] = data.get(calcDataDim, dataIndex);
var coordArrValue = data.get(targetDataDim, dataIndex); // Make it simple, do not visit all stacked value to count precision.
var precision = numberUtil.getPrecision(data.get(targetDataDim, dataIndex));
precision = Math.min(precision, 20);
if (precision >= 0) {
coordArr[targetCoordIndex] = +coordArr[targetCoordIndex].toFixed(precision);
}
return [coordArr, coordArrValue];
}
var curry = zrUtil.curry; // TODO Specified percent
var markerTypeCalculator = {
/**
* @method
* @param {module:echarts/data/List} data
* @param {string} baseAxisDim
* @param {string} valueAxisDim
*/
min: curry(markerTypeCalculatorWithExtent, 'min'),
/**
* @method
* @param {module:echarts/data/List} data
* @param {string} baseAxisDim
* @param {string} valueAxisDim
*/
max: curry(markerTypeCalculatorWithExtent, 'max'),
/**
* @method
* @param {module:echarts/data/List} data
* @param {string} baseAxisDim
* @param {string} valueAxisDim
*/
average: curry(markerTypeCalculatorWithExtent, 'average')
};
/**
* Transform markPoint data item to format used in List by do the following
* 1. Calculate statistic like `max`, `min`, `average`
* 2. Convert `item.xAxis`, `item.yAxis` to `item.coord` array
* @param {module:echarts/model/Series} seriesModel
* @param {module:echarts/coord/*} [coordSys]
* @param {Object} item
* @return {Object}
*/
function dataTransform(seriesModel, item) {
var data = seriesModel.getData();
var coordSys = seriesModel.coordinateSystem; // 1. If not specify the position with pixel directly
// 2. If `coord` is not a data array. Which uses `xAxis`,
// `yAxis` to specify the coord on each dimension
// parseFloat first because item.x and item.y can be percent string like '20%'
if (item && !hasXAndY(item) && !zrUtil.isArray(item.coord) && coordSys) {
var dims = coordSys.dimensions;
var axisInfo = getAxisInfo(item, data, coordSys, seriesModel); // Clone the option
// Transform the properties xAxis, yAxis, radiusAxis, angleAxis, geoCoord to value
item = zrUtil.clone(item);
if (item.type && markerTypeCalculator[item.type] && axisInfo.baseAxis && axisInfo.valueAxis) {
var otherCoordIndex = indexOf(dims, axisInfo.baseAxis.dim);
var targetCoordIndex = indexOf(dims, axisInfo.valueAxis.dim);
var coordInfo = markerTypeCalculator[item.type](data, axisInfo.baseDataDim, axisInfo.valueDataDim, otherCoordIndex, targetCoordIndex);
item.coord = coordInfo[0]; // Force to use the value of calculated value.
// let item use the value without stack.
item.value = coordInfo[1];
} else {
// FIXME Only has one of xAxis and yAxis.
var coord = [item.xAxis != null ? item.xAxis : item.radiusAxis, item.yAxis != null ? item.yAxis : item.angleAxis]; // Each coord support max, min, average
for (var i = 0; i < 2; i++) {
if (markerTypeCalculator[coord[i]]) {
coord[i] = numCalculate(data, data.mapDimension(dims[i]), coord[i]);
}
}
item.coord = coord;
}
}
return item;
}
function getAxisInfo(item, data, coordSys, seriesModel) {
var ret = {};
if (item.valueIndex != null || item.valueDim != null) {
ret.valueDataDim = item.valueIndex != null ? data.getDimension(item.valueIndex) : item.valueDim;
ret.valueAxis = coordSys.getAxis(dataDimToCoordDim(seriesModel, ret.valueDataDim));
ret.baseAxis = coordSys.getOtherAxis(ret.valueAxis);
ret.baseDataDim = data.mapDimension(ret.baseAxis.dim);
} else {
ret.baseAxis = seriesModel.getBaseAxis();
ret.valueAxis = coordSys.getOtherAxis(ret.baseAxis);
ret.baseDataDim = data.mapDimension(ret.baseAxis.dim);
ret.valueDataDim = data.mapDimension(ret.valueAxis.dim);
}
return ret;
}
function dataDimToCoordDim(seriesModel, dataDim) {
var data = seriesModel.getData();
var dimensions = data.dimensions;
dataDim = data.getDimension(dataDim);
for (var i = 0; i < dimensions.length; i++) {
var dimItem = data.getDimensionInfo(dimensions[i]);
if (dimItem.name === dataDim) {
return dimItem.coordDim;
}
}
}
/**
* Filter data which is out of coordinateSystem range
* [dataFilter description]
* @param {module:echarts/coord/*} [coordSys]
* @param {Object} item
* @return {boolean}
*/
function dataFilter(coordSys, item) {
// Alwalys return true if there is no coordSys
return coordSys && coordSys.containData && item.coord && !hasXOrY(item) ? coordSys.containData(item.coord) : true;
}
function dimValueGetter(item, dimName, dataIndex, dimIndex) {
// x, y, radius, angle
if (dimIndex < 2) {
return item.coord && item.coord[dimIndex];
}
return item.value;
}
function numCalculate(data, valueDataDim, type) {
if (type === 'average') {
var sum = 0;
var count = 0;
data.each(valueDataDim, function (val, idx) {
if (!isNaN(val)) {
sum += val;
count++;
}
});
return sum / count;
} else if (type === 'median') {
return data.getMedian(valueDataDim);
} else {
// max & min
return data.getDataExtent(valueDataDim, true)[type === 'max' ? 1 : 0];
}
}
exports.dataTransform = dataTransform;
exports.getAxisInfo = getAxisInfo;
exports.dataFilter = dataFilter;
exports.dimValueGetter = dimValueGetter;
exports.numCalculate = numCalculate;