@mxtommy/kip 1.2.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/.angulardoc.json +3 -3
  2. package/CHANGELOG.md +145 -135
  3. package/CONTRIBUTORS.md +16 -16
  4. package/README.md +102 -102
  5. package/angular.json +162 -153
  6. package/karma.conf.js +31 -31
  7. package/package.json +87 -84
  8. package/public/3rdpartylicenses.txt +301 -21
  9. package/public/assets/NoSleep.min.js +1 -1
  10. package/public/assets/fontawesome6/css/all.min.css +6 -0
  11. package/public/assets/fontawesome6/webfonts/fa-brands-400.ttf +0 -0
  12. package/public/assets/fontawesome6/webfonts/fa-brands-400.woff2 +0 -0
  13. package/public/assets/fontawesome6/webfonts/fa-regular-400.ttf +0 -0
  14. package/public/assets/fontawesome6/webfonts/fa-regular-400.woff2 +0 -0
  15. package/public/assets/fontawesome6/webfonts/fa-solid-900.ttf +0 -0
  16. package/public/assets/fontawesome6/webfonts/fa-solid-900.woff2 +0 -0
  17. package/public/assets/fontawesome6/webfonts/fa-v4compatibility.ttf +0 -0
  18. package/public/assets/fontawesome6/webfonts/fa-v4compatibility.woff2 +0 -0
  19. package/public/assets/icon-192x192.png +0 -0
  20. package/public/assets/icon-256x256.png +0 -0
  21. package/public/assets/icon-384x384.png +0 -0
  22. package/public/assets/icon-512x512.png +0 -0
  23. package/public/assets/steelseries-min.js +25 -25
  24. package/public/assets/steelseries-min.js.map +8 -8
  25. package/public/assets/steelseries.js +15834 -15834
  26. package/public/assets/svg-autopilot-inkscape-plain.svg +983 -983
  27. package/public/assets/svg-wind-inkscape.svg +1358 -1358
  28. package/public/assets/tween.js +381 -381
  29. package/public/index.html +19 -20
  30. package/public/main-es2018.98175eb4c61ccaf7eb17.js +1 -0
  31. package/public/main-es5.98175eb4c61ccaf7eb17.js +1 -0
  32. package/public/manifest.json +33 -0
  33. package/public/polyfills-es2018.3a61665863c173cd6ba3.js +1 -0
  34. package/public/polyfills-es5.44827ae4ff4e41de51fb.js +1 -0
  35. package/public/runtime-es2018.baedb88c6d2abacae2b8.js +1 -0
  36. package/public/runtime-es5.baedb88c6d2abacae2b8.js +1 -0
  37. package/public/styles.b92ae2c466c89712209d.css +5 -0
  38. package/src/app/alarm-menu/alarm-menu.component.html +55 -55
  39. package/src/app/alarm-menu/alarm-menu.component.scss +52 -53
  40. package/src/app/alarm-menu/alarm-menu.component.spec.ts +25 -25
  41. package/src/app/alarm-menu/alarm-menu.component.ts +186 -186
  42. package/src/app/app-help/app-help.component.css +4 -4
  43. package/src/app/app-help/app-help.component.html +135 -135
  44. package/src/app/app-help/app-help.component.ts +45 -45
  45. package/src/app/app.component.css +39 -39
  46. package/src/app/app.component.html +93 -93
  47. package/src/app/app.component.scss +79 -79
  48. package/src/app/app.component.spec.ts +32 -32
  49. package/src/app/app.component.ts +191 -192
  50. package/src/app/app.module.ts +200 -200
  51. package/src/app/config.blank.const.ts +51 -51
  52. package/src/app/config.blank.notification.const.ts +19 -19
  53. package/src/app/config.blank.units.const.ts +23 -23
  54. package/src/app/config.demo.const.ts +383 -383
  55. package/src/app/data-browser/data-browser.component.css +29 -29
  56. package/src/app/data-browser/data-browser.component.html +44 -44
  57. package/src/app/data-browser/data-browser.component.spec.ts +25 -25
  58. package/src/app/data-browser/data-browser.component.ts +91 -91
  59. package/src/app/data-browser-row/data-browser-row-unit-modal.html +17 -17
  60. package/src/app/data-browser-row/data-browser-row.component.css +9 -9
  61. package/src/app/data-browser-row/data-browser-row.component.html +4 -4
  62. package/src/app/data-browser-row/data-browser-row.component.ts +78 -78
  63. package/src/app/data-set.service.ts +273 -273
  64. package/src/app/dynamic-widget.directive.ts +11 -11
  65. package/src/app/gauge-steel/gauge-steel.component.css +4 -4
  66. package/src/app/gauge-steel/gauge-steel.component.html +4 -4
  67. package/src/app/gauge-steel/gauge-steel.component.spec.ts +25 -25
  68. package/src/app/gauge-steel/gauge-steel.component.ts +282 -282
  69. package/src/app/gauges-module/base-gauge.ts +300 -300
  70. package/src/app/gauges-module/linear-gauge.ts +49 -49
  71. package/src/app/gauges-module/radial-gauge.ts +47 -47
  72. package/src/app/layout-split/layout-split.component.html +30 -30
  73. package/src/app/layout-split/layout-split.component.scss +33 -33
  74. package/src/app/layout-split/layout-split.component.spec.ts +25 -25
  75. package/src/app/layout-split/layout-split.component.ts +59 -59
  76. package/src/app/layout-splits.service.ts +284 -284
  77. package/src/app/modal-path-selector/modal-path-selector.component.html +62 -62
  78. package/src/app/modal-path-selector/modal-path-selector.component.scss +39 -39
  79. package/src/app/modal-path-selector/modal-path-selector.component.spec.ts +25 -25
  80. package/src/app/modal-path-selector/modal-path-selector.component.ts +132 -132
  81. package/src/app/modal-widget/modal-widget.component.css +32 -32
  82. package/src/app/modal-widget/modal-widget.component.html +341 -341
  83. package/src/app/modal-widget/modal-widget.component.spec.ts +25 -25
  84. package/src/app/modal-widget/modal-widget.component.ts +84 -84
  85. package/src/app/notifications.service.ts +392 -392
  86. package/src/app/object-keys.pipe.spec.ts +8 -8
  87. package/src/app/object-keys.pipe.ts +13 -13
  88. package/src/app/reset-config/reset-config.component.html +3 -3
  89. package/src/app/reset-config/reset-config.component.spec.ts +25 -25
  90. package/src/app/reset-config/reset-config.component.ts +31 -31
  91. package/src/app/root-display/root-display.component.html +4 -4
  92. package/src/app/root-display/root-display.component.spec.ts +25 -25
  93. package/src/app/root-display/root-display.component.ts +57 -57
  94. package/src/app/safe.pipe.ts +15 -15
  95. package/src/app/settings/settings.component.css +9 -9
  96. package/src/app/settings/settings.component.html +25 -25
  97. package/src/app/settings/settings.component.spec.ts +25 -25
  98. package/src/app/settings/settings.component.ts +22 -22
  99. package/src/app/settings-config/settings-config.component.css +38 -38
  100. package/src/app/settings-config/settings-config.component.spec.ts +25 -25
  101. package/src/app/settings-config/settings-config.component.ts +161 -161
  102. package/src/app/settings-datasets/settings-datasets.component.html +43 -43
  103. package/src/app/settings-datasets/settings-datasets.component.scss +39 -39
  104. package/src/app/settings-datasets/settings-datasets.component.spec.ts +25 -25
  105. package/src/app/settings-datasets/settings-datasets.component.ts +98 -98
  106. package/src/app/settings-datasets/settings-datasets.modal.html +54 -54
  107. package/src/app/settings-notifications/settings-notifications.component.html +65 -65
  108. package/src/app/settings-notifications/settings-notifications.component.spec.ts +25 -25
  109. package/src/app/settings-notifications/settings-notifications.component.ts +29 -29
  110. package/src/app/settings-signalk/settings-signalk.component.html +8 -8
  111. package/src/app/settings-signalk/settings-signalk.component.spec.ts +25 -25
  112. package/src/app/settings-signalk/settings-signalk.component.ts +174 -174
  113. package/src/app/settings-units/settings-units.component.css +4 -4
  114. package/src/app/settings-units/settings-units.component.html +19 -19
  115. package/src/app/settings-units/settings-units.component.spec.ts +25 -25
  116. package/src/app/settings-units/settings-units.component.ts +62 -62
  117. package/src/app/settings-zones/settings-zones.component.css +21 -21
  118. package/src/app/settings-zones/settings-zones.component.html +70 -70
  119. package/src/app/settings-zones/settings-zones.modal.html +38 -38
  120. package/src/app/signalk-connection.service.ts +344 -344
  121. package/src/app/signalk-delta.service.spec.ts +15 -15
  122. package/src/app/signalk-delta.service.ts +97 -97
  123. package/src/app/signalk-full.service.ts +99 -99
  124. package/src/app/signalk-interfaces.ts +129 -129
  125. package/src/app/signalk-requests.service.spec.ts +12 -12
  126. package/src/app/signalk-requests.service.ts +180 -180
  127. package/src/app/svg-autopilot/svg-autopilot.component.html +1036 -1036
  128. package/src/app/svg-autopilot/svg-autopilot.component.spec.ts +25 -25
  129. package/src/app/svg-autopilot/svg-autopilot.component.ts +174 -174
  130. package/src/app/svg-simple-linear-gauge/svg-simple-linear-gauge.component.html +119 -119
  131. package/src/app/svg-simple-linear-gauge/svg-simple-linear-gauge.component.spec.ts +25 -25
  132. package/src/app/svg-simple-linear-gauge/svg-simple-linear-gauge.component.ts +49 -49
  133. package/src/app/svg-wind/svg-wind.component.html +969 -969
  134. package/src/app/svg-wind/svg-wind.component.scss +76 -76
  135. package/src/app/svg-wind/svg-wind.component.spec.ts +25 -25
  136. package/src/app/svg-wind/svg-wind.component.ts +280 -280
  137. package/src/app/unit-window/unit-window.component.css +37 -37
  138. package/src/app/unit-window/unit-window.component.html +8 -8
  139. package/src/app/unit-window/unit-window.component.spec.ts +25 -25
  140. package/src/app/unit-window/unit-window.component.ts +134 -134
  141. package/src/app/unit-window/unit-window.modal.html +24 -24
  142. package/src/app/units.service.ts +300 -300
  143. package/src/app/widget-autopilot/widget-autopilot.component.html +78 -85
  144. package/src/app/widget-autopilot/widget-autopilot.component.scss +191 -191
  145. package/src/app/widget-autopilot/widget-autopilot.component.spec.ts +25 -25
  146. package/src/app/widget-autopilot/widget-autopilot.component.ts +774 -781
  147. package/src/app/widget-blank/widget-blank.component.scss +21 -22
  148. package/src/app/widget-blank/widget-blank.component.spec.ts +25 -25
  149. package/src/app/widget-blank/widget-blank.component.ts +17 -17
  150. package/src/app/widget-gauge/widget-gauge.component.css +25 -25
  151. package/src/app/widget-gauge/widget-gauge.component.html +29 -29
  152. package/src/app/widget-gauge/widget-gauge.component.spec.ts +25 -25
  153. package/src/app/widget-gauge/widget-gauge.component.ts +120 -120
  154. package/src/app/widget-gauge-ng-linear/widget-gauge-ng-linear.component.html +126 -126
  155. package/src/app/widget-gauge-ng-linear/widget-gauge-ng-linear.component.scss +94 -93
  156. package/src/app/widget-gauge-ng-linear/widget-gauge-ng-linear.component.spec.ts +25 -25
  157. package/src/app/widget-gauge-ng-linear/widget-gauge-ng-linear.component.ts +424 -424
  158. package/src/app/widget-gauge-ng-radial/widget-gauge-ng-radial.component.html +1 -1
  159. package/src/app/widget-gauge-ng-radial/widget-gauge-ng-radial.component.scss +69 -69
  160. package/src/app/widget-gauge-ng-radial/widget-gauge-ng-radial.component.spec.ts +25 -25
  161. package/src/app/widget-gauge-ng-radial/widget-gauge-ng-radial.component.ts +553 -553
  162. package/src/app/widget-historical/widget-historical.component.html +14 -14
  163. package/src/app/widget-historical/widget-historical.component.spec.ts +25 -25
  164. package/src/app/widget-historical/widget-historical.component.ts +306 -306
  165. package/src/app/widget-iframe/widget-iframe.component.css +11 -11
  166. package/src/app/widget-iframe/widget-iframe.component.html +21 -21
  167. package/src/app/widget-iframe/widget-iframe.component.spec.ts +25 -25
  168. package/src/app/widget-iframe/widget-iframe.component.ts +63 -63
  169. package/src/app/widget-list.service.ts +135 -135
  170. package/src/app/widget-manager.service.ts +141 -141
  171. package/src/app/widget-numeric/widget-numeric.component.html +1 -1
  172. package/src/app/widget-numeric/widget-numeric.component.scss +3 -3
  173. package/src/app/widget-numeric/widget-numeric.component.spec.ts +25 -25
  174. package/src/app/widget-simple-linear/widget-simple-linear.component.html +28 -28
  175. package/src/app/widget-simple-linear/widget-simple-linear.component.scss +64 -64
  176. package/src/app/widget-simple-linear/widget-simple-linear.component.spec.ts +25 -25
  177. package/src/app/widget-simple-linear/widget-simple-linear.component.ts +199 -199
  178. package/src/app/widget-state/widget-state.component.html +27 -27
  179. package/src/app/widget-state/widget-state.component.scss +68 -68
  180. package/src/app/widget-state/widget-state.component.spec.ts +25 -25
  181. package/src/app/widget-state/widget-state.component.ts +178 -178
  182. package/src/app/widget-switch/widget-switch.component.css +69 -69
  183. package/src/app/widget-switch/widget-switch.component.html +17 -17
  184. package/src/app/widget-switch/widget-switch.component.spec.ts +25 -25
  185. package/src/app/widget-switch/widget-switch.component.ts +134 -134
  186. package/src/app/widget-text-generic/widget-text-generic.component.html +9 -9
  187. package/src/app/widget-text-generic/widget-text-generic.component.spec.ts +25 -25
  188. package/src/app/widget-tutorial/widget-tutorial.component.html +34 -34
  189. package/src/app/widget-tutorial/widget-tutorial.component.spec.ts +25 -25
  190. package/src/app/widget-tutorial/widget-tutorial.component.ts +18 -18
  191. package/src/app/widget-unknown/widget-unknown.component.spec.ts +25 -25
  192. package/src/app/widget-wind/widget-wind.component.css +23 -23
  193. package/src/app/widget-wind/widget-wind.component.html +20 -20
  194. package/src/app/widget-wind/widget-wind.component.spec.ts +25 -25
  195. package/src/app/widget-wind/widget-wind.component.ts +369 -369
  196. package/src/assets/NoSleep.min.js +1 -1
  197. package/src/assets/fontawesome6/css/all.min.css +6 -0
  198. package/src/assets/fontawesome6/webfonts/fa-brands-400.ttf +0 -0
  199. package/src/assets/fontawesome6/webfonts/fa-brands-400.woff2 +0 -0
  200. package/src/assets/fontawesome6/webfonts/fa-regular-400.ttf +0 -0
  201. package/src/assets/fontawesome6/webfonts/fa-regular-400.woff2 +0 -0
  202. package/src/assets/fontawesome6/webfonts/fa-solid-900.ttf +0 -0
  203. package/src/assets/fontawesome6/webfonts/fa-solid-900.woff2 +0 -0
  204. package/src/assets/fontawesome6/webfonts/fa-v4compatibility.ttf +0 -0
  205. package/src/assets/fontawesome6/webfonts/fa-v4compatibility.woff2 +0 -0
  206. package/src/assets/icon-192x192.png +0 -0
  207. package/src/assets/icon-256x256.png +0 -0
  208. package/src/assets/icon-384x384.png +0 -0
  209. package/src/assets/icon-512x512.png +0 -0
  210. package/src/assets/steelseries-min.js +25 -25
  211. package/src/assets/steelseries-min.js.map +8 -8
  212. package/src/assets/steelseries.js +15834 -15834
  213. package/src/assets/svg-autopilot-inkscape-plain.svg +983 -983
  214. package/src/assets/svg-wind-inkscape.svg +1358 -1358
  215. package/src/assets/tween.js +381 -381
  216. package/src/index.html +20 -20
  217. package/src/main.ts +11 -11
  218. package/src/manifest.json +33 -0
  219. package/src/polyfills.ts +80 -76
  220. package/src/styles.scss +11 -11
  221. package/src/themes/darkBlueTheme.scss +117 -116
  222. package/src/themes/defaultTheme.scss +50 -49
  223. package/src/themes/highContrastTheme.scss +47 -46
  224. package/src/themes/modernTheme.scss +143 -142
  225. package/src/themes/nightMode.scss +185 -184
  226. package/src/themes/platypusTheme.scss +80 -79
  227. package/src/themes/signalkTheme.scss +112 -111
  228. package/src/tsconfig.app.json +15 -15
  229. package/src/tsconfig.spec.json +20 -20
  230. package/tsconfig.json +23 -23
  231. package/tslint.json +143 -143
  232. package/public/assets/font-awesome/HELP-US-OUT.txt +0 -7
  233. package/public/assets/font-awesome/css/font-awesome.css +0 -2337
  234. package/public/assets/font-awesome/css/font-awesome.min.css +0 -4
  235. package/public/assets/font-awesome/desktop.ini +0 -4
  236. package/public/assets/font-awesome/fonts/FontAwesome.otf +0 -0
  237. package/public/assets/font-awesome/fonts/fontawesome-webfont.eot +0 -0
  238. package/public/assets/font-awesome/fonts/fontawesome-webfont.svg +0 -2671
  239. package/public/assets/font-awesome/fonts/fontawesome-webfont.ttf +0 -0
  240. package/public/assets/font-awesome/fonts/fontawesome-webfont.woff +0 -0
  241. package/public/assets/font-awesome/fonts/fontawesome-webfont.woff2 +0 -0
  242. package/public/assets/font-awesome/less/animated.less +0 -34
  243. package/public/assets/font-awesome/less/bordered-pulled.less +0 -25
  244. package/public/assets/font-awesome/less/core.less +0 -12
  245. package/public/assets/font-awesome/less/fixed-width.less +0 -6
  246. package/public/assets/font-awesome/less/font-awesome.less +0 -18
  247. package/public/assets/font-awesome/less/icons.less +0 -789
  248. package/public/assets/font-awesome/less/larger.less +0 -13
  249. package/public/assets/font-awesome/less/list.less +0 -19
  250. package/public/assets/font-awesome/less/mixins.less +0 -60
  251. package/public/assets/font-awesome/less/path.less +0 -15
  252. package/public/assets/font-awesome/less/rotated-flipped.less +0 -20
  253. package/public/assets/font-awesome/less/screen-reader.less +0 -5
  254. package/public/assets/font-awesome/less/stacked.less +0 -20
  255. package/public/assets/font-awesome/less/variables.less +0 -800
  256. package/public/assets/font-awesome/scss/_animated.scss +0 -34
  257. package/public/assets/font-awesome/scss/_bordered-pulled.scss +0 -25
  258. package/public/assets/font-awesome/scss/_core.scss +0 -12
  259. package/public/assets/font-awesome/scss/_fixed-width.scss +0 -6
  260. package/public/assets/font-awesome/scss/_icons.scss +0 -789
  261. package/public/assets/font-awesome/scss/_larger.scss +0 -13
  262. package/public/assets/font-awesome/scss/_list.scss +0 -19
  263. package/public/assets/font-awesome/scss/_mixins.scss +0 -60
  264. package/public/assets/font-awesome/scss/_path.scss +0 -15
  265. package/public/assets/font-awesome/scss/_rotated-flipped.scss +0 -20
  266. package/public/assets/font-awesome/scss/_screen-reader.scss +0 -5
  267. package/public/assets/font-awesome/scss/_stacked.scss +0 -20
  268. package/public/assets/font-awesome/scss/_variables.scss +0 -800
  269. package/public/assets/font-awesome/scss/font-awesome.scss +0 -18
  270. package/public/main-es2018.ab0adc5af3ab3e70c849.js +0 -1
  271. package/public/main-es5.ab0adc5af3ab3e70c849.js +0 -1
  272. package/public/polyfills-es2018.713f95af1f028e444854.js +0 -1
  273. package/public/polyfills-es5.c78877945523541d2597.js +0 -1
  274. package/public/runtime-es2018.a4dadbc03350107420a4.js +0 -1
  275. package/public/runtime-es5.a4dadbc03350107420a4.js +0 -1
  276. package/public/styles.71bb0d04cad96b5efbe1.css +0 -19
  277. package/src/assets/font-awesome/HELP-US-OUT.txt +0 -7
  278. package/src/assets/font-awesome/css/font-awesome.css +0 -2337
  279. package/src/assets/font-awesome/css/font-awesome.min.css +0 -4
  280. package/src/assets/font-awesome/desktop.ini +0 -4
  281. package/src/assets/font-awesome/fonts/FontAwesome.otf +0 -0
  282. package/src/assets/font-awesome/fonts/fontawesome-webfont.eot +0 -0
  283. package/src/assets/font-awesome/fonts/fontawesome-webfont.svg +0 -2671
  284. package/src/assets/font-awesome/fonts/fontawesome-webfont.ttf +0 -0
  285. package/src/assets/font-awesome/fonts/fontawesome-webfont.woff +0 -0
  286. package/src/assets/font-awesome/fonts/fontawesome-webfont.woff2 +0 -0
  287. package/src/assets/font-awesome/less/animated.less +0 -34
  288. package/src/assets/font-awesome/less/bordered-pulled.less +0 -25
  289. package/src/assets/font-awesome/less/core.less +0 -12
  290. package/src/assets/font-awesome/less/fixed-width.less +0 -6
  291. package/src/assets/font-awesome/less/font-awesome.less +0 -18
  292. package/src/assets/font-awesome/less/icons.less +0 -789
  293. package/src/assets/font-awesome/less/larger.less +0 -13
  294. package/src/assets/font-awesome/less/list.less +0 -19
  295. package/src/assets/font-awesome/less/mixins.less +0 -60
  296. package/src/assets/font-awesome/less/path.less +0 -15
  297. package/src/assets/font-awesome/less/rotated-flipped.less +0 -20
  298. package/src/assets/font-awesome/less/screen-reader.less +0 -5
  299. package/src/assets/font-awesome/less/stacked.less +0 -20
  300. package/src/assets/font-awesome/less/variables.less +0 -800
  301. package/src/assets/font-awesome/scss/_animated.scss +0 -34
  302. package/src/assets/font-awesome/scss/_bordered-pulled.scss +0 -25
  303. package/src/assets/font-awesome/scss/_core.scss +0 -12
  304. package/src/assets/font-awesome/scss/_fixed-width.scss +0 -6
  305. package/src/assets/font-awesome/scss/_icons.scss +0 -789
  306. package/src/assets/font-awesome/scss/_larger.scss +0 -13
  307. package/src/assets/font-awesome/scss/_list.scss +0 -19
  308. package/src/assets/font-awesome/scss/_mixins.scss +0 -60
  309. package/src/assets/font-awesome/scss/_path.scss +0 -15
  310. package/src/assets/font-awesome/scss/_rotated-flipped.scss +0 -20
  311. package/src/assets/font-awesome/scss/_screen-reader.scss +0 -5
  312. package/src/assets/font-awesome/scss/_stacked.scss +0 -20
  313. package/src/assets/font-awesome/scss/_variables.scss +0 -800
  314. package/src/assets/font-awesome/scss/font-awesome.scss +0 -18
@@ -1,553 +1,553 @@
1
- import { ViewChild, ElementRef, Component, Input, OnInit, OnDestroy, AfterContentInit, AfterContentChecked } from '@angular/core';
2
- import { Subscription } from 'rxjs';
3
- import { MatDialog } from '@angular/material/dialog';
4
- import { ResizedEvent } from 'angular-resize-event';
5
-
6
- import { SignalKService } from '../signalk.service';
7
- import { ModalWidgetComponent } from '../modal-widget/modal-widget.component';
8
- import { WidgetManagerService, IWidget, IWidgetConfig } from '../widget-manager.service';
9
- import { UnitsService } from '../units.service';
10
- import { AppSettingsService, IZone, ZoneState } from '../app-settings.service';
11
- import { RadialGauge, RadialGaugeOptions } from '../gauges-module/radial-gauge';
12
-
13
- const defaultConfig: IWidgetConfig = {
14
- displayName: null,
15
- filterSelfPaths: true,
16
- paths: {
17
- "gaugePath": {
18
- description: "Numeric Data",
19
- path: null,
20
- source: null,
21
- pathType: "number",
22
- isPathConfigurable: true,
23
- convertUnitTo: "unitless"
24
- }
25
- },
26
- gaugeType: 'ngRadial', //ngLinearVertical or ngLinearHorizontal
27
- gaugeTicks: false,
28
- radialSize: 'measuring',
29
- compassUseNumbers: false,
30
- minValue: 0,
31
- maxValue: 100,
32
- numInt: 1,
33
- numDecimal: 0,
34
- barColor: 'accent', // theme palette to select
35
- };
36
-
37
- interface IDataHighlight extends Array<{
38
- from : number;
39
- to : number;
40
- color: string;
41
- }> {};
42
-
43
- @Component({
44
- selector: 'app-widget-gauge-ng-radial',
45
- templateUrl: './widget-gauge-ng-radial.component.html',
46
- styleUrls: ['./widget-gauge-ng-radial.component.scss']
47
- })
48
- export class WidgetGaugeNgRadialComponent implements OnInit, OnDestroy, AfterContentInit, AfterContentChecked {
49
-
50
- @ViewChild('wrapperDiv', {static: true, read: ElementRef}) private wrapper: ElementRef;
51
- @ViewChild('radialGauge', {static: true, read: RadialGauge}) public radialGauge: RadialGauge;
52
-
53
- @Input('widgetUUID') widgetUUID: string;
54
- @Input('unlockStatus') unlockStatus: boolean;
55
-
56
- // hack to access material-theme palette colors
57
- @ViewChild('primary', {static: true, read: ElementRef}) private primaryElement: ElementRef;
58
- @ViewChild('accent', {static: true, read: ElementRef}) private accentElement: ElementRef;
59
- @ViewChild('warn', {static: true, read: ElementRef}) private warnElement: ElementRef;
60
- @ViewChild('primaryDark', {static: true, read: ElementRef}) private primaryDarkElement: ElementRef;
61
- @ViewChild('accentDark', {static: true, read: ElementRef}) private accentDarkElement: ElementRef;
62
- @ViewChild('warnDark', {static: true, read: ElementRef}) private warnDarkElement: ElementRef;
63
- @ViewChild('background', {static: true, read: ElementRef}) private backgroundElement: ElementRef;
64
- @ViewChild('text', {static: true, read: ElementRef}) private textElement: ElementRef;
65
-
66
- activeWidget: IWidget;
67
- config: IWidgetConfig;
68
-
69
- public dataValue = 0;
70
- valueSub: Subscription = null;
71
-
72
- // dynamics theme support
73
- themeNameSub: Subscription = null;
74
-
75
- public gaugeOptions = {} as RadialGaugeOptions;
76
- // fix for RadialGauge GaugeOptions object ** missing color-stroke-ticks property
77
- public colorStrokeTicks: string = "";
78
- public unitName: string = null;
79
-
80
- zones: Array<IZone> = [];
81
- zonesSub: Subscription;
82
-
83
- constructor(
84
- public dialog:MatDialog,
85
- private SignalKService: SignalKService,
86
- private WidgetManagerService: WidgetManagerService,
87
- private UnitsService: UnitsService,
88
- private AppSettingsService: AppSettingsService, // need for theme change subscription
89
- ) { }
90
-
91
- ngOnInit() {
92
- this.activeWidget = this.WidgetManagerService.getWidget(this.widgetUUID);
93
- if (this.activeWidget.config === null) {
94
- // no data, let's set some!
95
- this.WidgetManagerService.updateWidgetConfig(this.widgetUUID, defaultConfig);
96
- this.config = defaultConfig; // load default config.
97
- } else {
98
- this.config = this.activeWidget.config;
99
- //new config option, might not be set.
100
- if (!('compassUseNumbers' in this.config)) {
101
- console.log("compassUseNumbers not set");
102
- this.config.compassUseNumbers = false;
103
- }
104
- }
105
- this.subscribePath();
106
- this.subscribeTheme();
107
- this.subscribeZones();
108
- }
109
-
110
- ngOnDestroy() {
111
- this.unsubscribePath();
112
- this.unsubscribeTheme();
113
- this.unsubscribeZones();
114
- }
115
-
116
- ngAfterContentInit() {
117
- this.updateGaugeConfig();
118
- }
119
-
120
- ngAfterContentChecked() {
121
- // this.resizeWidget();
122
- }
123
-
124
- subscribePath() {
125
- this.unsubscribePath();
126
- if (typeof(this.config.paths['gaugePath'].path) != 'string') { return } // nothing to sub to...
127
-
128
- this.valueSub = this.SignalKService.subscribePath(this.widgetUUID, this.config.paths['gaugePath'].path, this.config.paths['gaugePath'].source).subscribe(
129
- newValue => {
130
- this.dataValue = this.UnitsService.convertUnit(this.config.paths['gaugePath'].convertUnitTo, newValue.value);
131
-
132
-
133
- // set colors for zone state
134
- switch (newValue.state) {
135
- case ZoneState.warning:
136
- this.gaugeOptions.colorValueText = getComputedStyle(this.warnDarkElement.nativeElement).color;
137
- break;
138
- case ZoneState.alarm:
139
- this.gaugeOptions.colorValueText = getComputedStyle(this.warnDarkElement.nativeElement).color;
140
- break;
141
- default:
142
- this.gaugeOptions.colorValueText = getComputedStyle(this.textElement.nativeElement).color;
143
-
144
- }
145
-
146
- }
147
- );
148
- }
149
-
150
- unsubscribePath() {
151
- if (this.valueSub !== null) {
152
- this.valueSub.unsubscribe();
153
- this.valueSub = null;
154
- this.SignalKService.unsubscribePath(this.widgetUUID, this.config.paths['gaugePath'].path)
155
- }
156
- }
157
-
158
- // Subscribe to theme event
159
- subscribeTheme() {
160
- this.themeNameSub = this.AppSettingsService.getThemeNameAsO().subscribe(
161
- themeChange => {
162
- setTimeout(() => { // need a delay so browser getComputedStyles has time to complete theme application.
163
- this.updateGaugeConfig();
164
- }, 50);
165
- })
166
- }
167
-
168
- unsubscribeTheme(){
169
- if (this.themeNameSub !== null) {
170
- this.themeNameSub.unsubscribe();
171
- this.themeNameSub = null;
172
- }
173
- }
174
-
175
- // Subscribe to Zones
176
- subscribeZones() {
177
- this.zonesSub = this.AppSettingsService.getZonesAsO().subscribe(
178
- zones => {
179
- this.zones = zones;
180
- this.updateGaugeConfig();
181
- });
182
- }
183
-
184
- unsubscribeZones(){
185
- if (this.zonesSub !== null) {
186
- this.zonesSub.unsubscribe();
187
- this.zonesSub = null;
188
- }
189
- }
190
-
191
- openWidgetSettings() {
192
- let dialogRef = this.dialog.open(ModalWidgetComponent, {
193
- width: '80%',
194
- data: this.config
195
- });
196
-
197
- dialogRef.afterClosed().subscribe(result => {
198
- // save new settings
199
- if (result) {
200
- console.log(result);
201
- this.unsubscribePath(); //unsub now as we will change variables so wont know what was subbed before...
202
- this.config = result;
203
- this.WidgetManagerService.updateWidgetConfig(this.widgetUUID, this.config);
204
- this.subscribePath();
205
- this.updateGaugeConfig();
206
- }
207
- });
208
- }
209
-
210
- updateGaugeConfig(){
211
- //// Hack to get Theme colors using hidden mixin, DIV and @ViewChild
212
- let themePaletteColor = "";
213
- let themePaletteDarkColor = "";
214
-
215
- this.gaugeOptions.colorTitle = this.gaugeOptions.colorUnits = getComputedStyle(this.textElement.nativeElement).color;
216
-
217
- this.gaugeOptions.colorPlate = getComputedStyle(this.wrapper.nativeElement).backgroundColor;
218
- this.gaugeOptions.colorBar = getComputedStyle(this.backgroundElement.nativeElement).color;
219
- this.gaugeOptions.colorNeedleShadowUp = "";
220
- this.gaugeOptions.colorNeedleShadowDown = "black";
221
- this.gaugeOptions.colorNeedleCircleInner = this.gaugeOptions.colorPlate;
222
- this.gaugeOptions.colorNeedleCircleInnerEnd = this.gaugeOptions.colorPlate;
223
- this.gaugeOptions.colorNeedleCircleOuter = this.gaugeOptions.colorPlate;
224
- this.gaugeOptions.colorNeedleCircleOuterEnd = this.gaugeOptions.colorPlate;
225
-
226
- // Theme colors
227
- switch (this.config.barColor) {
228
- case "primary":
229
- themePaletteColor = getComputedStyle(this.primaryElement.nativeElement).color;
230
- themePaletteDarkColor = getComputedStyle(this.primaryDarkElement.nativeElement).color;
231
- this.gaugeOptions.colorBarProgress = themePaletteColor;
232
- this.gaugeOptions.colorNeedle = themePaletteDarkColor;
233
- this.gaugeOptions.colorNeedleEnd = themePaletteDarkColor;
234
- break;
235
-
236
- case "accent":
237
- themePaletteColor = getComputedStyle(this.accentElement.nativeElement).color;
238
- themePaletteDarkColor = getComputedStyle(this.accentDarkElement.nativeElement).color;
239
- this.gaugeOptions.colorBarProgress = themePaletteColor;
240
- this.gaugeOptions.colorNeedle = themePaletteDarkColor;
241
- this.gaugeOptions.colorNeedleEnd = themePaletteDarkColor;
242
- break;
243
-
244
- case "warn":
245
- themePaletteColor = getComputedStyle(this.warnElement.nativeElement).color;
246
- themePaletteDarkColor = getComputedStyle(this.warnDarkElement.nativeElement).color;
247
- this.gaugeOptions.colorBarProgress = themePaletteColor;
248
- this.gaugeOptions.colorNeedle = themePaletteDarkColor;
249
- this.gaugeOptions.colorNeedleEnd = themePaletteDarkColor;
250
- break;
251
-
252
- default:
253
- break;
254
- }
255
-
256
- // highlights
257
- let myZones: IDataHighlight = [];
258
- this.zones.forEach(zone => {
259
- // get zones for our path
260
- if (zone.path == this.config.paths['gaugePath'].path) {
261
- let lower = zone.lower || this.config.minValue;
262
- let upper = zone.upper || this.config.maxValue;
263
- let color: string;
264
- switch (zone.state) {
265
- case 1:
266
- color = getComputedStyle(this.warnElement.nativeElement).color;
267
- break;
268
- case ZoneState.alarm:
269
- color = getComputedStyle(this.warnDarkElement.nativeElement).color;
270
- break;
271
- default:
272
- color = getComputedStyle(this.primaryElement.nativeElement).color;
273
- }
274
-
275
- myZones.push({from: lower, to: upper, color: color});
276
- }
277
- });
278
- this.gaugeOptions.highlights = myZones;
279
-
280
- // Config storage values
281
- this.gaugeOptions.valueInt = this.config.numInt;
282
- this.gaugeOptions.valueDec = this.config.numDecimal;
283
-
284
- this.gaugeOptions.majorTicksInt = this.config.numInt;
285
- this.gaugeOptions.majorTicksDec = this.config.numDecimal;
286
-
287
- // Radial gauge type
288
- switch(this.config.radialSize) {
289
- case "capacity":
290
- this.unitName = this.config.paths['gaugePath'].convertUnitTo;
291
- this.gaugeOptions.colorMajorTicks = this.gaugeOptions.colorPlate; // bug with MajorTicks drawing firs tick always and using color="" does not work
292
- this.gaugeOptions.colorNumbers = this.gaugeOptions.colorMinorTicks = "";
293
- this.gaugeOptions.fontTitleSize = 60;
294
- this.gaugeOptions.minValue = this.config.minValue;
295
- this.gaugeOptions.maxValue = this.config.maxValue;
296
- this.gaugeOptions.barProgress = true;
297
- this.gaugeOptions.barWidth = 15;
298
-
299
- this.gaugeOptions.valueBox = true;
300
- this.gaugeOptions.fontValueSize = 110;
301
- this.gaugeOptions.valueBoxWidth = 100;
302
- this.gaugeOptions.valueBoxBorderRadius = 0;
303
- this.gaugeOptions.valueBoxStroke = 0;
304
- this.gaugeOptions.colorValueBoxBackground = "";
305
-
306
- this.gaugeOptions.ticksAngle = 360;
307
- this.gaugeOptions.startAngle = 180;
308
- this.gaugeOptions.exactTicks = false;
309
- this.gaugeOptions.strokeTicks = false;
310
- this.gaugeOptions.majorTicks = [];
311
- this.gaugeOptions.minorTicks = 0;
312
- this.gaugeOptions.numbersMargin = 0;
313
- this.gaugeOptions.fontNumbersSize = 0;
314
- this.gaugeOptions.highlightsWidth = 15;
315
-
316
- this.gaugeOptions.needle = true;
317
- this.gaugeOptions.needleType = "line";
318
- this.gaugeOptions.needleWidth = 2;
319
- this.gaugeOptions.needleShadow = false;
320
- this.gaugeOptions.needleStart = 80;
321
- this.gaugeOptions.needleEnd = 95;
322
- this.gaugeOptions.needleCircleSize = 1;
323
- this.gaugeOptions.needleCircleInner = false;
324
- this.gaugeOptions.needleCircleOuter = false;
325
-
326
- this.gaugeOptions.borders = true;
327
- this.gaugeOptions.borderOuterWidth = 0;
328
- this.gaugeOptions.borderMiddleWidth = 2;
329
- this.gaugeOptions.borderInnerWidth = 2;
330
- this.gaugeOptions.borderShadowWidth = 0;
331
-
332
- this.gaugeOptions.animationTarget = "needle";
333
- this.gaugeOptions.useMinPath = false;
334
- break;
335
-
336
- case "measuring":
337
- this.unitName = this.config.paths['gaugePath'].convertUnitTo;
338
- let calculatedMajorTicks = this.calculateMajorTicks(this.config.minValue, this.config.maxValue);
339
-
340
- this.gaugeOptions.colorTitle = this.colorStrokeTicks = this.gaugeOptions.colorMinorTicks = this.gaugeOptions.colorNumbers = this.gaugeOptions.colorTitle;
341
-
342
- this.gaugeOptions.fontTitleSize = 20;
343
- this.gaugeOptions.minValue = this.config.minValue;
344
- this.gaugeOptions.maxValue = this.config.maxValue;
345
- this.gaugeOptions.barProgress = true;
346
- this.gaugeOptions.barWidth = 15;
347
-
348
- this.gaugeOptions.valueBox = true;
349
- this.gaugeOptions.fontValueSize = 60;
350
- this.gaugeOptions.valueBoxWidth = 100;
351
- this.gaugeOptions.valueBoxBorderRadius = 0;
352
- this.gaugeOptions.valueBoxStroke = 0;
353
- this.gaugeOptions.colorValueBoxBackground = "";
354
-
355
- this.gaugeOptions.ticksAngle = 270;
356
- this.gaugeOptions.startAngle = 45;
357
- this.gaugeOptions.exactTicks = false;
358
- this.gaugeOptions.strokeTicks = true;
359
- this.gaugeOptions.majorTicks = [calculatedMajorTicks.toString()];
360
- this.gaugeOptions.minorTicks = 2;
361
- this.gaugeOptions.numbersMargin = 3;
362
- this.gaugeOptions.fontNumbersSize = 15;
363
- this.gaugeOptions.highlightsWidth = 15;
364
-
365
- this.gaugeOptions.needle = true;
366
- this.gaugeOptions.needleType = "line";
367
- this.gaugeOptions.needleWidth = 2;
368
- this.gaugeOptions.needleShadow = false;
369
- this.gaugeOptions.needleStart = 0;
370
- this.gaugeOptions.needleEnd = 95;
371
- this.gaugeOptions.needleCircleSize = 10;
372
- this.gaugeOptions.needleCircleInner = false;
373
- this.gaugeOptions.needleCircleOuter = false;
374
-
375
- this.gaugeOptions.borders = false;
376
- this.gaugeOptions.borderOuterWidth = 0;
377
- this.gaugeOptions.borderMiddleWidth = 0;
378
- this.gaugeOptions.borderInnerWidth = 0;
379
- this.gaugeOptions.borderShadowWidth = 0;
380
-
381
- this.gaugeOptions.animationTarget = "needle";
382
- this.gaugeOptions.useMinPath = false;
383
- break;
384
-
385
- case "marineCompass":
386
- // overwrite min/max/unit to make sure we don't limit
387
- this.config.minValue = 0;
388
- this.config.maxValue = 360;
389
- this.config.paths["gaugePath"].convertUnitTo = "deg";
390
- this.unitName = null;
391
-
392
-
393
- this.gaugeOptions.colorMajorTicks = this.gaugeOptions.colorNumbers = this.gaugeOptions.colorMinorTicks = this.gaugeOptions.colorUnits;
394
- this.gaugeOptions.fontTitleSize = 60;
395
- this.gaugeOptions.minValue = 0;
396
- this.gaugeOptions.maxValue = 360;
397
- this.gaugeOptions.barProgress = false;
398
- this.gaugeOptions.barWidth = 0;
399
-
400
- this.gaugeOptions.valueBox = true
401
- this.gaugeOptions.fontValueSize = 50;
402
- this.gaugeOptions.valueBoxWidth = 0;
403
- this.gaugeOptions.valueBoxBorderRadius = 5;
404
- this.gaugeOptions.valueBoxStroke = 0;
405
- this.gaugeOptions.colorValueBoxBackground = this.gaugeOptions.colorBar;
406
-
407
- this.gaugeOptions.ticksAngle = 360;
408
- this.gaugeOptions.startAngle = 180;
409
- this.gaugeOptions.exactTicks = false;
410
- this.gaugeOptions.strokeTicks = false;
411
-
412
- this.gaugeOptions.majorTicks = this.config.compassUseNumbers ? ["0,45,90,135,180,225,270,315,0"] : ["N,NE,E,SE,S,SW,W,NW,N"];
413
- this.gaugeOptions.numbersMargin = 3;
414
- this.gaugeOptions.fontNumbersSize = 15;
415
- this.gaugeOptions.minorTicks = 22;
416
- this.gaugeOptions.highlights = [];
417
- this.gaugeOptions.highlightsWidth = 0;
418
-
419
- this.gaugeOptions.needle = true;
420
- this.gaugeOptions.needleType = "line";
421
- this.gaugeOptions.needleWidth = 3;
422
- this.gaugeOptions.needleShadow = false;
423
- this.gaugeOptions.needleStart = 75;
424
- this.gaugeOptions.needleEnd = 99;
425
- this.gaugeOptions.needleCircleSize = 2;
426
- this.gaugeOptions.needleCircleInner = false;
427
- this.gaugeOptions.needleCircleOuter = false;
428
-
429
- this.gaugeOptions.borders = true;
430
- this.gaugeOptions.borderOuterWidth = 0;
431
- this.gaugeOptions.borderMiddleWidth = 2;
432
- this.gaugeOptions.borderInnerWidth = 2;
433
- this.gaugeOptions.borderShadowWidth = 0;
434
-
435
- this.gaugeOptions.animationTarget = "plate";
436
- this.gaugeOptions.useMinPath = true;
437
- break;
438
-
439
- case "baseplateCompass":
440
- // overwrite min/max/unit to make sure we don't limit
441
- this.config.minValue = 0;
442
- this.config.maxValue = 360;
443
- this.config.paths["gaugePath"].convertUnitTo = "deg";
444
- this.unitName = null;
445
-
446
- this.gaugeOptions.colorMajorTicks = this.gaugeOptions.colorNumbers = this.gaugeOptions.colorMinorTicks = this.gaugeOptions.colorUnits;
447
- this.gaugeOptions.fontTitleSize = 60;
448
- this.gaugeOptions.minValue = 0;
449
- this.gaugeOptions.maxValue = 360;
450
- this.gaugeOptions.barProgress = false;
451
- this.gaugeOptions.barWidth = 0;
452
-
453
- this.gaugeOptions.valueBox = true
454
- this.gaugeOptions.fontValueSize = 50;
455
- this.gaugeOptions.valueBoxWidth = 0;
456
- this.gaugeOptions.valueBoxBorderRadius = 5;
457
- this.gaugeOptions.valueBoxStroke = 0;
458
- this.gaugeOptions.colorValueBoxBackground = this.gaugeOptions.colorBar;
459
-
460
- this.gaugeOptions.ticksAngle = 360;
461
- this.gaugeOptions.startAngle = 180;
462
- this.gaugeOptions.exactTicks = false;
463
- this.gaugeOptions.strokeTicks = false;
464
- this.gaugeOptions.majorTicks = this.config.compassUseNumbers ? ["0,45,90,135,180,225,270,315,0"] : ["N,NE,E,SE,S,SW,W,NW,N"];
465
- this.gaugeOptions.numbersMargin = 3;
466
- this.gaugeOptions.fontNumbersSize = 15;
467
- this.gaugeOptions.minorTicks = 22;
468
- this.gaugeOptions.highlights = [];
469
- this.gaugeOptions.highlightsWidth = 0;
470
-
471
- this.gaugeOptions.needle = true;
472
- this.gaugeOptions.needleType = "line";
473
- this.gaugeOptions.needleWidth = 3;
474
- this.gaugeOptions.needleShadow = false;
475
- this.gaugeOptions.needleStart = 75;
476
- this.gaugeOptions.needleEnd = 99;
477
- this.gaugeOptions.needleCircleSize = 2;
478
- this.gaugeOptions.needleCircleInner = false;
479
- this.gaugeOptions.needleCircleOuter = false;
480
-
481
- this.gaugeOptions.borders = true;
482
- this.gaugeOptions.borderOuterWidth = 0;
483
- this.gaugeOptions.borderMiddleWidth = 2;
484
- this.gaugeOptions.borderInnerWidth = 2;
485
- this.gaugeOptions.borderShadowWidth = 0;
486
-
487
- this.gaugeOptions.animationTarget = "needle";
488
- this.gaugeOptions.useMinPath = true;
489
- break;
490
-
491
- default:
492
- break;
493
- }
494
- }
495
-
496
- onResized(event: ResizedEvent) {
497
- this.gaugeOptions.height = Math.floor(event.newHeight * 0.88);
498
- this.gaugeOptions.width = Math.floor(event.newWidth * 0.88);
499
- }
500
-
501
- // Method to calculate nice values for min, max and range for the gaugeOptions.majorTicks
502
- calculateMajorTicks(minValue: number, maxValue: number): string[]|number[] {
503
- let niceMinValue = minValue;
504
- let niceMaxValue = maxValue;
505
- let niceRange = maxValue - minValue;
506
- let majorTickSpacing = 0;
507
- let maxNoOfMajorTicks = 10;
508
- let tickArray = [] as Array<number>;
509
-
510
- niceRange = this.calcNiceNumber(maxValue - minValue, false);
511
- majorTickSpacing = this.calcNiceNumber(niceRange / (maxNoOfMajorTicks - 1), true);
512
- niceMinValue = Math.floor(minValue / majorTickSpacing) * majorTickSpacing;
513
- niceMaxValue = Math.ceil(maxValue / majorTickSpacing) * majorTickSpacing;
514
-
515
- tickArray.push(niceMinValue);
516
-
517
- for (let index = 0; index < (niceRange / majorTickSpacing); index++) {
518
- if (tickArray[index] < niceMaxValue) {
519
- tickArray.push(tickArray[index] + majorTickSpacing);
520
- }
521
- }
522
- return tickArray;
523
- }
524
-
525
- calcNiceNumber(range: number, round: boolean): number {
526
- let exponent = Math.floor(Math.log10(range)), // exponent of range
527
- fraction = range / Math.pow(10, exponent), // fractional part of range
528
- niceFraction: number; // nice, rounded fraction
529
-
530
- if (round) {
531
- if (1.5 > fraction) {
532
- niceFraction = 1;
533
- } else if (3 > fraction) {
534
- niceFraction = 2;
535
- } else if (7 > fraction) {
536
- niceFraction = 5;
537
- } else {
538
- niceFraction = 10;
539
- }
540
- } else {
541
- if (1 >= fraction) {
542
- niceFraction = 1;
543
- } else if (2 >= fraction) {
544
- niceFraction = 2;
545
- } else if (5 >= fraction) {
546
- niceFraction = 5;
547
- } else {
548
- niceFraction = 10;
549
- }
550
- }
551
- return niceFraction * Math.pow(10, exponent);
552
- }
553
- }
1
+ import { ViewChild, ElementRef, Component, Input, OnInit, OnDestroy, AfterContentInit, AfterContentChecked } from '@angular/core';
2
+ import { Subscription } from 'rxjs';
3
+ import { MatDialog } from '@angular/material/dialog';
4
+ import { ResizedEvent } from 'angular-resize-event';
5
+
6
+ import { SignalKService } from '../signalk.service';
7
+ import { ModalWidgetComponent } from '../modal-widget/modal-widget.component';
8
+ import { WidgetManagerService, IWidget, IWidgetConfig } from '../widget-manager.service';
9
+ import { UnitsService } from '../units.service';
10
+ import { AppSettingsService, IZone, ZoneState } from '../app-settings.service';
11
+ import { RadialGauge, RadialGaugeOptions } from '../gauges-module/radial-gauge';
12
+
13
+ const defaultConfig: IWidgetConfig = {
14
+ displayName: null,
15
+ filterSelfPaths: true,
16
+ paths: {
17
+ "gaugePath": {
18
+ description: "Numeric Data",
19
+ path: null,
20
+ source: null,
21
+ pathType: "number",
22
+ isPathConfigurable: true,
23
+ convertUnitTo: "unitless"
24
+ }
25
+ },
26
+ gaugeType: 'ngRadial', //ngLinearVertical or ngLinearHorizontal
27
+ gaugeTicks: false,
28
+ radialSize: 'measuring',
29
+ compassUseNumbers: false,
30
+ minValue: 0,
31
+ maxValue: 100,
32
+ numInt: 1,
33
+ numDecimal: 0,
34
+ barColor: 'accent', // theme palette to select
35
+ };
36
+
37
+ interface IDataHighlight extends Array<{
38
+ from : number;
39
+ to : number;
40
+ color: string;
41
+ }> {};
42
+
43
+ @Component({
44
+ selector: 'app-widget-gauge-ng-radial',
45
+ templateUrl: './widget-gauge-ng-radial.component.html',
46
+ styleUrls: ['./widget-gauge-ng-radial.component.scss']
47
+ })
48
+ export class WidgetGaugeNgRadialComponent implements OnInit, OnDestroy, AfterContentInit, AfterContentChecked {
49
+
50
+ @ViewChild('wrapperDiv', {static: true, read: ElementRef}) private wrapper: ElementRef;
51
+ @ViewChild('radialGauge', {static: true, read: RadialGauge}) public radialGauge: RadialGauge;
52
+
53
+ @Input('widgetUUID') widgetUUID: string;
54
+ @Input('unlockStatus') unlockStatus: boolean;
55
+
56
+ // hack to access material-theme palette colors
57
+ @ViewChild('primary', {static: true, read: ElementRef}) private primaryElement: ElementRef;
58
+ @ViewChild('accent', {static: true, read: ElementRef}) private accentElement: ElementRef;
59
+ @ViewChild('warn', {static: true, read: ElementRef}) private warnElement: ElementRef;
60
+ @ViewChild('primaryDark', {static: true, read: ElementRef}) private primaryDarkElement: ElementRef;
61
+ @ViewChild('accentDark', {static: true, read: ElementRef}) private accentDarkElement: ElementRef;
62
+ @ViewChild('warnDark', {static: true, read: ElementRef}) private warnDarkElement: ElementRef;
63
+ @ViewChild('background', {static: true, read: ElementRef}) private backgroundElement: ElementRef;
64
+ @ViewChild('text', {static: true, read: ElementRef}) private textElement: ElementRef;
65
+
66
+ activeWidget: IWidget;
67
+ config: IWidgetConfig;
68
+
69
+ public dataValue = 0;
70
+ valueSub: Subscription = null;
71
+
72
+ // dynamics theme support
73
+ themeNameSub: Subscription = null;
74
+
75
+ public gaugeOptions = {} as RadialGaugeOptions;
76
+ // fix for RadialGauge GaugeOptions object ** missing color-stroke-ticks property
77
+ public colorStrokeTicks: string = "";
78
+ public unitName: string = null;
79
+
80
+ zones: Array<IZone> = [];
81
+ zonesSub: Subscription;
82
+
83
+ constructor(
84
+ public dialog:MatDialog,
85
+ private SignalKService: SignalKService,
86
+ private WidgetManagerService: WidgetManagerService,
87
+ private UnitsService: UnitsService,
88
+ private AppSettingsService: AppSettingsService, // need for theme change subscription
89
+ ) { }
90
+
91
+ ngOnInit() {
92
+ this.activeWidget = this.WidgetManagerService.getWidget(this.widgetUUID);
93
+ if (this.activeWidget.config === null) {
94
+ // no data, let's set some!
95
+ this.WidgetManagerService.updateWidgetConfig(this.widgetUUID, defaultConfig);
96
+ this.config = defaultConfig; // load default config.
97
+ } else {
98
+ this.config = this.activeWidget.config;
99
+ //new config option, might not be set.
100
+ if (!('compassUseNumbers' in this.config)) {
101
+ console.log("compassUseNumbers not set");
102
+ this.config.compassUseNumbers = false;
103
+ }
104
+ }
105
+ this.subscribePath();
106
+ this.subscribeTheme();
107
+ this.subscribeZones();
108
+ }
109
+
110
+ ngOnDestroy() {
111
+ this.unsubscribePath();
112
+ this.unsubscribeTheme();
113
+ this.unsubscribeZones();
114
+ }
115
+
116
+ ngAfterContentInit() {
117
+ this.updateGaugeConfig();
118
+ }
119
+
120
+ ngAfterContentChecked() {
121
+ // this.resizeWidget();
122
+ }
123
+
124
+ subscribePath() {
125
+ this.unsubscribePath();
126
+ if (typeof(this.config.paths['gaugePath'].path) != 'string') { return } // nothing to sub to...
127
+
128
+ this.valueSub = this.SignalKService.subscribePath(this.widgetUUID, this.config.paths['gaugePath'].path, this.config.paths['gaugePath'].source).subscribe(
129
+ newValue => {
130
+ this.dataValue = this.UnitsService.convertUnit(this.config.paths['gaugePath'].convertUnitTo, newValue.value);
131
+
132
+
133
+ // set colors for zone state
134
+ switch (newValue.state) {
135
+ case ZoneState.warning:
136
+ this.gaugeOptions.colorValueText = getComputedStyle(this.warnDarkElement.nativeElement).color;
137
+ break;
138
+ case ZoneState.alarm:
139
+ this.gaugeOptions.colorValueText = getComputedStyle(this.warnDarkElement.nativeElement).color;
140
+ break;
141
+ default:
142
+ this.gaugeOptions.colorValueText = getComputedStyle(this.textElement.nativeElement).color;
143
+
144
+ }
145
+
146
+ }
147
+ );
148
+ }
149
+
150
+ unsubscribePath() {
151
+ if (this.valueSub !== null) {
152
+ this.valueSub.unsubscribe();
153
+ this.valueSub = null;
154
+ this.SignalKService.unsubscribePath(this.widgetUUID, this.config.paths['gaugePath'].path)
155
+ }
156
+ }
157
+
158
+ // Subscribe to theme event
159
+ subscribeTheme() {
160
+ this.themeNameSub = this.AppSettingsService.getThemeNameAsO().subscribe(
161
+ themeChange => {
162
+ setTimeout(() => { // need a delay so browser getComputedStyles has time to complete theme application.
163
+ this.updateGaugeConfig();
164
+ }, 50);
165
+ })
166
+ }
167
+
168
+ unsubscribeTheme(){
169
+ if (this.themeNameSub !== null) {
170
+ this.themeNameSub.unsubscribe();
171
+ this.themeNameSub = null;
172
+ }
173
+ }
174
+
175
+ // Subscribe to Zones
176
+ subscribeZones() {
177
+ this.zonesSub = this.AppSettingsService.getZonesAsO().subscribe(
178
+ zones => {
179
+ this.zones = zones;
180
+ this.updateGaugeConfig();
181
+ });
182
+ }
183
+
184
+ unsubscribeZones(){
185
+ if (this.zonesSub !== null) {
186
+ this.zonesSub.unsubscribe();
187
+ this.zonesSub = null;
188
+ }
189
+ }
190
+
191
+ openWidgetSettings() {
192
+ let dialogRef = this.dialog.open(ModalWidgetComponent, {
193
+ width: '80%',
194
+ data: this.config
195
+ });
196
+
197
+ dialogRef.afterClosed().subscribe(result => {
198
+ // save new settings
199
+ if (result) {
200
+ console.log(result);
201
+ this.unsubscribePath(); //unsub now as we will change variables so wont know what was subbed before...
202
+ this.config = result;
203
+ this.WidgetManagerService.updateWidgetConfig(this.widgetUUID, this.config);
204
+ this.subscribePath();
205
+ this.updateGaugeConfig();
206
+ }
207
+ });
208
+ }
209
+
210
+ updateGaugeConfig(){
211
+ //// Hack to get Theme colors using hidden mixin, DIV and @ViewChild
212
+ let themePaletteColor = "";
213
+ let themePaletteDarkColor = "";
214
+
215
+ this.gaugeOptions.colorTitle = this.gaugeOptions.colorUnits = getComputedStyle(this.textElement.nativeElement).color;
216
+
217
+ this.gaugeOptions.colorPlate = getComputedStyle(this.wrapper.nativeElement).backgroundColor;
218
+ this.gaugeOptions.colorBar = getComputedStyle(this.backgroundElement.nativeElement).color;
219
+ this.gaugeOptions.colorNeedleShadowUp = "";
220
+ this.gaugeOptions.colorNeedleShadowDown = "black";
221
+ this.gaugeOptions.colorNeedleCircleInner = this.gaugeOptions.colorPlate;
222
+ this.gaugeOptions.colorNeedleCircleInnerEnd = this.gaugeOptions.colorPlate;
223
+ this.gaugeOptions.colorNeedleCircleOuter = this.gaugeOptions.colorPlate;
224
+ this.gaugeOptions.colorNeedleCircleOuterEnd = this.gaugeOptions.colorPlate;
225
+
226
+ // Theme colors
227
+ switch (this.config.barColor) {
228
+ case "primary":
229
+ themePaletteColor = getComputedStyle(this.primaryElement.nativeElement).color;
230
+ themePaletteDarkColor = getComputedStyle(this.primaryDarkElement.nativeElement).color;
231
+ this.gaugeOptions.colorBarProgress = themePaletteColor;
232
+ this.gaugeOptions.colorNeedle = themePaletteDarkColor;
233
+ this.gaugeOptions.colorNeedleEnd = themePaletteDarkColor;
234
+ break;
235
+
236
+ case "accent":
237
+ themePaletteColor = getComputedStyle(this.accentElement.nativeElement).color;
238
+ themePaletteDarkColor = getComputedStyle(this.accentDarkElement.nativeElement).color;
239
+ this.gaugeOptions.colorBarProgress = themePaletteColor;
240
+ this.gaugeOptions.colorNeedle = themePaletteDarkColor;
241
+ this.gaugeOptions.colorNeedleEnd = themePaletteDarkColor;
242
+ break;
243
+
244
+ case "warn":
245
+ themePaletteColor = getComputedStyle(this.warnElement.nativeElement).color;
246
+ themePaletteDarkColor = getComputedStyle(this.warnDarkElement.nativeElement).color;
247
+ this.gaugeOptions.colorBarProgress = themePaletteColor;
248
+ this.gaugeOptions.colorNeedle = themePaletteDarkColor;
249
+ this.gaugeOptions.colorNeedleEnd = themePaletteDarkColor;
250
+ break;
251
+
252
+ default:
253
+ break;
254
+ }
255
+
256
+ // highlights
257
+ let myZones: IDataHighlight = [];
258
+ this.zones.forEach(zone => {
259
+ // get zones for our path
260
+ if (zone.path == this.config.paths['gaugePath'].path) {
261
+ let lower = zone.lower || this.config.minValue;
262
+ let upper = zone.upper || this.config.maxValue;
263
+ let color: string;
264
+ switch (zone.state) {
265
+ case 1:
266
+ color = getComputedStyle(this.warnElement.nativeElement).color;
267
+ break;
268
+ case ZoneState.alarm:
269
+ color = getComputedStyle(this.warnDarkElement.nativeElement).color;
270
+ break;
271
+ default:
272
+ color = getComputedStyle(this.primaryElement.nativeElement).color;
273
+ }
274
+
275
+ myZones.push({from: lower, to: upper, color: color});
276
+ }
277
+ });
278
+ this.gaugeOptions.highlights = myZones;
279
+
280
+ // Config storage values
281
+ this.gaugeOptions.valueInt = this.config.numInt;
282
+ this.gaugeOptions.valueDec = this.config.numDecimal;
283
+
284
+ this.gaugeOptions.majorTicksInt = this.config.numInt;
285
+ this.gaugeOptions.majorTicksDec = this.config.numDecimal;
286
+
287
+ // Radial gauge type
288
+ switch(this.config.radialSize) {
289
+ case "capacity":
290
+ this.unitName = this.config.paths['gaugePath'].convertUnitTo;
291
+ this.gaugeOptions.colorMajorTicks = this.gaugeOptions.colorPlate; // bug with MajorTicks drawing firs tick always and using color="" does not work
292
+ this.gaugeOptions.colorNumbers = this.gaugeOptions.colorMinorTicks = "";
293
+ this.gaugeOptions.fontTitleSize = 60;
294
+ this.gaugeOptions.minValue = this.config.minValue;
295
+ this.gaugeOptions.maxValue = this.config.maxValue;
296
+ this.gaugeOptions.barProgress = true;
297
+ this.gaugeOptions.barWidth = 15;
298
+
299
+ this.gaugeOptions.valueBox = true;
300
+ this.gaugeOptions.fontValueSize = 110;
301
+ this.gaugeOptions.valueBoxWidth = 100;
302
+ this.gaugeOptions.valueBoxBorderRadius = 0;
303
+ this.gaugeOptions.valueBoxStroke = 0;
304
+ this.gaugeOptions.colorValueBoxBackground = "";
305
+
306
+ this.gaugeOptions.ticksAngle = 360;
307
+ this.gaugeOptions.startAngle = 180;
308
+ this.gaugeOptions.exactTicks = false;
309
+ this.gaugeOptions.strokeTicks = false;
310
+ this.gaugeOptions.majorTicks = [];
311
+ this.gaugeOptions.minorTicks = 0;
312
+ this.gaugeOptions.numbersMargin = 0;
313
+ this.gaugeOptions.fontNumbersSize = 0;
314
+ this.gaugeOptions.highlightsWidth = 15;
315
+
316
+ this.gaugeOptions.needle = true;
317
+ this.gaugeOptions.needleType = "line";
318
+ this.gaugeOptions.needleWidth = 2;
319
+ this.gaugeOptions.needleShadow = false;
320
+ this.gaugeOptions.needleStart = 80;
321
+ this.gaugeOptions.needleEnd = 95;
322
+ this.gaugeOptions.needleCircleSize = 1;
323
+ this.gaugeOptions.needleCircleInner = false;
324
+ this.gaugeOptions.needleCircleOuter = false;
325
+
326
+ this.gaugeOptions.borders = true;
327
+ this.gaugeOptions.borderOuterWidth = 0;
328
+ this.gaugeOptions.borderMiddleWidth = 2;
329
+ this.gaugeOptions.borderInnerWidth = 2;
330
+ this.gaugeOptions.borderShadowWidth = 0;
331
+
332
+ this.gaugeOptions.animationTarget = "needle";
333
+ this.gaugeOptions.useMinPath = false;
334
+ break;
335
+
336
+ case "measuring":
337
+ this.unitName = this.config.paths['gaugePath'].convertUnitTo;
338
+ let calculatedMajorTicks = this.calculateMajorTicks(this.config.minValue, this.config.maxValue);
339
+
340
+ this.gaugeOptions.colorTitle = this.colorStrokeTicks = this.gaugeOptions.colorMinorTicks = this.gaugeOptions.colorNumbers = this.gaugeOptions.colorTitle;
341
+
342
+ this.gaugeOptions.fontTitleSize = 20;
343
+ this.gaugeOptions.minValue = this.config.minValue;
344
+ this.gaugeOptions.maxValue = this.config.maxValue;
345
+ this.gaugeOptions.barProgress = true;
346
+ this.gaugeOptions.barWidth = 15;
347
+
348
+ this.gaugeOptions.valueBox = true;
349
+ this.gaugeOptions.fontValueSize = 60;
350
+ this.gaugeOptions.valueBoxWidth = 100;
351
+ this.gaugeOptions.valueBoxBorderRadius = 0;
352
+ this.gaugeOptions.valueBoxStroke = 0;
353
+ this.gaugeOptions.colorValueBoxBackground = "";
354
+
355
+ this.gaugeOptions.ticksAngle = 270;
356
+ this.gaugeOptions.startAngle = 45;
357
+ this.gaugeOptions.exactTicks = false;
358
+ this.gaugeOptions.strokeTicks = true;
359
+ this.gaugeOptions.majorTicks = [calculatedMajorTicks.toString()];
360
+ this.gaugeOptions.minorTicks = 2;
361
+ this.gaugeOptions.numbersMargin = 3;
362
+ this.gaugeOptions.fontNumbersSize = 15;
363
+ this.gaugeOptions.highlightsWidth = 15;
364
+
365
+ this.gaugeOptions.needle = true;
366
+ this.gaugeOptions.needleType = "line";
367
+ this.gaugeOptions.needleWidth = 2;
368
+ this.gaugeOptions.needleShadow = false;
369
+ this.gaugeOptions.needleStart = 0;
370
+ this.gaugeOptions.needleEnd = 95;
371
+ this.gaugeOptions.needleCircleSize = 10;
372
+ this.gaugeOptions.needleCircleInner = false;
373
+ this.gaugeOptions.needleCircleOuter = false;
374
+
375
+ this.gaugeOptions.borders = false;
376
+ this.gaugeOptions.borderOuterWidth = 0;
377
+ this.gaugeOptions.borderMiddleWidth = 0;
378
+ this.gaugeOptions.borderInnerWidth = 0;
379
+ this.gaugeOptions.borderShadowWidth = 0;
380
+
381
+ this.gaugeOptions.animationTarget = "needle";
382
+ this.gaugeOptions.useMinPath = false;
383
+ break;
384
+
385
+ case "marineCompass":
386
+ // overwrite min/max/unit to make sure we don't limit
387
+ this.config.minValue = 0;
388
+ this.config.maxValue = 360;
389
+ this.config.paths["gaugePath"].convertUnitTo = "deg";
390
+ this.unitName = null;
391
+
392
+
393
+ this.gaugeOptions.colorMajorTicks = this.gaugeOptions.colorNumbers = this.gaugeOptions.colorMinorTicks = this.gaugeOptions.colorUnits;
394
+ this.gaugeOptions.fontTitleSize = 60;
395
+ this.gaugeOptions.minValue = 0;
396
+ this.gaugeOptions.maxValue = 360;
397
+ this.gaugeOptions.barProgress = false;
398
+ this.gaugeOptions.barWidth = 0;
399
+
400
+ this.gaugeOptions.valueBox = true
401
+ this.gaugeOptions.fontValueSize = 50;
402
+ this.gaugeOptions.valueBoxWidth = 0;
403
+ this.gaugeOptions.valueBoxBorderRadius = 5;
404
+ this.gaugeOptions.valueBoxStroke = 0;
405
+ this.gaugeOptions.colorValueBoxBackground = this.gaugeOptions.colorBar;
406
+
407
+ this.gaugeOptions.ticksAngle = 360;
408
+ this.gaugeOptions.startAngle = 180;
409
+ this.gaugeOptions.exactTicks = false;
410
+ this.gaugeOptions.strokeTicks = false;
411
+
412
+ this.gaugeOptions.majorTicks = this.config.compassUseNumbers ? ["0,45,90,135,180,225,270,315,0"] : ["N,NE,E,SE,S,SW,W,NW,N"];
413
+ this.gaugeOptions.numbersMargin = 3;
414
+ this.gaugeOptions.fontNumbersSize = 15;
415
+ this.gaugeOptions.minorTicks = 22;
416
+ this.gaugeOptions.highlights = [];
417
+ this.gaugeOptions.highlightsWidth = 0;
418
+
419
+ this.gaugeOptions.needle = true;
420
+ this.gaugeOptions.needleType = "line";
421
+ this.gaugeOptions.needleWidth = 3;
422
+ this.gaugeOptions.needleShadow = false;
423
+ this.gaugeOptions.needleStart = 75;
424
+ this.gaugeOptions.needleEnd = 99;
425
+ this.gaugeOptions.needleCircleSize = 2;
426
+ this.gaugeOptions.needleCircleInner = false;
427
+ this.gaugeOptions.needleCircleOuter = false;
428
+
429
+ this.gaugeOptions.borders = true;
430
+ this.gaugeOptions.borderOuterWidth = 0;
431
+ this.gaugeOptions.borderMiddleWidth = 2;
432
+ this.gaugeOptions.borderInnerWidth = 2;
433
+ this.gaugeOptions.borderShadowWidth = 0;
434
+
435
+ this.gaugeOptions.animationTarget = "plate";
436
+ this.gaugeOptions.useMinPath = true;
437
+ break;
438
+
439
+ case "baseplateCompass":
440
+ // overwrite min/max/unit to make sure we don't limit
441
+ this.config.minValue = 0;
442
+ this.config.maxValue = 360;
443
+ this.config.paths["gaugePath"].convertUnitTo = "deg";
444
+ this.unitName = null;
445
+
446
+ this.gaugeOptions.colorMajorTicks = this.gaugeOptions.colorNumbers = this.gaugeOptions.colorMinorTicks = this.gaugeOptions.colorUnits;
447
+ this.gaugeOptions.fontTitleSize = 60;
448
+ this.gaugeOptions.minValue = 0;
449
+ this.gaugeOptions.maxValue = 360;
450
+ this.gaugeOptions.barProgress = false;
451
+ this.gaugeOptions.barWidth = 0;
452
+
453
+ this.gaugeOptions.valueBox = true
454
+ this.gaugeOptions.fontValueSize = 50;
455
+ this.gaugeOptions.valueBoxWidth = 0;
456
+ this.gaugeOptions.valueBoxBorderRadius = 5;
457
+ this.gaugeOptions.valueBoxStroke = 0;
458
+ this.gaugeOptions.colorValueBoxBackground = this.gaugeOptions.colorBar;
459
+
460
+ this.gaugeOptions.ticksAngle = 360;
461
+ this.gaugeOptions.startAngle = 180;
462
+ this.gaugeOptions.exactTicks = false;
463
+ this.gaugeOptions.strokeTicks = false;
464
+ this.gaugeOptions.majorTicks = this.config.compassUseNumbers ? ["0,45,90,135,180,225,270,315,0"] : ["N,NE,E,SE,S,SW,W,NW,N"];
465
+ this.gaugeOptions.numbersMargin = 3;
466
+ this.gaugeOptions.fontNumbersSize = 15;
467
+ this.gaugeOptions.minorTicks = 22;
468
+ this.gaugeOptions.highlights = [];
469
+ this.gaugeOptions.highlightsWidth = 0;
470
+
471
+ this.gaugeOptions.needle = true;
472
+ this.gaugeOptions.needleType = "line";
473
+ this.gaugeOptions.needleWidth = 3;
474
+ this.gaugeOptions.needleShadow = false;
475
+ this.gaugeOptions.needleStart = 75;
476
+ this.gaugeOptions.needleEnd = 99;
477
+ this.gaugeOptions.needleCircleSize = 2;
478
+ this.gaugeOptions.needleCircleInner = false;
479
+ this.gaugeOptions.needleCircleOuter = false;
480
+
481
+ this.gaugeOptions.borders = true;
482
+ this.gaugeOptions.borderOuterWidth = 0;
483
+ this.gaugeOptions.borderMiddleWidth = 2;
484
+ this.gaugeOptions.borderInnerWidth = 2;
485
+ this.gaugeOptions.borderShadowWidth = 0;
486
+
487
+ this.gaugeOptions.animationTarget = "needle";
488
+ this.gaugeOptions.useMinPath = true;
489
+ break;
490
+
491
+ default:
492
+ break;
493
+ }
494
+ }
495
+
496
+ onResized(event: ResizedEvent) {
497
+ this.gaugeOptions.height = Math.floor(event.newRect.height * 0.88);
498
+ this.gaugeOptions.width = Math.floor(event.newRect.width * 0.88);
499
+ }
500
+
501
+ // Method to calculate nice values for min, max and range for the gaugeOptions.majorTicks
502
+ calculateMajorTicks(minValue: number, maxValue: number): string[]|number[] {
503
+ let niceMinValue = minValue;
504
+ let niceMaxValue = maxValue;
505
+ let niceRange = maxValue - minValue;
506
+ let majorTickSpacing = 0;
507
+ let maxNoOfMajorTicks = 10;
508
+ let tickArray = [] as Array<number>;
509
+
510
+ niceRange = this.calcNiceNumber(maxValue - minValue, false);
511
+ majorTickSpacing = this.calcNiceNumber(niceRange / (maxNoOfMajorTicks - 1), true);
512
+ niceMinValue = Math.floor(minValue / majorTickSpacing) * majorTickSpacing;
513
+ niceMaxValue = Math.ceil(maxValue / majorTickSpacing) * majorTickSpacing;
514
+
515
+ tickArray.push(niceMinValue);
516
+
517
+ for (let index = 0; index < (niceRange / majorTickSpacing); index++) {
518
+ if (tickArray[index] < niceMaxValue) {
519
+ tickArray.push(tickArray[index] + majorTickSpacing);
520
+ }
521
+ }
522
+ return tickArray;
523
+ }
524
+
525
+ calcNiceNumber(range: number, round: boolean): number {
526
+ let exponent = Math.floor(Math.log10(range)), // exponent of range
527
+ fraction = range / Math.pow(10, exponent), // fractional part of range
528
+ niceFraction: number; // nice, rounded fraction
529
+
530
+ if (round) {
531
+ if (1.5 > fraction) {
532
+ niceFraction = 1;
533
+ } else if (3 > fraction) {
534
+ niceFraction = 2;
535
+ } else if (7 > fraction) {
536
+ niceFraction = 5;
537
+ } else {
538
+ niceFraction = 10;
539
+ }
540
+ } else {
541
+ if (1 >= fraction) {
542
+ niceFraction = 1;
543
+ } else if (2 >= fraction) {
544
+ niceFraction = 2;
545
+ } else if (5 >= fraction) {
546
+ niceFraction = 5;
547
+ } else {
548
+ niceFraction = 10;
549
+ }
550
+ }
551
+ return niceFraction * Math.pow(10, exponent);
552
+ }
553
+ }