提交 3ef37dd9 编写于 作者: P pah100

parallel tweak

上级 1544676e
......@@ -2,7 +2,6 @@ define(function (require) {
var graphic = require('../../util/graphic');
var zrUtil = require('zrender/core/util');
var each = zrUtil.each;
var ParallelView = require('../../view/Chart').extend({
......@@ -52,7 +51,8 @@ define(function (require) {
function add(newDataIndex) {
var values = data.getValues(dimensionNames, newDataIndex);
var els = [];
var elGroup = new graphic.Group();
dataGroup.add(elGroup);
eachAxisPair(
values, dimensions, coordSys,
......@@ -60,52 +60,52 @@ define(function (require) {
// FIXME
// init animation
if (pointPair) {
els[pairIndex] = createEl(pointPair, dataGroup);
elGroup.add(createEl(pointPair));
}
}
);
setStyle(els, data, newDataIndex, lineStyle);
data.setItemGraphicEl(newDataIndex, els);
setStyle(elGroup, data, newDataIndex, lineStyle);
data.setItemGraphicEl(newDataIndex, elGroup);
}
function update(newDataIndex, oldDataIndex) {
var values = data.getValues(dimensionNames, newDataIndex);
var els = oldData.getItemGraphicEl(oldDataIndex);
var elGroup = oldData.getItemGraphicEl(oldDataIndex);
var newEls = [];
var elGroupIndex = 0;
eachAxisPair(
values, dimensions, coordSys,
function (pointPair, pairIndex) {
var el = els[pairIndex];
var el = elGroup.childAt(elGroupIndex++);
if (pointPair && !el) {
els[pairIndex] = createEl(pointPair, dataGroup);
newEls.push(createEl(pointPair));
}
else if (pointPair) {
el.setShape({points: pointPair});
}
else {
els[pairIndex] = null;
dataGroup.remove(el);
}
}
);
// Remove redundent els
for (var i = axisPairCount(dimensions), len = els.length; i < len; i++) {
els[i] = null;
dataGroup.remove(els[i]);
for (var i = elGroup.childCount() - 1; i >= elGroupIndex; i--) {
elGroup.remove(elGroup.childAt(i));
}
// Add new els
for (var i = 0, len = newEls.length; i < len; i++) {
elGroup.add(newEls[i]);
}
setStyle(els, data, newDataIndex, lineStyle);
data.setItemGraphicEl(newDataIndex, els);
setStyle(elGroup, data, newDataIndex, lineStyle);
data.setItemGraphicEl(newDataIndex, elGroup);
}
function remove(oldDataIndex) {
var els = oldData.getItemGraphicEl(oldDataIndex);
each(els, function (el) {
el && dataGroup.remove(el);
});
var elGroup = oldData.getItemGraphicEl(oldDataIndex);
dataGroup.remove(elGroup);
}
},
......@@ -114,15 +114,12 @@ define(function (require) {
*/
remove: function () {
this._dataGroup && this._dataGroup.removeAll();
this._data = null;
}
});
function axisPairCount(dimensions) {
return dimensions.length - 1;
}
function eachAxisPair(values, dimensions, coordSys, cb) {
for (var i = 0, len = axisPairCount(dimensions); i < len; i++) {
for (var i = 0, len = dimensions.length - 1; i < len; i++) {
var dimA = dimensions[i];
var dimB = dimensions[i + 1];
var valueA = values[i];
......@@ -140,23 +137,18 @@ define(function (require) {
}
}
function createEl(pointPair, dataGroup) {
var el = new graphic.Polyline({
function createEl(pointPair) {
return new graphic.Polyline({
shape: {points: pointPair},
silent: true
});
dataGroup.add(el);
return el;
}
function setStyle(els, data, dataIndex, lineStyle) {
each(els, function (el, pairIndex) {
if (!el) {
return;
}
function setStyle(elGroup, data, dataIndex, lineStyle) {
elGroup.eachChild(function (el) {
el.setStyle(lineStyle);
var opacity = data.getItemVisual(dataIndex, 'opacity', true);
opacity != null && el.setStyle('opacity', opacity);
el.setStyle('opacity', opacity);
});
}
......
......@@ -16,46 +16,20 @@ define(function (require) {
|| globalColors[seriesModel.seriesIndex % globalColors.length];
var inactiveOpacity = seriesModel.get('inactiveOpacity');
var activeOpacity = seriesModel.get('activeOpacity');
var lineStyle = seriesModel.getModel('lineStyle.normal').getLineStyle();
var coordSys = seriesModel.coordinateSystem;
var dimensions = coordSys.dimensions;
var dimensionNames = coordSys.getDimensionNames();
var data = seriesModel.getData();
var opacityMap = {
all: null,
normal: lineStyle.opacity,
active: activeOpacity,
inactive: inactiveOpacity
};
var hasActiveSet = false;
for (var j = 0, lenj = dimensions.length; j < lenj; j++) {
if (coordSys.getAxis(dimensions[j].name).isActive() !== null) {
hasActiveSet = true;
}
}
for (var i = 0, len = data.count(); i < len; i++) {
var values = data.getValues(dimensionNames, i);
var activeState;
if (!hasActiveSet) {
activeState = 'all';
}
else {
activeState = 'inactive';
for (var j = 0, lenj = dimensions.length; j < lenj; j++) {
var dimName = dimensions[j].name;
if (coordSys.getAxis(dimName).isActive(values[j], j)) {
activeState = 'active';
break;
}
}
}
data.setItemVisual(i, 'opacity', opacityMap[activeState]);
}
coordSys.eachActiveState(data, function (activeState, dataIndex) {
data.setItemVisual(dataIndex, 'opacity', opacityMap[activeState]);
});
data.setVisual('color', color);
});
......
......@@ -15,7 +15,7 @@ define(function (require) {
var mathMax = Math.max;
var mathPow = Math.pow;
var UNSELECT_THRESHOLD = 3;
var UNSELECT_THRESHOLD = 2;
var EVENTS = ['mousedown', 'mousemove', 'mouseup'];
/**
......
......@@ -216,6 +216,48 @@ define(function(require) {
);
},
/**
* @param {module:echarts/data/List} data
* @param {Functio} cb param: {string} activeState 'active' or 'inactive' or 'normal'
* {number} dataIndex
* @param {Object} context
*/
eachActiveState: function (data, callback, context) {
var dimensions = this.dimensions;
var dimensionNames = this.getDimensionNames();
var axesMap = this._axesMap;
var hasActiveSet = false;
for (var j = 0, lenj = dimensions.length; j < lenj; j++) {
if (axesMap[dimensions[j].name].getActiveState() !== 'normal') {
hasActiveSet = true;
}
}
for (var i = 0, len = data.count(); i < len; i++) {
var values = data.getValues(dimensionNames, i);
var activeState;
if (!hasActiveSet) {
activeState = 'normal';
}
else {
activeState = 'active';
for (var j = 0, lenj = dimensions.length; j < lenj; j++) {
var dimName = dimensions[j].name;
var state = axesMap[dimName].getActiveState(values[j], j);
if (state === 'inactive') {
activeState = 'inactive';
break;
}
}
}
callback.call(context, activeState, i);
}
},
/**
* Convert coords of each axis to Point.
* Return point. For example: [10, 20]
......@@ -230,13 +272,6 @@ define(function(require) {
return point;
},
/**
* Get axis
*/
getAxis: function (dim) {
return this._axesMap[dim];
},
/**
* Get axis layout.
*/
......
......@@ -63,29 +63,30 @@ define(function (require) {
},
/**
* @param {number} [value] When attempting to detect 'no activeIntervals set',
* @param {number|string} [value] When attempting to detect 'no activeIntervals set',
* value can not be input.
* @return {boolean|string} When no activeIntervals set, it returns null,
* which means active.
* @return {string} 'normal': no activeIntervals set,
* 'active',
* 'inactive'.
* @public
*/
isActive: function (value) {
getActiveState: function (value) {
var activeIntervals = this._activeIntervals;
if (!activeIntervals) {
return null;
return 'normal';
}
if (value == null) {
return false;
return 'inactive';
}
for (var i = 0, len = activeIntervals.length; i < len; i++) {
if (activeIntervals[i][0] <= value && value <= activeIntervals[i][1]) {
return true;
return 'active';
}
}
return false;
return 'inactive';
}
};
......
......@@ -909,33 +909,23 @@ define(function (require) {
};
/**
* @param {number} idx
* @param {module:zrender/Element|Array.<module:zrender/Element>} el
* @param {module:zrender/Element} el
*/
listProto.setItemGraphicEl = function (idx, el) {
var hostModel = this.hostModel;
if (zrUtil.isArray(el)) {
zrUtil.each(el, function (singleEl) {
singleEl && addIndexToGraphicEl(singleEl, idx, hostModel);
});
}
else {
addIndexToGraphicEl(el, idx, hostModel);
if (el) {
// Add data index and series index for indexing the data by element
// Useful in tooltip
el.dataIndex = idx;
el.seriesIndex = hostModel && hostModel.seriesIndex;
if (el.type === 'group') {
el.traverse(setItemDataAndSeriesIndex, el);
}
this._graphicEls[idx] = el;
}
this._graphicEls[idx] = el;
};
function addIndexToGraphicEl(el, dataIndex, hostModel) {
// Add data index and series index for indexing the data by element
// Useful in tooltip
el.dataIndex = dataIndex;
el.seriesIndex = hostModel && hostModel.seriesIndex;
if (el.type === 'group') {
el.traverse(setItemDataAndSeriesIndex, el);
}
}
/**
* @param {number} idx
* @return {module:zrender/Element}
......
......@@ -24,7 +24,8 @@
{name: 'PM10', index: 3, text: 'PM10'},
{name: 'CO', index: 4, text: '一氧化碳(CO)'},
{name: 'NO2', index: 5, text: '二氧化氮(NO2)'},
{name: 'SO2', index: 6, text: '二氧化硫(SO2)'}
{name: 'SO2', index: 6, text: '二氧化硫(SO2)'},
{name: '等级', index: 7, text: '等级'}
];
require([
......@@ -92,7 +93,9 @@
{dim: 'dim3', name: schema[3].text},
{dim: 'dim4', name: schema[4].text},
{dim: 'dim5', name: schema[5].text},
{dim: 'dim6', name: schema[6].text}
{dim: 'dim6', name: schema[6].text},
{dim: 'dim7', name: schema[7].text,
type: 'category', data: ['', '', '轻度污染', '重度污染', '严重污染']}
],
parallel: {
y2: 100,
......@@ -130,20 +133,26 @@
name: '北京',
type: 'parallel',
lineStyle: lineStyle,
data: dataBJ
// data: dataBJ
data: [
[ 1, 32,12 , 19, 28,1.39,24, 8,""],
]
},
{
name: '上海',
type: 'parallel',
lineStyle: lineStyle,
data: dataSH
// data: dataSH
data: [
[ 1, 332,212 , 119, 128,12.39,124, 18,""],
]
},
{
name: '广州',
type: 'parallel',
lineStyle: lineStyle,
data: dataGZ
}
// {
// name: '广州',
// type: 'parallel',
// lineStyle: lineStyle,
// data: dataGZ
// }
]
});
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册