mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
add decimal places option to smooth node
This commit is contained in:
parent
73269848ba
commit
952a794db5
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
Copyright 2014 IBM Corp.
|
||||
Copyright 2014,2016 IBM Corp.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -29,12 +29,12 @@
|
||||
<div class="form-row">
|
||||
<label for="node-input-count"> </label>
|
||||
<span id="node-over">over the most recent </span>
|
||||
<input type="text" id="node-input-count" placeholder="10" style="width:80px;"/>
|
||||
<span id="node-over2"> values.</span>
|
||||
<input type="text" id="node-input-count" placeholder="10" style="width:50px;"/>
|
||||
<span id="node-over2"> values</span>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-round"> </label>
|
||||
<input type="checkbox" id="node-input-round" style="display: inline-block; width: auto; vertical-align: top;"> Round to the nearest integer ?
|
||||
<label for="node-input-round">(optionally)</label>
|
||||
round to <input type="text" id="node-input-round" placeholder="ignore" style="width:50px;"/> decimal places
|
||||
</div>
|
||||
<br/>
|
||||
<div class="form-row">
|
||||
@ -56,10 +56,10 @@
|
||||
color: "#E2D96E",
|
||||
category: 'function',
|
||||
defaults: {
|
||||
count: {value:"10",required:true,validate:RED.validators.number()},
|
||||
name: {value:""},
|
||||
action: {value:"mean"},
|
||||
round: {value:false},
|
||||
name: {value:""}
|
||||
count: {value:"10",required:true,validate:RED.validators.number()},
|
||||
round: {value:""}
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
@ -72,8 +72,9 @@
|
||||
},
|
||||
oneditprepare: function() {
|
||||
$("#node-input-count").spinner({
|
||||
min:1,
|
||||
width:80
|
||||
min:1
|
||||
});
|
||||
$("#node-input-round").spinner({
|
||||
});
|
||||
$("#node-input-action").change( function() {
|
||||
var a = $("#node-input-action").val();
|
||||
@ -83,10 +84,13 @@
|
||||
}
|
||||
else {
|
||||
$("#node-over").html("over the most recent ");
|
||||
$("#node-over2").html(" values.");
|
||||
$("#node-over2").html(" values");
|
||||
}
|
||||
});
|
||||
$("#node-input-action").change();
|
||||
if ($("#node-input-round").val() === "true") {
|
||||
$("#node-input-round").val(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2014 IBM Corp.
|
||||
* Copyright 2014,2016 IBM Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -21,6 +21,7 @@ module.exports = function(RED) {
|
||||
RED.nodes.createNode(this, n);
|
||||
this.action = n.action;
|
||||
this.round = n.round || false;
|
||||
if (this.round == "true") { this.round = 0; }
|
||||
this.count = Number(n.count);
|
||||
var node = this;
|
||||
var a = [];
|
||||
@ -61,7 +62,9 @@ module.exports = function(RED) {
|
||||
else { msg.payload = 0; }
|
||||
}
|
||||
}
|
||||
if (node.round) { msg.payload = Math.round(msg.payload); }
|
||||
if (node.round !== false) {
|
||||
msg.payload = Math.round(msg.payload * Math.pow(10, node.round)) / Math.pow(10, node.round);
|
||||
}
|
||||
node.send(msg);
|
||||
}
|
||||
else { node.log("Not a number: "+msg.payload); }
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-smooth",
|
||||
"version" : "0.0.5",
|
||||
"version" : "0.0.6",
|
||||
"description" : "A Node-RED node that provides several simple smoothing algorithms for incoming data values.",
|
||||
"dependencies" : {
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user