Set 'heating' graph series only for climate graphs (#665)

PR #617 added a steppedArea series to climate graphs to show when the
thermostat is calling for heat. It also accidentally converted the second
series in every graph to steppedArea. This moves the option specification
into the `if (domain === 'thermostat' || domain === 'climate')` block so
it will only be applied when it's relevant (and gets it closer to the
series it's configuring).

It also calculates the series index by counting the number of columns
immediately after the target one is added. Which still isn't elegant,
but seems solidly better than hard-coding the index as `1`.
This commit is contained in:
Klaas Hoekema 2017-11-23 15:27:31 -05:00 committed by Paulus Schoutsen
parent 95288f8c3d
commit 6c2cd420f5

View File

@ -106,11 +106,6 @@
maxZoomIn: 0.1, maxZoomIn: 0.1,
}, },
seriesType: 'line', seriesType: 'line',
// The "heating" series uses steppedArea to shade the area below the current
// temperature when the thermostat is calling for heat. It would be nice to
// apply this config in a more direct way than by column index, but it
// doesn't seem to be possible.
series: { 1: { type: 'steppedArea' } }
}; };
if (this.isSingleDevice) { if (this.isSingleDevice) {
@ -183,6 +178,15 @@
dataTable.addColumn('number', name + ' current temperature'); dataTable.addColumn('number', name + ' current temperature');
dataTable.addColumn('number', name + ' heating'); dataTable.addColumn('number', name + ' heating');
// The "heating" series uses steppedArea to shade the area below the current
// temperature when the thermostat is calling for heat.
// Its series index is 2 less than its column number--1 because
// zero-based and 1 because the first becomes the horizontal axis.
var seriesIndex = dataTable.getNumberOfColumns() - 2;
// Get existing series config, if there is any, rather than clobbering
options.series = Object.assign({}, options.series);
options.series[seriesIndex] = { type: 'steppedArea' };
if (hasTargetRange) { if (hasTargetRange) {
dataTable.addColumn('number', name + ' target temperature high'); dataTable.addColumn('number', name + ' target temperature high');
dataTable.addColumn('number', name + ' target temperature low'); dataTable.addColumn('number', name + ' target temperature low');