Node-Red configuration
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ui_gauge.html 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <style>
  2. input.gauge-color {
  3. width: 100px;
  4. text-align: center;
  5. }
  6. input.gauge-color::-webkit-color-swatch {
  7. border: none;
  8. }
  9. </style>
  10. <script type="text/javascript">
  11. RED.nodes.registerType('ui_gauge',{
  12. category: RED._("node-red-dashboard/ui_base:ui_base.label.category"),
  13. color: 'rgb(119, 198, 204)',
  14. defaults: {
  15. name: {value: ''},
  16. group: {type: 'ui_group', required: true},
  17. order: {value: 0},
  18. width: {value: 0, validate: function(v) {
  19. var width = v || 0;
  20. var currentGroup = $('#node-input-group').val() || this.group;
  21. var groupNode = RED.nodes.node(currentGroup);
  22. var valid = !groupNode || +width <= +groupNode.width;
  23. $("#node-input-size").toggleClass("input-error",!valid);
  24. return valid;
  25. }
  26. },
  27. height: {value: 0},
  28. gtype: {value: 'gage'},
  29. title: {value: 'gauge'},
  30. label: {value: 'units'},
  31. format: {value: '{{value}}'},
  32. min: {value: 0, required: true, validate: RED.validators.number()},
  33. max: {value: 10, required: true, validate: RED.validators.number()},
  34. colors: {value: ["#00B500","#E6E600","#CA3838"]},
  35. seg1: {value: ""},
  36. seg2: {value: ""},
  37. className: {value: ''}
  38. },
  39. inputs:1,
  40. outputs:0,
  41. inputLabels: function() { return this.min+" - "+this.max; },
  42. align: "right",
  43. icon: "ui_gauge.png",
  44. paletteLabel: 'gauge',
  45. label: function() { return this.name || (~this.title.indexOf("{{") ? null : this.title) || ((this.gtype === "gage") ? "gauge" : this.gtype) || 'gauge'; },
  46. labelStyle: function() { return this.name?"node_label_italic":""; },
  47. oneditprepare: function() {
  48. var setColour = function(id, value) {
  49. $(id).val(value);
  50. $(id).css("background-color", value);
  51. var rgb = tinycolor(value).toRgb();
  52. var level = ((rgb.r*299) + (rgb.g*587) + (rgb.b*114))/1000;
  53. var textColor = (level >= 128) ? '#111111' : '#eeeeee';
  54. $(id).css("color", textColor);
  55. }
  56. $(".gauge-color").on("change", function() {
  57. setColour("#"+$(this).attr("id"), $(this).val());
  58. });
  59. var defaultColors = ['#00B500', '#E6E600', '#CA3838'];
  60. if (this.colors) {
  61. for (var i=0; i<this.colors.length; i++) {
  62. var value = this.colors[i] || defaultColors[i];
  63. setColour("#node-input-color"+(i+1), value);
  64. }
  65. }
  66. else {
  67. for (var j=0; j<defaultColors.length; j++) {
  68. setColour("#node-input-color"+(j+1), defaultColors[j]);
  69. }
  70. }
  71. if (this.gtype === undefined) {
  72. this.gtype = "gage";
  73. $("#node-input-gtype").val("gage");
  74. }
  75. $("#node-input-size").elementSizer({
  76. width: "#node-input-width",
  77. height: "#node-input-height",
  78. group: "#node-input-group"
  79. });
  80. $("#node-input-gtype").on("change", function() {
  81. if (($(this).val() === "compass") || ($(this).val() === "wave")) {
  82. $("#ui-gauge-colours").hide();
  83. $("#ui-gauge-segments").hide();
  84. }
  85. else {
  86. $("#ui-gauge-colours").show();
  87. $("#ui-gauge-segments").show();
  88. }
  89. });
  90. $("#node-input-min").on("change", function() {
  91. $("#seg-min").text($(this).val());
  92. });
  93. $("#node-input-max").on("change", function() {
  94. $("#seg-max").text($(this).val());
  95. });
  96. },
  97. oneditsave: function() {
  98. this.colors = [$("#node-input-color1").val(),$("#node-input-color2").val(),$("#node-input-color3").val()];
  99. }
  100. });
  101. </script>
  102. <script type="text/html" data-template-name="ui_gauge">
  103. <div class="form-row">
  104. <label for="node-input-group"><i class="fa fa-table"></i> Group</label>
  105. <input type="text" id="node-input-group">
  106. </div>
  107. <div class="form-row">
  108. <label><i class="fa fa-object-group"></i> Size</label>
  109. <input type="hidden" id="node-input-width">
  110. <input type="hidden" id="node-input-height">
  111. <button class="editor-button" id="node-input-size"></button>
  112. </div>
  113. <div class="form-row">
  114. <label for="node-input-gtype"><i class="fa fa-list"></i> Type</label>
  115. <select id="node-input-gtype" style="width:150px">
  116. <option value="gage">Gauge</option>
  117. <option value="donut">Donut</option>
  118. <option value="compass">Compass</option>
  119. <option value="wave">Level</option>
  120. </select>
  121. </div>
  122. <div id="ui-gauge-labels">
  123. <div class="form-row">
  124. <label for="node-input-title"><i class="fa fa-i-cursor"></i> Label</label>
  125. <input type="text" id="node-input-title">
  126. </div>
  127. <div class="form-row" id="ui-gauge-format">
  128. <label for="node-input-format"><i class="fa fa-i-cursor"></i> Value format</label>
  129. <input type="text" id="node-input-format" placeholder="{{value}}">
  130. </div>
  131. <div class="form-row" id="ui-gauge-units">
  132. <label for="node-input-label"><i class="fa fa-i-cursor"></i> Units</label>
  133. <input type="text" id="node-input-label" placeholder="optional sub-label">
  134. </div>
  135. </div>
  136. <div class="form-row">
  137. <label for="node-input-min">Range</label>
  138. <span for="node-input-min">min</span>
  139. <input type="text" id="node-input-min" style="width:80px">
  140. <span for="node-input-max" style="margin-left:20px;">max</span>
  141. <input type="text" id="node-input-max" style="width:80px">
  142. </div>
  143. <div class="form-row" id="ui-gauge-colours">
  144. <label for="node-input-color1">Colour gradient</label>
  145. <input type="color" id="node-input-color1" class="gauge-color" style="width:100px;"/>
  146. <input type="color" id="node-input-color2" class="gauge-color" style="width:100px;"/>
  147. <input type="color" id="node-input-color3" class="gauge-color" style="width:100px;"/>
  148. </div>
  149. <div class="form-row" id="ui-gauge-segments">
  150. <label>Sectors</label>
  151. <span id="seg-min" style="display:inline-block; width:40px;">0</span>...
  152. <input type="text" id="node-input-seg1" style="text-align:center; width:87px;" placeholder="optional"> ...
  153. <input type="text" id="node-input-seg2" style="text-align:center; width:87px;" placeholder="optional"> ...
  154. <span id="seg-max" style="display:inline-block; width:40px; text-align:right">10</span>
  155. </div>
  156. <div class="form-row">
  157. <label for="node-input-className"><i class="fa fa-code"></i> Class</label>
  158. <input type="text" id="node-input-className" placeholder="Optional CSS class name(s) for widget"/>
  159. </div>
  160. <div class="form-row">
  161. <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
  162. <input type="text" id="node-input-name">
  163. </div>
  164. </script>