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