From 8d0e152da93640ef51b31d4e2123349b7dcde32c Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 16 Jan 2017 01:06:28 -0500 Subject: [PATCH] Tilemap should notify correctly when it is ready This regression was introduced when extracting tilemap from vislib. --- src/ui/public/vis_maps/maps.js | 15 +++++++++++++-- src/ui/public/vis_maps/visualizations/_map.js | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ui/public/vis_maps/maps.js b/src/ui/public/vis_maps/maps.js index 2611192e28104..5a23cf13a48d5 100644 --- a/src/ui/public/vis_maps/maps.js +++ b/src/ui/public/vis_maps/maps.js @@ -1,4 +1,5 @@ import _ from 'lodash'; +import $ from 'jquery'; import d3 from 'd3'; import MapsConfigProvider from './lib/maps_config'; import TileMapChartProvider from './visualizations/tile_map'; @@ -91,10 +92,13 @@ export default function MapsFactory(Private) { } this.layout.render(); - // todo: title const self = this; this.charts = []; - d3.select(this.el).selectAll('.chart').each(function (chartData) { + + + let loadedCount = 0; + const chartSelection = d3.select(this.el).selectAll('.chart'); + chartSelection.each(function (chartData) { const chart = new TileMapChart(self, this, chartData); self.activeEvents().forEach(function (event) { @@ -103,6 +107,13 @@ export default function MapsFactory(Private) { self.charts.push(chart); chart.render(); + + chart.events.on('rendered', function () { + loadedCount++; + if (loadedCount === chartSelection.length) { + $(self.el).trigger('renderComplete'); + } + }); }); } diff --git a/src/ui/public/vis_maps/visualizations/_map.js b/src/ui/public/vis_maps/visualizations/_map.js index 6331e820d44b5..e592e36cfebc7 100644 --- a/src/ui/public/vis_maps/visualizations/_map.js +++ b/src/ui/public/vis_maps/visualizations/_map.js @@ -192,7 +192,10 @@ export default function MapFactory(Private, tilemapSettings) { this._tileLayer.on('tileload', saturateTiles); this._tileLayer.on('load', () => { - if (!self._events) return; + + if (!self._events) { + return; + } self._events.emit('rendered', { chart: self._chartData,