提交 0f1aa933 编写于 作者: L lang

Line highlight, other tweaks

上级 c5a49ea4
......@@ -49,6 +49,29 @@ define(function (require) {
this.add(symbolPath);
};
/**
* Highlight symbol
*/
symbolProto.highlight = function () {
this.childAt(0).trigger('emphasis');
};
/**
* Downplay symbol
*/
symbolProto.downplay = function () {
this.childAt(0).trigger('normal');
};
/**
* @param {number} zlevel
* @param {number} z
*/
symbolProto.setZ = function (zlevel, z) {
var symbolPath = this.childAt(0);
symbolPath.zlevel = zlevel;
symbolPath.z = z;
};
/**
* Update symbol properties
* @param {module:echarts/data/List} data
......
......@@ -4,11 +4,14 @@ define(function(require) {
var zrUtil = require('zrender/core/util');
var SymbolDraw = require('../helper/SymbolDraw');
var Symbol = require('../helper/Symbol');
var lineAnimationDiff = require('./lineAnimationDiff');
var graphic = require('../../util/graphic');
var polyHelper = require('./poly');
var ChartView = require('../../view/Chart');
function isPointsSame(points1, points2) {
if (points1.length !== points2.length) {
return;
......@@ -77,7 +80,16 @@ define(function(require) {
}, true);
}
return require('../../echarts').extendChartView({
function queryDataIndex(data, payload) {
if (payload.dataIndex != null) {
return payload.dataIndex;
}
else if (payload.name != null) {
return data.indexOfName(payload.name);
}
}
return ChartView.extend({
type: 'line',
......@@ -220,6 +232,58 @@ define(function(require) {
this._points = points;
},
highlight: function (seriesModel, ecModel, api, payload) {
var data = seriesModel.getData();
var dataIndex = queryDataIndex(data, payload);
if (dataIndex >= 0) {
var symbol = data.getItemGraphicEl(dataIndex);
if (!symbol) {
// Create a temporary symbol if it is not exists
symbol = new Symbol(data, dataIndex, api);
symbol.position = data.getItemLayout(dataIndex);
symbol.setZ(
seriesModel.get('zlevel'),
seriesModel.get('z')
);
symbol.__temp = true;
data.setItemGraphicEl(dataIndex, symbol);
this.group.add(symbol);
}
symbol.highlight();
}
else {
// Highlight whole series
ChartView.prototype.highlight.call(
this, seriesModel, ecModel, api, payload
);
}
},
downplay: function (seriesModel, ecModel, api, payload) {
var data = seriesModel.getData();
var dataIndex = queryDataIndex(data, payload);
if (dataIndex >= 0) {
var symbol = data.getItemGraphicEl(dataIndex);
if (symbol) {
if (symbol.__temp) {
data.setItemGraphicEl(dataIndex, null);
this.group.remove(symbol);
}
else {
symbol.downplay();
}
}
}
else {
// Downplay whole series
ChartView.prototype.downplay.call(
this, seriesModel, ecModel, api, payload
);
}
},
/**
* @param {module:zrender/container/Group} group
* @param {Array.<Array.<number>>} points
......
......@@ -5,7 +5,6 @@ define(function(require) {
var echarts = require('../echarts');
var graphic = require('../util/graphic');
var layout = require('../util/layout');
var formatUtil = require('../util/format');
// Model
echarts.extendComponentModel({
......
......@@ -282,7 +282,6 @@ define(function (require) {
_showAxisTooltip: function (tooltipModel, ecModel, e) {
var axisPointerModel = tooltipModel.getModel('axisPointer');
var axisPointerType = axisPointerModel.get('type');
var api = this._api;
if (axisPointerType === 'cross') {
var el = e.target;
......@@ -646,25 +645,28 @@ define(function (require) {
var val = value[baseAxis.dim === 'x' ? 0 : 1];
var dataIndex = data.indexOfNearest(baseAxis.dim, val);
// FIXME Not here
var lastHover = this._lastHover;
if (lastHover.seriesIndex != null) {
if (lastHover.seriesIndex != null && !contentNotChange) {
this._api.dispatch({
type: 'downplay',
seriesIndex: lastHover.seriesIndex,
dataIndex: lastHover.dataIndex
});
}
var seriesIndices = zrUtil.map(seriesList, function (series) {
return series.seriesIndex;
});
// Dispatch highlight action
this._api.dispatch({
type: 'highlight',
seriesIndex: seriesIndices,
dataIndex: dataIndex
});
lastHover.seriesIndex = seriesIndices;
lastHover.dataIndex = dataIndex;
if (!contentNotChange) {
var seriesIndices = zrUtil.map(seriesList, function (series) {
return series.seriesIndex;
});
this._api.dispatch({
type: 'highlight',
seriesIndex: seriesIndices,
dataIndex: dataIndex
});
lastHover.seriesIndex = seriesIndices;
lastHover.dataIndex = dataIndex;
}
if (baseAxis && rootTooltipModel.get('showContent')) {
......
......@@ -909,13 +909,15 @@ define(function (require) {
listProto.setItemGraphicEl = function (idx, el) {
var hostModel = this.hostModel;
if (zrUtil.isArray(el)) {
zrUtil.each(el, function (singleEl) {
addIndexToGraphicEl(singleEl, idx, hostModel);
});
}
else {
addIndexToGraphicEl(el, idx, hostModel);
if (el) {
if (zrUtil.isArray(el)) {
zrUtil.each(el, function (singleEl) {
addIndexToGraphicEl(singleEl, idx, hostModel);
});
}
else {
addIndexToGraphicEl(el, idx, hostModel);
}
}
this._graphicEls[idx] = el;
......
......@@ -2,10 +2,9 @@
define(function (require) {
return function (seriesType, ecModel) {
var offset = 0;
var colorList = ecModel.get('color');
ecModel.eachRawSeriesByType(seriesType, function (seriesModel) {
ecModel.eachSeriesByType(seriesType, function (seriesModel) {
var dataAll = seriesModel.getRawData();
if (!ecModel.isSeriesFiltered(seriesModel)) {
var data = seriesModel.getData();
......@@ -13,13 +12,12 @@ define(function (require) {
var itemModel = data.getItemModel(idx);
var rawIdx = data.getRawIndex(idx);
var color = itemModel.get('itemStyle.normal.color')
|| colorList[(offset + rawIdx) % colorList.length];
|| colorList[rawIdx % colorList.length];
// Legend may use the visual info in data before processed
dataAll.setItemVisual(rawIdx, 'color', color);
data.setItemVisual(idx, 'color', color);
});
}
offset += dataAll.count();
});
};
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册