提交 536f61f4 编写于 作者: P pah100

save / restore data, legend problem

上级 77231023
......@@ -9,6 +9,8 @@ define(function(require) {
type: 'series.line',
dependencies: ['xAxis', 'yAxis'],
getInitialData: function (option, ecModel) {
return List.fromArray(option.data, this, ecModel);
},
......
......@@ -9,6 +9,8 @@ define(function (require) {
type: 'series.scatter',
dependencies: ['xAxis', 'yAxis'],
getInitialData: function (option, ecModel) {
return List.fromArray(option.data, this, ecModel);
},
......
......@@ -3,7 +3,6 @@ define(function (require) {
var echarts = require('../../echarts');
var zrUtil = require('zrender/core/util');
var helper = require('./helper');
var unique = require('../../util/unique');
var retrieveValue = helper.retrieveValue;
// Constants
......@@ -16,7 +15,6 @@ define(function (require) {
init: function (echarts) {
this._location;
this._uid = unique.getUID('dataZoomView');
},
render: function (dataZoomModel, ecModel, api, event) {
......@@ -29,7 +27,7 @@ define(function (require) {
this._api = api;
this._orient = dataZoomModel.get('orient');
if (!event || event.type !== 'dataZoom' || event.from !== this._uid) {
if (!event || event.type !== 'dataZoom' || event.from !== this.uid) {
this.group.clear();
if (this.dataZoomModel.get('show') === false) {
......@@ -300,8 +298,9 @@ define(function (require) {
this._api.dispatch({
type: 'dataZoom',
from: this._uid,
param: this._normalizeToRange()
from: this.uid,
param: this._normalizeToRange(),
targetModel: this._dataZoomModel
});
// FIXME
......
......@@ -8,7 +8,8 @@ define(function(require) {
var echarts = require('../../echarts');
var helper = require('./helper');
echarts.registerAction(function (event, ecModel) {
echarts.registerAction('dataZoom', function (event, ecModel) {
var sourceDataZoomModel = event.targetModel;
ecModel.eachComponent('dataZoom', zrUtil.curry(processSingleDataZoom, event, ecModel));
});
......@@ -21,4 +22,11 @@ define(function(require) {
});
}
function processSingleAxis(ecModel, dataZoomModel, dimNames, axisIndex) {
}
function isSharingAxis(dataZoomModel0, dataZoomModel1) {
}
});
\ No newline at end of file
......@@ -62,11 +62,13 @@ define(function (require) {
// 这里仅仅处理了list类型
var seriesData = seriesModel.getData();
seriesModel.setData(
seriesData['filter' + dimNames.dim.toUpperCase()](start, end)
seriesData['filter' + dimNames.dim.toUpperCase()](function (value) {
return value >= start && value <= end;
})
);
// FIXME
// 对于数值轴,还要考虑log等情况
// 对于数值轴,还要考虑log等情况.
// FIXME
// 对于时间河流图,还要考虑是否须整块移除。
});
......
......@@ -48,5 +48,82 @@ define(function(require) {
return zrUtil.isArray(value) ? value : (value == null ? [] : [value]);
};
/**
* @public
*/
helper.findLinkSet = function (forEachModel, axisIndicesGetter, sourceModel) {
var result = {models: [], dims: {}};
var dimRecords = {};
helper.eachAxisDim(function (dimNames) {
result.dims[dimNames.dim] = [];
dimRecords[dimNames.dim] = [];
});
if (!sourceModel) {
return result;
}
absorb(sourceModel);
var existsLink;
do {
existsLink = false;
forEachModel(processSingleModel);
}
while (existsLink);
wrapUpResult();
return result;
function processSingleModel(model) {
if (!isModelAbsorded(model) && isLink(model)) {
absorb(model);
existsLink = true;
}
}
function isModelAbsorded(model) {
return zrUtil.indexOf(result.models, model) >= 0;
}
function isLink(model) {
var hasLink = false;
helper.eachAxisDim(function (dimNames) {
var axisIndices = axisIndicesGetter(model, dimNames);
var singleDimSet = dimRecords[dimNames.dim];
for (var i = 0, len = axisIndices.length; i < len; i++) {
if (singleDimSet[axisIndices[i]]) {
hasLink = true;
return;
}
}
});
return hasLink;
}
function absorb(model) {
result.models.push(model);
helper.eachAxisDim(function (dimNames) {
var axisIndices = axisIndicesGetter(model, dimNames);
var singleDimSet = dimRecords[dimNames.dim];
for (var i = 0, len = axisIndices.length; i < len; i++) {
singleDimSet[axisIndices[i]] = true;
}
});
}
function wrapUpResult() {
helper.eachAxisDim(function (dimNames) {
var dimRecord = dimRecords[dimNames.dim];
for (var i = 0; i < dimRecord.length; i++) {
if (dimRecord[i]) {
result.dims[dimNames.dim].push(i);
}
}
});
}
};
return helper;
});
\ No newline at end of file
......@@ -34,7 +34,7 @@ define(function (require) {
legendModel.getData().each(function (dataItem) {
var seriesName = dataItem.name;
var seriesModel = ecModel.getSeriesByName(seriesName);
var seriesModel = ecModel.getSeriesByName(seriesName, true);
var color = legendModel.isSelected(seriesName)
? seriesModel.getVisual('color')
: '#ccc';
......
......@@ -159,9 +159,7 @@ define(function (require) {
var ecModel = this._model;
ecModel.restore();
ecModel.save();
ecModel.restoreData();
this._processData(ecModel);
......
......@@ -48,6 +48,12 @@ define(function (require) {
*/
this._componentsMap = {};
/**
* @type {Object.<string, module:echarts/model/Model>}
* @private
*/
this._componentsMapBeforeProcessing = {};
/**
* @type {module:echarts/model/Model}
* @private
......@@ -149,6 +155,11 @@ define(function (require) {
}
}
}, this);
// Backup data
zrUtil.each(componentsMap, function (components, componentType) {
this._componentsMapBeforeProcessing[componentType] = components.slice();
}, this);
},
/**
......@@ -179,10 +190,13 @@ define(function (require) {
/**
* @param {string} name
* @param {boolean} beforeProcessing
* @return {module:echarts/model/Series}
*/
getSeriesByName: function (name) {
var series = this._componentsMap.series;
getSeriesByName: function (name, beforeProcessing) {
var series = beforeProcessing
? this._componentsMapBeforeProcessing.series
: this._componentsMap.series;
for (var i = 0, len = series.length; i < len; i++) {
// name should be unique.
if (series[i].name === name) {
......@@ -238,36 +252,20 @@ define(function (require) {
);
},
save: function () {
var seriesList = this._componentsMap.series;
this._stack.push({
series: seriesList.slice()
});
var components = this._components;
var i;
for (i = 0; i < components.length; i++) {
components[i].save();
}
for (i = 0; i < seriesList.length; i++) {
seriesList[i].save();
}
},
restoreData: function () {
var componentsMap = this._componentsMap;
var componentTypes = [];
restore: function () {
if (this._stack.length) {
this._componentsMap.series = this._stack.pop().series;
}
zrUtil.each(this._componentsMapBeforeProcessing, function (components, componentType) {
componentsMap[componentType] = components.slice();
componentTypes.push(componentType);
});
var seriesList = this._componentsMap.series;
var components = this._components;
var i;
for (i = 0; i < components.length; i++) {
components[i].restore();
}
for (i = 0; i < seriesList.length; i++) {
seriesList[i].restore();
}
ComponentModel.topologicalTravel(componentTypes, function (componentType, dependencies) {
zrUtil.each(componentsMap[componentType], function (component) {
component.restoreData();
});
});
},
/**
......
......@@ -4,6 +4,7 @@
define(function (require) {
var zrUtil = require('zrender/core/util');
var unique = require('../util/unique');
/**
* @alias module:echarts/model/Model
......@@ -37,6 +38,13 @@ define(function (require) {
*/
this.dependentModels = dependentModels;
/**
* @type {string}
* @public
* @readOnly
*/
this.uid = unique.getUID('model');
this.init.apply(this, arguments);
}
......@@ -133,9 +141,7 @@ define(function (require) {
this._visual[key] = val;
},
save: function () {},
restore: function () {},
restoreData: function () {},
// Pending
clone: function () {
......
......@@ -49,7 +49,7 @@ define(function(require) {
*/
this._data = this.getInitialData(option, ecModel);
this._stack = [];
this._dataBeforeProcessing = this._data.clone();
},
mergeDefaultAndTheme: function (option, ecModel) {
......@@ -74,16 +74,8 @@ define(function(require) {
return this._data;
},
save: function () {
this._stack.push({
data: this._data.clone()
});
},
restore: function () {
if (this._stack.length) {
this._data = this._stack.pop().data;
}
restoreData: function () {
this._data = this._dataBeforeProcessing.clone();
}
});
......
......@@ -2,6 +2,7 @@ define(function (require) {
var zrUtil = require('zrender/core/util');
var Group = require('zrender/container/Group');
var unique = require('../util/unique');
function Chart() {
......@@ -10,6 +11,12 @@ define(function (require) {
* @readOnly
*/
this.group = new Group();
/**
* @type {string}
* @readOnly
*/
this.uid = unique.getUID('viewChart');
}
Chart.prototype = {
......
......@@ -2,6 +2,7 @@ define(function (require) {
var zrUtil = require('zrender/core/util');
var Group = require('zrender/container/Group');
var unique = require('../util/unique');
var Component = function () {
/**
......@@ -9,6 +10,12 @@ define(function (require) {
* @readOnly
*/
this.group = new Group();
/**
* @type {string}
* @readOnly
*/
this.uid = unique.getUID('viewComponent');
};
Component.prototype = {
......
document.write('<script src="ut/spec/common/helper.js"><\/script>');
document.write('<script src="ut/core/utHelper.js"><\/script>');
// Specs ...
document.write('<script src="ut/spec/model/Component.js"><\/script>');
document.write('<script src="ut/spec/dataZoom/helper.js"><\/script>');
......@@ -6,6 +6,8 @@
*/
var helper = context.utHelper = {};
var nativeSlice = Array.prototype.slice;
/**
* @public
*/
......@@ -40,6 +42,26 @@
|| document.documentElement;
};
/**
* @public
*/
helper.curry = function (func) {
var args = nativeSlice.call(arguments, 1);
return function () {
return func.apply(this, args.concat(nativeSlice.call(arguments)));
};
};
/**
* @public
*/
helper.bind = function (func, context) {
var args = nativeSlice.call(arguments, 2);
return function () {
return func.apply(context, args.concat(nativeSlice.call(arguments)));
};
};
/**
* Load javascript script
*
......
......@@ -53,6 +53,6 @@ body { overflow-y: scroll; }
.jasmine_html-reporter .failures .spec-detail { margin-bottom: 28px; }
.jasmine_html-reporter .failures .spec-detail .description { background-color: #ca3a11; }
.jasmine_html-reporter .failures .spec-detail .description a { color: white; }
.jasmine_html-reporter .result-message { padding-top: 14px; color: #333; white-space: pre; }
.jasmine_html-reporter .result-message { padding-top: 14px; color: #333; }
.jasmine_html-reporter .result-message span.result { display: block; }
.jasmine_html-reporter .stack-trace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666; border: 1px solid #ddd; background: white; white-space: pre; }
describe('dataZoom#helper', function() {
var utHelper = window.utHelper;
var helper;
beforeAll(function (done) { // jshint ignore:line
utHelper.resetPackageLoader(function () {
window.require(['echarts/component/dataZoom/helper'], function (h) {
helper = h;
done();
});
});
});
describe('findLinkSet', function () {
function forEachModel(models, callback) {
for (var i = 0; i < models.length; i++) {
callback(models[i]);
}
}
function axisIndicesGetter(model, dimNames) {
return model[dimNames.axisIndex];
}
it('findLinkSet_base', function (done) {
var models = [
{xAxisIndex: [1, 2], yAxisIndex: [0]},
{xAxisIndex: [3], yAxisIndex: [1]},
{xAxisIndex: [5], yAxisIndex: []},
{xAxisIndex: [2, 5], yAxisIndex: []}
];
var result = helper.findLinkSet(
utHelper.curry(forEachModel, models),
axisIndicesGetter,
models[0]
);
expect(result).toEqual({
models: [models[0], models[3], models[2]],
dims: {x: [1, 2, 5], y: [0]}
});
done();
});
it('findLinkSet_crossXY', function (done) {
var models = [
{xAxisIndex: [1, 2], yAxisIndex: [0]},
{xAxisIndex: [3], yAxisIndex: [3, 0]},
{xAxisIndex: [6, 3], yAxisIndex: [9]},
{xAxisIndex: [5, 3], yAxisIndex: []},
{xAxisIndex: [8], yAxisIndex: [4]}
];
var result = helper.findLinkSet(
utHelper.curry(forEachModel, models),
axisIndicesGetter,
models[0]
);
expect(result).toEqual({
models: [models[0], models[1], models[2], models[3]],
dims: {x: [1, 2, 3, 5, 6], y: [0, 3, 9]}
});
done();
});
it('findLinkSet_emptySourceModel', function (done) {
var models = [
{xAxisIndex: [1, 2], yAxisIndex: [0]},
{xAxisIndex: [3], yAxisIndex: [3, 0]},
{xAxisIndex: [6, 3], yAxisIndex: [9]},
{xAxisIndex: [5, 3], yAxisIndex: []},
{xAxisIndex: [8], yAxisIndex: [4]}
];
var result = helper.findLinkSet(
utHelper.curry(forEachModel, models),
axisIndicesGetter
);
expect(result).toEqual({
models: [],
dims: {x: [], y: []}
});
done();
});
});
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册