Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. /* jshint browser: true, esversion: 5 */
  2. /* globals document,Vue,window,uibuilder */
  3. // @ts-nocheck
  4. /*
  5. Copyright (c) 2019 Julian Knight (Totally Information)
  6.  
  7. Licensed under the Apache License, Version 2.0 (the "License");
  8. you may not use this file except in compliance with the License.
  9. You may obtain a copy of the License at
  10.  
  11. http://www.apache.org/licenses/LICENSE-2.0
  12.  
  13. Unless required by applicable law or agreed to in writing, software
  14. distributed under the License is distributed on an "AS IS" BASIS,
  15. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. See the License for the specific language governing permissions and
  17. limitations under the License.
  18. */
  19. 'use strict'
  20.  
  21. /** @see https://github.com/TotallyInformation/node-red-contrib-uibuilder/wiki/Front-End-Library---available-properties-and-methods */
  22.  
  23. // eslint-disable-next-line no-unused-vars
  24. var app1 = new Vue({
  25. el: '#app',
  26. data: {
  27. // Single series line chart
  28. lineChartData: [
  29. ['Jan', 4], ['Feb', 2], ['Mar', 10], ['Apr', 5], ['May', 3],
  30. ],
  31. // Multi-series line chart
  32. lineChartData2: [
  33. {name: 'Workout', data: {'2017-01-01 00:00:00 -0800': 3, '2017-01-02 00:00:00 -0800': 4}},
  34. {name: 'Call parents', data: {'2017-01-01 00:00:00 -0800': 5, '2017-01-02 00:00:00 -0800': 3}},
  35. ],
  36.  
  37. // Area chart
  38. areaChartData: [], //{
  39. //'2017-01-01 00:00:00 -0800': 2,
  40. //'2017-01-01 00:01:00 -0800': 5,
  41. //},
  42. barChartData: [],
  43.  
  44.  
  45.  
  46. }, // --- End of data --- //
  47. computed: {
  48.  
  49. }, // --- End of computed --- //
  50. methods: {
  51. }, // --- End of methods --- //
  52.  
  53. // Available hooks: init,mounted,updated,destroyed
  54. mounted: function(){
  55. /** **REQUIRED** Start uibuilder comms with Node-RED @since v2.0.0-dev3
  56. * Pass the namespace and ioPath variables if hosting page is not in the instance root folder
  57. * e.g. If you get continual `uibuilderfe:ioSetup: SOCKET CONNECT ERROR` error messages.
  58. * e.g. uibuilder.start('/nr/uib', '/nr/uibuilder/vendor/socket.io') // change to use your paths/names
  59. */
  60. uibuilder.start()
  61.  
  62. var vueApp = this
  63.  
  64. // Process new messages from Node-RED
  65. uibuilder.onChange('msg', function (newVal) {
  66. // We are assuming that msg.payload is an array like [datenum, value]
  67.  
  68. // Add new element
  69. vueApp.areaChartData.push( new Array(newVal.payload[0].data[0].value, newVal.payload[0].data[0].value2 ) )
  70. //vueApp.areaChartData.push( new Array(newVal.payload.data.value, newVal.payload.data.value2 ) )
  71.  
  72. // If data array > 1000 points, keep it at that length by losing the first point
  73. if ( vueApp.areaChartData.length > 1000 ) vueApp.areaChartData.shift()
  74.  
  75. console.log(vueApp.areaChartData)
  76.  
  77. // WTF part
  78. //var labels = newVal.payload[0].topic
  79. // var barChartData = newVal.payload[0].data
  80. vueApp.barChartData.push( new Array(newVal.payload[0].data[0].value, newVal.payload[0].data[0].value2 ))
  81.  
  82. console.log(vueApp.barChartData)
  83.  
  84. })
  85.  
  86. } // --- End of mounted hook --- //
  87.  
  88. }) // --- End of app1 --- //
  89.  
  90. // EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement