提交 a88b24a1 编写于 作者: L lang

Add event

上级 13ddcf9b
{
"bitwise": false,
"camelcase": true,
"curly": true,
"es3": true,
"eqeqeq": false,
"forin": false,
"immed": true,
"latedef": false,
"newcap": true,
"noarg": false,
"noempty": true,
"nonew": true,
"plusplus": false,
"quotmark": "single",
"regexp": false,
"undef": true,
"unused": "vars",
"strict": false,
"trailing": false,
"maxparams": 20,
"maxdepth": 6,
"maxlen": 200,
"asi": false,
"boss": false,
"debug": false,
"eqnull": true,
"esnext": false,
"evil": true,
"expr": true,
"funcscope": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": true,
"laxcomma": false,
"loopfunc": false,
"multistr": false,
"onecase": false,
"proto": false,
"regexdash": false,
"scripturl": false,
"smarttabs": false,
"shadow": true,
"sub": true,
"supernew": false,
"validthis": true,
"browser": true,
"couch": false,
"devel": true,
"dojo": false,
"jquery": true,
"mootools": false,
"node": false,
"nonstandard": false,
"prototypejs": false,
"rhino": false,
"wsh": false,
"nomen": false,
"onevar": false,
"passfail": false,
"white": false,
"predef": [
"define",
"require"
]
}
\ No newline at end of file
......@@ -9,10 +9,9 @@ define(function (require) {
var LEGEND_DISABLE_COLOR = '#ccc';
function createSelectActionDispatcher(uid, seriesName, api) {
function createSelectActionDispatcher(seriesName, api) {
api.dispatch({
type: 'legendToggleSelect',
from: uid,
seriesName: seriesName
});
}
......@@ -218,7 +217,7 @@ define(function (require) {
this.group.add(itemGroup);
itemGroup.on('click', zrUtil.curry(createSelectActionDispatcher, this.uid, name, api), this);
itemGroup.on('click', zrUtil.curry(createSelectActionDispatcher, name, api), this);
}
});
});
\ No newline at end of file
......@@ -12,7 +12,7 @@ define(function(require) {
* @property {string} [from]
* @property {string} seriesName
*/
echarts.registerAction('legendToggleSelect', function (event, ecModel) {
echarts.registerAction('legendToggleSelect', 'legendSelected', function (event, ecModel) {
// Update all legend components
ecModel.eachComponent('legend', function (legendModel) {
legendModel && legendModel.toggleSelected(event.seriesName);
......
......@@ -19,6 +19,7 @@ define(function (require) {
var zrUtil = require('zrender/core/util');
var colorTool = require('zrender/tool/color');
var env = require('zrender/core/env');
var Eventful = require('zrender/mixin/Eventful');
var each = zrUtil.each;
......@@ -88,6 +89,10 @@ define(function (require) {
*/
this._coordinateSystem = new CoordinateSystemManager();
Eventful.call(this);
// Init mouse events
this._initEvents();
}
var echartsProto = ECharts.prototype;
......@@ -152,7 +157,7 @@ define(function (require) {
* @param {Object} payload
*/
echartsProto.update = function (payload) {
console.time && console.time('update');
// console.time && console.time('update');
var ecModel = this._model;
......@@ -186,7 +191,7 @@ define(function (require) {
}
backgroundColor && (this._dom.style.backgroundColor = backgroundColor);
console.time && console.timeEnd('update');
// console.time && console.timeEnd('update');
};
// PENDING
......@@ -239,6 +244,15 @@ define(function (require) {
this.update();
};
/**
* @return {[type]} [description]
*/
echartsProto.makeActionFromEvent = function (eventObj) {
var payload = zrUtil.extend({}, eventObj);
payload.type = eventActionMap[eventObj.type];
return payload;
};
/**
* @pubilc
* @param {Object} payload
......@@ -248,9 +262,16 @@ define(function (require) {
echartsProto.dispatch = function (payload) {
var actionWrap = actions[payload.type];
if (actionWrap) {
var updateMethod = actionWrap.actionInfo.update || 'update';
var actionInfo = actionWrap.actionInfo;
var updateMethod = actionInfo.update || 'update';
actionWrap.action(payload, this._model);
updateMethod !== 'none' && this[updateMethod](payload);
// Emit event outside
// Convert type to eventType
var eventObj = zrUtil.extend({}, payload);
eventObj.type = actionInfo.event || eventObj.type;
this.trigger(eventObj.type, eventObj);
}
};
......@@ -279,6 +300,11 @@ define(function (require) {
};
/**
* Prepare charts view instances
* @param {module:echarts/model/Global} ecModel
* @private
*/
echartsProto._prepareCharts = function (ecModel) {
var chartsList = this._chartsList;
......@@ -327,6 +353,11 @@ define(function (require) {
}
};
/**
* Prepare component view instances
* @param {module:echarts/model/Global} ecModel
* @private
*/
echartsProto._prepareComponents = function (ecModel) {
var componentsMap = this._componentsMap;
......@@ -418,9 +449,6 @@ define(function (require) {
*/
echartsProto._doLayout = function (ecModel, payload) {
var api = this._extensionAPI;
each(this._layouts, function (layout) {
layout.update(ecModel, api, payload);
});
each(layoutFuncs, function (layout) {
layout(ecModel, api, payload);
});
......@@ -475,6 +503,31 @@ define(function (require) {
}, this);
};
var MOUSE_EVENT_NAMES = [
'click', 'dblclick', 'mouseover', 'mouseout', 'globalout'
];
/**
* @private
*/
echartsProto._initEvents = function () {
var zr = this._zr;
each(MOUSE_EVENT_NAMES, function (eveName) {
zr.on(eveName, function (e) {
var ecModel = this.getModel();
var el = e.target;
if (el && el.dataIndex != null) {
var hostModel = el.hostModel || ecModel.getSeriesByIndex(
el.seriesIndex, true
);
var params = hostModel && hostModel.getDataParams(el.dataIndex) || {};
params.event = e;
params.type = eveName;
this.trigger(eveName, params);
}
}, this);
}, this);
};
echartsProto.dispose = function () {
each(this._components, function (component) {
component.dispose();
......@@ -486,6 +539,8 @@ define(function (require) {
this.zr.dispose();
};
zrUtil.mixin(ECharts, Eventful);
/**
* @param {module:echarts/model/Series|module:echarts/model/Component} model
* @param {module:echarts/view/Component|module:echarts/view/Chart} view
......@@ -506,6 +561,12 @@ define(function (require) {
*/
var actions = [];
/**
* Map from eventType to actionType
* @type {Object}
*/
var eventActionMap = {};
/**
* @type {Array.<Function>}
* @inner
......@@ -577,21 +638,27 @@ define(function (require) {
*
* @param {(string|Object)} actionInfo
* @param {string} actionInfo.type
* @param {string=} actionInfo.event
* @param {string=} actionInfo.update
* @param {Function=} action
*/
echarts.registerAction = function (actionInfo, action) {
* @param {string} [actionInfo.event]
* @param {string} [actionInfo.update]
* @param {string} [eventName]
* @param {Function} action
*/
echarts.registerAction = function (actionInfo, eventName, action) {
if (typeof eventName === 'function') {
action = eventName;
eventName = '';
}
var actionType = zrUtil.isObject(actionInfo)
? actionInfo.type
: ([actionInfo, actionInfo = {}][0]);
: ([actionInfo, actionInfo = {
event: eventName
}][0]);
eventName = actionInfo.event;
if (!actions[actionType]) {
actions[actionType] = {action: action, actionInfo: actionInfo};
}
// TODO
// event
eventActionMap[eventName] = actionType;
};
/**
......
......@@ -10,7 +10,6 @@ define(function () {
// '#1e90ff','#ff6347','#7b68ee','#00fa9a','#ffd700',
// '#6699FF','#ff6666','#3cb371','#b8860b','#30e0e0'],
// https://dribbble.com/shots/1065960-Infographic-Pie-chart-visualization
color: ['#5793f3', '#d14a61', '#fd9c35', '#675bba', '#fec42c',
'#dd4444', '#d4df5a', '#cd4870'],
......@@ -28,42 +27,11 @@ define(function () {
fontStyle: 'normal',
fontWeight: 'normal'
},
EVENT: {
// -------全局通用
REFRESH: 'refresh',
RESTORE: 'restore',
RESIZE: 'resize',
CLICK: 'click',
DBLCLICK: 'dblclick',
HOVER: 'hover',
MOUSEOUT: 'mouseout',
// -------业务交互逻辑
DATA_CHANGED: 'dataChanged',
DATA_ZOOM: 'dataZoom',
DATA_RANGE: 'dataRange',
DATA_RANGE_SELECTED: 'dataRangeSelected',
DATA_RANGE_HOVERLINK: 'dataRangeHoverLink',
LEGEND_SELECTED: 'legendSelected',
LEGEND_HOVERLINK: 'legendHoverLink',
MAP_SELECTED: 'mapSelected',
PIE_SELECTED: 'pieSelected',
MAGIC_TYPE_CHANGED: 'magicTypeChanged',
DATA_VIEW_CHANGED: 'dataViewChanged',
TIMELINE_CHANGED: 'timelineChanged',
MAP_ROAM: 'mapRoam',
FORCE_LAYOUT_END: 'forceLayoutEnd',
// -------内部通信
TOOLTIP_HOVER: 'tooltipHover',
TOOLTIP_IN_GRID: 'tooltipInGrid',
TOOLTIP_OUT_GRID: 'tooltipOutGrid',
ROAMCONTROLLER: 'roamController'
},
// 主题,默认标志图形类型列表
symbolList: [
'circle', 'rectangle', 'triangle', 'diamond',
'emptyCircle', 'emptyRectangle', 'emptyTriangle', 'emptyDiamond'
],
// symbolList: [
// 'circle', 'rectangle', 'triangle', 'diamond',
// 'emptyCircle', 'emptyRectangle', 'emptyTriangle', 'emptyDiamond'
// ],
animation: true, // 过渡动画是否开启
animationThreshold: 2000, // 动画元素阀值,产生的图形原素超过2000不出动画
animationDuration: 1000, // 过渡动画参数:进入
......
......@@ -139,7 +139,7 @@ define(function (require) {
TimeScale.prototype[methodName] = function (val) {
val = +parseDate(val);
return intervalScaleProto[methodName].call(this, val);
}
};
});
zrUtil.inherits(TimeScale, IntervalScale);
......@@ -174,7 +174,7 @@ define(function (require) {
*/
TimeScale.create = function () {
return new TimeScale();
}
};
require('./scale').register(TimeScale);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册