From d6c8cbcd82c8bca4bcfd37fe465880b0a10b34f7 Mon Sep 17 00:00:00 2001 From: kener Date: Tue, 29 Apr 2014 11:00:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AB=98=E4=BA=AE=E5=85=B3=E8=81=94=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chart/map.js | 33 +++++++++++---------------------- src/component/base.js | 24 ++++++++++++++++++++++++ src/component/legend.js | 17 +++++++++-------- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/chart/map.js b/src/chart/map.js index 7a42f34ee..f380cedf6 100644 --- a/src/chart/map.js +++ b/src/chart/map.js @@ -43,16 +43,6 @@ define(function (require) { this.messageCenter = messageCenter; var self = this; - /** - * 输出关联区域 - */ - self.shapeHandler.onmouseover = function (param) { - var target = param.target; - var name = target.style._text; - if (self._shapeListMap[name]) { - self.zr.addHoverShape(self._shapeListMap[name]); - } - }; self._onmousewheel = function(param){ return self.__onmousewheel(param); }; @@ -229,12 +219,6 @@ define(function (require) { self._shapeListMap = {}; for (var i = 0, l = self.shapeList.length; i < l; i++) { self.zr.addShape(self.shapeList[i]); - // 通过name关联shape,用于onmouseover - if (self.shapeList[i].type == 'path' - && typeof self.shapeList[i].style._text != 'undefined' - ) { - self._shapeListMap[self.shapeList[i].style._text] = self.shapeList[i]; - } } self.zr.refresh(); if (!self._markAnimation) { @@ -395,7 +379,8 @@ define(function (require) { }); } - + //console.log(JSON.stringify(province)); + //console.log(JSON.stringify(this._mapDataMap[mapType].transform)); return province; }, @@ -811,20 +796,24 @@ define(function (require) { } } + textShape = new TextShape(textShape); + shape = new PathShape(shape); + if (typeof data.hoverable != 'undefined') { // 数据级优先 textShape.hoverable = shape.hoverable = data.hoverable; if (data.hoverable) { - textShape.onmouseover = this.shapeHandler.onmouseover; + textShape.hoverConnect = shape.id; + textShape.onmouseover = this.hoverConnect; } } else if (this._hoverable[mapType]){ // 系列级,补充一个关联响应 - textShape.onmouseover = this.shapeHandler.onmouseover; + textShape.hoverConnect = shape.id; + textShape.onmouseover = this.hoverConnect; } // console.log(name,shape); - ecData.pack( textShape, { @@ -835,7 +824,7 @@ define(function (require) { data, 0, name ); - this.shapeList.push(new TextShape(textShape)); + this.shapeList.push(textShape); ecData.pack( shape, @@ -847,7 +836,7 @@ define(function (require) { data, 0, name ); - this.shapeList.push(new PathShape(shape)); + this.shapeList.push(shape); } //console.log(this._selected); }, diff --git a/src/component/base.js b/src/component/base.js index 0afaa499b..f9cda079c 100644 --- a/src/component/base.js +++ b/src/component/base.js @@ -40,6 +40,21 @@ define(function (require) { this._zlevelBase = this.getZlevelBase(); this.shapeList = []; this.effectList = []; + + var self = this; + self.hoverConnect = function (param) { + var target = (param.target || {}).hoverConnect; + if (target) { + if (!(target instanceof Array)) { + self.zr.addHoverShape(self.getShapeById(target)); + } + else { + for (var i = 0, l = target.length; i < l; i++) { + self.zr.addHoverShape(self.getShapeById(target[i])); + } + } + } + } } /** @@ -129,6 +144,15 @@ define(function (require) { } }, + getShapeById : function(id) { + for (var i = 0, l = this.shapeList.length; i < l; i++) { + if (this.shapeList[i].id == id) { + return this.shapeList[i]; + } + } + return null; + }, + /** * 获取自定义和默认配置合并后的字体设置 */ diff --git a/src/component/legend.js b/src/component/legend.js index 55e540275..ab544dc92 100644 --- a/src/component/legend.js +++ b/src/component/legend.js @@ -147,12 +147,7 @@ define(function (require) { color ); itemShape._name = itemName; - if (this.legendOption.selectedMode) { - itemShape.onclick = function (param) { - self._legendSelected(param); - }; - } - this.shapeList.push(new IconShape(itemShape)); + itemShape = new IconShape(itemShape); // 文字 textShape = { @@ -184,12 +179,18 @@ define(function (require) { } textShape._name = itemName; + textShape = new TextShape(textShape); + if (this.legendOption.selectedMode) { - textShape.onclick = function (param) { + itemShape.onclick = textShape.onclick = function (param) { self._legendSelected(param); }; + itemShape.onmouseover = textShape.onmouseover = this.hoverConnect; + itemShape.hoverConnect = textShape.id; + textShape.hoverConnect = itemShape.id; } - this.shapeList.push(new TextShape(textShape)); + this.shapeList.push(itemShape); + this.shapeList.push(textShape); if (this.legendOption.orient == 'horizontal') { lastX += itemWidth + 5 -- GitLab