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

Carga gráficas bajo demanda desde la leyenda

En progreso, aun muestra descoordinaciones.
parent e6fbda45
Loading
Loading
Loading
Loading
+103 −10
Original line number Diff line number Diff line
define([
	"app/designs/chart/layout/SideAndTopAndBottomContent"
	, "app/designs/chart/main/_ChartsWithToolbarsAndSlider"
	, "dojo/_base/declare"
	, "dojo/_base/lang"
	, "redmic/modules/chart/SmartLegend/TimeSeriesSmartLegendImpl"
	'app/designs/chart/layout/SideAndTopAndBottomContent'
	, 'app/designs/chart/main/_ChartsWithToolbarsAndSlider'
	, 'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'dojo/Deferred'
	, 'redmic/modules/chart/SmartLegend/TimeSeriesSmartLegendImpl'
], function (
	SideAndTopAndBottomContent
	, _ChartsWithToolbarsAndSlider
	, declare
	, lang
	, Deferred
	, TimeSeriesSmartLegendImpl
) {

	return declare([SideAndTopAndBottomContent, _ChartsWithToolbarsAndSlider], {
		//	summary:
		//		Main ChartsWithLegendAndToolbarsAndSlider.
@@ -19,20 +22,110 @@ define([

			this._smartLegend = new TimeSeriesSmartLegendImpl({
				parentChannel: this.getChannel(),
				getChartsContainerChannel: lang.hitch(this.chartsContainer,
					this.chartsContainer.getChannel)
				getChartsContainerChannel: lang.hitch(this.chartsContainer, this.chartsContainer.getChannel)
			});

			this.inherited(arguments);
		},

		_defineMainSubscriptions: function() {

			this.inherited(arguments);

			this.subscriptionsConfig.push({
				channel : this._smartLegend.getChannel('ENTRY_ENABLED'),
				callback: '_subSmartLegendEntryEnabled'
			},{
				channel : this._smartLegend.getChannel('ENTRY_DISABLED'),
				callback: '_subSmartLegendEntryDisabled'
			});
		},

		postCreate: function() {

			this.inherited(arguments);

			this._publish(this._smartLegend.getChannel("SHOW"), {
			this._layerHasData = {};

			this._publish(this._smartLegend.getChannel('SHOW'), {
				node: this.sideNode
			});
		},

		_addChartLayersWithoutData: function() {

			if (!this.chartsData) {
				return;
			}

			var definitionIds = Object.keys(this.chartsData.definitionIndex);

			for (var i = 0; i < definitionIds.length; i++) {
				var cat = definitionIds[i];
				this._addChartLayerWithoutData(cat, 'avg');
				if (i === 0) {
					var dfd = new Deferred();
					this._continueBuildQueryAndRequestData(dfd, cat);
				}
			}
		},

		_addChartLayerWithoutData: function(cat, agg) {

			var catLayers = this._layers[cat],
				layerInstance = catLayers && catLayers[agg];

			if (layerInstance) {
				return;
			}

			layerInstance = this._createChartLayer(cat, agg, {
				pathToValue: agg === 'raw' ? '' : agg,
				hierarchicalInfo: this._getHierarchicalInfo(cat),
				definition: this._getDefinitions(cat),
				parameterName: this._getParameterName(cat),
				label: this._createChartLabel(agg)
			});

			this._once(layerInstance.getChannel('GOT_INFO'), lang.hitch(this, function(layerRes) {

				this._publish(this._smartLegend.getChannel('ADD_ENTRY'), layerRes);
			}));

			this._publish(layerInstance.getChannel('GET_INFO'));
		},

		_subSmartLegendEntryEnabled: function(res) {

			var layerId = res.layerId,
				indexByLayerId = this._layersIndexByLayerId[layerId],
				dataDefinitionIds = indexByLayerId && indexByLayerId.cat;

			if (!dataDefinitionIds || this._layerHasData[layerId]) {
				return;
			}

			var dfd = new Deferred();
			dfd.then(lang.hitch(this, function(id) {

				this._layerHasData[id] = true;
			}, layerId));

			this._continueBuildQueryAndRequestData(dfd, dataDefinitionIds);
		},

		_subSmartLegendEntryDisabled: function(res) {

			console.log('disabled de leyenda capa', res);
		},

		_removeChartLayer: function(cat, agg) {

			var layerId = this._layers[cat][agg];

			delete this._layerHasData[layerId];

			this.inherited(arguments);
		}
	});
});
+4 −3
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ define([
				dataDefinitions: this._parseDataForAggregationTool(this.categories)
			});

			if (this._chartsContainerIsReady) {
			if (changeObj.oldValue && this._chartsContainerIsReady) {
				this._emitEvt('CLEAR_LAYERS');
				this._interval && this._setInterval(this._interval);
			}
@@ -254,6 +254,7 @@ define([
		_setInterval: function(interval) {

			this._interval = interval;

			this._publish(this.chartsContainer.getChannel('INTERVAL_CHANGED'), {
				interval: interval
			});
@@ -426,9 +427,9 @@ define([

		_createChartLabel: function(agg) {

			var intervalLabel = this.intervalLabelKey || this._intervalLabelKey;
			var intervalLabel = this.intervalLabelKey || this._intervalLabelKey || this._interval;

			return this._interval !== 'raw' ? agg + '_by_' + intervalLabel || this._interval : agg;
			return this._interval !== 'raw' ? agg + '_by_' + intervalLabel : agg;
		}

	});
+10 −2
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ define([

			lang.mixin(this, this.config, args);

			aspect.after(this, '_setInterval', lang.hitch(this, this._buildQueryAndRequestData));
			aspect.after(this, '_setInterval', lang.hitch(this, this._prepareChartsRepresentation));
		},

		_getCategories: function() {
@@ -269,7 +269,6 @@ define([
			var definitionData = lang.clone(this.chartsData.data.definitions[key]);

			switch (this._interval) {

				case "day":
					definitionData.timeInterval = 86400;
					break;
@@ -313,6 +312,15 @@ define([
			}
		},

		_prepareChartsRepresentation: function() {

			if (this._addChartLayersWithoutData) {
				this._addChartLayersWithoutData();
			} else {
				this._buildQueryAndRequestData();
			}
		},

		_buildQueryAndRequestData: function() {

			if (!this.chartsData || this._dataRequestInProgress) {
+24 −1
Original line number Diff line number Diff line
@@ -166,6 +166,29 @@ define([
		_updateButton: function(item, config, node) {

			this._conditionButton(item, config, node);
			this._updateToggleState(item, config, node);
		},

		_updateToggleState: function(item, config, node) {

			var itemState = item.state,
				stateInItem = itemState !== undefined;

			if (stateInItem) {
				if (!itemState) {
					this._updateIconClass(config, node);
				}
				return;
			}

			var configState = config.state,
				stateInConfig = configState !== undefined;

			if (stateInConfig) {
				if (!configState) {
					this._updateIconClass(config, node);
				}
			}
		},

		_conditionButton: function(item, config, node) {
@@ -343,7 +366,7 @@ define([
				obj.iconNode = node;
			}

			if (config.state) {
			if (config.state !== undefined) {
				obj.state = domClass.contains(node, config.icon);
			}

+3 −0
Original line number Diff line number Diff line
@@ -401,6 +401,9 @@ define([
			this._preparePublicationsForLayer(layerId);
			this._doPublicationsForLayer(layerId);
			this._tryToDrawLayer(this._layers[layerId]);

			// todo
			//this._emitEvt('LAYER_ADDED', layerId);
		},

		_doSubscriptionsForLayer: function(layerId) {
Loading