提交 bc0cc601 编写于 作者: P pah100

Merge branch 'master' of https://github.com/ecomfe/echarts

......@@ -4,6 +4,8 @@ define(function (require) {
var List = require('../../data/List');
var zrUtil = require('zrender/core/util');
var modelUtil = require('../../util/model');
var Model = require('../../model/Model');
var createGraphFromNodeEdge = require('../helper/createGraphFromNodeEdge');
......@@ -19,24 +21,37 @@ define(function (require) {
return this._categoriesData;
};
this.fillDataTextStyle(option.edges || option.links);
this._updateCategoriesData();
this._updateEdgeDataModel();
},
mergeOption: function (option) {
GraphSeries.superApply(this, 'mergeOption', arguments);
this.fillDataTextStyle(option.edges || option.links);
this._updateCategoriesData();
this._updateEdgeDataModel();
},
mergeDefaultAndTheme: function (option) {
GraphSeries.superApply(this, 'mergeDefaultAndTheme', arguments);
modelUtil.defaultEmphasis(option.edgeLabel, modelUtil.LABEL_OPTIONS);
},
getInitialData: function (option, ecModel) {
var edges = option.edges || option.links;
var nodes = option.data || option.nodes;
if (nodes && edges) {
var graph = createGraphFromNodeEdge(nodes, edges, this, true);
var list = graph.data;
var nodeData = graph.data;
var edgeData = graph.edgeData;
var self = this;
// Overwrite list.getItemModel to
list.wrapMethod('getItemModel', function (model) {
// Overwrite nodeData.getItemModel to
nodeData.wrapMethod('getItemModel', function (model) {
var categoriesModels = self._categoriesModels;
var categoryIdx = model.getShallow('category');
var categoryModel = categoriesModels[categoryIdx];
......@@ -46,7 +61,29 @@ define(function (require) {
}
return model;
});
return list;
var edgeLabelModel = this.getModel('edgeLabel');
var wrappedGetEdgeModel = function (path, parentModel) {
var pathArr = (path || '').split('.');
if (pathArr[0] === 'label') {
parentModel = parentModel
|| edgeLabelModel.getModel(pathArr.slice(1));
}
var model = Model.prototype.getModel.call(this, pathArr, parentModel);
model.getModel = wrappedGetEdgeModel;
return model;
};
edgeData.wrapMethod('getItemModel', function (model) {
// FIXME Wrap get method ?
model.getModel = wrappedGetEdgeModel;
return model;
});
// Set edge data again to ensure the backup data has the wrapped method
// FIXME
graph.setEdgeData(edgeData);
return nodeData;
}
},
......@@ -69,6 +106,10 @@ define(function (require) {
return this.getGraph().edgeData;
},
getEdgeDataModel: function () {
return this._edgeDataModel;
},
/**
* @return {module:echarts/data/List}
*/
......@@ -76,6 +117,25 @@ define(function (require) {
return this._categoriesData;
},
_updateEdgeDataModel: function () {
var graph = this.getGraph();
var edgeData = this.getEdgeData();
var data = this.getData();
this._edgeDataModel = modelUtil.createDataFormatModel(edgeData, this);
this._edgeDataModel.formatTooltip = function (dataIndex) {
var params = this.getDataParams(dataIndex);
var edge = graph.getEdgeByIndex(dataIndex);
var sourceName = data.getName(edge.node1.dataIndex);
var targetName = data.getName(edge.node2.dataIndex);
var html = sourceName + ' > ' + targetName;
if (params.value) {
html += ' : ' + params.value;
}
return html;
};
},
_updateCategoriesData: function () {
var categories = zrUtil.map(this.option.categories || [], function (category) {
// Data must has value
......@@ -136,6 +196,13 @@ define(function (require) {
symbol: 'circle',
symbolSize: 10,
edgeSymbol: ['none', 'none'],
edgeSymbolSize: 10,
edgeLabel: {
normal: {},
emphasis: {}
},
draggable: false,
roam: false,
......@@ -159,7 +226,8 @@ define(function (require) {
label: {
normal: {
show: false
show: false,
formatter: '{b}'
},
emphasis: {
show: true
......
......@@ -44,32 +44,15 @@ define(function (require) {
symbolDraw.updateData(data);
var edgeData = data.graph.edgeData;
var formatModel = modelUtil.createDataFormatModel(seriesModel, edgeData);
formatModel.formatTooltip = function (dataIndex) {
var params = this.getDataParams(dataIndex);
var edge = data.graph.getEdgeByIndex(dataIndex);
var sourceName = data.getName(edge.node1.dataIndex);
var targetName = data.getName(edge.node2.dataIndex);
var html = sourceName + ' > ' + targetName;
if (params.value) {
html += ' : ' + params.value;
}
return html;
};
var edgeData = seriesModel.getEdgeData();
lineDraw.updateData(edgeData, null, null);
lineDraw.updateData(edgeData);
edgeData.eachItemGraphicEl(function (el) {
el.traverse(function (child) {
child.dataModel = formatModel;
child.dataModel = seriesModel.getEdgeDataModel();
});
});
// Save the original lineWidth
// data.graph.eachEdge(function (edge) {
// edge.__lineWidth = edge.getModel('lineStyle.normal').get('width');
// });
var group = this.group;
var groupNewProp = {
position: coordSys.position,
......@@ -186,7 +169,6 @@ define(function (require) {
var nodeScale = (roamZoom - 1) * nodeScaleRatio + 1;
var invScale = [
// nodeScale / roamZoom / (groupZoom / roamZoom)
nodeScale / groupZoom,
nodeScale / groupZoom
];
......
......@@ -15,10 +15,10 @@ define(function (require) {
* @extends {module:zrender/graphic/Group}
* @alias {module:echarts/chart/helper/Line}
*/
function EffectLine(lineData, fromData, toData, idx) {
function EffectLine(lineData, idx) {
graphic.Group.call(this);
var line = new Line(lineData, fromData, toData, idx);
var line = new Line(lineData, idx);
this.add(line);
this._updateEffectSymbol(lineData, idx);
......@@ -98,13 +98,13 @@ define(function (require) {
symbol.attr('scale', size);
};
effectLineProto.updateData = function (lineData, fromData, toData, idx) {
this.childAt(0).updateData(lineData, fromData, toData, idx);
effectLineProto.updateData = function (lineData, idx) {
this.childAt(0).updateData(lineData, idx);
this._updateEffectSymbol(lineData, idx);
};
effectLineProto.updateLayout = function (lineData, fromData, toData, idx) {
this.childAt(0).updateLayout(lineData, fromData, toData, idx);
effectLineProto.updateLayout = function (lineData, idx) {
this.childAt(0).updateLayout(lineData, idx);
var symbol = this.childAt(1);
var points = lineData.getItemLayout(idx);
setAnimationPoints(symbol, points);
......
......@@ -5,20 +5,25 @@ define(function (require) {
var symbolUtil = require('../../util/symbol');
var vector = require('zrender/core/vector');
var matrix = require('zrender/core/matrix');
var LinePath = require('./LinePath');
var graphic = require('../../util/graphic');
var zrUtil = require('zrender/core/util');
var numberUtil = require('../../util/number');
var SYMBOL_CATEGORIES = ['fromSymbol', 'toSymbol'];
function makeSymbolTypeKey(symbolCategory) {
return '_' + symbolCategory + 'Type';
}
/**
* @inner
*/
function createSymbol(name, data, idx) {
var color = data.getItemVisual(idx, 'color');
var symbolType = data.getItemVisual(idx, 'symbol');
var symbolSize = data.getItemVisual(idx, 'symbolSize');
function createSymbol(name, lineData, idx) {
var color = lineData.getItemVisual(idx, 'color');
var symbolType = lineData.getItemVisual(idx, name);
var symbolSize = lineData.getItemVisual(idx, name + 'Size');
if (symbolType === 'none') {
if (!symbolType || symbolType === 'none') {
return;
}
......@@ -58,6 +63,21 @@ define(function (require) {
}
}
function lineAfterUpdate() {
// Ignore scale
var m = this.transform;
if (m) {
var sx = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
var sy = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
m[0] /= sx;
m[1] /= sx;
m[2] /= sy;
m[3] /= sy;
matrix.invert(this.invTransform, m);
}
}
// function isSymbolArrow(symbol) {
// return symbol.type === 'symbol' && symbol.shape.symbolType === 'arrow';
// }
......@@ -72,6 +92,7 @@ define(function (require) {
var symbolFrom = lineGroup.childOfName('fromSymbol');
var symbolTo = lineGroup.childOfName('toSymbol');
var label = lineGroup.childOfName('label');
var fromPos = line.pointAt(0);
var toPos = line.pointAt(line.shape.percent);
......@@ -80,17 +101,17 @@ define(function (require) {
if (symbolFrom) {
symbolFrom.attr('position', fromPos);
// Rotate the arrow
// FIXME Hard coded ?
// if (isSymbolArrow(symbolFrom)) {
symbolFrom.attr('rotation', tangentRotation(toPos, fromPos));
// }
var tangent = line.tangentAt(0);
symbolFrom.attr('rotation', -Math.PI / 2 - Math.atan2(
tangent[1], tangent[0]
));
}
if (symbolTo) {
symbolTo.attr('position', toPos);
// if (isSymbolArrow(symbolTo)) {
symbolTo.attr('rotation', tangentRotation(fromPos, toPos));
// }
var tangent = line.tangentAt(1);
symbolTo.attr('rotation', -Math.PI / 2 - Math.atan2(
tangent[1], tangent[0]
));
}
label.attr('position', toPos);
......@@ -98,25 +119,35 @@ define(function (require) {
var textPosition;
var textAlign;
var textVerticalAlign;
var distance = 5;
var parentNode = this.parent;
while (parentNode) {
if (parentNode.scale) {
distance /= parentNode.scale[0];
}
parentNode = parentNode.parent;
}
// End
if (label.__position === 'end') {
textPosition = [d[0] * 5 + toPos[0], d[1] * 5 + toPos[1]];
textPosition = [d[0] * distance + toPos[0], d[1] * distance + toPos[1]];
textAlign = d[0] > 0.8 ? 'left' : (d[0] < -0.8 ? 'right' : 'center');
textVerticalAlign = d[1] > 0.8 ? 'top' : (d[1] < -0.8 ? 'bottom' : 'middle');
}
// Middle
else if (label.__position === 'middle') {
var n = [d[1], -d[0]];
var halfPercent = line.shape.percent / 2;
var tangent = line.tangentAt(halfPercent);
var n = [tangent[1], -tangent[0]];
var cp = line.pointAt(halfPercent);
if (n[1] > 0) {
n[0] = -n[0];
n[1] = -n[1];
}
textPosition = [(toPos[0] + fromPos[0]) / 2 + n[0] * 5, (toPos[1] + fromPos[1]) / 2 + n[1] * 5];
textPosition = [cp[0] + n[0] * distance, cp[1] + n[1] * distance];
textAlign = 'center';
textVerticalAlign = 'bottom';
var rotation = -Math.atan2(
toPos[1] - fromPos[1], toPos[0] - fromPos[0]
);
var rotation = -Math.atan2(tangent[1], tangent[0]);
if (toPos[0] < fromPos[0]) {
rotation = Math.PI + rotation;
}
......@@ -124,7 +155,7 @@ define(function (require) {
}
// Start
else {
textPosition = [-d[0] * 5 + fromPos[0], -d[1] * 5 + fromPos[1]];
textPosition = [-d[0] * distance + fromPos[0], -d[1] * distance + fromPos[1]];
textAlign = d[0] > 0.8 ? 'right' : (d[0] < -0.8 ? 'left' : 'center');
textVerticalAlign = d[1] > 0.8 ? 'bottom' : (d[1] < -0.8 ? 'top' : 'middle');
}
......@@ -138,21 +169,15 @@ define(function (require) {
});
}
function tangentRotation(p1, p2) {
return -Math.PI / 2 - Math.atan2(
p2[1] - p1[1], p2[0] - p1[0]
);
}
/**
* @constructor
* @extends {module:zrender/graphic/Group}
* @alias {module:echarts/chart/helper/Line}
*/
function Line(lineData, fromData, toData, idx) {
function Line(lineData, idx) {
graphic.Group.call(this);
this._createLine(lineData, fromData, toData, idx);
this._createLine(lineData, idx);
}
var lineProto = Line.prototype;
......@@ -160,7 +185,7 @@ define(function (require) {
// Update symbol position and rotation
lineProto.beforeUpdate = updateSymbolBeforeLineUpdate;
lineProto._createLine = function (lineData, fromData, toData, idx) {
lineProto._createLine = function (lineData, idx) {
var seriesModel = lineData.hostModel;
var linePoints = lineData.getItemLayout(idx);
......@@ -179,26 +204,19 @@ define(function (require) {
});
this.add(label);
if (fromData) {
var symbolFrom = createSymbol('fromSymbol', fromData, idx);
zrUtil.each(SYMBOL_CATEGORIES, function (symbolCategory) {
var symbol = createSymbol(symbolCategory, lineData, idx);
// symbols must added after line to make sure
// it will be updated after line#update.
// Or symbol position and rotation update in line#beforeUpdate will be one frame slow
this.add(symbolFrom);
this._fromSymbolType = fromData.getItemVisual(idx, 'symbol');
}
if (toData) {
var symbolTo = createSymbol('toSymbol', toData, idx);
this.add(symbolTo);
this._toSymbolType = toData.getItemVisual(idx, 'symbol');
}
this.add(symbol);
this[makeSymbolTypeKey(symbolCategory)] = lineData.getItemVisual(idx, symbolCategory);
}, this);
this._updateCommonStl(lineData, fromData, toData, idx);
this._updateCommonStl(lineData, idx);
};
lineProto.updateData = function (lineData, fromData, toData, idx) {
lineProto.updateData = function (lineData, idx) {
var seriesModel = lineData.hostModel;
var line = this.childOfName('line');
......@@ -209,31 +227,22 @@ define(function (require) {
setLinePoints(target.shape, linePoints);
graphic.updateProps(line, target, seriesModel);
// Symbol changed
if (fromData) {
var fromSymbolType = fromData.getItemVisual(idx, 'symbol');
if (this._fromSymbolType !== fromSymbolType) {
var symbolFrom = createSymbol('fromSymbol', fromData, idx);
this.remove(this.childOfName('fromSymbol'));
this.add(symbolFrom);
}
this._fromSymbolType = fromSymbolType;
}
if (toData) {
var toSymbolType = toData.getItemVisual(idx, 'symbol');
zrUtil.each(SYMBOL_CATEGORIES, function (symbolCategory) {
var symbolType = lineData.getItemVisual(idx, symbolCategory);
var key = makeSymbolTypeKey(symbolCategory);
// Symbol changed
if (toSymbolType !== this._toSymbolType) {
var symbolTo = createSymbol('toSymbol', toData, idx);
this.remove(this.childOfName('toSymbol'));
this.add(symbolTo);
if (this[key] !== symbolType) {
var symbol = createSymbol(symbolCategory, lineData, idx);
this.remove(this.childOfName(symbolCategory));
this.add(symbol);
}
this._toSymbolType = toSymbolType;
}
this[key] = symbolType;
}, this);
this._updateCommonStl(lineData, fromData, toData, idx);
this._updateCommonStl(lineData, idx);
};
lineProto._updateCommonStl = function (lineData, fromData, toData, idx) {
lineProto._updateCommonStl = function (lineData, idx) {
var seriesModel = lineData.hostModel;
var line = this.childOfName('line');
......@@ -257,27 +266,28 @@ define(function (require) {
},
itemModel.getModel('lineStyle.normal').getLineStyle()
));
var defaultColor = lineData.getItemVisual(idx, 'color') || '#000';
var label = this.childOfName('label');
label.afterUpdate = lineAfterUpdate;
label.setStyle({
text: labelModel.get('show')
? zrUtil.retrieve(
seriesModel.getFormattedLabel(idx, 'normal'),
seriesModel.getFormattedLabel(idx, 'normal', lineData),
defaultText
)
: '',
textFont: textStyleModel.getFont(),
fill: textStyleModel.getTextColor() || lineData.getItemVisual(idx, 'color')
fill: textStyleModel.getTextColor() || defaultColor
});
label.hoverStyle = {
text: labelHoverModel.get('show')
? zrUtil.retrieve(
seriesModel.getFormattedLabel(idx, 'emphasis'),
seriesModel.getFormattedLabel(idx, 'emphasis', lineData),
defaultText
)
: '',
textFont: textStyleHoverModel.getFont(),
fill: textStyleHoverModel.getTextColor()
fill: textStyleHoverModel.getTextColor() || defaultColor
};
label.__textAlign = textStyleModel.get('align');
label.__verticalAlign = textStyleModel.get('baseline');
......@@ -288,15 +298,11 @@ define(function (require) {
);
};
lineProto.updateLayout = function (lineData, fromData, toData, idx) {
lineProto.updateLayout = function (lineData, idx) {
var points = lineData.getItemLayout(idx);
var linePath = this.childOfName('line');
setLinePoints(linePath.shape, points);
linePath.dirty(true);
// var fromEl = fromData && fromData.getItemGraphicEl(idx);
// var toEl = toData && toData.getItemGraphicEl(idx);
// fromEl && fromEl.attr('position', points[0]);
// toEl && toEl.attr('position', points[1]);
};
zrUtil.inherits(Line, graphic.Group);
......
......@@ -19,10 +19,8 @@ define(function (require) {
/**
* @param {module:echarts/data/List} lineData
* @param {module:echarts/data/List} [fromData]
* @param {module:echarts/data/List} [toData]
*/
lineDrawProto.updateData = function (lineData, fromData, toData) {
lineDrawProto.updateData = function (lineData) {
var oldLineData = this._lineData;
var group = this.group;
......@@ -30,7 +28,7 @@ define(function (require) {
lineData.diff(oldLineData)
.add(function (idx) {
var lineGroup = new LineCtor(lineData, fromData, toData, idx);
var lineGroup = new LineCtor(lineData, idx);
lineData.setItemGraphicEl(idx, lineGroup);
......@@ -38,7 +36,7 @@ define(function (require) {
})
.update(function (newIdx, oldIdx) {
var lineGroup = oldLineData.getItemGraphicEl(oldIdx);
lineGroup.updateData(lineData, fromData, toData, newIdx);
lineGroup.updateData(lineData, newIdx);
lineData.setItemGraphicEl(newIdx, lineGroup);
......@@ -50,14 +48,12 @@ define(function (require) {
.execute();
this._lineData = lineData;
this._fromData = fromData;
this._toData = toData;
};
lineDrawProto.updateLayout = function () {
var lineData = this._lineData;
lineData.eachItemGraphicEl(function (el, idx) {
el.updateLayout(lineData, this._fromData, this._toData, idx);
el.updateLayout(lineData, idx);
}, this);
};
......
......@@ -3,10 +3,15 @@
*/
define(function (require) {
var graphic = require('../../util/graphic');
var vec2 = require('zrender/core/vector');
var straightLineProto = graphic.Line.prototype;
var bezierCurveProto = graphic.BezierCurve.prototype;
function isLine(shape) {
return shape.cpx1 == null || shape.cpy1 == null;
}
return graphic.extendShape({
type: 'ec-line',
......@@ -27,15 +32,21 @@ define(function (require) {
},
buildPath: function (ctx, shape) {
(shape.cpx1 == null || shape.cpy1 == null
? straightLineProto : bezierCurveProto).buildPath(ctx, shape);
(isLine(shape) ? straightLineProto : bezierCurveProto).buildPath(ctx, shape);
},
pointAt: function (t) {
var shape = this.shape;
return shape.cpx1 == null || shape.cpy1 == null
return isLine(this.shape)
? straightLineProto.pointAt.call(this, t)
: bezierCurveProto.pointAt.call(this, t);
},
tangentAt: function (t) {
var shape = this.shape;
var p = isLine(shape)
? [shape.x2 - shape.x1, shape.y2 - shape.y1]
: bezierCurveProto.tangentAt.call(this, t);
return vec2.normalize(p, p);
}
});
});
\ No newline at end of file
......@@ -46,15 +46,13 @@ define(function(require) {
}).join('<br />');
},
getFormattedLabel: function (dataIndex, status, formatter, indicatorIndex) {
getFormattedLabel: function (dataIndex, status, otherData, indicatorIndex) {
status = status || 'normal';
var data = this.getData();
var data = otherData || this.getData();
var itemModel = data.getItemModel(dataIndex);
var params = this.getDataParams(dataIndex);
if (formatter == null) {
formatter = itemModel.get(['label', status, 'formatter']);
}
var params = this.getDataParams(dataIndex, otherData);
var formatter = itemModel.get(['label', status, 'formatter']);
// Get value of specified indicator
params.value = params.value[indicatorIndex || 0];
if (typeof formatter === 'function') {
......
......@@ -54,8 +54,7 @@ define(function (require) {
group.position = [layoutInfo.x, layoutInfo.y];
var edgeData = graph.edgeData;
var rawOption = seriesModel.option;
var formatModel = modelUtil.createDataFormatModel(seriesModel, edgeData);
var formatModel = modelUtil.createDataFormatModel(edgeData, seriesModel);
formatModel.formatTooltip = function (dataIndex) {
var params = this.getDataParams(dataIndex);
......
......@@ -68,13 +68,12 @@ define(function (require) {
defaultOption: {
zlevel: 0,
z: 5,
// 标线起始和结束的symbol介绍类型,如果都一样,可以直接传string
symbol: ['circle', 'arrow'],
// 标线起始和结束的symbol大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2
symbolSize: [8, 16],
// 标线起始和结束的symbol旋转控制
//symbolRotate: null,
//smooth: false,
//symbolRotate: 0,
precision: 2,
tooltip: {
trigger: 'item'
......@@ -82,12 +81,7 @@ define(function (require) {
label: {
normal: {
show: true,
// 标签文本格式器,同Tooltip.formatter,不支持回调
// formatter: null,
// 可选为 'start'|'end'|'left'|'right'|'top'|'bottom'
position: 'end'
// 默认使用全局文本样式,详见TEXTSTYLE
// textStyle: null
},
emphasis: {
show: true
......@@ -95,13 +89,7 @@ define(function (require) {
},
lineStyle: {
normal: {
// color
// width
type: 'dashed'
// shadowColor: 'rgba(0,0,0,0)',
// shadowBlur: 0,
// shadowOffsetX: 0,
// shadowOffsetY: 0
},
emphasis: {
width: 3
......
......@@ -255,9 +255,16 @@ define(function (require) {
fromData.getItemLayout(idx),
toData.getItemLayout(idx)
]);
lineData.setItemVisual(idx, {
'fromSymbolSize': fromData.getItemVisual(idx, 'symbolSize'),
'fromSymbol': fromData.getItemVisual(idx, 'symbol'),
'toSymbolSize': toData.getItemVisual(idx, 'symbolSize'),
'toSymbol': toData.getItemVisual(idx, 'symbol')
});
});
lineDraw.updateData(lineData, fromData, toData);
lineDraw.updateData(lineData);
// Set host model for tooltip
// FIXME
......@@ -275,12 +282,9 @@ define(function (require) {
);
data.setItemVisual(idx, {
symbolSize: itemModel.get('symbolSize')
|| symbolSize[isFrom ? 0 : 1],
symbol: itemModel.get('symbol', true)
|| symbolType[isFrom ? 0 : 1],
color: itemModel.get('itemStyle.normal.color')
|| seriesData.getVisual('color')
symbolSize: itemModel.get('symbolSize') || symbolSize[isFrom ? 0 : 1],
symbol: itemModel.get('symbol', true) || symbolType[isFrom ? 0 : 1],
color: itemModel.get('itemStyle.normal.color') || seriesData.getVisual('color')
});
}
......
......@@ -59,40 +59,25 @@ define(function (require) {
defaultOption: {
zlevel: 0,
z: 5,
symbol: 'pin', // 标注类型
symbolSize: 50, // 标注大小
// symbolRotate: null, // 标注旋转控制
symbol: 'pin',
symbolSize: 50,
//symbolRotate: 0,
//symbolOffset: [0, 0]
tooltip: {
trigger: 'item'
},
label: {
normal: {
show: true,
// 标签文本格式器,同Tooltip.formatter,不支持回调
// formatter: null,
// 可选为'left'|'right'|'top'|'bottom'
position: 'inside'
// 默认使用全局文本样式,详见TEXTSTYLE
// textStyle: null
},
emphasis: {
show: true
// 标签文本格式器,同Tooltip.formatter,不支持回调
// formatter: null,
// position: 'inside' // 'left'|'right'|'top'|'bottom'
// textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
}
},
itemStyle: {
normal: {
// color: 各异,
// 标注边线颜色,优先于color
// borderColor: 各异,
// 标注边线线宽,单位px,默认为1
borderWidth: 2
},
emphasis: {
// color: 各异
}
}
}
......
......@@ -382,7 +382,7 @@ define(function (require) {
*/
_prepareTooltipHostModel: function (data, timelineModel) {
var tooltipHostModel = modelUtil.createDataFormatModel(
{mainType: 'timeline', subType: 'slider'}, data
data, { mainType: 'timeline', subType: 'slider' }
);
var me = this;
......
......@@ -31,12 +31,14 @@ define(function (require) {
'stackedOn', '_nameList', '_idList', '_rawData'
];
var transferImmuProperties = function (a, b, wrappedMethod) {
zrUtil.each(IMMUTABLE_PROPERTIES.concat(wrappedMethod || []), function (propName) {
var transferImmuProperties = function (a, b) {
zrUtil.each(IMMUTABLE_PROPERTIES.concat(b.__wrappedMethods || []), function (propName) {
if (b.hasOwnProperty(propName)) {
a[propName] = b[propName];
}
});
a.__wrappedMethods = b.__wrappedMethods;
};
/**
......@@ -527,7 +529,7 @@ define(function (require) {
* @return {number}
*/
listProto.getRawDataItem = function (idx) {
return (this._rawData || [])[this.getRawIndex(idx)];
return this._rawData[this.getRawIndex(idx)];
};
/**
......@@ -689,7 +691,7 @@ define(function (require) {
original.hostModel
);
// FIXME If needs stackedOn, value may already been stacked
transferImmuProperties(list, original, original._wrappedMethods);
transferImmuProperties(list, original);
var storage = list._storage = {};
var originalStorage = original._storage;
......@@ -1006,7 +1008,7 @@ define(function (require) {
// FIXME
list._storage = this._storage;
transferImmuProperties(list, this, this._wrappedMethods);
transferImmuProperties(list, this);
list.indices = this.indices.slice();
......@@ -1023,8 +1025,8 @@ define(function (require) {
if (typeof originalMethod !== 'function') {
return;
}
this._wrappedMethods = this._wrappedMethods || [];
this._wrappedMethods.push(methodName);
this.__wrappedMethods = this.__wrappedMethods || [];
this.__wrappedMethods.push(methodName);
this[methodName] = function () {
var res = originalMethod.apply(this, arguments);
return injectFunction.call(this, res);
......
......@@ -367,6 +367,7 @@ define(function (require) {
return;
}
// Fixme First time update ?
ecModel.restoreData();
// TODO
......
......@@ -78,6 +78,10 @@ define(function (require) {
var obj = this.option;
var parentModel = this.parentModel;
for (var i = 0; i < path.length; i++) {
// Ignore empty
if (!path[i]) {
continue;
}
// obj could be number/string/... (like 0)
obj = (obj && typeof obj === 'object') ? obj[path[i]] : null;
if (obj == null) {
......
......@@ -70,19 +70,16 @@ define(function(require) {
zrUtil.merge(option, this.getDefaultOption());
// Default label emphasis `position` and `show`
// FIXME Set label in merge
// FIXME Set label in mergeOption
modelUtil.defaultEmphasis(option.label, modelUtil.LABEL_OPTIONS);
if (option.data) {
this._fillDataTextStyle(option.data);
}
this.fillDataTextStyle(option.data);
},
mergeOption: function (newSeriesOption, ecModel) {
newSeriesOption = zrUtil.merge(this.option, newSeriesOption, true);
if (newSeriesOption.data) {
this._fillDataTextStyle(newSeriesOption.data);
}
this.fillDataTextStyle(newSeriesOption.data);
var data = this.getInitialData(newSeriesOption, ecModel);
// TODO Merge data?
if (data) {
......@@ -91,13 +88,15 @@ define(function(require) {
}
},
_fillDataTextStyle: function (data) {
fillDataTextStyle: function (data) {
// Default data label emphasis `position` and `show`
// FIXME Tree structure data ?
// FIXME Performance ?
for (var i = 0; i < data.length; i++) {
if (data[i] && data[i].label) {
modelUtil.defaultEmphasis(data[i].label, modelUtil.LABEL_OPTIONS);
if (data) {
for (var i = 0; i < data.length; i++) {
if (data[i] && data[i].label) {
modelUtil.defaultEmphasis(data[i].label, modelUtil.LABEL_OPTIONS);
}
}
}
},
......
......@@ -180,14 +180,14 @@ define(function(require) {
/**
* Create a model proxy to be used in tooltip for edge data, markLine data, markPoint data.
* @param {(Object|module:echarts/model/Series)} opt
* @param {module:echarts/data/List} data
* @param {Object} opt
* @param {string} [opt.seriesIndex]
* @param {Object} [opt.name]
* @param {Object} [opt.mainType]
* @param {Object} [opt.subType]
* @param {module:echarts/data/List} data
*/
modelUtil.createDataFormatModel = function (opt, data) {
modelUtil.createDataFormatModel = function (data, opt) {
var model = new Model();
zrUtil.mixin(model, modelUtil.dataFormatMixin);
model.seriesIndex = opt.seriesIndex;
......@@ -239,10 +239,11 @@ define(function(require) {
/**
* Get params for formatter
* @param {number} dataIndex
* @param {module:echarts/data/List} [otherData]
* @return {Object}
*/
getDataParams: function (dataIndex) {
var data = this.getData();
getDataParams: function (dataIndex, otherData) {
var data = otherData || this.getData();
var seriesIndex = this.seriesIndex;
var seriesName = this.name;
......@@ -273,18 +274,16 @@ define(function(require) {
* Format label
* @param {number} dataIndex
* @param {string} [status='normal'] 'normal' or 'emphasis'
* @param {Function|string} [formatter] Default use the `itemStyle[status].label.formatter`
* @param {module:echarts/data/List} [otherData]
* @return {string}
*/
getFormattedLabel: function (dataIndex, status, formatter) {
getFormattedLabel: function (dataIndex, status, otherData) {
status = status || 'normal';
var data = this.getData();
var data = otherData || this.getData();
var itemModel = data.getItemModel(dataIndex);
var params = this.getDataParams(dataIndex);
if (formatter == null) {
formatter = itemModel.get(['label', status, 'formatter']);
}
var params = this.getDataParams(dataIndex, otherData);
var formatter = itemModel.get(['label', status, 'formatter']);
if (typeof formatter === 'function') {
params.status = status;
......@@ -298,12 +297,13 @@ define(function(require) {
/**
* Get raw value in option
* @param {number} idx
* @param {module:echarts/data/List} [otherData]
* @return {Object}
*/
getRawValue: function (idx) {
var itemModel = this.getData().getItemModel(idx);
if (itemModel && itemModel.option != null) {
var dataItem = itemModel.option;
getRawValue: function (idx, otherData) {
var data = otherData || this.getData();
var dataItem = data.getRawDataItem(idx);
if (dataItem != null) {
return (zrUtil.isObject(dataItem) && !zrUtil.isArray(dataItem))
? dataItem.value : dataItem;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册