提交 a4718851 编写于 作者: L lang

Graph category filtering

上级 1882405b
......@@ -17,21 +17,56 @@ define(function (require) {
init: function (option) {
seriesModelProto.init.apply(this, arguments);
this._udpateCategoriesData();
// Provide data for legend select
this.legendDataProvider = function () {
return this._categoriesData;
};
this._updateCategoriesData();
},
mergeOption: function (option) {
seriesModelProto.mergeOption.apply(this, arguments);
this._udpateCategoriesData();
this._updateCategoriesData();
},
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);
return graph.data;
}
},
restoreData: function () {
seriesModelProto.restoreData.apply(this, arguments);
this.getGraph().restoreData();
},
_udpateCategoriesData: function () {
/**
* @return {module:echarts/data/Graph}
*/
getGraph: function () {
return this.getData().graph;
},
/**
* @return {module:echarts/data/List}
*/
getEdgeData: function () {
return this.getGraph().edgeData;
},
/**
* @return {module:echarts/data/List}
*/
getCategoriesData: function () {
return this._categoriesData;
},
_updateCategoriesData: function () {
var categories = zrUtil.map(this.option.categories || [], function (category) {
// Data must has value
return category.value != null ? category : zrUtil.extend({value : 0}, category);
......@@ -42,22 +77,24 @@ define(function (require) {
this._categoriesData = categoriesData;
},
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);
return graph.data;
}
/**
* @param {number} zoom
*/
setRoamZoom: function (zoom) {
var roamDetail = this.option.roamDetail;
roamDetail && (roamDetail.zoom = zoom);
},
/**
* Get category model by index
* @param {number} id Category index
* @return {module:echarts/model/Model}
* @param {number} x
* @param {number} y
*/
getCategoriesData: function () {
return this._categoriesData;
setRoamPan: function (x, y) {
var roamDetail = this.option.roamDetail;
if (roamDetail) {
roamDetail.x = x;
roamDetail.y = y;
}
},
defaultOption: {
......@@ -125,26 +162,6 @@ define(function (require) {
},
emphasis: {}
}
},
/**
* @param {number} zoom
*/
setRoamZoom: function (zoom) {
var roamDetail = this.option.roamDetail;
roamDetail && (roamDetail.zoom = zoom);
},
/**
* @param {number} x
* @param {number} y
*/
setRoamPan: function (x, y) {
var roamDetail = this.option.roamDetail;
if (roamDetail) {
roamDetail.x = x;
roamDetail.y = y;
}
}
});
......
define(function (require) {
var SymbolDraw = require('../helper/SymbolDraw');
......@@ -42,10 +43,7 @@ define(function (require) {
lineDraw.updateData(
data.graph.edgeData,
seriesModel, api, false,
function (idx) {
return data.graph.edges[idx].dataIndex >= 0;
}
seriesModel, api, false
);
// Save the original lineWidth
......
......@@ -7,7 +7,8 @@ define(function (require) {
}
ecModel.eachSeriesByType('graph', function (graphSeries) {
var categoriesData = graphSeries.getCategoriesData();
var data = graphSeries.getData();
var graph = graphSeries.getGraph();
var data = graph.data;
var categoryNames = categoriesData.mapArray(categoriesData.getName);
......@@ -22,7 +23,6 @@ define(function (require) {
}
return true;
});
}, this);
};
});
\ No newline at end of file
......@@ -35,6 +35,11 @@ define(function (require) {
var max = [];
bbox.fromPoints(positions, min, max);
// Position may be NaN, use view rect instead
if (isNaN(min[0]) || isNaN(min[1])) {
min = [viewRect.x, viewRect.y];
max = [viewRect.x + viewRect.width, viewRect.y + viewRect.height];
}
var bbWidth = max[0] - min[0];
var bbHeight = max[1] - min[1];
......
......@@ -9,7 +9,7 @@ define(function (require) {
if (coordSys && coordSys.type !== 'view') {
return;
}
var graph = seriesModel.getData().graph;
var graph = seriesModel.getGraph();
graph.eachNode(function (node) {
var model = node.getModel();
......
......@@ -24,42 +24,29 @@ define(function (require) {
data.diff(oldData)
.add(function (idx) {
var shape = data.getItemLayout(idx);
if (!(isIgnore && isIgnore[idx])) {
var line = new graphic[shape.cpx1 != null ? 'BezierCurve' : 'Line']({
shape: shape
});
var line = new graphic[shape.cpx1 != null ? 'BezierCurve' : 'Line']({
shape: shape
});
data.setItemGraphicEl(idx, line);
group.add(line);
}
data.setItemGraphicEl(idx, line);
group.add(line);
})
.update(function (newIdx, oldIdx) {
var line = oldData.getItemGraphicEl(oldIdx);
var shape = data.getItemLayout(newIdx);
if (!(isIgnore && isIgnore(newIdx))) {
group.remove(line);
return;
}
if (!line) {
line = new graphic[shape.cpx1 != null ? 'BezierCurve' : 'Line']({
shape: shape
if (shape.cpx1 != null && line.type === 'line') {
var oldShape = line.shape;
line = new graphic.BezierCurve({
shape: oldShape
});
}
else {
if (shape.cpx1 != null && line.type === 'line') {
var oldShape = line.shape;
line = new graphic.BezierCurve({
shape: oldShape
});
line.setShape({
cpx1: (oldShape.x1 + oldShape.x2) / 2,
cpy1: (oldShape.y1 + oldShape.y2) / 2
});
}
api.updateGraphicEl(line, {
shape: shape
line.setShape({
cpx1: (oldShape.x1 + oldShape.x2) / 2,
cpy1: (oldShape.y1 + oldShape.y2) / 2
});
}
api.updateGraphicEl(line, {
shape: shape
});
data.setItemGraphicEl(newIdx, line);
group.add(line);
......@@ -95,7 +82,9 @@ define(function (require) {
});
};
lineDrawProto.remove = function () {
};
return LineDraw;
});
\ No newline at end of file
......@@ -42,14 +42,16 @@ define(function (require) {
});
if (enableAnimation) {
symbolEl.scale = [0, 0];
// FIXME Use scale to improve performance
var zeroShape = symbolUtil.getSymbolShape(
symbolType, 0, 0, 0, 0
).shape;
var normalShape = symbolEl.shape;
symbolEl.shape = zeroShape;
symbolEl.animateTo({
scale: [1, 1]
shape: normalShape
}, 500);
}
else {
symbolEl.scale = [1, 1];
}
return symbolEl;
}
......
......@@ -28,7 +28,7 @@ define(function (require) {
nodeData.initData(nodes);
edgeData.initData(edges, linkNameList, 'weight');
graph.edgeData = edgeData;
graph.setEdgeData(edgeData);
linkList.linkToGraph(nodeData, graph);
......
......@@ -16,7 +16,7 @@ define(function(require) {
option.selected = option.selected || {};
this._data = zrUtil.map(option.data, function (dataItem) {
var legendData = zrUtil.map(option.data, function (dataItem) {
if (typeof dataItem === 'string') {
dataItem = {
name: dataItem
......@@ -24,6 +24,7 @@ define(function(require) {
}
return new Model(dataItem, this);
}, this);
this._data = legendData;
var availableNames = zrUtil.map(ecModel.getSeries(), function (series) {
return series.name;
......@@ -41,7 +42,7 @@ define(function(require) {
this._availableNames = availableNames;
// Try select the first if selectedMode is single
this.select(availableNames[0]);
legendData[0] && this.select(legendData[0].get('name'));
},
/**
......@@ -58,9 +59,9 @@ define(function(require) {
var selected = this.option.selected;
var selectedMode = this.get('selectedMode');
if (selectedMode === 'single') {
var availableNames = this._availableNames;
zrUtil.each(availableNames, function (name) {
selected[name] = false;
var data = this._data;
zrUtil.each(data, function (dataItem) {
selected[dataItem.get('name')] = false;
});
}
selected[name] = true;
......
......@@ -96,7 +96,7 @@ define(function (require) {
);
}, this);
ecModel.eachSeries(function (seriesModel) {
ecModel.eachSeriesAll(function (seriesModel) {
if (seriesModel.legendDataProvider) {
var data = seriesModel.legendDataProvider();
data.each(function (idx) {
......
......@@ -55,7 +55,7 @@ define(function(require) {
// Travel by inverted order to make sure order consistency
// when duplicate keys exists (consider newDataIndex.pop() below).
// For performance consideration, these code below do not look neat.
for (i = oldArr.length - 1; i >= 0; i--) {
for (i = 0; i < oldArr.length; i++) {
var key = keyGetter(oldArr[i]);
var idx = newDataIndexMap[key];
......@@ -66,7 +66,7 @@ define(function(require) {
var len = idx.length;
if (len) {
len === 1 && (newDataIndexMap[key] = null);
idx = idx.pop();
idx = idx.unshift();
}
else {
newDataIndexMap[key] = null;
......
......@@ -46,6 +46,18 @@ define(function(require) {
* @private
*/
this._edgesMap = {};
/**
* @type {module:echarts/data/List}
* @readOnly
*/
this.data;
/**
* @type {module:echarts/data/List}
* @readOnly
*/
this.edgeData;
};
var graphProto = Graph.prototype;
......@@ -249,6 +261,7 @@ define(function(require) {
};
// Filter update
graphProto.update = function () {
var data = this.data;
var edgeData = this.edgeData;
......@@ -262,17 +275,33 @@ define(function(require) {
nodes[data.getRawIndex(i)].dataIndex = i;
}
edgeData.filterSelf(function (idx) {
var edge = edges[edgeData.getRawIndex(idx)];
return edge.node1.dataIndex >= 0 && edge.node2.dataIndex >= 0;
});
// Update edge
for (var i = 0, len = edges.length; i < len; i++) {
edges[i].dataIndex = -1;
}
for (var i = 0, len = edgeData.count(); i < len; i++) {
if (edges[i].node1.dataIndex >= 0 && edges[i].node2.dataIndex >= 0) {
edges[edgeData.getRawIndex(i)].dataIndex = i;
}
edges[edgeData.getRawIndex(i)].dataIndex = i;
}
};
/**
* Set edge data
* @param {module:echarts/data/List} edgeData
*/
graphProto.setEdgeData = function (edgeData) {
this.edgeData = edgeData;
this._edgeDataSaved = edgeData.cloneShallow();
};
graphProto.restoreData = function () {
this.edgeData = this._edgeDataSaved.cloneShallow();
};
/**
* @return {module:echarts/data/Graph}
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册