From 7e6f5b5b442315ecb8b28d3bc5fc88308d64c33b Mon Sep 17 00:00:00 2001 From: lang Date: Thu, 16 Jun 2016 17:53:03 +0800 Subject: [PATCH] Enable tooltip when scatter is large --- src/chart/helper/LargeSymbolDraw.js | 39 +++++++++++++++++++++++++++-- src/chart/lines/LinesView.js | 11 ++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/chart/helper/LargeSymbolDraw.js b/src/chart/helper/LargeSymbolDraw.js index 5b505726e..bdd79190d 100644 --- a/src/chart/helper/LargeSymbolDraw.js +++ b/src/chart/helper/LargeSymbolDraw.js @@ -37,6 +37,28 @@ define(function (require) { symbolProxy.buildPath(path, symbolProxyShape, true); } } + }, + + findDataIndex: function (x, y) { + var shape = this.shape; + var points = shape.points; + var sizes = shape.sizes; + + // Not consider transform + // Treat each element as a rect + // top down traverse + for (var i = points.length - 1; i >= 0; i--) { + var pt = points[i]; + var size = sizes[i]; + var x0 = pt[0] - size[0] / 2; + var y0 = pt[1] - size[1] / 2; + if (x >= x0 && y >= y0 && x <= x0 + size[0] && y <= y0 + size[1]) { + // i is dataIndex + return i; + } + } + + return -1; } }); @@ -44,7 +66,8 @@ define(function (require) { this.group = new graphic.Group(); this._symbolEl = new LargeSymbolPath({ - silent: true + // rectHover: true, + // cursor: 'default' }); } @@ -90,8 +113,20 @@ define(function (require) { symbolEl.setColor(visualColor); } + // Enable tooltip + // PENDING May have performance issue when path is extremely large + symbolEl.seriesIndex = seriesModel.seriesIndex; + symbolEl.on('mousemove', function (e) { + symbolEl.dataIndex = null; + var dataIndex = symbolEl.findDataIndex(e.offsetX, e.offsetY); + if (dataIndex > 0) { + // Provide dataIndex for tooltip + symbolEl.dataIndex = dataIndex; + } + }); + // Add back - this.group.add(this._symbolEl); + this.group.add(symbolEl); }; largeSymbolProto.updateLayout = function (seriesModel) { diff --git a/src/chart/lines/LinesView.js b/src/chart/lines/LinesView.js index 7f2389e21..01575da4d 100644 --- a/src/chart/lines/LinesView.js +++ b/src/chart/lines/LinesView.js @@ -39,12 +39,23 @@ define(function (require) { }); } if (hasEffect && trailLength) { + if (__DEV__) { + var notInIndividual = false; + ecModel.eachSeries(function (otherSeriesModel) { + if (otherSeriesModel !== seriesModel && otherSeriesModel.get('zlevel') === zlevel) { + notInIndividual = true; + } + }); + notInIndividual && console.warn('Lines with trail effect should have an individual zlevel'); + } + zr.configLayer(zlevel, { motionBlur: true, lastFrameAlpha: Math.max(Math.min(trailLength / 10 + 0.9, 1), 0) }); } + this.group.add(lineDraw.group); lineDraw.updateData(data); -- GitLab