From e198f4129f4c1f1b81b47252bbc92a74eb2f2e9a Mon Sep 17 00:00:00 2001 From: ppisljar Date: Tue, 20 Sep 2016 12:22:43 +0200 Subject: [PATCH 1/3] adding mapLoaded event to tile_map visualization --- src/ui/public/vislib/visualizations/_map.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ui/public/vislib/visualizations/_map.js b/src/ui/public/vislib/visualizations/_map.js index 1b138c338a33f..ec9a67c52df5f 100644 --- a/src/ui/public/vislib/visualizations/_map.js +++ b/src/ui/public/vislib/visualizations/_map.js @@ -211,6 +211,17 @@ export default function MapFactory(Private, tilemap, $sanitize) { this._tileLayer.on('tileload', saturateTiles); + this._tileLayer.on('load', () => { + if (!self._events) return; + + self._events.emit('mapLoaded', { + chart: self._chartData, + map: self.map, + center: self._mapCenter, + zoom: self._mapZoom, + }); + }); + this.map.on('unload', function () { self._tileLayer.off('tileload', saturateTiles); }); From 8324f5a83e9bc573684cc230b946d8239968e4b3 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Tue, 20 Sep 2016 19:54:52 +0200 Subject: [PATCH 2/3] adding rendered event to each chart and renderComplete to vis --- src/ui/public/vislib/lib/handler/handler.js | 12 ++++++++++-- src/ui/public/vislib/visualizations/_map.js | 2 +- src/ui/public/vislib/visualizations/area_chart.js | 4 ++++ src/ui/public/vislib/visualizations/column_chart.js | 4 ++++ src/ui/public/vislib/visualizations/line_chart.js | 4 ++++ src/ui/public/vislib/visualizations/pie_chart.js | 4 ++++ 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/ui/public/vislib/lib/handler/handler.js b/src/ui/public/vislib/lib/handler/handler.js index 18aa28ab5686b..c02067d6e7449 100644 --- a/src/ui/public/vislib/lib/handler/handler.js +++ b/src/ui/public/vislib/lib/handler/handler.js @@ -116,14 +116,22 @@ export default function HandlerBaseClass(Private) { }); // render the chart(s) - selection.selectAll('.chart') - .each(function (chartData) { + this.loadedCount = 0; + const chartSelection = selection.selectAll('.chart'); + chartSelection.each(function (chartData) { const chart = new self.ChartClass(self, this, chartData); self.vis.activeEvents().forEach(function (event) { self.enable(event, chart); }); + chart.events.on('rendered', () => { + self.loadedCount++; + if (self.loadedCount === chartSelection.length) { + charts[0].events.emit('renderComplete'); + } + }); + charts.push(chart); chart.render(); }); diff --git a/src/ui/public/vislib/visualizations/_map.js b/src/ui/public/vislib/visualizations/_map.js index ec9a67c52df5f..7d724aee693f8 100644 --- a/src/ui/public/vislib/visualizations/_map.js +++ b/src/ui/public/vislib/visualizations/_map.js @@ -214,7 +214,7 @@ export default function MapFactory(Private, tilemap, $sanitize) { this._tileLayer.on('load', () => { if (!self._events) return; - self._events.emit('mapLoaded', { + self._events.emit('rendered', { chart: self._chartData, map: self.map, center: self._mapCenter, diff --git a/src/ui/public/vislib/visualizations/area_chart.js b/src/ui/public/vislib/visualizations/area_chart.js index c7599800d4c25..04528482c3776 100644 --- a/src/ui/public/vislib/visualizations/area_chart.js +++ b/src/ui/public/vislib/visualizations/area_chart.js @@ -365,6 +365,10 @@ export default function AreaChartFactory(Private) { timeMarker.render(svg); } + self.events.emit('rendered', { + chart: data + }); + return svg; }); }; diff --git a/src/ui/public/vislib/visualizations/column_chart.js b/src/ui/public/vislib/visualizations/column_chart.js index 172fef57fd57b..c587025f85564 100644 --- a/src/ui/public/vislib/visualizations/column_chart.js +++ b/src/ui/public/vislib/visualizations/column_chart.js @@ -315,6 +315,10 @@ export default function ColumnChartFactory(Private) { timeMarker.render(svg); } + self.events.emit('rendered', { + chart: data + }); + return svg; }); }; diff --git a/src/ui/public/vislib/visualizations/line_chart.js b/src/ui/public/vislib/visualizations/line_chart.js index 867a503056a37..d1721c59dc63b 100644 --- a/src/ui/public/vislib/visualizations/line_chart.js +++ b/src/ui/public/vislib/visualizations/line_chart.js @@ -339,6 +339,10 @@ export default function LineChartFactory(Private) { timeMarker.render(svg); } + self.events.emit('rendered', { + chart: data + }); + return svg; }); }; diff --git a/src/ui/public/vislib/visualizations/pie_chart.js b/src/ui/public/vislib/visualizations/pie_chart.js index e3ad68584c7be..ac467990b2661 100644 --- a/src/ui/public/vislib/visualizations/pie_chart.js +++ b/src/ui/public/vislib/visualizations/pie_chart.js @@ -202,6 +202,10 @@ export default function PieChartFactory(Private) { const path = self.addPath(width, height, svg, slices); self.addPathEvents(path); + self.events.emit('rendered', { + chart: data + }); + return svg; }); }; From b4780fe04b1b41a086532e14ce39e366f762f548 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Thu, 22 Sep 2016 09:24:19 +0200 Subject: [PATCH 3/3] fixing based on Spencers comments --- src/ui/public/vislib/lib/handler/handler.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ui/public/vislib/lib/handler/handler.js b/src/ui/public/vislib/lib/handler/handler.js index c02067d6e7449..76d05d91316d6 100644 --- a/src/ui/public/vislib/lib/handler/handler.js +++ b/src/ui/public/vislib/lib/handler/handler.js @@ -116,7 +116,7 @@ export default function HandlerBaseClass(Private) { }); // render the chart(s) - this.loadedCount = 0; + let loadedCount = 0; const chartSelection = selection.selectAll('.chart'); chartSelection.each(function (chartData) { const chart = new self.ChartClass(self, this, chartData); @@ -126,8 +126,9 @@ export default function HandlerBaseClass(Private) { }); chart.events.on('rendered', () => { - self.loadedCount++; - if (self.loadedCount === chartSelection.length) { + loadedCount++; + if (loadedCount === chartSelection.length) { + // events from all charts are propagated to vis, we only need to fire renderComplete on one (first) charts[0].events.emit('renderComplete'); } });