Skip to content

Commit

Permalink
Merge pull request #224 from andig/fix-negatives
Browse files Browse the repository at this point in the history
Fix axis handling
  • Loading branch information
andig committed Jan 20, 2015
2 parents e50a49a + 96b9746 commit 290f4c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
11 changes: 9 additions & 2 deletions htdocs/frontend/javascripts/entity.js
Expand Up @@ -125,6 +125,8 @@ Entity.prototype.assignAxis = function() {
this.assignedYaxis = parseInt(this.yaxis); // string to int for multi-property

while (vz.options.plot.yaxes.length < this.assignedYaxis) { // no more axes available
// create new right-hand axis
// TODO clone existing axis including its styling
vz.options.plot.yaxes.push({ position: 'right' });
}

Expand All @@ -151,16 +153,21 @@ Entity.prototype.assignAxis = function() {

/**
* Set axis minimum depending on data
*
* Note: axis.min can have the following values:
* - undefined: not initialized yet, will only happen during assignment of first entity to axis
* - null: min value intentionally set to 'auto' to allow negative values
* - 0: min value assumed to be '0' as long as no entity with negative values is encountered
*/
Entity.prototype.updateAxisScale = function() {
if (this.assignedYaxis !== undefined && vz.options.plot.yaxes.length >= this.assignedYaxis) {
if (vz.options.plot.yaxes[this.assignedYaxis-1].min === null) {
if (vz.options.plot.yaxes[this.assignedYaxis-1].min === undefined) { // axis min still not set
// avoid overriding user-defined options
vz.options.plot.yaxes[this.assignedYaxis-1].min = 0;
}
if (this.data && this.data.tuples && this.data.tuples.length > 0) {
// allow negative values, e.g. for temperature sensors
if (this.data.min && this.data.min[1] < 0) {
if (this.data.min && this.data.min[1] < 0) { // set axis min to 'auto'
vz.options.plot.yaxes[this.assignedYaxis-1].min = null;
}
}
Expand Down
29 changes: 15 additions & 14 deletions htdocs/frontend/javascripts/wui.js
Expand Up @@ -231,6 +231,18 @@ vz.wui.dialogs.addProperties = function(container, proplist, className, entity)
});
};

/**
* Add entity after UI has already been initialized
* Tiggers refresh of entity data, plot and axes
*/
vz.wui.addEntity = function(entity) {
vz.entities.push(entity);
vz.entities.saveCookie();
vz.entities.showTable();
vz.entities.loadData().done(vz.wui.drawPlot);
vz.options.plot.axesAssigned = false; // force axis assignment
};

/**
* Initialize dialogs
*/
Expand Down Expand Up @@ -313,10 +325,7 @@ vz.wui.dialogs.init = function() {
entity.setMiddleware($('#entity-subscribe-middleware').val());

entity.loadDetails().done(function() {
vz.entities.push(entity);
vz.entities.saveCookie();
vz.entities.showTable();
vz.entities.loadData().done(vz.wui.drawPlot);
vz.wui.addEntity(entity);
}); // reload entity details and load data
}
catch (e) {
Expand All @@ -333,11 +342,7 @@ vz.wui.dialogs.init = function() {
try {
entity.cookie = Boolean($('#entity-public-cookie').prop('checked'));
entity.setMiddleware($('#entity-public-middleware option:selected').val());

vz.entities.push(entity);
vz.entities.saveCookie();
vz.entities.showTable();
vz.entities.loadData().done(vz.wui.drawPlot);
vz.wui.addEntity(entity);
}
catch (e) {
vz.wui.dialogs.exception(e);
Expand Down Expand Up @@ -390,11 +395,7 @@ vz.wui.dialogs.init = function() {
try {
entity.cookie = Boolean($('#entity-create-cookie').prop('checked'));
entity.setMiddleware($('#entity-create-middleware').val());

vz.entities.push(entity);
vz.entities.saveCookie();
vz.entities.showTable();
vz.entities.loadData().done(vz.wui.drawPlot);
vz.wui.addEntity(entity);
}
catch (e) {
vz.wui.dialogs.exception(e);
Expand Down

0 comments on commit 290f4c8

Please sign in to comment.