@mwater/visualization 5.0.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 (860) hide show
  1. package/.prettierrc +11 -0
  2. package/.storybook/config.js +7 -0
  3. package/.storybook/head.html +4 -0
  4. package/.storybook/webpack.config.js +15 -0
  5. package/.vscode/launch.json +40 -0
  6. package/LICENSE +21 -0
  7. package/README.md +19 -0
  8. package/build-demo.ts +54 -0
  9. package/lib/CheckboxComponent.d.ts +15 -0
  10. package/lib/CheckboxComponent.js +25 -0
  11. package/lib/ColorComponent.d.ts +24 -0
  12. package/lib/ColorComponent.js +77 -0
  13. package/lib/ColorSchemeFactory.d.ts +8 -0
  14. package/lib/ColorSchemeFactory.js +164 -0
  15. package/lib/CsvBuilder.d.ts +5 -0
  16. package/lib/CsvBuilder.js +63 -0
  17. package/lib/DateRangeComponent.d.ts +81 -0
  18. package/lib/DateRangeComponent.js +190 -0
  19. package/lib/FiltersDesignerComponent.d.ts +25 -0
  20. package/lib/FiltersDesignerComponent.js +38 -0
  21. package/lib/ImplicitFilterBuilder.d.ts +8 -0
  22. package/lib/ImplicitFilterBuilder.js +114 -0
  23. package/lib/JsonQLFilter.d.ts +7 -0
  24. package/lib/JsonQLFilter.js +2 -0
  25. package/lib/LocaleContextInjector.d.ts +14 -0
  26. package/lib/LocaleContextInjector.js +20 -0
  27. package/lib/MWaterAddRelatedFormComponent.d.ts +25 -0
  28. package/lib/MWaterAddRelatedFormComponent.js +155 -0
  29. package/lib/MWaterAddRelatedIndicatorComponent.d.ts +31 -0
  30. package/lib/MWaterAddRelatedIndicatorComponent.js +129 -0
  31. package/lib/MWaterAssetSystemsListComponent.d.ts +17 -0
  32. package/lib/MWaterAssetSystemsListComponent.js +78 -0
  33. package/lib/MWaterCompleteTableSelectComponent.d.ts +224 -0
  34. package/lib/MWaterCompleteTableSelectComponent.js +680 -0
  35. package/lib/MWaterContextComponent.d.ts +31 -0
  36. package/lib/MWaterContextComponent.js +111 -0
  37. package/lib/MWaterCustomTablesetListComponent.d.ts +17 -0
  38. package/lib/MWaterCustomTablesetListComponent.js +87 -0
  39. package/lib/MWaterGlobalFiltersComponent.d.ts +16 -0
  40. package/lib/MWaterGlobalFiltersComponent.js +103 -0
  41. package/lib/MWaterLoaderComponent.d.ts +42 -0
  42. package/lib/MWaterLoaderComponent.js +77 -0
  43. package/lib/MWaterMetricsTableListComponent.d.ts +17 -0
  44. package/lib/MWaterMetricsTableListComponent.js +79 -0
  45. package/lib/MWaterResponsesFilterComponent.d.ts +42 -0
  46. package/lib/MWaterResponsesFilterComponent.js +145 -0
  47. package/lib/MWaterTableSelectComponent.d.ts +36 -0
  48. package/lib/MWaterTableSelectComponent.js +206 -0
  49. package/lib/MenuItemComponent.d.ts +0 -0
  50. package/lib/MenuItemComponent.js +3 -0
  51. package/lib/PopoverComponent.d.ts +15 -0
  52. package/lib/PopoverComponent.js +49 -0
  53. package/lib/RadioButtonComponent.d.ts +16 -0
  54. package/lib/RadioButtonComponent.js +25 -0
  55. package/lib/TableSelectComponent.d.ts +21 -0
  56. package/lib/TableSelectComponent.js +68 -0
  57. package/lib/UIComponents.d.ts +85 -0
  58. package/lib/UIComponents.js +195 -0
  59. package/lib/UndoStack.d.ts +11 -0
  60. package/lib/UndoStack.js +51 -0
  61. package/lib/VerticalLayoutComponent.d.ts +21 -0
  62. package/lib/VerticalLayoutComponent.js +76 -0
  63. package/lib/WidgetScope.d.ts +13 -0
  64. package/lib/WidgetScope.js +2 -0
  65. package/lib/axes/Axis.d.ts +81 -0
  66. package/lib/axes/Axis.js +2 -0
  67. package/lib/axes/AxisBuilder.d.ts +66 -0
  68. package/lib/axes/AxisBuilder.js +1202 -0
  69. package/lib/axes/AxisColorEditorComponent.d.ts +39 -0
  70. package/lib/axes/AxisColorEditorComponent.js +133 -0
  71. package/lib/axes/AxisComponent.d.ts +65 -0
  72. package/lib/axes/AxisComponent.js +359 -0
  73. package/lib/axes/BinsComponent.d.ts +21 -0
  74. package/lib/axes/BinsComponent.js +96 -0
  75. package/lib/axes/CategoryMapComponent.d.ts +41 -0
  76. package/lib/axes/CategoryMapComponent.js +175 -0
  77. package/lib/axes/ColorPaletteCollectionComponent.d.ts +17 -0
  78. package/lib/axes/ColorPaletteCollectionComponent.js +130 -0
  79. package/lib/axes/RangesComponent.d.ts +35 -0
  80. package/lib/axes/RangesComponent.js +119 -0
  81. package/lib/componenttest.d.ts +1 -0
  82. package/lib/componenttest.js +47 -0
  83. package/lib/compressJson.d.ts +4 -0
  84. package/lib/compressJson.js +19 -0
  85. package/lib/dashboards/DashboardComponent.d.ts +115 -0
  86. package/lib/dashboards/DashboardComponent.js +297 -0
  87. package/lib/dashboards/DashboardDataSource.d.ts +9 -0
  88. package/lib/dashboards/DashboardDataSource.js +14 -0
  89. package/lib/dashboards/DashboardDesign.d.ts +45 -0
  90. package/lib/dashboards/DashboardDesign.js +2 -0
  91. package/lib/dashboards/DashboardUpgrader.d.ts +4 -0
  92. package/lib/dashboards/DashboardUpgrader.js +95 -0
  93. package/lib/dashboards/DashboardUtils.d.ts +7 -0
  94. package/lib/dashboards/DashboardUtils.js +69 -0
  95. package/lib/dashboards/DashboardViewComponent.d.ts +71 -0
  96. package/lib/dashboards/DashboardViewComponent.js +235 -0
  97. package/lib/dashboards/DirectDashboardDataSource.d.ts +31 -0
  98. package/lib/dashboards/DirectDashboardDataSource.js +62 -0
  99. package/lib/dashboards/LayoutOptionsComponent.d.ts +11 -0
  100. package/lib/dashboards/LayoutOptionsComponent.js +119 -0
  101. package/lib/dashboards/README.md +13 -0
  102. package/lib/dashboards/ServerDashboardDataSource.d.ts +96 -0
  103. package/lib/dashboards/ServerDashboardDataSource.js +383 -0
  104. package/lib/dashboards/SettingsModalComponent.d.ts +33 -0
  105. package/lib/dashboards/SettingsModalComponent.js +122 -0
  106. package/lib/dashboards/WidgetComponent.d.ts +53 -0
  107. package/lib/dashboards/WidgetComponent.js +66 -0
  108. package/lib/dashboards/layoutOptions.d.ts +19 -0
  109. package/lib/dashboards/layoutOptions.js +19 -0
  110. package/lib/datagrids/DatagridComponent.d.ts +122 -0
  111. package/lib/datagrids/DatagridComponent.js +285 -0
  112. package/lib/datagrids/DatagridDataSource.d.ts +9 -0
  113. package/lib/datagrids/DatagridDataSource.js +13 -0
  114. package/lib/datagrids/DatagridDesign.d.ts +75 -0
  115. package/lib/datagrids/DatagridDesign.js +2 -0
  116. package/lib/datagrids/DatagridDesignerComponent.d.ts +114 -0
  117. package/lib/datagrids/DatagridDesignerComponent.js +389 -0
  118. package/lib/datagrids/DatagridQueryBuilder.d.ts +68 -0
  119. package/lib/datagrids/DatagridQueryBuilder.js +540 -0
  120. package/lib/datagrids/DatagridUtils.d.ts +8 -0
  121. package/lib/datagrids/DatagridUtils.js +91 -0
  122. package/lib/datagrids/DatagridViewComponent.d.ts +86 -0
  123. package/lib/datagrids/DatagridViewComponent.js +321 -0
  124. package/lib/datagrids/DirectDatagridDataSource.d.ts +20 -0
  125. package/lib/datagrids/DirectDatagridDataSource.js +62 -0
  126. package/lib/datagrids/EditExprCellComponent.d.ts +77 -0
  127. package/lib/datagrids/EditExprCellComponent.js +212 -0
  128. package/lib/datagrids/ExprCellComponent.d.ts +34 -0
  129. package/lib/datagrids/ExprCellComponent.js +81 -0
  130. package/lib/datagrids/FindReplaceModalComponent.d.ts +52 -0
  131. package/lib/datagrids/FindReplaceModalComponent.js +248 -0
  132. package/lib/datagrids/LabeledExprGenerator.d.ts +40 -0
  133. package/lib/datagrids/LabeledExprGenerator.js +252 -0
  134. package/lib/datagrids/OrderBysDesignerComponent.d.ts +22 -0
  135. package/lib/datagrids/OrderBysDesignerComponent.js +67 -0
  136. package/lib/datagrids/README.md +3 -0
  137. package/lib/datagrids/ServerDatagridDataSource.d.ts +40 -0
  138. package/lib/datagrids/ServerDatagridDataSource.js +79 -0
  139. package/lib/demo.d.ts +1 -0
  140. package/lib/demo.js +4006 -0
  141. package/lib/demoBlocks.d.ts +1 -0
  142. package/lib/demoBlocks.js +112 -0
  143. package/lib/index.css +550 -0
  144. package/lib/index.d.ts +69 -0
  145. package/lib/index.js +156 -0
  146. package/lib/injectTableAlias.d.ts +2 -0
  147. package/lib/injectTableAlias.js +30 -0
  148. package/lib/languages.d.ts +9 -0
  149. package/lib/languages.js +926 -0
  150. package/lib/layout-styles.css +263 -0
  151. package/lib/layouts/DecoratedBlockComponent.d.ts +44 -0
  152. package/lib/layouts/DecoratedBlockComponent.js +96 -0
  153. package/lib/layouts/DragSourceComponent.d.ts +2 -0
  154. package/lib/layouts/DragSourceComponent.js +26 -0
  155. package/lib/layouts/LayoutManager.d.ts +50 -0
  156. package/lib/layouts/LayoutManager.js +41 -0
  157. package/lib/layouts/blocks/BlocksDisplayComponent.d.ts +75 -0
  158. package/lib/layouts/blocks/BlocksDisplayComponent.js +336 -0
  159. package/lib/layouts/blocks/BlocksLayoutManager.d.ts +36 -0
  160. package/lib/layouts/blocks/BlocksLayoutManager.js +74 -0
  161. package/lib/layouts/blocks/ClipboardPaletteItemComponent.d.ts +9 -0
  162. package/lib/layouts/blocks/ClipboardPaletteItemComponent.js +59 -0
  163. package/lib/layouts/blocks/DraggableBlockComponent.d.ts +2 -0
  164. package/lib/layouts/blocks/DraggableBlockComponent.js +163 -0
  165. package/lib/layouts/blocks/HorizontalBlockComponent.d.ts +31 -0
  166. package/lib/layouts/blocks/HorizontalBlockComponent.js +191 -0
  167. package/lib/layouts/blocks/PaletteItemComponent.d.ts +14 -0
  168. package/lib/layouts/blocks/PaletteItemComponent.js +15 -0
  169. package/lib/layouts/blocks/README.md +11 -0
  170. package/lib/layouts/blocks/blockUtils.d.ts +22 -0
  171. package/lib/layouts/blocks/blockUtils.js +155 -0
  172. package/lib/layouts/decorated-block.css +100 -0
  173. package/lib/layouts/grid/GridLayoutComponent.d.ts +23 -0
  174. package/lib/layouts/grid/GridLayoutComponent.js +49 -0
  175. package/lib/layouts/grid/GridLayoutManager.d.ts +29 -0
  176. package/lib/layouts/grid/GridLayoutManager.js +141 -0
  177. package/lib/layouts/grid/LegoLayoutEngine.d.ts +33 -0
  178. package/lib/layouts/grid/LegoLayoutEngine.js +129 -0
  179. package/lib/layouts/grid/PaletteItemComponent.d.ts +14 -0
  180. package/lib/layouts/grid/PaletteItemComponent.js +15 -0
  181. package/lib/layouts/grid/README.md +14 -0
  182. package/lib/layouts/grid/WidgetContainerComponent.d.ts +9 -0
  183. package/lib/layouts/grid/WidgetContainerComponent.js +333 -0
  184. package/lib/mWaterLoader.d.ts +26 -0
  185. package/lib/mWaterLoader.js +55 -0
  186. package/lib/mapdemo.d.ts +0 -0
  187. package/lib/mapdemo.js +115 -0
  188. package/lib/maps/AddLayerComponent.d.ts +22 -0
  189. package/lib/maps/AddLayerComponent.js +85 -0
  190. package/lib/maps/AdminScopeAndDetailLevelComponent.d.ts +19 -0
  191. package/lib/maps/AdminScopeAndDetailLevelComponent.js +59 -0
  192. package/lib/maps/BaseLayerDesignerComponent.d.ts +28 -0
  193. package/lib/maps/BaseLayerDesignerComponent.js +57 -0
  194. package/lib/maps/BingLayer.d.ts +1 -0
  195. package/lib/maps/BingLayer.js +151 -0
  196. package/lib/maps/BufferLayer.d.ts +51 -0
  197. package/lib/maps/BufferLayer.js +816 -0
  198. package/lib/maps/BufferLayerDesign.d.ts +37 -0
  199. package/lib/maps/BufferLayerDesign.js +2 -0
  200. package/lib/maps/BufferLayerDesignerComponent.d.ts +49 -0
  201. package/lib/maps/BufferLayerDesignerComponent.js +217 -0
  202. package/lib/maps/ChoroplethLayer.d.ts +74 -0
  203. package/lib/maps/ChoroplethLayer.js +1515 -0
  204. package/lib/maps/ChoroplethLayerDesign.d.ts +56 -0
  205. package/lib/maps/ChoroplethLayerDesign.js +2 -0
  206. package/lib/maps/ChoroplethLayerDesigner.d.ts +53 -0
  207. package/lib/maps/ChoroplethLayerDesigner.js +382 -0
  208. package/lib/maps/ClusterLayer.d.ts +38 -0
  209. package/lib/maps/ClusterLayer.js +746 -0
  210. package/lib/maps/ClusterLayerDesign.d.ts +22 -0
  211. package/lib/maps/ClusterLayerDesign.js +2 -0
  212. package/lib/maps/ClusterLayerDesignerComponent.d.ts +37 -0
  213. package/lib/maps/ClusterLayerDesignerComponent.js +110 -0
  214. package/lib/maps/DetailLevelSelectComponent.d.ts +122 -0
  215. package/lib/maps/DetailLevelSelectComponent.js +91 -0
  216. package/lib/maps/DirectMapDataSource.d.ts +68 -0
  217. package/lib/maps/DirectMapDataSource.js +265 -0
  218. package/lib/maps/EditHoverOver.d.ts +18 -0
  219. package/lib/maps/EditHoverOver.js +88 -0
  220. package/lib/maps/EditPopupComponent.d.ts +26 -0
  221. package/lib/maps/EditPopupComponent.js +75 -0
  222. package/lib/maps/Grid Functions.sql +167 -0
  223. package/lib/maps/GridLayer.d.ts +48 -0
  224. package/lib/maps/GridLayer.js +684 -0
  225. package/lib/maps/GridLayerDesign.d.ts +35 -0
  226. package/lib/maps/GridLayerDesign.js +2 -0
  227. package/lib/maps/GridLayerDesigner.d.ts +38 -0
  228. package/lib/maps/GridLayerDesigner.js +229 -0
  229. package/lib/maps/HoverContent.d.ts +13 -0
  230. package/lib/maps/HoverContent.js +92 -0
  231. package/lib/maps/HtmlUrlLegend.d.ts +16 -0
  232. package/lib/maps/HtmlUrlLegend.js +38 -0
  233. package/lib/maps/Layer.d.ts +164 -0
  234. package/lib/maps/Layer.js +193 -0
  235. package/lib/maps/LayerFactory.d.ts +5 -0
  236. package/lib/maps/LayerFactory.js +47 -0
  237. package/lib/maps/LayerLegendComponent.d.ts +23 -0
  238. package/lib/maps/LayerLegendComponent.js +68 -0
  239. package/lib/maps/LayerSwitcherComponent.d.ts +7 -0
  240. package/lib/maps/LayerSwitcherComponent.js +97 -0
  241. package/lib/maps/LeafletLoading.css +24 -0
  242. package/lib/maps/LeafletLoading.d.ts +42 -0
  243. package/lib/maps/LeafletLoading.js +318 -0
  244. package/lib/maps/LeafletMapComponent.d.ts +141 -0
  245. package/lib/maps/LeafletMapComponent.js +438 -0
  246. package/lib/maps/LegendComponent.d.ts +14 -0
  247. package/lib/maps/LegendComponent.js +74 -0
  248. package/lib/maps/LegendGroup.d.ts +24 -0
  249. package/lib/maps/LegendGroup.js +86 -0
  250. package/lib/maps/MWaterServerLayer.d.ts +40 -0
  251. package/lib/maps/MWaterServerLayer.js +101 -0
  252. package/lib/maps/MapBoundsCalculator.d.ts +16 -0
  253. package/lib/maps/MapBoundsCalculator.js +85 -0
  254. package/lib/maps/MapComponent.d.ts +98 -0
  255. package/lib/maps/MapComponent.js +186 -0
  256. package/lib/maps/MapControlComponent.d.ts +17 -0
  257. package/lib/maps/MapControlComponent.js +25 -0
  258. package/lib/maps/MapDataSource.d.ts +18 -0
  259. package/lib/maps/MapDataSource.js +2 -0
  260. package/lib/maps/MapDesign.d.ts +77 -0
  261. package/lib/maps/MapDesign.js +2 -0
  262. package/lib/maps/MapDesignerComponent.d.ts +39 -0
  263. package/lib/maps/MapDesignerComponent.js +215 -0
  264. package/lib/maps/MapFiltersDesignerComponent.d.ts +21 -0
  265. package/lib/maps/MapFiltersDesignerComponent.js +70 -0
  266. package/lib/maps/MapLayerDataSource.d.ts +22 -0
  267. package/lib/maps/MapLayerDataSource.js +2 -0
  268. package/lib/maps/MapLayerViewDesignerComponent.d.ts +87 -0
  269. package/lib/maps/MapLayerViewDesignerComponent.js +151 -0
  270. package/lib/maps/MapLayersDesignerComponent.d.ts +32 -0
  271. package/lib/maps/MapLayersDesignerComponent.js +98 -0
  272. package/lib/maps/MapUtils.d.ts +21 -0
  273. package/lib/maps/MapUtils.js +119 -0
  274. package/lib/maps/MapViewComponent.d.ts +38 -0
  275. package/lib/maps/MapViewComponent.js +20 -0
  276. package/lib/maps/Maptiler-logo.png +0 -0
  277. package/lib/maps/MarkerSymbolSelectComponent.d.ts +10 -0
  278. package/lib/maps/MarkerSymbolSelectComponent.js +28 -0
  279. package/lib/maps/MarkersLayer.d.ts +66 -0
  280. package/lib/maps/MarkersLayer.js +838 -0
  281. package/lib/maps/MarkersLayerDesign.d.ts +44 -0
  282. package/lib/maps/MarkersLayerDesign.js +2 -0
  283. package/lib/maps/MarkersLayerDesignerComponent.d.ts +56 -0
  284. package/lib/maps/MarkersLayerDesignerComponent.js +269 -0
  285. package/lib/maps/PopupFilterJoinsEditComponent.d.ts +30 -0
  286. package/lib/maps/PopupFilterJoinsEditComponent.js +75 -0
  287. package/lib/maps/PopupFilterJoinsUtils.d.ts +15 -0
  288. package/lib/maps/PopupFilterJoinsUtils.js +91 -0
  289. package/lib/maps/RasterMapViewComponent.d.ts +108 -0
  290. package/lib/maps/RasterMapViewComponent.js +283 -0
  291. package/lib/maps/RegionSelectComponent.d.ts +55 -0
  292. package/lib/maps/RegionSelectComponent.js +61 -0
  293. package/lib/maps/ScopeAndDetailLevelComponent.d.ts +21 -0
  294. package/lib/maps/ScopeAndDetailLevelComponent.js +76 -0
  295. package/lib/maps/ServerMapDataSource.d.ts +86 -0
  296. package/lib/maps/ServerMapDataSource.js +273 -0
  297. package/lib/maps/SwitchableTileUrlLayer.d.ts +53 -0
  298. package/lib/maps/SwitchableTileUrlLayer.js +69 -0
  299. package/lib/maps/SwitchableTileUrlLayerDesigner.d.ts +14 -0
  300. package/lib/maps/SwitchableTileUrlLayerDesigner.js +26 -0
  301. package/lib/maps/TileUrlLayer.d.ts +40 -0
  302. package/lib/maps/TileUrlLayer.js +96 -0
  303. package/lib/maps/UtfGridLayer.d.ts +1 -0
  304. package/lib/maps/UtfGridLayer.js +216 -0
  305. package/lib/maps/VectorMapViewComponent.css +21 -0
  306. package/lib/maps/VectorMapViewComponent.d.ts +44 -0
  307. package/lib/maps/VectorMapViewComponent.js +565 -0
  308. package/lib/maps/ZoomLevelsComponent.d.ts +15 -0
  309. package/lib/maps/ZoomLevelsComponent.js +37 -0
  310. package/lib/maps/mapSymbols.d.ts +6 -0
  311. package/lib/maps/mapSymbols.js +167 -0
  312. package/lib/maps/mapboxUtils.d.ts +6 -0
  313. package/lib/maps/mapboxUtils.js +60 -0
  314. package/lib/maps/maps.d.ts +36 -0
  315. package/lib/maps/maps.js +2 -0
  316. package/lib/maps/marker-icon-2x.png +0 -0
  317. package/lib/maps/marker-icon.png +0 -0
  318. package/lib/maps/marker-shadow.png +0 -0
  319. package/lib/maps/symbols/font-awesome/asterisk.png +0 -0
  320. package/lib/maps/symbols/font-awesome/ban.png +0 -0
  321. package/lib/maps/symbols/font-awesome/beer.png +0 -0
  322. package/lib/maps/symbols/font-awesome/bell.png +0 -0
  323. package/lib/maps/symbols/font-awesome/bolt.png +0 -0
  324. package/lib/maps/symbols/font-awesome/building.png +0 -0
  325. package/lib/maps/symbols/font-awesome/bullseye.png +0 -0
  326. package/lib/maps/symbols/font-awesome/bus.png +0 -0
  327. package/lib/maps/symbols/font-awesome/caret-up.png +0 -0
  328. package/lib/maps/symbols/font-awesome/certificate.png +0 -0
  329. package/lib/maps/symbols/font-awesome/check-circle.png +0 -0
  330. package/lib/maps/symbols/font-awesome/check.png +0 -0
  331. package/lib/maps/symbols/font-awesome/chevron-circle-down.png +0 -0
  332. package/lib/maps/symbols/font-awesome/chevron-circle-up.png +0 -0
  333. package/lib/maps/symbols/font-awesome/cloud.png +0 -0
  334. package/lib/maps/symbols/font-awesome/comment.png +0 -0
  335. package/lib/maps/symbols/font-awesome/crosshairs.png +0 -0
  336. package/lib/maps/symbols/font-awesome/dot-circle-o.png +0 -0
  337. package/lib/maps/symbols/font-awesome/exclamation-circle.png +0 -0
  338. package/lib/maps/symbols/font-awesome/exclamation-triangle.png +0 -0
  339. package/lib/maps/symbols/font-awesome/female.png +0 -0
  340. package/lib/maps/symbols/font-awesome/file.png +0 -0
  341. package/lib/maps/symbols/font-awesome/flag.png +0 -0
  342. package/lib/maps/symbols/font-awesome/flask.png +0 -0
  343. package/lib/maps/symbols/font-awesome/h-square.png +0 -0
  344. package/lib/maps/symbols/font-awesome/home.png +0 -0
  345. package/lib/maps/symbols/font-awesome/info-circle.png +0 -0
  346. package/lib/maps/symbols/font-awesome/male.png +0 -0
  347. package/lib/maps/symbols/font-awesome/medkit.png +0 -0
  348. package/lib/maps/symbols/font-awesome/mobile.png +0 -0
  349. package/lib/maps/symbols/font-awesome/plus-circle.png +0 -0
  350. package/lib/maps/symbols/font-awesome/plus-square.png +0 -0
  351. package/lib/maps/symbols/font-awesome/plus.png +0 -0
  352. package/lib/maps/symbols/font-awesome/square.png +0 -0
  353. package/lib/maps/symbols/font-awesome/star.png +0 -0
  354. package/lib/maps/symbols/font-awesome/thumbs-down.png +0 -0
  355. package/lib/maps/symbols/font-awesome/thumbs-up.png +0 -0
  356. package/lib/maps/symbols/font-awesome/ticket.png +0 -0
  357. package/lib/maps/symbols/font-awesome/times-circle.png +0 -0
  358. package/lib/maps/symbols/font-awesome/times.png +0 -0
  359. package/lib/maps/symbols/font-awesome/tint.png +0 -0
  360. package/lib/maps/symbols/font-awesome/tree.png +0 -0
  361. package/lib/maps/symbols/font-awesome/university.png +0 -0
  362. package/lib/maps/symbols/font-awesome/usd.png +0 -0
  363. package/lib/maps/symbols/font-awesome/user.png +0 -0
  364. package/lib/maps/symbols/font-awesome/users.png +0 -0
  365. package/lib/maps/symbols/font-awesome/wheelchair.png +0 -0
  366. package/lib/maps/vectorMaps.d.ts +42 -0
  367. package/lib/maps/vectorMaps.js +331 -0
  368. package/lib/memoizedDebounce.d.ts +6 -0
  369. package/lib/memoizedDebounce.js +21 -0
  370. package/lib/quickfilter/DateExprComponent.d.ts +81 -0
  371. package/lib/quickfilter/DateExprComponent.js +197 -0
  372. package/lib/quickfilter/IdArrayQuickfilterComponent.d.ts +24 -0
  373. package/lib/quickfilter/IdArrayQuickfilterComponent.js +30 -0
  374. package/lib/quickfilter/Quickfilter.d.ts +21 -0
  375. package/lib/quickfilter/Quickfilter.js +2 -0
  376. package/lib/quickfilter/QuickfilterCompiler.d.ts +16 -0
  377. package/lib/quickfilter/QuickfilterCompiler.js +167 -0
  378. package/lib/quickfilter/QuickfilterUtils.d.ts +7 -0
  379. package/lib/quickfilter/QuickfilterUtils.js +106 -0
  380. package/lib/quickfilter/QuickfiltersComponent.d.ts +293 -0
  381. package/lib/quickfilter/QuickfiltersComponent.js +257 -0
  382. package/lib/quickfilter/QuickfiltersDataSource.d.ts +7 -0
  383. package/lib/quickfilter/QuickfiltersDataSource.js +2 -0
  384. package/lib/quickfilter/QuickfiltersDesignComponent.d.ts +46 -0
  385. package/lib/quickfilter/QuickfiltersDesignComponent.js +176 -0
  386. package/lib/quickfilter/README.md +8 -0
  387. package/lib/quickfilter/TextLiteralComponent.d.ts +216 -0
  388. package/lib/quickfilter/TextLiteralComponent.js +128 -0
  389. package/lib/richtext/ExprItemsHtmlConverter.d.ts +39 -0
  390. package/lib/richtext/ExprItemsHtmlConverter.js +118 -0
  391. package/lib/richtext/FontColorPaletteItem.d.ts +23 -0
  392. package/lib/richtext/FontColorPaletteItem.js +84 -0
  393. package/lib/richtext/FontSizePaletteItem.d.ts +29 -0
  394. package/lib/richtext/FontSizePaletteItem.js +70 -0
  395. package/lib/richtext/ItemsHtmlConverter.d.ts +31 -0
  396. package/lib/richtext/ItemsHtmlConverter.js +209 -0
  397. package/lib/richtext/README.md +3 -0
  398. package/lib/richtext/RichTextComponent.d.ts +84 -0
  399. package/lib/richtext/RichTextComponent.js +255 -0
  400. package/lib/valueFormatter.d.ts +16 -0
  401. package/lib/valueFormatter.js +93 -0
  402. package/lib/widgets/DirectWidgetDataSource.d.ts +43 -0
  403. package/lib/widgets/DirectWidgetDataSource.js +39 -0
  404. package/lib/widgets/DropdownWidgetComponent.d.ts +31 -0
  405. package/lib/widgets/DropdownWidgetComponent.js +41 -0
  406. package/lib/widgets/IFrameWidget.d.ts +16 -0
  407. package/lib/widgets/IFrameWidget.js +38 -0
  408. package/lib/widgets/IFrameWidgetComponent.d.ts +33 -0
  409. package/lib/widgets/IFrameWidgetComponent.js +101 -0
  410. package/lib/widgets/ImageUploaderComponent.d.ts +29 -0
  411. package/lib/widgets/ImageUploaderComponent.js +91 -0
  412. package/lib/widgets/ImageWidget.d.ts +49 -0
  413. package/lib/widgets/ImageWidget.js +112 -0
  414. package/lib/widgets/ImageWidgetComponent.d.ts +125 -0
  415. package/lib/widgets/ImageWidgetComponent.js +368 -0
  416. package/lib/widgets/ImagelistCarouselComponent.d.ts +29 -0
  417. package/lib/widgets/ImagelistCarouselComponent.js +64 -0
  418. package/lib/widgets/MapWidget.d.ts +55 -0
  419. package/lib/widgets/MapWidget.js +167 -0
  420. package/lib/widgets/MarkdownWidget.d.ts +53 -0
  421. package/lib/widgets/MarkdownWidget.js +134 -0
  422. package/lib/widgets/TOCWidget.d.ts +39 -0
  423. package/lib/widgets/TOCWidget.js +254 -0
  424. package/lib/widgets/Widget.d.ts +61 -0
  425. package/lib/widgets/Widget.js +33 -0
  426. package/lib/widgets/WidgetDataSource.d.ts +20 -0
  427. package/lib/widgets/WidgetDataSource.js +2 -0
  428. package/lib/widgets/WidgetFactory.d.ts +4 -0
  429. package/lib/widgets/WidgetFactory.js +40 -0
  430. package/lib/widgets/WidgetScoper.d.ts +9 -0
  431. package/lib/widgets/WidgetScoper.js +49 -0
  432. package/lib/widgets/WidgetScopesViewComponent.d.ts +26 -0
  433. package/lib/widgets/WidgetScopesViewComponent.js +36 -0
  434. package/lib/widgets/charts/Chart.d.ts +57 -0
  435. package/lib/widgets/charts/Chart.js +83 -0
  436. package/lib/widgets/charts/ChartViewComponent.d.ts +72 -0
  437. package/lib/widgets/charts/ChartViewComponent.js +120 -0
  438. package/lib/widgets/charts/ChartWidget.d.ts +87 -0
  439. package/lib/widgets/charts/ChartWidget.js +248 -0
  440. package/lib/widgets/charts/calendar/CalendarChart.d.ts +39 -0
  441. package/lib/widgets/charts/calendar/CalendarChart.js +175 -0
  442. package/lib/widgets/charts/calendar/CalendarChartDesignerComponent.d.ts +35 -0
  443. package/lib/widgets/charts/calendar/CalendarChartDesignerComponent.js +142 -0
  444. package/lib/widgets/charts/calendar/CalendarChartViewComponent.d.ts +56 -0
  445. package/lib/widgets/charts/calendar/CalendarChartViewComponent.js +263 -0
  446. package/lib/widgets/charts/imagemosaic/ImageMosaicChart.d.ts +21 -0
  447. package/lib/widgets/charts/imagemosaic/ImageMosaicChart.js +183 -0
  448. package/lib/widgets/charts/imagemosaic/ImageMosaicChartDesignerComponent.d.ts +28 -0
  449. package/lib/widgets/charts/imagemosaic/ImageMosaicChartDesignerComponent.js +105 -0
  450. package/lib/widgets/charts/imagemosaic/ImageMosaicChartViewComponent.d.ts +31 -0
  451. package/lib/widgets/charts/imagemosaic/ImageMosaicChartViewComponent.js +87 -0
  452. package/lib/widgets/charts/imagemosaic/ImagePopupComponent.d.ts +20 -0
  453. package/lib/widgets/charts/imagemosaic/ImagePopupComponent.js +38 -0
  454. package/lib/widgets/charts/layered/LayeredChart.d.ts +28 -0
  455. package/lib/widgets/charts/layered/LayeredChart.js +324 -0
  456. package/lib/widgets/charts/layered/LayeredChartCompiler.d.ts +113 -0
  457. package/lib/widgets/charts/layered/LayeredChartCompiler.js +1092 -0
  458. package/lib/widgets/charts/layered/LayeredChartDesign.d.ts +76 -0
  459. package/lib/widgets/charts/layered/LayeredChartDesign.js +2 -0
  460. package/lib/widgets/charts/layered/LayeredChartDesignerComponent.d.ts +80 -0
  461. package/lib/widgets/charts/layered/LayeredChartDesignerComponent.js +317 -0
  462. package/lib/widgets/charts/layered/LayeredChartLayerDesignerComponent.d.ts +72 -0
  463. package/lib/widgets/charts/layered/LayeredChartLayerDesignerComponent.js +329 -0
  464. package/lib/widgets/charts/layered/LayeredChartSvgFileSaver.d.ts +5 -0
  465. package/lib/widgets/charts/layered/LayeredChartSvgFileSaver.js +138 -0
  466. package/lib/widgets/charts/layered/LayeredChartUtils.d.ts +1 -0
  467. package/lib/widgets/charts/layered/LayeredChartUtils.js +25 -0
  468. package/lib/widgets/charts/layered/LayeredChartViewComponent.d.ts +44 -0
  469. package/lib/widgets/charts/layered/LayeredChartViewComponent.js +406 -0
  470. package/lib/widgets/charts/pivot/IntersectionDesignerComponent.d.ts +115 -0
  471. package/lib/widgets/charts/pivot/IntersectionDesignerComponent.js +235 -0
  472. package/lib/widgets/charts/pivot/PivotChart.d.ts +36 -0
  473. package/lib/widgets/charts/pivot/PivotChart.js +343 -0
  474. package/lib/widgets/charts/pivot/PivotChartDesign.d.ts +88 -0
  475. package/lib/widgets/charts/pivot/PivotChartDesign.js +2 -0
  476. package/lib/widgets/charts/pivot/PivotChartDesignerComponent.d.ts +37 -0
  477. package/lib/widgets/charts/pivot/PivotChartDesignerComponent.js +159 -0
  478. package/lib/widgets/charts/pivot/PivotChartLayout.d.ts +73 -0
  479. package/lib/widgets/charts/pivot/PivotChartLayout.js +2 -0
  480. package/lib/widgets/charts/pivot/PivotChartLayoutBuilder.d.ts +37 -0
  481. package/lib/widgets/charts/pivot/PivotChartLayoutBuilder.js +676 -0
  482. package/lib/widgets/charts/pivot/PivotChartLayoutComponent.d.ts +74 -0
  483. package/lib/widgets/charts/pivot/PivotChartLayoutComponent.js +333 -0
  484. package/lib/widgets/charts/pivot/PivotChartQueryBuilder.d.ts +31 -0
  485. package/lib/widgets/charts/pivot/PivotChartQueryBuilder.js +263 -0
  486. package/lib/widgets/charts/pivot/PivotChartUtils.d.ts +12 -0
  487. package/lib/widgets/charts/pivot/PivotChartUtils.js +195 -0
  488. package/lib/widgets/charts/pivot/PivotChartViewComponent.d.ts +84 -0
  489. package/lib/widgets/charts/pivot/PivotChartViewComponent.js +205 -0
  490. package/lib/widgets/charts/pivot/README.md +30 -0
  491. package/lib/widgets/charts/pivot/SegmentDesignerComponent.d.ts +96 -0
  492. package/lib/widgets/charts/pivot/SegmentDesignerComponent.js +216 -0
  493. package/lib/widgets/charts/table/OrderingsComponent.d.ts +15 -0
  494. package/lib/widgets/charts/table/OrderingsComponent.js +66 -0
  495. package/lib/widgets/charts/table/TableChart.d.ts +57 -0
  496. package/lib/widgets/charts/table/TableChart.js +310 -0
  497. package/lib/widgets/charts/table/TableChartDesignerComponent.d.ts +48 -0
  498. package/lib/widgets/charts/table/TableChartDesignerComponent.js +291 -0
  499. package/lib/widgets/charts/table/TableChartViewComponent.d.ts +28 -0
  500. package/lib/widgets/charts/table/TableChartViewComponent.js +206 -0
  501. package/lib/widgets/text/ExprInsertModalComponent.d.ts +35 -0
  502. package/lib/widgets/text/ExprInsertModalComponent.js +51 -0
  503. package/lib/widgets/text/ExprItemEditorComponent.d.ts +34 -0
  504. package/lib/widgets/text/ExprItemEditorComponent.js +92 -0
  505. package/lib/widgets/text/ExprUpdateModalComponent.d.ts +33 -0
  506. package/lib/widgets/text/ExprUpdateModalComponent.js +47 -0
  507. package/lib/widgets/text/README.md +2 -0
  508. package/lib/widgets/text/TextComponent.d.ts +48 -0
  509. package/lib/widgets/text/TextComponent.js +109 -0
  510. package/lib/widgets/text/TextWidget.d.ts +29 -0
  511. package/lib/widgets/text/TextWidget.js +243 -0
  512. package/lib/widgets/text/TextWidgetComponent.d.ts +33 -0
  513. package/lib/widgets/text/TextWidgetComponent.js +88 -0
  514. package/lib/widgets/text/TextWidgetDesign.d.ts +6 -0
  515. package/lib/widgets/text/TextWidgetDesign.js +2 -0
  516. package/mocha.html +10 -0
  517. package/package.json +113 -0
  518. package/server.js +10 -0
  519. package/src/CheckboxComponent.ts +33 -0
  520. package/src/ColorComponent.ts +117 -0
  521. package/src/ColorSchemeFactory.ts +144 -0
  522. package/src/CsvBuilder.ts +65 -0
  523. package/src/DateRangeComponent.ts +279 -0
  524. package/src/FiltersDesignerComponent.ts +55 -0
  525. package/src/ImplicitFilterBuilder.ts +135 -0
  526. package/src/JsonQLFilter.ts +8 -0
  527. package/src/LocaleContextInjector.tsx +17 -0
  528. package/src/MWaterAddRelatedFormComponent.ts +213 -0
  529. package/src/MWaterAddRelatedIndicatorComponent.ts +205 -0
  530. package/src/MWaterAssetSystemsListComponent.tsx +114 -0
  531. package/src/MWaterCompleteTableSelectComponent.tsx +984 -0
  532. package/src/MWaterContextComponent.ts +144 -0
  533. package/src/MWaterCustomTablesetListComponent.tsx +141 -0
  534. package/src/MWaterGlobalFiltersComponent.ts +117 -0
  535. package/src/MWaterLoaderComponent.ts +118 -0
  536. package/src/MWaterMetricsTableListComponent.tsx +120 -0
  537. package/src/MWaterResponsesFilterComponent.ts +194 -0
  538. package/src/MWaterTableSelectComponent.ts +316 -0
  539. package/src/MenuItemComponent.ts +2 -0
  540. package/src/PopoverComponent.ts +59 -0
  541. package/src/RadioButtonComponent.ts +34 -0
  542. package/src/TableSelectComponent.ts +60 -0
  543. package/src/UIComponents.ts +289 -0
  544. package/src/UndoStack.ts +59 -0
  545. package/src/VerticalLayoutComponent.ts +108 -0
  546. package/src/WidgetScope.ts +17 -0
  547. package/src/axes/Axis.ts +89 -0
  548. package/src/axes/AxisBuilder.ts +1325 -0
  549. package/src/axes/AxisColorEditorComponent.ts +210 -0
  550. package/src/axes/AxisComponent.ts +449 -0
  551. package/src/axes/BinsComponent.tsx +169 -0
  552. package/src/axes/CategoryMapComponent.ts +278 -0
  553. package/src/axes/ColorPaletteCollectionComponent.ts +163 -0
  554. package/src/axes/RangesComponent.ts +234 -0
  555. package/src/color-mixer.d.ts +1 -0
  556. package/src/componenttest.ts +64 -0
  557. package/src/compressJson.ts +13 -0
  558. package/src/dashboards/DashboardComponent.ts +468 -0
  559. package/src/dashboards/DashboardDataSource.ts +15 -0
  560. package/src/dashboards/DashboardDesign.ts +57 -0
  561. package/src/dashboards/DashboardUpgrader.ts +103 -0
  562. package/src/dashboards/DashboardUtils.ts +82 -0
  563. package/src/dashboards/DashboardViewComponent.ts +304 -0
  564. package/src/dashboards/DirectDashboardDataSource.ts +69 -0
  565. package/src/dashboards/LayoutOptionsComponent.tsx +227 -0
  566. package/src/dashboards/README.md +13 -0
  567. package/src/dashboards/ServerDashboardDataSource.ts +520 -0
  568. package/src/dashboards/SettingsModalComponent.ts +169 -0
  569. package/src/dashboards/WidgetComponent.tsx +131 -0
  570. package/src/dashboards/layoutOptions.ts +40 -0
  571. package/src/datagrids/DatagridComponent.ts +430 -0
  572. package/src/datagrids/DatagridDataSource.ts +21 -0
  573. package/src/datagrids/DatagridDesign.ts +94 -0
  574. package/src/datagrids/DatagridDesignerComponent.tsx +585 -0
  575. package/src/datagrids/DatagridQueryBuilder.ts +722 -0
  576. package/src/datagrids/DatagridUtils.ts +74 -0
  577. package/src/datagrids/DatagridViewComponent.ts +460 -0
  578. package/src/datagrids/DirectDatagridDataSource.ts +57 -0
  579. package/src/datagrids/EditExprCellComponent.tsx +305 -0
  580. package/src/datagrids/ExprCellComponent.ts +104 -0
  581. package/src/datagrids/FindReplaceModalComponent.ts +354 -0
  582. package/src/datagrids/LabeledExprGenerator.ts +302 -0
  583. package/src/datagrids/OrderBysDesignerComponent.tsx +128 -0
  584. package/src/datagrids/README.md +3 -0
  585. package/src/datagrids/ServerDatagridDataSource.ts +119 -0
  586. package/src/datagrids/react-linkify.d.ts +1 -0
  587. package/src/demo.ts +4148 -0
  588. package/src/demoBlocks.ts +130 -0
  589. package/src/globals.d.ts +2 -0
  590. package/src/index.css +550 -0
  591. package/src/index.ts +112 -0
  592. package/src/injectTableAlias.ts +31 -0
  593. package/src/languages.ts +931 -0
  594. package/src/layout-styles.css +263 -0
  595. package/src/layouts/DecoratedBlockComponent.ts +167 -0
  596. package/src/layouts/DragSourceComponent.ts +35 -0
  597. package/src/layouts/LayoutManager.ts +86 -0
  598. package/src/layouts/blocks/BlocksDisplayComponent.ts +461 -0
  599. package/src/layouts/blocks/BlocksLayoutManager.ts +78 -0
  600. package/src/layouts/blocks/ClipboardPaletteItemComponent.ts +89 -0
  601. package/src/layouts/blocks/DraggableBlockComponent.ts +219 -0
  602. package/src/layouts/blocks/HorizontalBlockComponent.ts +288 -0
  603. package/src/layouts/blocks/PaletteItemComponent.ts +27 -0
  604. package/src/layouts/blocks/README.md +11 -0
  605. package/src/layouts/blocks/blockUtils.ts +207 -0
  606. package/src/layouts/decorated-block.css +100 -0
  607. package/src/layouts/grid/GridLayoutComponent.ts +67 -0
  608. package/src/layouts/grid/GridLayoutManager.ts +185 -0
  609. package/src/layouts/grid/LegoLayoutEngine.ts +142 -0
  610. package/src/layouts/grid/PaletteItemComponent.ts +28 -0
  611. package/src/layouts/grid/README.md +14 -0
  612. package/src/layouts/grid/WidgetContainerComponent.ts +420 -0
  613. package/src/mWaterLoader.ts +82 -0
  614. package/src/mapdemo.ts +127 -0
  615. package/src/maps/AddLayerComponent.ts +125 -0
  616. package/src/maps/AdminScopeAndDetailLevelComponent.ts +90 -0
  617. package/src/maps/BaseLayerDesignerComponent.ts +104 -0
  618. package/src/maps/BingLayer.ts +156 -0
  619. package/src/maps/BufferLayer.ts +927 -0
  620. package/src/maps/BufferLayerDesign.ts +48 -0
  621. package/src/maps/BufferLayerDesignerComponent.ts +311 -0
  622. package/src/maps/ChoroplethLayer.ts +1712 -0
  623. package/src/maps/ChoroplethLayerDesign.ts +73 -0
  624. package/src/maps/ChoroplethLayerDesigner.tsx +558 -0
  625. package/src/maps/ClusterLayer.ts +836 -0
  626. package/src/maps/ClusterLayerDesign.ts +29 -0
  627. package/src/maps/ClusterLayerDesignerComponent.ts +190 -0
  628. package/src/maps/DetailLevelSelectComponent.ts +119 -0
  629. package/src/maps/DirectMapDataSource.ts +386 -0
  630. package/src/maps/EditHoverOver.tsx +151 -0
  631. package/src/maps/EditPopupComponent.ts +121 -0
  632. package/src/maps/Grid Functions.sql +167 -0
  633. package/src/maps/GridLayer.ts +776 -0
  634. package/src/maps/GridLayerDesign.ts +53 -0
  635. package/src/maps/GridLayerDesigner.tsx +332 -0
  636. package/src/maps/HoverContent.tsx +96 -0
  637. package/src/maps/HtmlUrlLegend.tsx +44 -0
  638. package/src/maps/Layer.ts +338 -0
  639. package/src/maps/LayerFactory.ts +51 -0
  640. package/src/maps/LayerLegendComponent.ts +88 -0
  641. package/src/maps/LayerSwitcherComponent.tsx +91 -0
  642. package/src/maps/LeafletLoading.css +24 -0
  643. package/src/maps/LeafletLoading.ts +355 -0
  644. package/src/maps/LeafletMapComponent.tsx +587 -0
  645. package/src/maps/LegendComponent.tsx +101 -0
  646. package/src/maps/LegendGroup.ts +120 -0
  647. package/src/maps/MWaterServerLayer.ts +116 -0
  648. package/src/maps/MapBoundsCalculator.ts +88 -0
  649. package/src/maps/MapComponent.ts +312 -0
  650. package/src/maps/MapControlComponent.ts +46 -0
  651. package/src/maps/MapDataSource.ts +20 -0
  652. package/src/maps/MapDesign.ts +103 -0
  653. package/src/maps/MapDesignerComponent.ts +356 -0
  654. package/src/maps/MapFiltersDesignerComponent.ts +95 -0
  655. package/src/maps/MapLayerDataSource.ts +27 -0
  656. package/src/maps/MapLayerViewDesignerComponent.ts +243 -0
  657. package/src/maps/MapLayersDesignerComponent.ts +144 -0
  658. package/src/maps/MapUtils.ts +148 -0
  659. package/src/maps/MapViewComponent.tsx +62 -0
  660. package/src/maps/Maptiler-logo.png +0 -0
  661. package/src/maps/MarkerSymbolSelectComponent.ts +41 -0
  662. package/src/maps/MarkersLayer.ts +941 -0
  663. package/src/maps/MarkersLayerDesign.ts +56 -0
  664. package/src/maps/MarkersLayerDesignerComponent.ts +374 -0
  665. package/src/maps/PopupFilterJoinsEditComponent.ts +114 -0
  666. package/src/maps/PopupFilterJoinsUtils.ts +99 -0
  667. package/src/maps/RasterMapViewComponent.ts +382 -0
  668. package/src/maps/RegionSelectComponent.ts +80 -0
  669. package/src/maps/ScopeAndDetailLevelComponent.ts +82 -0
  670. package/src/maps/ServerMapDataSource.ts +399 -0
  671. package/src/maps/SwitchableTileUrlLayer.tsx +130 -0
  672. package/src/maps/SwitchableTileUrlLayerDesigner.tsx +60 -0
  673. package/src/maps/TileUrlLayer.tsx +142 -0
  674. package/src/maps/UtfGridLayer.ts +286 -0
  675. package/src/maps/VectorMapViewComponent.css +21 -0
  676. package/src/maps/VectorMapViewComponent.tsx +743 -0
  677. package/src/maps/ZoomLevelsComponent.ts +72 -0
  678. package/src/maps/mapSymbols.ts +162 -0
  679. package/src/maps/mapboxUtils.ts +61 -0
  680. package/src/maps/maps.ts +38 -0
  681. package/src/maps/marker-icon-2x.png +0 -0
  682. package/src/maps/marker-icon.png +0 -0
  683. package/src/maps/marker-shadow.png +0 -0
  684. package/src/maps/png.d.ts +1 -0
  685. package/src/maps/symbols/font-awesome/asterisk.png +0 -0
  686. package/src/maps/symbols/font-awesome/ban.png +0 -0
  687. package/src/maps/symbols/font-awesome/beer.png +0 -0
  688. package/src/maps/symbols/font-awesome/bell.png +0 -0
  689. package/src/maps/symbols/font-awesome/bolt.png +0 -0
  690. package/src/maps/symbols/font-awesome/building.png +0 -0
  691. package/src/maps/symbols/font-awesome/bullseye.png +0 -0
  692. package/src/maps/symbols/font-awesome/bus.png +0 -0
  693. package/src/maps/symbols/font-awesome/caret-up.png +0 -0
  694. package/src/maps/symbols/font-awesome/certificate.png +0 -0
  695. package/src/maps/symbols/font-awesome/check-circle.png +0 -0
  696. package/src/maps/symbols/font-awesome/check.png +0 -0
  697. package/src/maps/symbols/font-awesome/chevron-circle-down.png +0 -0
  698. package/src/maps/symbols/font-awesome/chevron-circle-up.png +0 -0
  699. package/src/maps/symbols/font-awesome/cloud.png +0 -0
  700. package/src/maps/symbols/font-awesome/comment.png +0 -0
  701. package/src/maps/symbols/font-awesome/crosshairs.png +0 -0
  702. package/src/maps/symbols/font-awesome/dot-circle-o.png +0 -0
  703. package/src/maps/symbols/font-awesome/exclamation-circle.png +0 -0
  704. package/src/maps/symbols/font-awesome/exclamation-triangle.png +0 -0
  705. package/src/maps/symbols/font-awesome/female.png +0 -0
  706. package/src/maps/symbols/font-awesome/file.png +0 -0
  707. package/src/maps/symbols/font-awesome/flag.png +0 -0
  708. package/src/maps/symbols/font-awesome/flask.png +0 -0
  709. package/src/maps/symbols/font-awesome/h-square.png +0 -0
  710. package/src/maps/symbols/font-awesome/home.png +0 -0
  711. package/src/maps/symbols/font-awesome/info-circle.png +0 -0
  712. package/src/maps/symbols/font-awesome/male.png +0 -0
  713. package/src/maps/symbols/font-awesome/medkit.png +0 -0
  714. package/src/maps/symbols/font-awesome/mobile.png +0 -0
  715. package/src/maps/symbols/font-awesome/plus-circle.png +0 -0
  716. package/src/maps/symbols/font-awesome/plus-square.png +0 -0
  717. package/src/maps/symbols/font-awesome/plus.png +0 -0
  718. package/src/maps/symbols/font-awesome/square.png +0 -0
  719. package/src/maps/symbols/font-awesome/star.png +0 -0
  720. package/src/maps/symbols/font-awesome/thumbs-down.png +0 -0
  721. package/src/maps/symbols/font-awesome/thumbs-up.png +0 -0
  722. package/src/maps/symbols/font-awesome/ticket.png +0 -0
  723. package/src/maps/symbols/font-awesome/times-circle.png +0 -0
  724. package/src/maps/symbols/font-awesome/times.png +0 -0
  725. package/src/maps/symbols/font-awesome/tint.png +0 -0
  726. package/src/maps/symbols/font-awesome/tree.png +0 -0
  727. package/src/maps/symbols/font-awesome/university.png +0 -0
  728. package/src/maps/symbols/font-awesome/usd.png +0 -0
  729. package/src/maps/symbols/font-awesome/user.png +0 -0
  730. package/src/maps/symbols/font-awesome/users.png +0 -0
  731. package/src/maps/symbols/font-awesome/wheelchair.png +0 -0
  732. package/src/maps/vectorMaps.tsx +410 -0
  733. package/src/memoizedDebounce.tsx +32 -0
  734. package/src/quickfilter/DateExprComponent.ts +284 -0
  735. package/src/quickfilter/IdArrayQuickfilterComponent.ts +58 -0
  736. package/src/quickfilter/Quickfilter.ts +29 -0
  737. package/src/quickfilter/QuickfilterCompiler.ts +167 -0
  738. package/src/quickfilter/QuickfilterUtils.ts +123 -0
  739. package/src/quickfilter/QuickfiltersComponent.ts +416 -0
  740. package/src/quickfilter/QuickfiltersDataSource.ts +15 -0
  741. package/src/quickfilter/QuickfiltersDesignComponent.tsx +257 -0
  742. package/src/quickfilter/README.md +8 -0
  743. package/src/quickfilter/TextLiteralComponent.ts +161 -0
  744. package/src/quickfilter/react-onclickout.d.ts +1 -0
  745. package/src/richtext/ExprItemsHtmlConverter.ts +144 -0
  746. package/src/richtext/FontColorPaletteItem.ts +172 -0
  747. package/src/richtext/FontSizePaletteItem.ts +110 -0
  748. package/src/richtext/ItemsHtmlConverter.ts +246 -0
  749. package/src/richtext/README.md +3 -0
  750. package/src/richtext/RichTextComponent.tsx +390 -0
  751. package/src/richtext/react-float-affixed.d.ts +1 -0
  752. package/src/update-object.d.ts +1 -0
  753. package/src/valueFormatter.ts +110 -0
  754. package/src/widgets/DirectWidgetDataSource.ts +67 -0
  755. package/src/widgets/DropdownWidgetComponent.ts +78 -0
  756. package/src/widgets/IFrameWidget.ts +36 -0
  757. package/src/widgets/IFrameWidgetComponent.ts +116 -0
  758. package/src/widgets/ImageUploaderComponent.tsx +143 -0
  759. package/src/widgets/ImageWidget.ts +147 -0
  760. package/src/widgets/ImageWidgetComponent.ts +546 -0
  761. package/src/widgets/ImagelistCarouselComponent.ts +109 -0
  762. package/src/widgets/MapWidget.ts +219 -0
  763. package/src/widgets/MarkdownWidget.ts +201 -0
  764. package/src/widgets/TOCWidget.ts +326 -0
  765. package/src/widgets/Widget.ts +83 -0
  766. package/src/widgets/WidgetDataSource.ts +23 -0
  767. package/src/widgets/WidgetFactory.ts +37 -0
  768. package/src/widgets/WidgetScoper.ts +51 -0
  769. package/src/widgets/WidgetScopesViewComponent.ts +54 -0
  770. package/src/widgets/charts/Chart.ts +140 -0
  771. package/src/widgets/charts/ChartViewComponent.ts +209 -0
  772. package/src/widgets/charts/ChartWidget.ts +345 -0
  773. package/src/widgets/charts/calendar/CalendarChart.ts +227 -0
  774. package/src/widgets/charts/calendar/CalendarChartDesignerComponent.ts +187 -0
  775. package/src/widgets/charts/calendar/CalendarChartViewComponent.tsx +320 -0
  776. package/src/widgets/charts/calendar/d3-tip.d.ts +1 -0
  777. package/src/widgets/charts/imagemosaic/ImageMosaicChart.ts +213 -0
  778. package/src/widgets/charts/imagemosaic/ImageMosaicChartDesignerComponent.ts +121 -0
  779. package/src/widgets/charts/imagemosaic/ImageMosaicChartViewComponent.ts +117 -0
  780. package/src/widgets/charts/imagemosaic/ImagePopupComponent.ts +51 -0
  781. package/src/widgets/charts/imagemosaic/react-lazy-load-image-component.d.ts +1 -0
  782. package/src/widgets/charts/layered/LayeredChart.ts +361 -0
  783. package/src/widgets/charts/layered/LayeredChartCompiler.ts +1299 -0
  784. package/src/widgets/charts/layered/LayeredChartDesign.ts +106 -0
  785. package/src/widgets/charts/layered/LayeredChartDesignerComponent.tsx +523 -0
  786. package/src/widgets/charts/layered/LayeredChartLayerDesignerComponent.tsx +448 -0
  787. package/src/widgets/charts/layered/LayeredChartSvgFileSaver.ts +146 -0
  788. package/src/widgets/charts/layered/LayeredChartUtils.ts +24 -0
  789. package/src/widgets/charts/layered/LayeredChartViewComponent.ts +486 -0
  790. package/src/widgets/charts/layered/save-svg-as-png.d.ts +1 -0
  791. package/src/widgets/charts/pivot/IntersectionDesignerComponent.tsx +338 -0
  792. package/src/widgets/charts/pivot/PivotChart.ts +377 -0
  793. package/src/widgets/charts/pivot/PivotChartDesign.ts +115 -0
  794. package/src/widgets/charts/pivot/PivotChartDesignerComponent.tsx +240 -0
  795. package/src/widgets/charts/pivot/PivotChartLayout.ts +99 -0
  796. package/src/widgets/charts/pivot/PivotChartLayoutBuilder.ts +779 -0
  797. package/src/widgets/charts/pivot/PivotChartLayoutComponent.tsx +504 -0
  798. package/src/widgets/charts/pivot/PivotChartQueryBuilder.ts +273 -0
  799. package/src/widgets/charts/pivot/PivotChartUtils.ts +219 -0
  800. package/src/widgets/charts/pivot/PivotChartViewComponent.ts +276 -0
  801. package/src/widgets/charts/pivot/README.md +30 -0
  802. package/src/widgets/charts/pivot/SegmentDesignerComponent.tsx +353 -0
  803. package/src/widgets/charts/table/OrderingsComponent.tsx +119 -0
  804. package/src/widgets/charts/table/TableChart.ts +420 -0
  805. package/src/widgets/charts/table/TableChartDesignerComponent.ts +441 -0
  806. package/src/widgets/charts/table/TableChartViewComponent.ts +327 -0
  807. package/src/widgets/text/ExprInsertModalComponent.ts +77 -0
  808. package/src/widgets/text/ExprItemEditorComponent.tsx +164 -0
  809. package/src/widgets/text/ExprUpdateModalComponent.ts +70 -0
  810. package/src/widgets/text/README.md +2 -0
  811. package/src/widgets/text/TextComponent.tsx +151 -0
  812. package/src/widgets/text/TextWidget.ts +265 -0
  813. package/src/widgets/text/TextWidgetComponent.ts +120 -0
  814. package/src/widgets/text/TextWidgetDesign.ts +7 -0
  815. package/stories/UpdateableComponent.js +29 -0
  816. package/stories/consoles.js +202 -0
  817. package/stories/dashboards.js +217 -0
  818. package/stories/datagridDesign.js +114 -0
  819. package/stories/datagrids.js +69 -0
  820. package/stories/dates.js +80 -0
  821. package/stories/exprcomponent.js +43 -0
  822. package/stories/index.js +18 -0
  823. package/stories/leaflet.js +59 -0
  824. package/stories/maps.js +24 -0
  825. package/stories/pivotChart.js +235 -0
  826. package/test/AxisBuilderTests.ts +931 -0
  827. package/test/ChartWidgetTests.ts +85 -0
  828. package/test/ColorSchemeFactoryTests.ts +29 -0
  829. package/test/CsvBuilderTests.ts +22 -0
  830. package/test/DashboardUpgraderTests.ts +170 -0
  831. package/test/ImplicitFilterBuilderTests.ts +161 -0
  832. package/test/LayeredChartCompilerTests.ts +1067 -0
  833. package/test/LayeredChartTests.ts +88 -0
  834. package/test/LegoLayoutEngineTests.ts +69 -0
  835. package/test/MWaterGlobalFiltersComponentTests.ts +130 -0
  836. package/test/MWaterResponsesFilterComponentTests.ts +164 -0
  837. package/test/QuickfilterCompilerTests.ts +167 -0
  838. package/test/TestComponent.ts +49 -0
  839. package/test/UndoStackTests.ts +73 -0
  840. package/test/WidgetScoperTests.ts +35 -0
  841. package/test/blockUtilsTests.ts +290 -0
  842. package/test/canonical-json.d.ts +1 -0
  843. package/test/dashboards/DashboardUtilsTests.ts +131 -0
  844. package/test/datagrids/DatagridQueryBuilderTests.ts +445 -0
  845. package/test/datagrids/DatagridUtilsTests.ts +54 -0
  846. package/test/datagrids/LabeledExprGeneratorTests.ts +121 -0
  847. package/test/fixtures.ts +263 -0
  848. package/test/index.ts +2 -0
  849. package/test/maps/MapUtilsTests.ts +168 -0
  850. package/test/maps/PopupFilterJoinsUtilsTests.ts +105 -0
  851. package/test/richtext/ItemsHtmlConverterTests.ts +41 -0
  852. package/test/test_index.ts +4 -0
  853. package/test/widgets/TextWidgetTests.ts +42 -0
  854. package/test/widgets/charts/pivot/PivotChartLayoutBuilderTests.ts +817 -0
  855. package/test/widgets/charts/pivot/PivotChartQueryBuilderTests.ts +359 -0
  856. package/test/widgets/charts/pivot/PivotChartTests.ts +64 -0
  857. package/test/widgets/charts/pivot/PivotChartUtilsTests.ts +184 -0
  858. package/test/widgets/charts/table/TableChartTests.ts +253 -0
  859. package/tsconfig.build.json +26 -0
  860. package/types/utm.d.ts +10 -0
@@ -0,0 +1,1299 @@
1
+ import _ from "lodash"
2
+ import { Expr, ExprCompiler, Schema } from "@mwater/expressions"
3
+ import { ExprUtils } from "@mwater/expressions"
4
+ import AxisBuilder from "../../../axes/AxisBuilder"
5
+ import { injectTableAlias } from "@mwater/expressions"
6
+ import * as d3Format from "d3-format"
7
+ import { JsonQLFilter, WidgetScope } from "../../.."
8
+ import { LayeredChartDesign } from "./LayeredChartDesign"
9
+ import { JsonQLExpr, JsonQLQuery, JsonQLSelectQuery } from "@mwater/jsonql"
10
+ import { Axis } from "../../../axes/Axis"
11
+ import { bar, line, spline, scatter, area, pie, donut, ChartOptions, PrimitiveArray, ChartTypes } from "billboard.js"
12
+
13
+ /** Chart types */
14
+ const chartTypes = {
15
+ bar,
16
+ line,
17
+ spline,
18
+ scatter,
19
+ area,
20
+ pie,
21
+ donut,
22
+ }
23
+
24
+ const commaFormatter = d3Format.format(",")
25
+
26
+ const compactFormatter = (d: number) => {
27
+ // Only if large, otherwise use standard formatting
28
+ if (Math.abs(d) > 999) {
29
+ return d3Format.format("~s")(d).replace('G', 'B')
30
+ }
31
+ else {
32
+ return commaFormatter(d)
33
+ }
34
+ }
35
+
36
+ /** Data for a chart */
37
+ type C3ChartData = { [key: string]: any[] }
38
+
39
+ /** Intermediate data structure that contains most of chart formatting */
40
+ interface C3Data {
41
+ types?: { [key: string]: ChartTypes }
42
+
43
+ columns: PrimitiveArray[]
44
+
45
+ xAxisType?: "category" | "indexed" | "log" | "timeseries"
46
+
47
+ xAxisTickFit?: boolean
48
+
49
+ xs?: { [key: string]: string }
50
+
51
+ /** map of "layername:index" to { layerIndex, row } */
52
+ dataMap: { [key: string]: { layerIndex: number, row: any[] }}
53
+
54
+ format: { [layerId: string]: (value: any) => string }
55
+
56
+ xAxisLabelText?: string
57
+
58
+ yAxisLabelText?: string
59
+
60
+ titleText?: string
61
+
62
+ legendHide?: boolean
63
+
64
+ /**
65
+ * Set custom data name.
66
+ */
67
+ names?: { [key: string]: string };
68
+
69
+ /**
70
+ * Set groups for the data for stacking.
71
+ */
72
+ groups?: string[][];
73
+
74
+ /**
75
+ * Set label text colors.
76
+ */
77
+ colors?: { [key: string]: string }
78
+
79
+ order?: "asc" | "desc" | null
80
+
81
+ color?: any
82
+
83
+ /**
84
+ * Set custom data class.
85
+ * If this option is specified, the element g for the data has an additional class that has the prefix billboard-target- (e.g. billboard-target-additional-data1-class).
86
+ */
87
+ classes?: { [key: string]: string };
88
+ }
89
+
90
+ function pieLabelValueFormatter(format: any, hidePercent = false) {
91
+ function percent(ratio: any) {
92
+ if (hidePercent) {
93
+ return ""
94
+ } else {
95
+ return `(${d3Format.format(".1%")(ratio)})`
96
+ }
97
+ }
98
+ return function (value: any, ratio: any, id: any) {
99
+ if (format[id]) {
100
+ return `${format[id](value)} ${percent(ratio)}`
101
+ } else {
102
+ return `${d3Format.format(",")(value)} ${percent(ratio)}`
103
+ }
104
+ }
105
+ }
106
+
107
+ function labelValueFormatter(format: any) {
108
+ return function (value: any, ratio: any, id: any) {
109
+ if (format[id]) {
110
+ return format[id](value)
111
+ } else {
112
+ return value
113
+ }
114
+ }
115
+ }
116
+
117
+ const d3Round = d3Format.format(".2f")
118
+
119
+ const defaultColors = [
120
+ "#1f77b4",
121
+ "#ff7f0e",
122
+ "#2ca02c",
123
+ "#d62728",
124
+ "#9467bd",
125
+ "#8c564b",
126
+ "#e377c2",
127
+ "#7f7f7f",
128
+ "#bcbd22",
129
+ "#17becf",
130
+ "#aec7e8",
131
+ "#ffbb78",
132
+ "#98df8a",
133
+ "#ff9896",
134
+ "#c5b0d5",
135
+ "#c49c94",
136
+ "#f7b6d2",
137
+ "#c7c7c7",
138
+ "#dbdb8d",
139
+ "#9edae5"
140
+ ]
141
+
142
+ // Compiles various parts of a layered chart (line, bar, scatter, spline, area) to C3.js format
143
+ export default class LayeredChartCompiler {
144
+ schema: Schema
145
+ exprUtils: ExprUtils
146
+ axisBuilder: AxisBuilder
147
+
148
+ // Pass in schema
149
+ constructor(options: { schema: Schema }) {
150
+ this.schema = options.schema
151
+ this.exprUtils = new ExprUtils(this.schema)
152
+ this.axisBuilder = new AxisBuilder({ schema: this.schema })
153
+ }
154
+
155
+ /** Create the queries needed for the chart.
156
+ * extraFilters: array of filters to apply. Each is { table: table id, jsonql: jsonql condition with {alias} for tableAlias. }
157
+ * @returns queries indexed by layerX
158
+ */
159
+ createQueries(design: LayeredChartDesign, extraFilters?: JsonQLFilter[] | null): { [key: string]: JsonQLQuery } {
160
+ const exprCompiler = new ExprCompiler(this.schema)
161
+
162
+ const queries = {}
163
+
164
+ // For each layer
165
+ for (
166
+ let layerIndex = 0, end = design.layers.length, asc = 0 <= end;
167
+ asc ? layerIndex < end : layerIndex > end;
168
+ asc ? layerIndex++ : layerIndex--
169
+ ) {
170
+ const layer = design.layers[layerIndex]
171
+
172
+ // Limit depends on layer type
173
+ let limit = 1000
174
+ if (layer.type === "scatter" || design.type === "scatter") {
175
+ limit = 10000 // More possible for scatter chart
176
+ }
177
+
178
+ // Create shell of query
179
+ const query: JsonQLSelectQuery = {
180
+ type: "query",
181
+ selects: [],
182
+ from: exprCompiler.compileTable(layer.table, "main"),
183
+ limit,
184
+ groupBy: [],
185
+ orderBy: []
186
+ }
187
+
188
+ if (layer.axes.x) {
189
+ query.selects.push({
190
+ type: "select",
191
+ expr: this.axisBuilder.compileAxis({ axis: layer.axes.x, tableAlias: "main" }),
192
+ alias: "x"
193
+ })
194
+ }
195
+ if (layer.axes.color) {
196
+ query.selects.push({
197
+ type: "select",
198
+ expr: this.axisBuilder.compileAxis({ axis: layer.axes.color, tableAlias: "main" }),
199
+ alias: "color"
200
+ })
201
+ }
202
+ if (layer.axes.y) {
203
+ query.selects.push({
204
+ type: "select",
205
+ expr: this.axisBuilder.compileAxis({ axis: layer.axes.y, tableAlias: "main" }),
206
+ alias: "y"
207
+ })
208
+ }
209
+
210
+ // Sort by x and color
211
+ if (layer.axes.x || layer.axes.color) {
212
+ query.orderBy!.push({ ordinal: 1 })
213
+ }
214
+ if (layer.axes.x && layer.axes.color) {
215
+ query.orderBy!.push({ ordinal: 2 })
216
+ }
217
+
218
+ // If grouping type
219
+ if (this.doesLayerNeedGrouping(design, layerIndex)) {
220
+ if (layer.axes.x || layer.axes.color) {
221
+ query.groupBy!.push(1)
222
+ }
223
+
224
+ if (layer.axes.x && layer.axes.color) {
225
+ query.groupBy!.push(2)
226
+ }
227
+ }
228
+
229
+ // Add where
230
+ let whereClauses = []
231
+ if (layer.filter) {
232
+ whereClauses.push(this.compileExpr(layer.filter))
233
+ }
234
+
235
+ // Add filters
236
+ if (extraFilters && extraFilters.length > 0) {
237
+ // Get relevant filters
238
+ const relevantFilters = _.where(extraFilters, { table: layer.table })
239
+
240
+ // If any, create and
241
+ if (relevantFilters.length > 0) {
242
+ // Add others
243
+ for (let filter of relevantFilters) {
244
+ whereClauses.push(injectTableAlias(filter.jsonql, "main"))
245
+ }
246
+ }
247
+ }
248
+
249
+ // Wrap if multiple
250
+ whereClauses = _.compact(whereClauses)
251
+
252
+ if (whereClauses.length > 1) {
253
+ query.where = { type: "op", op: "and", exprs: whereClauses }
254
+ } else {
255
+ query.where = whereClauses[0]
256
+ }
257
+
258
+ queries[`layer${layerIndex}`] = query
259
+ }
260
+
261
+ return queries
262
+ }
263
+
264
+ // Create data map of "{layer name}" or "{layer name}:{index}" to { layerIndex, row }
265
+ createDataMap(design: LayeredChartDesign, data: C3ChartData) {
266
+ return this.compileData(design, data).dataMap
267
+ }
268
+
269
+ // Create the chartOptions to pass to c3.generate
270
+ // options is
271
+ // design: chart design element
272
+ // data: chart data
273
+ // width: chart width
274
+ // height: chart height
275
+ // locale: locale to use
276
+ createChartOptions(options: {
277
+ design: LayeredChartDesign
278
+ data: any
279
+ width: number
280
+ height: number
281
+ locale?: string
282
+ }): ChartOptions {
283
+ const c3Data = this.compileData(options.design, options.data, options.locale)
284
+
285
+ // Pick first format to use as the tick formatter
286
+ let tickFormatter = _.keys(c3Data.format).length > 0 ? c3Data.format[_.keys(c3Data.format)[0]] : commaFormatter
287
+ if (options.design.transpose) {
288
+ tickFormatter = compactFormatter
289
+ }
290
+
291
+ // Create chart
292
+ // NOTE: this structure must be comparable with _.isEqual, so don't add any inline functiona
293
+ const chartDesign: ChartOptions = {
294
+ data: {
295
+ types: c3Data.types,
296
+ columns: c3Data.columns,
297
+ names: c3Data.names,
298
+ groups: c3Data.groups,
299
+ xs: c3Data.xs,
300
+ colors: c3Data.colors,
301
+ labels: options.design.labels,
302
+ order: c3Data.order,
303
+ color: c3Data.color,
304
+ classes: c3Data.classes
305
+ },
306
+ // Hide if one layer with no color axis
307
+ legend: {
308
+ hide: options.design.layers.length === 1 && !options.design.layers[0].axes.color ? true : c3Data.legendHide
309
+ },
310
+ grid: { focus: { show: false } }, // Don't display hover grid
311
+ axis: {
312
+ x: {
313
+ type: c3Data.xAxisType,
314
+ label: {
315
+ text: cleanString(c3Data.xAxisLabelText),
316
+ position: options.design.transpose ? "outer-middle" : "outer-center"
317
+ },
318
+ tick: { fit: c3Data.xAxisTickFit }
319
+ },
320
+ y: {
321
+ label: {
322
+ text: cleanString(c3Data.yAxisLabelText),
323
+ position: options.design.transpose ? "outer-center" : "outer-middle"
324
+ },
325
+ // Set max to 100 if proportional (with no padding)
326
+ max: options.design.type === "bar" && options.design.proportional ? 100 : options.design.yMax,
327
+ min: options.design.type === "bar" && options.design.proportional ? 0 : options.design.yMin,
328
+ padding:
329
+ options.design.type === "bar" && options.design.proportional
330
+ ? { top: 0, bottom: 0 }
331
+ : {
332
+ top: options.design.yMax != null ? 0 : undefined,
333
+ bottom: options.design.yMin != null ? 0 : undefined
334
+ },
335
+ tick: {
336
+ format: tickFormatter
337
+ }
338
+ },
339
+ rotated: options.design.transpose
340
+ },
341
+ size: { width: options.width, height: options.height },
342
+ pie: {
343
+ label: {
344
+ show: !options.design.hidePercentage || !!options.design.labels,
345
+ format: options.design.labels
346
+ ? pieLabelValueFormatter(c3Data.format, options.design.hidePercentage)
347
+ : undefined
348
+ },
349
+ expand: false // Don't expand/contract
350
+ },
351
+ donut: {
352
+ label: {
353
+ show: !options.design.hidePercentage || !!options.design.labels,
354
+ format: options.design.labels
355
+ ? pieLabelValueFormatter(c3Data.format, options.design.hidePercentage)
356
+ : undefined
357
+ },
358
+ expand: false // Don't expand/contract
359
+ },
360
+
361
+ transition: { duration: 0 } // Transitions interfere with scoping
362
+ }
363
+
364
+ // && (options.design.type === "pie" || options.design.type === "donut")
365
+ if(options.design.labels) {
366
+ // same color values gets hidden!! https://github.com/naver/billboard.js/issues/871
367
+ chartDesign.data!.labels = {
368
+ colors: chartDesign.data!.columns!.reduce((a, c) => {
369
+ a[c[0] as string] = '#000'
370
+ return a
371
+ }, {})
372
+ }
373
+ if(!options.design.transpose) {
374
+ chartDesign.data!.labels = {
375
+ ...chartDesign.data!.labels,
376
+ position: {
377
+ y: 15
378
+ } as any, // TODO why does this not type correctly?
379
+ }
380
+ }
381
+ }
382
+
383
+ if(_.isEmpty(chartDesign.data!.types)) {
384
+ chartDesign.data!.type = this.getLayerType(options.design, 0)
385
+ }
386
+
387
+ if (!_.isEmpty(c3Data.format)) {
388
+ if (options.design.type === "pie" || options.design.type === "donut") {
389
+ chartDesign.tooltip = {
390
+ format: {
391
+ value: pieLabelValueFormatter(c3Data.format)
392
+ }
393
+ }
394
+ } else {
395
+ chartDesign.tooltip = {
396
+ format: {
397
+ value: labelValueFormatter(c3Data.format)
398
+ }
399
+ }
400
+ }
401
+ }
402
+
403
+ if (options.design.labels && !_.isEmpty(c3Data.format)) {
404
+ // format = _.map options.design.layers, (layer, layerIndex) =>
405
+ // return if c3Data.format[layerIndex] then c3Data.format[layerIndex] else true
406
+ chartDesign.data!.labels = {
407
+ ...chartDesign.data!.labels as any,
408
+ format: c3Data.format
409
+ }
410
+ }
411
+
412
+ if (options.design.yThresholds) {
413
+ chartDesign.grid!.y = {
414
+ lines: _.map(options.design.yThresholds, (t) => ({
415
+ value: t.value!,
416
+ text: t.label!
417
+ }))
418
+ }
419
+ }
420
+
421
+ // This doesn't work in new C3. Removing.
422
+ // # If x axis is year only, display year in ticks
423
+ // if options.design.layers[0]?.axes.x?.xform?.type == "year"
424
+ // chartDesign.axis.x.tick.format = (x) -> if _.isDate(x) then x.getFullYear() else x
425
+ console.log(chartDesign)
426
+ return chartDesign
427
+ }
428
+
429
+ isCategoricalX(design: LayeredChartDesign) {
430
+ // Check if categorical x axis (bar charts always are)
431
+ let categoricalX = design.type === "bar" || _.any(design.layers, (l) => l.type === "bar")
432
+
433
+ // Check if x axis is categorical type
434
+ const xType = this.axisBuilder.getAxisType(design.layers[0].axes.x)
435
+ if (["enum", "text", "boolean"].includes(xType || "")) {
436
+ categoricalX = true
437
+ }
438
+
439
+ // Dates that are stacked must be categorical to make stacking work in C3
440
+ if (xType === "date" && design.stacked) {
441
+ categoricalX = true
442
+ }
443
+
444
+ return categoricalX
445
+ }
446
+
447
+ // Compiles data part of C3 chart, including data map back to original data
448
+ // Outputs: columns, types, names, colors. Also dataMap which is a map of "layername:index" to { layerIndex, row }
449
+ compileData(design: LayeredChartDesign, data: C3ChartData, locale?: string): C3Data {
450
+ // If polar chart (no x axis)
451
+ if (["pie", "donut"].includes(design.type) || _.any(design.layers, (l) => ["pie", "donut"].includes(l.type))) {
452
+ return this.compileDataPolar(design, data, locale)
453
+ }
454
+
455
+ if (this.isCategoricalX(design)) {
456
+ return this.compileDataCategorical(design, data, locale)
457
+ } else {
458
+ return this.compileDataNonCategorical(design, data, locale)
459
+ }
460
+ }
461
+
462
+ // Compiles data for a polar chart (pie/donut) with no x axis
463
+ compileDataPolar(design: LayeredChartDesign, data: C3ChartData, locale: any): C3Data {
464
+ let order: "asc" | "desc" | null
465
+ const columns: any = []
466
+ const types = {}
467
+ const names = {}
468
+ const dataMap = {}
469
+ const colors = {}
470
+ const format = {}
471
+
472
+ // For each layer
473
+ _.each(design.layers, (layer, layerIndex) => {
474
+ // If has color axis
475
+ if (layer.axes.color) {
476
+ let layerData: any[] = data[`layer${layerIndex}`]
477
+
478
+ // Categories will be in form [{ value, label }]
479
+ const categories = this.axisBuilder.getCategories(layer.axes.color, _.pluck(layerData, "color"), { locale })
480
+
481
+ // Get indexed ordering of categories (lookup from value to index) without removing excluded values
482
+ const categoryOrder = _.zipObject(_.map(categories, (c, i) => [c.value, i]))
483
+
484
+ // Sort by category order
485
+ layerData = _.sortBy(layerData, (row) => categoryOrder[row.color])
486
+
487
+ // Create a series for each row
488
+ _.each(layerData, (row, rowIndex) => {
489
+ // Skip if value excluded
490
+ if (_.includes(layer.axes.color!.excludedValues || [], row.color)) {
491
+ return
492
+ }
493
+
494
+ const series = `${layerIndex}:${rowIndex}`
495
+ // Pie series contain a single value
496
+ columns.push([series, row.y])
497
+ types[series] = this.getLayerType(design, layerIndex)
498
+ names[series] = this.axisBuilder.formatValue(layer.axes.color!, row.color, locale, true)
499
+ dataMap[series] = { layerIndex, row }
500
+ format[series] = (value: any) =>
501
+ value != null ? this.axisBuilder.formatValue(layer.axes.y!, value, locale, true) : ""
502
+ // Get specific color if present
503
+ const color = this.axisBuilder.getValueColor(layer.axes.color!, row.color)
504
+ //color = color or layer.color
505
+ if (color) {
506
+ colors[series] = color
507
+ }
508
+ })
509
+ } else {
510
+ // Create a single series
511
+ const row = data[`layer${layerIndex}`][0]
512
+ if (row) {
513
+ const series = `${layerIndex}`
514
+ columns.push([series, row.y])
515
+ types[series] = this.getLayerType(design, layerIndex)
516
+
517
+ // Name is name of entire layer
518
+ names[series] = layer.name || (design.layers.length === 1 ? "Value" : `Series ${layerIndex + 1}`)
519
+ dataMap[series] = { layerIndex, row }
520
+ format[series] = (value: any) =>
521
+ value != null ? this.axisBuilder.formatValue(layer.axes.y!, value, locale, true) : ""
522
+
523
+ // Set color if present
524
+ if (layer.color) {
525
+ colors[series] = layer.color
526
+ }
527
+ }
528
+ }
529
+ })
530
+
531
+ // Determine order (default is desc)
532
+ if (design.polarOrder === "desc") {
533
+ order = "desc"
534
+ } else if (design.polarOrder === "asc") {
535
+ order = "asc"
536
+ } else if (design.polarOrder === "natural") {
537
+ order = null
538
+ } else {
539
+ order = "desc"
540
+ }
541
+
542
+ return {
543
+ columns,
544
+ types,
545
+ names,
546
+ dataMap,
547
+ colors,
548
+ xAxisType: "category", // Polar charts are always category x-axis
549
+ titleText: this.compileTitleText(design, locale),
550
+ order,
551
+ format
552
+ }
553
+ }
554
+
555
+ // Compiles data for a chart like line or scatter that does not have a categorical x axis
556
+ compileDataNonCategorical(design: LayeredChartDesign, data: C3ChartData, locale?: string): C3Data {
557
+ const columns: any = []
558
+ const types = {}
559
+ const names = {}
560
+ const dataMap = {}
561
+ const colors = {}
562
+ const xs = {}
563
+ let groups: any = []
564
+ const format = {}
565
+ const legendHide: any = [] // Which series to hide
566
+ const classes = {} // Custom classes to add to series
567
+
568
+ const xType = this.axisBuilder.getAxisType(design.layers[0].axes.x)
569
+
570
+ // For each layer
571
+ _.each(design.layers, (layer, layerIndex) => {
572
+ // Get data of layer
573
+ let layerData = data[`layer${layerIndex}`]
574
+ this.fixStringYValues(layerData)
575
+
576
+ if (layer.cumulative) {
577
+ layerData = this.makeRowsCumulative(layerData)
578
+ }
579
+
580
+ // Remove excluded values
581
+ layerData = _.filter(layerData, (row) => !_.includes(layer.axes.x!.excludedValues || [], row.x))
582
+
583
+ // If has color axis
584
+ if (layer.axes.color) {
585
+ // Create a series for each color value
586
+ let colorValues = _.uniq(_.pluck(layerData, "color"))
587
+
588
+ // Sort color values by category order:
589
+ // Get categories
590
+ const categories = this.axisBuilder.getCategories(layer.axes.color, colorValues, { locale })
591
+
592
+ // Get indexed ordering of categories (lookup from value to index) without removing excluded values
593
+ const categoryOrder = _.zipObject(_.map(categories, (c, i) => [c.value, i]))
594
+
595
+ // Sort
596
+ colorValues = _.sortBy(colorValues, (v) => categoryOrder[v])
597
+
598
+ // Exclude excluded ones
599
+ colorValues = _.difference(colorValues, layer.axes.color.excludedValues || [])
600
+
601
+ // For each color value
602
+ _.each(colorValues, (colorValue) => {
603
+ // One series for x values, one for y
604
+ const seriesX = `${layerIndex}:${colorValue}:x`
605
+ const seriesY = `${layerIndex}:${colorValue}:y`
606
+
607
+ // Get specific color if present
608
+ let color = this.axisBuilder.getValueColor(layer.axes.color!, colorValue)
609
+ color = color || layer.color || null
610
+ if (color) {
611
+ colors[seriesY] = color
612
+ }
613
+
614
+ // Get rows for this series
615
+ const rows = _.where(layerData, { color: colorValue })
616
+
617
+ const yValues = _.pluck(rows, "y")
618
+
619
+ columns.push([seriesY].concat(yValues))
620
+ columns.push([seriesX].concat(_.pluck(rows, "x")))
621
+
622
+ types[seriesY] = this.getLayerType(design, layerIndex)
623
+ names[seriesY] = this.axisBuilder.formatValue(layer.axes.color!, colorValue, locale, true)
624
+ xs[seriesY] = seriesX
625
+ format[seriesY] = (value: any) =>
626
+ value != null ? this.axisBuilder.formatValue(layer.axes.y!, value, locale, true) : ""
627
+
628
+ _.each(rows, (row, rowIndex) => {
629
+ dataMap[`${seriesY}:${rowIndex}`] = { layerIndex, row }
630
+ })
631
+ })
632
+ } else {
633
+ // One series for x values, one for y
634
+ const seriesX = `${layerIndex}:x`
635
+ const seriesY = `${layerIndex}:y`
636
+
637
+ const yValues = _.pluck(layerData, "y")
638
+ const xValues = _.pluck(layerData, "x")
639
+
640
+ columns.push([seriesY].concat(yValues))
641
+ columns.push([seriesX].concat(xValues))
642
+
643
+ types[seriesY] = this.getLayerType(design, layerIndex)
644
+ names[seriesY] = layer.name || (design.layers.length === 1 ? "Value" : `Series ${layerIndex + 1}`)
645
+ xs[seriesY] = seriesX
646
+ colors[seriesY] = layer.color || defaultColors[layerIndex]
647
+ format[seriesY] = (value: any) =>
648
+ value != null ? this.axisBuilder.formatValue(layer.axes.y!, value, locale, true) : ""
649
+
650
+ // Add data map for each row
651
+ _.each(layerData, (row, rowIndex) => {
652
+ return (dataMap[`${seriesY}:${rowIndex}`] = { layerIndex, row })
653
+ })
654
+
655
+ // Add trendline
656
+ if (layer.trendline === "linear") {
657
+ const trendlineSeries = seriesY + ":trendline"
658
+ columns.push([trendlineSeries].concat(calculateLinearRegression(yValues, xValues)))
659
+ types[trendlineSeries] = line()
660
+ names[trendlineSeries] = names[seriesY] + " Trendline"
661
+ xs[trendlineSeries] = seriesX
662
+ colors[trendlineSeries] = layer.color || defaultColors[layerIndex]
663
+ legendHide.push(trendlineSeries) // Hide in legend
664
+ format[trendlineSeries] = (value: any) =>
665
+ value != null ? this.axisBuilder.formatValue(layer.axes.y!, d3Round(value), locale, true) : ""
666
+ // Set dots as invisible in CSS and line as dashed
667
+ classes[trendlineSeries] = "trendline"
668
+ }
669
+ }
670
+ })
671
+
672
+ // Stack by putting into groups
673
+ if (design.stacked) {
674
+ groups = [_.keys(names)]
675
+ }
676
+
677
+ return {
678
+ columns,
679
+ types,
680
+ names,
681
+ groups,
682
+ dataMap,
683
+ colors,
684
+ xs,
685
+ legendHide,
686
+ classes,
687
+ xAxisType: ["date"].includes(xType || "") ? "timeseries" : "indexed",
688
+ xAxisTickFit: false, // Don't put a tick for each point
689
+ xAxisLabelText: this.compileXAxisLabelText(design, locale),
690
+ yAxisLabelText: this.compileYAxisLabelText(design, locale),
691
+ titleText: this.compileTitleText(design, locale),
692
+ order: undefined, // Use order of data for stacking
693
+ format
694
+ }
695
+ }
696
+
697
+ // Numbers sometimes arrive as strings from database. Fix by parsing
698
+ fixStringYValues(rows: any = []) {
699
+ for (let row of rows) {
700
+ if (_.isString(row.y)) {
701
+ row.y = parseFloat(row.y)
702
+ }
703
+ }
704
+ return rows
705
+ }
706
+
707
+ // Flatten if x-type is enumset. e.g. if one row has x = ["a", "b"], make into two rows with x="a" and x="b", summing if already exists
708
+ flattenRowData(rows: any) {
709
+ const flatRows = []
710
+ for (var row of rows) {
711
+ // Handle null
712
+ var xs
713
+ if (!row.x) {
714
+ flatRows.push(row)
715
+ continue
716
+ }
717
+
718
+ if (_.isString(row.x)) {
719
+ // Handle failed parsings graciously in case question used to be a non-array
720
+ try {
721
+ xs = JSON.parse(row.x)
722
+ } catch (error) {
723
+ xs = row.x
724
+ }
725
+ } else {
726
+ xs = row.x
727
+ }
728
+
729
+ for (var x of xs) {
730
+ // Find existing row
731
+ const existingRow = _.find(flatRows, (r) => r.x === x && r.color === row.color)
732
+ if (existingRow) {
733
+ existingRow.y += row.y
734
+ } else {
735
+ flatRows.push(_.extend({}, row, { x }))
736
+ }
737
+ }
738
+ }
739
+
740
+ return flatRows
741
+ }
742
+
743
+ compileDataCategorical(design: LayeredChartDesign, data: C3ChartData, locale?: string): C3Data {
744
+ let categoryXs: any
745
+ const columns: any[][] = []
746
+ const types = {}
747
+ const names = {}
748
+ const dataMap = {}
749
+ const colors = {}
750
+ const xs = {}
751
+ let groups: any[][] = []
752
+ const format = {}
753
+ const colorOverrides = {} // Mapping of "<layer>:<index>" to color if overridden
754
+ const legendHide: any = [] // Which series to hide
755
+ const classes = {} // Custom classes to add to series
756
+
757
+ // Get all values of the x-axis, taking into account values that might be missing
758
+ const xAxis: Axis = _.extend({}, design.layers[0].axes.x)
759
+ const nullLabel: string | undefined = _.first(_.compact(design.layers.map((l: any) => l.axes.x.nullLabel)))
760
+ xAxis.nullLabel = nullLabel
761
+
762
+ const xType = this.axisBuilder.getAxisType(xAxis)
763
+
764
+ // Get all known values from all layers
765
+ let xValues: any = []
766
+ _.each(design.layers, (layer, layerIndex) => {
767
+ // Get data of layer
768
+ const layerData = data[`layer${layerIndex}`]
769
+ return (xValues = _.union(xValues, _.uniq(_.pluck(layerData, "x"))))
770
+ })
771
+
772
+ // Categories will be in form [{ value, label }]
773
+ let categories = this.axisBuilder.getCategories(xAxis, xValues, { locale, onlyValuesPresent: design.layers[0].xAxisOnlyValuesPresent })
774
+
775
+ // Get indexed ordering of categories (lookup from value to index) without removing excluded values
776
+ const categoryOrder = _.zipObject(_.map(categories, (c, i) => [c.value, i]))
777
+
778
+ // Exclude excluded values
779
+ categories = _.filter(categories, (category) => !_.includes(xAxis.excludedValues || [], category.value))
780
+
781
+ // Limit categories to prevent crashes in C3 (https://github.com/mWater/mwater-visualization/issues/272)
782
+ if (xType !== "enumset") {
783
+ // Take last ones to make dates prettier (enough to show all weeks)
784
+ categories = _.takeRight(categories, 55)
785
+ categoryXs = _.indexBy(categories, "value")
786
+ }
787
+
788
+ // Create map of category value to index
789
+ const categoryMap = _.object(_.map(categories, (c, i) => [c.value, i]))
790
+
791
+ // Create common x series
792
+ columns.push(["x"].concat(_.map(categories, (category) => this.axisBuilder.formatCategory(xAxis, category))))
793
+
794
+ // For each layer
795
+ _.each(design.layers, (layer, layerIndex) => {
796
+ // Get data of layer
797
+ let column, series: any
798
+ let layerData = data[`layer${layerIndex}`]
799
+
800
+ // Fix string y values
801
+ layerData = this.fixStringYValues(layerData)
802
+
803
+ // Flatten if x-type is enumset. e.g. if one row has x = ["a", "b"], make into two rows with x="a" and x="b", summing if already exists
804
+ if (xType === "enumset") {
805
+ layerData = this.flattenRowData(layerData)
806
+ }
807
+
808
+ // Reorder to category order for x-axis
809
+ layerData = _.sortBy(layerData, (row) => categoryOrder[row.x])
810
+
811
+ // Make rows cumulative
812
+ if (layer.cumulative) {
813
+ layerData = this.makeRowsCumulative(layerData)
814
+ }
815
+
816
+ // Filter out categories that were removed
817
+ if (xType !== "enumset") {
818
+ layerData = _.filter(layerData, (row) => categoryXs[row.x] != null)
819
+ }
820
+
821
+ // If has color axis
822
+ if (layer.axes.color) {
823
+ // Create a series for each color value
824
+ let colorValues = _.uniq(_.pluck(layerData, "color"))
825
+
826
+ // Sort color values by category order:
827
+ // Get categories
828
+ const colorCategories = this.axisBuilder.getCategories(layer.axes.color, colorValues, { locale })
829
+
830
+ // Get indexed ordering of categories (lookup from value to index) without removing excluded values
831
+ const colorCategoryOrder = _.zipObject(_.map(colorCategories, (c, i) => [c.value, i]))
832
+
833
+ // Sort
834
+ colorValues = _.sortBy(colorValues, (v) => colorCategoryOrder[v])
835
+
836
+ // Exclude excluded ones
837
+ colorValues = _.difference(colorValues, layer.axes.color.excludedValues || [])
838
+
839
+ if (colorValues.length > 0) {
840
+ _.each(colorValues, (colorValue) => {
841
+ // One series for y values
842
+ const series = `${layerIndex}:${colorValue}`
843
+
844
+ // Get specific color if present
845
+ let color: string | undefined | null = this.axisBuilder.getValueColor(layer.axes.color!, colorValue)
846
+ color = color || layer.color
847
+ if (color) {
848
+ colors[series] = color
849
+ }
850
+
851
+ // Get rows for this series
852
+ const rows = _.where(layerData, { color: colorValue })
853
+
854
+ // Create empty series
855
+ const column: any[] = _.map(categories, (c) => null)
856
+
857
+ // Set rows
858
+ _.each(rows, (row) => {
859
+ // Get index
860
+ const index = categoryMap[row.x]
861
+ if (index != null) {
862
+ column[index] = row.y
863
+ dataMap[`${series}:${index}`] = { layerIndex, row }
864
+ }
865
+ })
866
+
867
+ // Fill in nulls if cumulative
868
+ if (layer.cumulative) {
869
+ for (let i = 0; i < column.length; i++) {
870
+ const value = column[i]
871
+ if (value == null && i > 0) {
872
+ column[i] = column[i - 1]
873
+ }
874
+ }
875
+ }
876
+
877
+ columns.push([series].concat(column))
878
+
879
+ types[series] = this.getLayerType(design, layerIndex)
880
+ names[series] = this.axisBuilder.formatValue(layer.axes.color!, colorValue, locale, true)
881
+ xs[series] = "x"
882
+ format[series] = (value: any) =>
883
+ value != null ? this.axisBuilder.formatValue(layer.axes.y!, value, locale, true) : ""
884
+ })
885
+ } else {
886
+ //c3 acts funny when there is a split axis but no data
887
+ series = `${layerIndex}:dumm`
888
+ column = _.map(categories, (c) => null)
889
+ columns.push([series].concat(column))
890
+
891
+ types[series] = this.getLayerType(design, layerIndex)
892
+ names[series] = this.axisBuilder.formatValue(layer.axes.color, null, locale, true)
893
+ xs[series] = "x"
894
+ format[series] = (value: any) =>
895
+ value != null ? this.axisBuilder.formatValue(layer.axes.y!, value, locale, true) : ""
896
+ }
897
+ } else {
898
+ // One series for y
899
+ series = `${layerIndex}`
900
+
901
+ // Create empty series
902
+ column = _.map(categories, (c) => null)
903
+
904
+ // Set rows
905
+ _.each(layerData, (row) => {
906
+ // Skip if value excluded
907
+ if (_.includes(layer.axes.x!.excludedValues || [], row.x)) {
908
+ return
909
+ }
910
+
911
+ // Get index
912
+ const index = categoryMap[row.x]
913
+ column[index] = row.y
914
+ dataMap[`${series}:${index}`] = { layerIndex, row }
915
+
916
+ // Get color override
917
+ if (layer.xColorMap) {
918
+ const color = this.axisBuilder.getValueColor(layer.axes.x!, row.x)
919
+ if (color) {
920
+ colorOverrides[`${series}:${index}`] = color
921
+ }
922
+ }
923
+ })
924
+
925
+ columns.push([series].concat(column))
926
+
927
+ types[series] = this.getLayerType(design, layerIndex)
928
+ names[series] = layer.name || (design.layers.length === 1 ? "Value" : `Series ${layerIndex + 1}`)
929
+ xs[series] = "x"
930
+ colors[series] = layer.color || defaultColors[layerIndex]
931
+ format[series] = (value: any) =>
932
+ value != null ? this.axisBuilder.formatValue(layer.axes.y!, value, locale, true) : ""
933
+
934
+ // Add trendline
935
+ if (layer.trendline === "linear") {
936
+ const trendlineSeries = series + ":trendline"
937
+ let trendXs = _.range(column.length)
938
+ let trendYs = column
939
+ // Skip null last value
940
+ if (categories.length > 0 && _.last(categories).value === null) {
941
+ trendXs = _.initial(trendXs)
942
+ trendYs = _.initial(trendYs)
943
+ }
944
+ columns.push([trendlineSeries].concat(calculateLinearRegression(trendYs, trendXs)))
945
+ types[trendlineSeries] = line()
946
+ names[trendlineSeries] = names[series] + " Trendline"
947
+ xs[trendlineSeries] = "x"
948
+ colors[trendlineSeries] = layer.color || defaultColors[layerIndex]
949
+ legendHide.push(trendlineSeries) // Hide in legend
950
+ format[trendlineSeries] = (value: any) =>
951
+ value != null ? this.axisBuilder.formatValue(layer.axes.y!, d3Round(value), locale, true) : ""
952
+
953
+ // Set dots as invisible in CSS and line as dashed
954
+ classes[trendlineSeries] = "trendline"
955
+ }
956
+ }
957
+ })
958
+
959
+ // Stack by putting into groups
960
+ if (design.stacked) {
961
+ groups = [_.keys(names)]
962
+ } else if (design.layers.length > 1) {
963
+ groups = []
964
+ for (var layerIndex = 0; layerIndex < design.layers.length; layerIndex++) {
965
+ // If has multiple layers and color axes within layers. Stack individual layers unless stacked is false
966
+ const layer = design.layers[layerIndex]
967
+ const defaultStacked = layer.axes.color != null
968
+ const stacked = layer.stacked != null ? layer.stacked : defaultStacked
969
+
970
+ if (stacked) {
971
+ groups.push(_.filter(_.keys(names), (series) => series.split(":")[0] === `${layerIndex}`))
972
+ }
973
+ }
974
+
975
+ // Remove empty groups
976
+ groups = _.filter(groups, (g) => g.length > 1)
977
+ }
978
+
979
+ // If proportional
980
+ if (design.proportional) {
981
+ // Calculate total for each x
982
+ let column, i
983
+ const xtotals: any = []
984
+ for (column of columns) {
985
+ // Skip x column
986
+ if (column[0] === "x") {
987
+ continue
988
+ }
989
+
990
+ for (let i = 1 ; i < column.length ; i++) {
991
+ xtotals[i] = (xtotals[i] || 0) + (column[i] || 0)
992
+ }
993
+ }
994
+
995
+ // Now make percentage with one decimal
996
+ for (column of columns) {
997
+ // Skip x column
998
+ var asc1, end1
999
+ if (column[0] === "x") {
1000
+ continue
1001
+ }
1002
+
1003
+ for (let i = 1 ; i < column.length ; i++) {
1004
+ if (column[i] > 0) {
1005
+ column[i] = Math.round(((100 * column[i]) / xtotals[i]) * 10) / 10
1006
+ }
1007
+ }
1008
+ }
1009
+ }
1010
+
1011
+ return {
1012
+ columns,
1013
+ types,
1014
+ names,
1015
+ dataMap,
1016
+ colors,
1017
+ xs,
1018
+ groups,
1019
+ legendHide,
1020
+ classes,
1021
+ xAxisType: "category",
1022
+ xAxisTickFit: xType !== "date", // Put a tick for each point since categorical unless date
1023
+ xAxisLabelText: this.compileXAxisLabelText(design, locale),
1024
+ yAxisLabelText: this.compileYAxisLabelText(design, locale),
1025
+ titleText: this.compileTitleText(design, locale),
1026
+ order: null, // Use order of data for stacking
1027
+ format,
1028
+ color: (color: any, d: any) => {
1029
+ // Handle overall series color which calls with a non-object for d
1030
+ if (typeof d !== "object") {
1031
+ // Overall series is not changed in color
1032
+ return color
1033
+ }
1034
+
1035
+ const key = `${d.id}:${d.index}`
1036
+ if (colorOverrides[key]) {
1037
+ color = colorOverrides[key]
1038
+ }
1039
+
1040
+ // Apply thresholds (in order)
1041
+ const sortedYThresholds = _.sortBy(design.yThresholds || [], "value")
1042
+ for (let yThreshold of sortedYThresholds) {
1043
+ if (yThreshold.value != null && d.value > yThreshold.value && yThreshold.highlightColor) {
1044
+ color = yThreshold.highlightColor
1045
+ }
1046
+ }
1047
+
1048
+ return color
1049
+ }
1050
+ }
1051
+ }
1052
+
1053
+ // Compile an expression
1054
+ compileExpr(expr: any) {
1055
+ const exprCompiler = new ExprCompiler(this.schema)
1056
+ return exprCompiler.compileExpr({ expr, tableAlias: "main" })
1057
+ }
1058
+
1059
+ // Get layer type, defaulting to overall type
1060
+ getLayerType(design: any, layerIndex: any) {
1061
+ // Special handling for mocha tests where chartTypes has all undefined values
1062
+ // See https://github.com/mWater/mwater-visualization/issues/453#issuecomment-1103671467
1063
+ const chartTypeString = design.layers[layerIndex].type || design.type
1064
+ if (chartTypes[chartTypeString]) {
1065
+ return chartTypes[chartTypeString]()
1066
+ }
1067
+ return chartTypeString
1068
+ }
1069
+
1070
+ getLayerTypeString(design: any, layerIndex: any) {
1071
+ return design.layers[layerIndex].type || design.type
1072
+ }
1073
+
1074
+ // Determine if layer required grouping by x (and color)
1075
+ doesLayerNeedGrouping(design: any, layerIndex: any) {
1076
+ return this.getLayerTypeString(design, layerIndex) !== "scatter"
1077
+ }
1078
+
1079
+ // Determine if layer can use x axis
1080
+ canLayerUseXExpr(design: any, layerIndex: any) {
1081
+ let needle
1082
+ return (needle = this.getLayerTypeString(design, layerIndex)), !["pie", "donut"].includes(needle)
1083
+ }
1084
+
1085
+ isXAxisRequired(design: any, layerIndex: any) {
1086
+ let needle
1087
+ return _.any(
1088
+ design.layers,
1089
+ (layer, i) => ((needle = this.getLayerTypeString(design, i)), !["pie", "donut"].includes(needle))
1090
+ )
1091
+ }
1092
+
1093
+ isColorAxisRequired(design: any, layerIndex: any) {
1094
+ let needle
1095
+ return (needle = this.getLayerTypeString(design, layerIndex)), ["pie", "donut"].includes(needle)
1096
+ }
1097
+
1098
+ compileDefaultTitleText(design: any, locale: any) {
1099
+ // Don't default this for now
1100
+ return ""
1101
+ }
1102
+ // if design.layers[0].axes.x
1103
+ // return @compileYAxisLabelText(design) + " by " + @compileXAxisLabelText(design)
1104
+ // else
1105
+ // return @compileYAxisLabelText(design) + " by " + @axisBuilder.summarizeAxis(design.layers[0].axes.color)
1106
+
1107
+ compileDefaultYAxisLabelText(design: any, locale?: string) {
1108
+ return this.axisBuilder.summarizeAxis(design.layers[0].axes.y, locale)
1109
+ }
1110
+
1111
+ compileDefaultXAxisLabelText(design: any, locale?: string) {
1112
+ return this.axisBuilder.summarizeAxis(design.layers[0].axes.x, locale)
1113
+ }
1114
+
1115
+ compileTitleText(design: any, locale?: string) {
1116
+ return design.titleText || this.compileDefaultTitleText(design, locale)
1117
+ }
1118
+
1119
+ compileYAxisLabelText(design: any, locale?: string) {
1120
+ if (design.yAxisLabelText === "") {
1121
+ return this.compileDefaultYAxisLabelText(design, locale)
1122
+ }
1123
+ return design.yAxisLabelText
1124
+ }
1125
+
1126
+ compileXAxisLabelText(design: any, locale: any) {
1127
+ if (design.xAxisLabelText === "") {
1128
+ return this.compileDefaultXAxisLabelText(design, locale)
1129
+ }
1130
+ return design.xAxisLabelText
1131
+ }
1132
+
1133
+ // Create a scope based on a row of a layer
1134
+ // Scope data is relevant data from row that uniquely identifies scope
1135
+ // plus a layer index
1136
+ createScope(design: LayeredChartDesign, layerIndex: number, row: any, locale?: string): WidgetScope {
1137
+ let filter: JsonQLFilter, filterExpr: Expr
1138
+
1139
+ // Get layer
1140
+ const layer = design.layers[layerIndex]
1141
+
1142
+ const filters: JsonQLExpr[] = []
1143
+ const filterExprs: Expr[] = []
1144
+ const names: string[] = []
1145
+ const data: any = { layerIndex }
1146
+
1147
+ // If x
1148
+ if (layer.axes.x) {
1149
+ // Handle special case of enumset which is flattened to enum type
1150
+ if (this.axisBuilder.getAxisType(layer.axes.x) === "enumset") {
1151
+ filters.push({
1152
+ type: "op",
1153
+ op: "@>",
1154
+ exprs: [
1155
+ {
1156
+ type: "op",
1157
+ op: "::jsonb",
1158
+ exprs: [this.axisBuilder.compileAxis({ axis: layer.axes.x, tableAlias: "{alias}" })]
1159
+ },
1160
+ { type: "op", op: "::jsonb", exprs: [JSON.stringify(row.x)] }
1161
+ ]
1162
+ })
1163
+ filterExprs.push({
1164
+ table: layer.table,
1165
+ type: "op",
1166
+ op: "contains",
1167
+ exprs: [
1168
+ this.axisBuilder.convertAxisToExpr(layer.axes.x),
1169
+ { type: "literal", valueType: "enumset", value: [row.x] }
1170
+ ]
1171
+ })
1172
+
1173
+ names.push(
1174
+ this.axisBuilder.summarizeAxis(layer.axes.x, locale) +
1175
+ " includes " +
1176
+ this.exprUtils.stringifyExprLiteral(layer.axes.x.expr, [row.x], locale)
1177
+ )
1178
+ data.x = row.x
1179
+ } else {
1180
+ filters.push(this.axisBuilder.createValueFilter(layer.axes.x, row.x))
1181
+ filterExprs.push(this.axisBuilder.createValueFilterExpr(layer.axes.x, row.x))
1182
+ names.push(
1183
+ this.axisBuilder.summarizeAxis(layer.axes.x, locale) +
1184
+ " is " +
1185
+ this.axisBuilder.formatValue(layer.axes.x, row.x, locale, true)
1186
+ )
1187
+ data.x = row.x
1188
+ }
1189
+ }
1190
+
1191
+ if (layer.axes.color) {
1192
+ filters.push(this.axisBuilder.createValueFilter(layer.axes.color, row.color))
1193
+ filterExprs.push(this.axisBuilder.createValueFilterExpr(layer.axes.color, row.color))
1194
+ names.push(
1195
+ this.axisBuilder.summarizeAxis(layer.axes.color, locale) +
1196
+ " is " +
1197
+ this.axisBuilder.formatValue(layer.axes.color, row.color, locale, true)
1198
+ )
1199
+ data.color = row.color
1200
+ }
1201
+
1202
+ if (filters.length > 1) {
1203
+ filter = {
1204
+ table: layer.table,
1205
+ jsonql: {
1206
+ type: "op",
1207
+ op: "and",
1208
+ exprs: filters
1209
+ }
1210
+ }
1211
+ filterExpr = {
1212
+ table: layer.table,
1213
+ type: "op",
1214
+ op: "and",
1215
+ exprs: filterExprs
1216
+ }
1217
+ } else {
1218
+ filter = {
1219
+ table: layer.table,
1220
+ jsonql: filters[0]
1221
+ }
1222
+ filterExpr = filterExprs[0]
1223
+ }
1224
+
1225
+ const scope: WidgetScope = {
1226
+ name: ExprUtils.localizeString(this.schema.getTable(layer.table)!.name, locale) + " " + names.join(" and "),
1227
+ filter,
1228
+ filterExpr,
1229
+ data
1230
+ }
1231
+
1232
+ return scope
1233
+ }
1234
+
1235
+ // Converts a series of rows to have cumulative y axis, separating out by color axis if present
1236
+ makeRowsCumulative(rows: any) {
1237
+ // Indexed by color
1238
+ const totals = {}
1239
+
1240
+ const newRows = []
1241
+ for (let row of rows) {
1242
+ // Add up total
1243
+ const total = totals[row.color] || 0
1244
+ const y = total + row.y
1245
+ totals[row.color] = y
1246
+
1247
+ // If x is null, don't make cumulative
1248
+ if (row.x === null) {
1249
+ newRows.push(row)
1250
+ } else {
1251
+ // Create new row
1252
+ newRows.push(_.extend({}, row, { y }))
1253
+ }
1254
+ }
1255
+
1256
+ return newRows
1257
+ }
1258
+ }
1259
+
1260
+ // Clean out nbsp (U+00A0) as it causes c3 errors
1261
+ function cleanString(str: any) {
1262
+ if (!str) {
1263
+ return str
1264
+ }
1265
+ return str.replace("\u00A0", " ")
1266
+ }
1267
+
1268
+ // Calculate a linear regression, returning a series of y values that match the x values
1269
+ function calculateLinearRegression(ys: any[], xs: any[]): any[] {
1270
+ // If xs are dates, convert to numbers
1271
+ if (_.isString(xs[0])) {
1272
+ xs = _.map(xs, (x) => Date.parse(x))
1273
+ }
1274
+
1275
+ // Remove null ys
1276
+ const nonNullxs = _.filter(xs, (x, index) => ys[index] !== null)
1277
+ const nonNullys = _.filter(ys, (y, index) => ys[index] !== null)
1278
+
1279
+ const n = nonNullys.length
1280
+
1281
+ const sumXY = _.sum(_.map(nonNullxs, (x, i) => x * nonNullys[i]))
1282
+
1283
+ const sumXX = _.sum(_.map(nonNullxs, (x) => x * x))
1284
+
1285
+ const sumX = _.sum(nonNullxs)
1286
+
1287
+ const sumY = _.sum(nonNullys)
1288
+
1289
+ // Calculate denominator
1290
+ const den = n * sumXX - sumX * sumX
1291
+
1292
+ // Calculate slope
1293
+ const slope = (n * sumXY - sumX * sumY) / den
1294
+
1295
+ // Calculate intercept
1296
+ const intercept = (sumY * sumXX - sumX * sumXY) / den
1297
+
1298
+ return _.map(xs, (x) => x * slope + intercept)
1299
+ }