提交 62b02fed 编写于 作者: L lang

markLine and markPoint data label fill. Always rotate symbol on markLine. Mark...

markLine and markPoint data label fill. Always rotate symbol on markLine. Mark line label position support 'middle'
上级 139896bb
...@@ -58,9 +58,9 @@ define(function (require) { ...@@ -58,9 +58,9 @@ define(function (require) {
} }
} }
function isSymbolArrow(symbol) { // function isSymbolArrow(symbol) {
return symbol.type === 'symbol' && symbol.shape.symbolType === 'arrow'; // return symbol.type === 'symbol' && symbol.shape.symbolType === 'arrow';
} // }
function updateSymbolBeforeLineUpdate () { function updateSymbolBeforeLineUpdate () {
var lineGroup = this; var lineGroup = this;
...@@ -82,15 +82,15 @@ define(function (require) { ...@@ -82,15 +82,15 @@ define(function (require) {
symbolFrom.attr('position', fromPos); symbolFrom.attr('position', fromPos);
// Rotate the arrow // Rotate the arrow
// FIXME Hard coded ? // FIXME Hard coded ?
if (isSymbolArrow(symbolFrom)) { // if (isSymbolArrow(symbolFrom)) {
symbolFrom.attr('rotation', tangentRotation(toPos, fromPos)); symbolFrom.attr('rotation', tangentRotation(toPos, fromPos));
} // }
} }
if (symbolTo) { if (symbolTo) {
symbolTo.attr('position', toPos); symbolTo.attr('position', toPos);
if (isSymbolArrow(symbolTo)) { // if (isSymbolArrow(symbolTo)) {
symbolTo.attr('rotation', tangentRotation(fromPos, toPos)); symbolTo.attr('rotation', tangentRotation(fromPos, toPos));
} // }
} }
label.attr('position', toPos); label.attr('position', toPos);
...@@ -104,6 +104,24 @@ define(function (require) { ...@@ -104,6 +104,24 @@ define(function (require) {
textAlign = d[0] > 0.8 ? 'left' : (d[0] < -0.8 ? 'right' : 'center'); textAlign = d[0] > 0.8 ? 'left' : (d[0] < -0.8 ? 'right' : 'center');
textVerticalAlign = d[1] > 0.8 ? 'top' : (d[1] < -0.8 ? 'bottom' : 'middle'); textVerticalAlign = d[1] > 0.8 ? 'top' : (d[1] < -0.8 ? 'bottom' : 'middle');
} }
// Middle
else if (label.__position === 'middle') {
var n = [d[1], -d[0]];
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];
textAlign = 'center';
textVerticalAlign = 'bottom';
var rotation = -Math.atan2(
toPos[1] - fromPos[1], toPos[0] - fromPos[0]
);
if (toPos[0] < fromPos[0]) {
rotation = Math.PI + rotation;
}
label.attr('rotation', rotation);
}
// Start // Start
else { else {
textPosition = [-d[0] * 5 + fromPos[0], -d[1] * 5 + fromPos[1]]; textPosition = [-d[0] * 5 + fromPos[0], -d[1] * 5 + fromPos[1]];
......
define(function (require) { define(function (require) {
// Default enable markLine
// var globalDefault = require('../../model/globalDefault');
var modelUtil = require('../../util/model'); var modelUtil = require('../../util/model');
var zrUtil = require('zrender/core/util');
// // Force to load markLine component function fillLabel(opt) {
// globalDefault.markLine = {}; modelUtil.defaultEmphasis(
opt.label,
modelUtil.LABEL_OPTIONS
);
}
var MarkLineModel = require('../../echarts').extendComponentModel({ var MarkLineModel = require('../../echarts').extendComponentModel({
type: 'markLine', type: 'markLine',
dependencies: ['series', 'grid', 'polar'], dependencies: ['series', 'grid', 'polar', 'geo'],
/** /**
* @overrite * @overrite
*/ */
...@@ -32,11 +35,17 @@ define(function (require) { ...@@ -32,11 +35,17 @@ define(function (require) {
if (!mlModel) { if (!mlModel) {
if (isInit) { if (isInit) {
// Default label emphasis `position` and `show` // Default label emphasis `position` and `show`
modelUtil.defaultEmphasis( fillLabel(markLineOpt);
markLineOpt.label,
['position', 'show', 'textStyle', 'distance', 'formatter']
);
} }
zrUtil.each(markLineOpt.data, function (item) {
if (item instanceof Array) {
fillLabel(item[0]);
fillLabel(item[1]);
}
else {
fillLabel(item);
}
});
var opt = { var opt = {
// Use the same series index and name // Use the same series index and name
seriesIndex: seriesModel.seriesIndex, seriesIndex: seriesModel.seriesIndex,
......
define(function (require) { define(function (require) {
// Default enable markPoint
// var globalDefault = require('../../model/globalDefault');
var modelUtil = require('../../util/model'); var modelUtil = require('../../util/model');
// // Force to load markPoint component var zrUtil = require('zrender/core/util');
// globalDefault.markPoint = {};
function fillLabel(opt) {
modelUtil.defaultEmphasis(
opt.label,
modelUtil.LABEL_OPTIONS
);
}
var MarkPointModel = require('../../echarts').extendComponentModel({ var MarkPointModel = require('../../echarts').extendComponentModel({
type: 'markPoint', type: 'markPoint',
...@@ -30,11 +34,9 @@ define(function (require) { ...@@ -30,11 +34,9 @@ define(function (require) {
if (!mpModel) { if (!mpModel) {
if (isInit) { if (isInit) {
// Default label emphasis `position` and `show` // Default label emphasis `position` and `show`
modelUtil.defaultEmphasis( fillLabel(markPointOpt);
markPointOpt.label,
['position', 'show', 'textStyle', 'distance', 'formatter']
);
} }
zrUtil.each(markPointOpt.data, fillLabel);
var opt = { var opt = {
// Use the same series index and name // Use the same series index and name
seriesIndex: seriesModel.seriesIndex, seriesIndex: seriesModel.seriesIndex,
......
...@@ -81,7 +81,7 @@ define(function (require) { ...@@ -81,7 +81,7 @@ define(function (require) {
// `yAxis` to specify the coord on each dimension // `yAxis` to specify the coord on each dimension
// parseFloat first because item.x and item.y can be percent string like '20%' // parseFloat first because item.x and item.y can be percent string like '20%'
if ((isNaN(parseFloat(item.x)) || isNaN(parseFloat(item.y))) if (item && (isNaN(parseFloat(item.x)) || isNaN(parseFloat(item.y)))
&& !zrUtil.isArray(item.coord) && !zrUtil.isArray(item.coord)
&& coordSys && coordSys
) { ) {
...@@ -155,9 +155,7 @@ define(function (require) { ...@@ -155,9 +155,7 @@ define(function (require) {
if (dimIndex < 2) { if (dimIndex < 2) {
return item.coord && item.coord[dimIndex]; return item.coord && item.coord[dimIndex];
} }
else { return item.value;
return item.value;
}
}; };
var numCalculate = function (data, valueDataDim, mlType) { var numCalculate = function (data, valueDataDim, mlType) {
......
...@@ -71,9 +71,7 @@ define(function(require) { ...@@ -71,9 +71,7 @@ define(function(require) {
// Default label emphasis `position` and `show` // Default label emphasis `position` and `show`
// FIXME Set label in merge // FIXME Set label in merge
modelUtil.defaultEmphasis( modelUtil.defaultEmphasis(option.label, modelUtil.LABEL_OPTIONS);
option.label, ['position', 'show', 'textStyle', 'distance', 'formatter']
);
if (option.data) { if (option.data) {
this._fillDataTextStyle(option.data); this._fillDataTextStyle(option.data);
...@@ -99,9 +97,7 @@ define(function(require) { ...@@ -99,9 +97,7 @@ define(function(require) {
// FIXME Performance ? // FIXME Performance ?
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
if (data[i] && data[i].label) { if (data[i] && data[i].label) {
modelUtil.defaultEmphasis( modelUtil.defaultEmphasis(data[i].label, modelUtil.LABEL_OPTIONS);
data[i].label, ['position', 'show', 'textStyle', 'distance', 'formatter']
);
} }
} }
}, },
......
...@@ -176,6 +176,8 @@ define(function(require) { ...@@ -176,6 +176,8 @@ define(function(require) {
} }
}; };
modelUtil.LABEL_OPTIONS = ['position', 'show', 'textStyle', 'distance', 'formatter'];
/** /**
* Create a model proxy to be used in tooltip for edge data, markLine data, markPoint data. * Create a model proxy to be used in tooltip for edge data, markLine data, markPoint data.
* @param {Object} opt * @param {Object} opt
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册