Commit ef014b8d authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Gestiona las entradas de charts al actualizar

Elimina entradas para gráficas no representadas, para evitar dejar
rastros de parámetros de estaciones que han sido deseleccionados.
parent 4b219455
Loading
Loading
Loading
Loading
+33 −1
Original line number Diff line number Diff line
@@ -102,6 +102,14 @@ define([
			this._publish(layerInstance.getChannel('GET_INFO'));
		},

		_addDataToChart: function(chartInstance) {

			this.inherited(arguments);

			var layerId = chartInstance.getOwnChannel();
			this._layerHasData[layerId] = true;
		},

		_subSmartLegendEntryEnabled: function(res) {

			var layerId = res.layerId,
@@ -132,7 +140,8 @@ define([

		_removeChartLayer: function(cat, agg) {

			var layerId = this._layers[cat][agg];
			var layerInstance = this._layers[cat][agg],
				layerId = layerInstance.getOwnChannel();

			delete this._layerHasData[layerId];

@@ -141,6 +150,29 @@ define([

		_clearOldChartsData: function() {

			for (var layerCategoryId in this._layers) {
				var layerCategory = this._layers[layerCategoryId],
					layerAggregationsInCategory = Object.keys(layerCategory);

				for (var i = 0; i < layerAggregationsInCategory.length; i++) {
					var layerAggregation = layerAggregationsInCategory[i],
						layerInstance = layerCategory[layerAggregation],
						layerId = layerInstance.getOwnChannel();

					if (this._layerHasData[layerId]) {
						continue;
					}

					this._publish(this._smartLegend.getChannel('REMOVE_ENTRY'), {
						chart: layerId
					});

					this._publish(layerInstance.getChannel('DESTROY'));

					delete layerCategory[layerAggregation];
				}
			}

			this.inherited(arguments);

			this._layerHasData = {};
+34 −2
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ define([
				},
				actions: {
					ADD_ENTRY: 'addEntry',
					REMOVE_ENTRY: 'removeEntry',
					ENTRY_ENABLED: 'entryEnabled',
					ENTRY_DISABLED: 'entryDisabled'
				},
@@ -159,6 +160,9 @@ define([
			this.subscriptionsConfig.push({
				channel : this.getChannel('ADD_ENTRY'),
				callback: '_subAddEntry'
			},{
				channel : this.getChannel('REMOVE_ENTRY'),
				callback: '_subRemoveEntry'
			},{
				channel : this.getChartsContainerChannel("LAYER_ADDED"),
				callback: "_subLayerAdded"
@@ -252,10 +256,38 @@ define([
				return;
			}

			this._layerEntries[layerId] = req;
			this._addEntry(layerId, req);
		},

		_addEntry: function(layerId, data) {

			this._layerEntries[layerId] = data;
			this._stateByLayerId[layerId] = false;

			this._updateLegendContentWithNewInfo(req);
			this._updateLegendContentWithNewInfo(data);
		},

		_subRemoveEntry: function(req) {

			var layerId = req.chart;

			if (layerId) {
				this._removeEntry(layerId);
				return;
			}

			for (layerId in this._layerEntries) {
				this._removeEntry(layerId);
			}
		},

		_removeEntry: function(layerId) {

			var layerPath = this._pathsByLayerId[layerId];
			layerPath && this._removeLayerAndUpdateAncestors(layerPath);

			delete this._layerEntries[layerId];
			delete this._stateByLayerId[layerId];
		},

		_subLayerAdded: function(res) {