Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui_gauge.js 4.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. module.exports = function (RED) {
  2. var ui = require('../ui')(RED);
  3. function GaugeNode(config) {
  4. RED.nodes.createNode(this, config);
  5. this.colors = config.colors || ["#00B500","#E6E600","#CA3838"];
  6. var node = this;
  7. var group = RED.nodes.getNode(config.group);
  8. if (!group) { return; }
  9. var tab = RED.nodes.getNode(group.config.tab);
  10. if (!tab) { return; }
  11. if (config.width === "0") { delete config.width; }
  12. if (config.height === "0") { delete config.height; }
  13. if (config.height === "1") { config.hideMinMax = true; }
  14. node.autoheight = parseInt(group.config.width*0.5+1.5) || 4;
  15. if (config.gtype && config.gtype === "wave") { node.autoheight = parseInt(group.config.width*0.75+0.5); }
  16. if (config.gtype && config.gtype === "donut") { node.autoheight = parseInt(group.config.width -1); }
  17. if (config.gtype && config.gtype === "compass") { node.autoheight = parseInt(group.config.width -1); }
  18. var sizes = ui.getSizes();
  19. var theme = ui.getTheme();
  20. if (theme === undefined) {
  21. theme = {"group-textColor":{value:"#000"}};
  22. theme["widget-textColor"] = {value:"#000"};
  23. theme["widget-backgroundColor"] = {value:'#1784be'};
  24. }
  25. var gageoptions = {};
  26. gageoptions.lineWidth = {'theme-dark':0.75};
  27. gageoptions.pointerOptions = {'theme-dark':{color:'#8e8e93'}, 'theme-custom':theme["group-textColor"].value};
  28. gageoptions.backgroundColor = {'theme-dark':'#515151', 'theme-custom':theme["widget-textColor"].value };
  29. gageoptions.compassColor = {'theme-dark':theme["widget-backgroundColor"].value, 'theme-light':theme["widget-backgroundColor"].value, 'theme-custom':theme["widget-backgroundColor"].value};
  30. gageoptions.valueFontColor = {'theme-dark':'#eee', 'theme-light':'#111', 'theme-custom':theme["widget-textColor"].value};
  31. var waveoptions = {};
  32. waveoptions.circleColor = {'theme-dark':theme["widget-backgroundColor"].value, 'theme-light':theme["widget-backgroundColor"].value, 'theme-custom':theme["widget-backgroundColor"].value};
  33. waveoptions.waveColor = {'theme-dark':theme["widget-backgroundColor"].value, 'theme-light':theme["widget-backgroundColor"].value, 'theme-custom':theme["widget-backgroundColor"].value};
  34. waveoptions.textColor = {'theme-dark':theme["widget-textColor"].value, 'theme-light':theme["widget-textColor"].value, 'theme-custom':theme["widget-textColor"].value};
  35. waveoptions.waveTextColor = {'theme-dark':theme["widget-textColor"].value, 'theme-light':theme["widget-textColor"].value, 'theme-custom':theme["widget-textColor"].value};
  36. var done = ui.add({
  37. node: node,
  38. tab: tab,
  39. group: group,
  40. emitOnlyNewValues: false,
  41. control: {
  42. type: 'gauge',
  43. name: config.name,
  44. label: config.title,
  45. units: config.label,
  46. order: config.order,
  47. value: config.min,
  48. format: config.format,
  49. gtype: config.gtype || 'gage',
  50. min: (parseFloat(config.min) < parseFloat(config.max)) ? parseFloat(config.min) : parseFloat(config.max),
  51. seg1: (parseFloat(config.seg1) < parseFloat(config.seg2)) ? parseFloat(config.seg1) : parseFloat(config.seg2),
  52. seg2: (parseFloat(config.seg1) < parseFloat(config.seg2)) ? parseFloat(config.seg2) : parseFloat(config.seg1),
  53. max: (parseFloat(config.min) < parseFloat(config.max)) ? parseFloat(config.max) : parseFloat(config.min),
  54. reverse: (parseFloat(config.max) < parseFloat(config.min)) ? true : false,
  55. sizes: sizes,
  56. hideMinMax: config.hideMinMax,
  57. width: config.width || group.config.width || 6,
  58. height: config.height || node.autoheight,
  59. colors: node.colors,
  60. gageoptions: gageoptions,
  61. waveoptions: waveoptions,
  62. options: null,
  63. className: config.className || '',
  64. },
  65. convert: function(p,o,m) {
  66. var form = config.format.replace(/{{/g,"").replace(/}}/g,"").replace(/\s/g,"") || "_zzz_zzz_zzz_";
  67. form = form.split('|')[0];
  68. var value = RED.util.getMessageProperty(m,form);
  69. if (value !== undefined) {
  70. if (!isNaN(parseFloat(value))) { value = parseFloat(value); }
  71. return value;
  72. }
  73. if (!isNaN(parseFloat(p))) { p = parseFloat(p); }
  74. return p;
  75. //return ui.toFloat.bind(this, config);
  76. }
  77. });
  78. node.on("close", done);
  79. }
  80. RED.nodes.registerType("ui_gauge", GaugeNode);
  81. };