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_chart.html 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <style>
  2. input.series-color {
  3. width: 100px;
  4. text-align: center;
  5. }
  6. input.series-color::-webkit-color-swatch {
  7. border: none;
  8. }
  9. </style>
  10. <script type="text/javascript">
  11. RED.nodes.registerType('ui_chart',{
  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. height: {value: 0},
  27. label: {value: 'chart'},
  28. chartType: {value: 'line'},
  29. legend: {value: 'false'},
  30. xformat: {value: 'HH:mm:ss'},
  31. interpolate: {value: 'linear', required:true},
  32. nodata: {value: ''},
  33. dot: {value: false},
  34. ymin: {value: '', validate:function(value) { return value === '' || RED.validators.number(); }},
  35. ymax: {value: '', validate:function(value) { return value === '' || RED.validators.number(); }},
  36. removeOlder: {value: 1, validate:RED.validators.number(), required:true},
  37. removeOlderPoints: {value: '', validate:function(value) { return value === '' || RED.validators.number(); }},
  38. removeOlderUnit: {value: '3600', required:true},
  39. cutout: {value: 0},
  40. useOneColor: {value: false},
  41. useUTC: {value: false},
  42. colors: {value: ['#1F77B4', '#AEC7E8', '#FF7F0E', '#2CA02C', '#98DF8A', '#D62728', '#FF9896', '#9467BD', '#C5B0D5']},
  43. outputs: {value: 1},
  44. useDifferentColor: {value: false},
  45. className: {value: ''}
  46. },
  47. inputs:1,
  48. outputs:1,
  49. inputLabels: function() { return this.chartType; },
  50. outputLabels: ["chart state"],
  51. align: "right",
  52. icon: "ui_chart.png",
  53. paletteLabel: 'chart',
  54. label: function() { return this.name || (~this.label.indexOf("{{") ? null : this.label) || 'chart'; },
  55. labelStyle: function() { return this.name?"node_label_italic":""; },
  56. oneditprepare: function() {
  57. var oldouts = this.outputs;
  58. if (RED.nodes.filterLinks({source:{id:this.id},sourcePort:1}).length > 0) { this.outputs = 2; }
  59. else { this.outputs = 1; }
  60. if (this.outputs !== oldouts) { this.changed = true; }
  61. if (!$("#node-input-chartType").val()) {
  62. $("#node-input-chartType").val("line");
  63. }
  64. $("#node-input-size").elementSizer({
  65. width: "#node-input-width",
  66. height: "#node-input-height",
  67. group: "#node-input-group"
  68. });
  69. $("#node-input-chartType").on("change", function() {
  70. $("#legend-show").hide();
  71. $("#show-useDifferentColor").hide();
  72. if ($(this).val() === "horizontalBar") {
  73. $("#y-label-show").hide();
  74. $("#x-label-show").show();
  75. }
  76. else {
  77. $("#y-label-show").show();
  78. $("#x-label-show").hide();
  79. }
  80. if ($(this).val() === "line") {
  81. $("#x-axis-show").show();
  82. $("#x-axis-label-show").show();
  83. $("#interpolate-show").show();
  84. $("#legend-show").show();
  85. $("#y-axis-show").show();
  86. $("#hole-size-show").hide();
  87. $("#show-dot-field").show();
  88. $("#show-useOneColor").hide();
  89. }
  90. else {
  91. $("#x-axis-show").hide();
  92. $("#x-axis-label-show").hide();
  93. $("#interpolate-show").hide();
  94. $("#show-dot-field").hide();
  95. if (($(this).val() === "bar")||($(this).val() === "horizontalBar")) {
  96. $("#show-useOneColor").show();
  97. $("#legend-show").show();
  98. }
  99. else {
  100. $("#show-useOneColor").hide();
  101. }
  102. if ($(this).val() === "pie") {
  103. $("#y-axis-show").hide();
  104. $("#legend-show").show();
  105. $("#hole-size-show").show();
  106. }
  107. else if ($(this).val() === "polar-area") {
  108. $("#y-axis-show").show();
  109. $("#legend-show").show();
  110. $("#hole-size-show").hide();
  111. $("#show-useDifferentColor").show();
  112. }
  113. else if ($(this).val() === "radar") {
  114. $("#y-axis-show").show();
  115. $("#legend-show").show();
  116. $("#hole-size-show").hide();
  117. }
  118. else {
  119. $("#y-axis-show").show();
  120. $("#hole-size-show").hide();
  121. }
  122. }
  123. });
  124. var setColour = function(id, value) {
  125. $(id).val(value);
  126. $(id).css("background-color", value);
  127. var rgb = tinycolor(value).toRgb();
  128. var level = ((rgb.r*299) + (rgb.g*587) + (rgb.b*114))/1000;
  129. var textColor = (level >= 128) ? '#111111' : '#eeeeee';
  130. $(id).css("color", textColor);
  131. }
  132. $(".series-color").on("change", function() {
  133. setColour("#"+$(this).attr("id"), $(this).val());
  134. });
  135. var oval = $("#node-input-xformat").val();
  136. if (!oval) { $("#node-input-xformat").val("HH:mm:ss"); }
  137. var odef = 'custom';
  138. if (oval === "HH:mm:ss") { odef = oval; }
  139. if (oval === "HH:mm") { odef = oval; }
  140. if (oval === "Y-M-D") { odef = oval; }
  141. if (oval === "D/M") { odef = oval; }
  142. if (oval === "dd HH:mm") { odef = oval; }
  143. if (oval === "auto") { odef = oval; }
  144. var ohms = {value: "HH:mm:ss", label: RED._("node-red-dashboard/ui_chart:ui_chart.label.HHmmss"), hasValue: false};
  145. var ohm = {value: "HH:mm", label: RED._("node-red-dashboard/ui_chart:ui_chart.label.HHmm"), hasValue: false};
  146. var oymd = {value: "Y-M-D", label: RED._("node-red-dashboard/ui_chart:ui_chart.label.yearMonthDate"), hasValue: false};
  147. var odm = {value: "D/M", label: RED._("node-red-dashboard/ui_chart:ui_chart.label.dateMonth"), hasValue: false};
  148. var oahm = {value: "dd HH:mm", label: RED._("node-red-dashboard/ui_chart:ui_chart.label.dayHHmm"), hasValue: false};
  149. var ocus = {value: "custom", label: RED._("node-red-dashboard/ui_chart:ui_chart.label.custom"), icon: "red/images/typedInput/az.png"};
  150. var oaut = {value: "auto", label: RED._("node-red-dashboard/ui_chart:ui_chart.label.automatic"), hasValue: false};
  151. $("#node-input-xformat").typedInput({
  152. default: odef,
  153. types:[ ohms, ohm, oahm, odm, oymd, ocus, oaut ]
  154. });
  155. var defaultColors = ['#1F77B4', '#AEC7E8', '#FF7F0E', '#2CA02C', '#98DF8A', '#D62728', '#FF9896', '#9467BD', '#C5B0D5'];
  156. if (this.colors) {
  157. for (var i=0; i<this.colors.length; i++) {
  158. var value = this.colors[i] || defaultColors[i];
  159. setColour("#node-input-color"+(i+1), value);
  160. }
  161. }
  162. else {
  163. for (var c=0; c<defaultColors.length; c++) {
  164. setColour("#node-input-color"+(c+1), defaultColors[c]);
  165. }
  166. }
  167. },
  168. oneditsave: function() {
  169. if ($("#node-input-xformat").typedInput('type') !== 'custom') {
  170. $("#node-input-xformat").val($("#node-input-xformat").typedInput('type'));
  171. }
  172. this.colors = [$("#node-input-color1").val(),$("#node-input-color2").val(),$("#node-input-color3").val(),
  173. $("#node-input-color4").val(),$("#node-input-color5").val(),$("#node-input-color6").val(),
  174. $("#node-input-color7").val(),$("#node-input-color8").val(),$("#node-input-color9").val()];
  175. }
  176. });
  177. </script>
  178. <script type="text/html" data-template-name="ui_chart">
  179. <div class="form-row">
  180. <label for="node-input-group"><i class="fa fa-table"></i> <span data-i18n="ui_chart.label.group"></label>
  181. <input type="text" id="node-input-group">
  182. </div>
  183. <div class="form-row">
  184. <label><i class="fa fa-object-group"></i> <span data-i18n="ui_chart.label.size"></label>
  185. <input type="hidden" id="node-input-width">
  186. <input type="hidden" id="node-input-height">
  187. <button class="editor-button" id="node-input-size"></button>
  188. </div>
  189. <div class="form-row">
  190. <label for="node-input-label"><i class="fa fa-i-cursor"></i> <span data-i18n="ui_chart.label.label"></label>
  191. <input type="text" id="node-input-label" data-i18n="[placeholder]ui_chart.label.optionalChartTitle">
  192. </div>
  193. <div class="form-row">
  194. <label for="node-input-removeOlder"><i class="fa fa-line-chart"></i> <span data-i18n="ui_chart.label.type"></label>
  195. <select id="node-input-chartType" style="width:159px; font-family:'FontAwesome','Helvetica Neue', Helvetica, Arial, sans-serif">
  196. <option value="line" data-i18n="[html]ui_chart.label.lineChart"></option>
  197. <option value="bar" data-i18n="[html]ui_chart.label.barChart"></option>
  198. <option value="horizontalBar" data-i18n="[html]ui_chart.label.barChartH"></option>
  199. <option value="pie" data-i18n="[html]ui_chart.label.pieChart"></option>
  200. <option value="polar-area" data-i18n="[html]ui_chart.label.polarAreaChart"></option>
  201. <option value="radar" data-i18n="[html]ui_chart.label.radarChart"></option>
  202. </select>
  203. <div id="show-dot-field" style="display:inline-block;">
  204. <input type="checkbox" id="node-input-dot" style="display:inline-block; width:auto; vertical-align:baseline; margin-left:40px; margin-right:5px;"><span data-i18n="ui_chart.label.enlargePoints">
  205. </div>
  206. </div>
  207. <div class="form-row" id="x-axis-show">
  208. <label for="node-input-removeOlder" data-i18n="ui_chart.label.xAxis"></label>
  209. <label for="node-input-removeOlder" style="width:auto" data-i18n="ui_chart.label.last"></label>
  210. <input type="text" id="node-input-removeOlder" style="width:50px;">
  211. <select id="node-input-removeOlderUnit" style="width:80px;">
  212. <option value="1" data-i18n="ui_chart.label.seconds"></option>
  213. <option value="60" data-i18n="ui_chart.label.minutes"></option>
  214. <option value="3600" data-i18n="ui_chart.label.hours"></option>
  215. <option value="86400" data-i18n="ui_chart.label.days"></option>
  216. <option value="604800" data-i18n="ui_chart.label.weeks"></option>
  217. </select>
  218. <label for="node-input-removeOlderPoints" style="width:auto; margin-left:10px; margin-right:10px;" data-i18n="ui_chart.label.or"></label>
  219. <input type="text" id="node-input-removeOlderPoints" style="width:60px;" placeholder="1000">
  220. <span style="margin-left:5px;" data-i18n="ui_chart.label.points"></span>
  221. </div>
  222. <div class="form-row" id="x-axis-label-show">
  223. <label for="node-input-xformat" data-i18n="ui_chart.label.xAxisLabel"></label>
  224. <input type="text" id="node-input-xformat" style="width:250px;">
  225. <input type="checkbox" id="node-input-useUTC" style="display:inline-block; width:auto; vertical-align:baseline; margin-left:8px; margin-right:4px;"> <span data-i18n="ui_chart.label.asUTC"></span>
  226. </div>
  227. <div class="form-row" id="y-axis-show">
  228. <label id="y-label-show" for="node-input-ymin" data-i18n="ui_chart.label.yAxis"></label>
  229. <label id="x-label-show" for="node-input-ymin" data-i18n="ui_chart.label.xAxis"></label>
  230. <label for="node-input-ymin" style="width:auto" data-i18n="ui_chart.label.min"></label>
  231. <input type="text" id="node-input-ymin" style="width:92px">
  232. <label for="node-input-ymax" style="width:auto; margin-left:20px;" data-i18n="ui_chart.label.max"></label>
  233. <input type="text" id="node-input-ymax" style="width:92px">
  234. </div>
  235. <div class="form-row" id="legend-show">
  236. <label for="node-input-legend" data-i18n="ui_chart.label.legend"></label>
  237. <select id="node-input-legend" style="width:120px;">
  238. <option value="false" data-i18n="ui_chart.label.none"></option>
  239. <option value="true" data-i18n="ui_chart.label.show"></option>
  240. </select>
  241. <span id="interpolate-show">&nbsp;&nbsp;&nbsp;&nbsp;<span data-i18n="ui_chart.label.interpolate"></span>
  242. <select id="node-input-interpolate" style="width:120px;">
  243. <option value="linear" data-i18n="ui_chart.label.linear"></option>
  244. <option value="step" data-i18n="ui_chart.label.step"></option>
  245. <option value="bezier" data-i18n="ui_chart.label.bezier"></option>
  246. <option value="cubic" data-i18n="ui_chart.label.cubic"></option>
  247. <option value="monotone" data-i18n="ui_chart.label.cubicMono"></option>
  248. </select>
  249. </span>
  250. <span id="hole-size-show">&nbsp;&nbsp;&nbsp;&nbsp;<span data-i18n="ui_chart.label.cutout"></span>
  251. <input type="text" id="node-input-cutout" style="width:35px"> %
  252. </span>
  253. </div>
  254. <div id="show-useOneColor" style="display:none; height:24px;">
  255. <input type="checkbox" id="node-input-useOneColor" style="display:inline-block; width:auto; vertical-align:baseline; margin-left:105px; margin-right:5px;"><span data-i18n="ui_chart.label.useFirstColourForAllBars"></span>
  256. </div>
  257. <div class="form-row" id="ui-chart-colours">
  258. <label for="node-input-color1" data-i18n="ui_chart.label.seriesColours"></label>
  259. <input type="color" id="node-input-color1" class="series-color" style="width:100px;"/>
  260. <input type="color" id="node-input-color2" class="series-color" style="width:100px;"/>
  261. <input type="color" id="node-input-color3" class="series-color" style="width:100px;"/>
  262. <div style="margin-top:5px; margin-left:104px;">
  263. <input type="color" id="node-input-color4" class="series-color" style="width:100px;"/>
  264. <input type="color" id="node-input-color5" class="series-color" style="width:100px;"/>
  265. <input type="color" id="node-input-color6" class="series-color" style="width:100px;"/>
  266. </div>
  267. <div style="margin-top:5px; margin-left:104px;">
  268. <input type="color" id="node-input-color7" class="series-color" style="width:100px;"/>
  269. <input type="color" id="node-input-color8" class="series-color" style="width:100px;"/>
  270. <input type="color" id="node-input-color9" class="series-color" style="width:100px;"/>
  271. </div>
  272. </div>
  273. <div id="show-useDifferentColor" class="form-row">
  274. <label></label>
  275. <input type="checkbox" id="node-input-useDifferentColor" style="display:inline-block; width:auto; vertical-align:top;">
  276. <span data-i18n="ui_chart.label.useDifferentColor"></span>
  277. </input>
  278. </div>
  279. <div class="form-row">
  280. <label for="node-input-nodata" data-i18n="ui_chart.label.blankLabel"></label>
  281. <input type="text" id="node-input-nodata" data-i18n="[placeholder]ui_chart.label.displayThisTextBeforeValidDataArrives">
  282. </div>
  283. <div class="form-row">
  284. <label for="node-input-className"><i class="fa fa-code"></i> <span data-i18n="ui_chart.label.className"></span></label>
  285. <input type="text" id="node-input-className" data-i18n="[placeholder]ui_chart.label.classNamePlaceholder"/>
  286. </div>
  287. <div class="form-row">
  288. <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></label>
  289. <input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
  290. </div>
  291. </script>