@mwater/visualization 5.4.1 → 5.4.2

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 (269) hide show
  1. package/lib/ColorComponent.js +2 -1
  2. package/lib/IdSelection.d.ts +16 -0
  3. package/lib/IdSelection.js +59 -0
  4. package/lib/MWaterAddRelatedIndicatorComponent.js +2 -2
  5. package/lib/MWaterCompleteTableSelectComponent.d.ts +3 -8
  6. package/lib/MWaterCompleteTableSelectComponent.js +36 -42
  7. package/lib/MWaterLoaderComponent.d.ts +11 -10
  8. package/lib/MWaterLoaderComponent.js +1 -1
  9. package/lib/MWaterResponsesFilterComponent.js +1 -1
  10. package/lib/MWaterTableSelectComponent.d.ts +0 -1
  11. package/lib/MWaterTableSelectComponent.js +4 -6
  12. package/lib/autotranslate.d.ts +20 -0
  13. package/lib/autotranslate.js +122 -0
  14. package/lib/axes/AxisBuilder.js +3 -3
  15. package/lib/axes/AxisColorEditorComponent.js +4 -0
  16. package/lib/axes/AxisComponent.d.ts +8 -12
  17. package/lib/axes/AxisComponent.js +32 -80
  18. package/lib/axes/CategoryMapComponent.js +4 -4
  19. package/lib/axes/RangesComponent.js +2 -2
  20. package/lib/dashboards/DashboardComponent.d.ts +6 -0
  21. package/lib/dashboards/DashboardComponent.js +44 -12
  22. package/lib/dashboards/DashboardDesign.d.ts +11 -2
  23. package/lib/dashboards/DashboardUtils.d.ts +5 -0
  24. package/lib/dashboards/DashboardUtils.js +30 -0
  25. package/lib/dashboards/DashboardViewComponent.d.ts +2 -0
  26. package/lib/dashboards/DashboardViewComponent.js +16 -3
  27. package/lib/dashboards/ServerDashboardDataSource.js +2 -1
  28. package/lib/dashboards/SettingsModalComponent.d.ts +1 -1
  29. package/lib/dashboards/SettingsModalComponent.js +256 -19
  30. package/lib/dashboards/WidgetComponent.d.ts +6 -3
  31. package/lib/dashboards/WidgetComponent.js +3 -1
  32. package/lib/datagrids/CellEditor.d.ts +19 -0
  33. package/lib/datagrids/CellEditor.js +223 -0
  34. package/lib/datagrids/DatagridComponent.d.ts +18 -87
  35. package/lib/datagrids/DatagridComponent.js +304 -222
  36. package/lib/datagrids/DatagridViewComponent.d.ts +15 -53
  37. package/lib/datagrids/DatagridViewComponent.js +256 -257
  38. package/lib/datagrids/DirectDatagridDataSource.js +2 -3
  39. package/lib/datagrids/ExprCellComponent.d.ts +8 -15
  40. package/lib/datagrids/ExprCellComponent.js +11 -15
  41. package/lib/datagrids/FindReplaceModalComponent.d.ts +4 -6
  42. package/lib/datagrids/FindReplaceModalComponent.js +38 -75
  43. package/lib/index.css +1 -1
  44. package/lib/index.d.ts +0 -1
  45. package/lib/index.js +0 -1
  46. package/lib/layouts/blocks/HorizontalBlockComponent.js +2 -2
  47. package/lib/mWaterLoader.d.ts +1 -1
  48. package/lib/maps/BufferLayer.d.ts +7 -5
  49. package/lib/maps/BufferLayer.js +69 -48
  50. package/lib/maps/BufferLayerDesign.d.ts +21 -14
  51. package/lib/maps/BufferLayerDesignerComponent.d.ts +16 -31
  52. package/lib/maps/BufferLayerDesignerComponent.js +68 -102
  53. package/lib/maps/ChoroplethLayer.d.ts +5 -4
  54. package/lib/maps/ChoroplethLayer.js +32 -9
  55. package/lib/maps/ChoroplethLayerDesign.d.ts +6 -2
  56. package/lib/maps/ChoroplethLayerDesigner.js +4 -2
  57. package/lib/maps/ClusterLayer.d.ts +3 -4
  58. package/lib/maps/ClusterLayer.js +2 -1
  59. package/lib/maps/DetailLevelSelectComponent.js +1 -1
  60. package/lib/maps/DirectMapDataSource.js +2 -1
  61. package/lib/maps/EditPopupComponent.js +5 -3
  62. package/lib/maps/GridLayer.d.ts +3 -4
  63. package/lib/maps/GridLayer.js +2 -1
  64. package/lib/maps/GridLayerDesigner.js +5 -3
  65. package/lib/maps/HoverContent.d.ts +11 -3
  66. package/lib/maps/HoverContent.js +25 -9
  67. package/lib/maps/Layer.d.ts +24 -3
  68. package/lib/maps/Layer.js +5 -1
  69. package/lib/maps/LayerFactory.js +0 -8
  70. package/lib/maps/LayerLegendComponent.js +0 -1
  71. package/lib/maps/LayerSwitcherComponent.d.ts +1 -0
  72. package/lib/maps/LayerSwitcherComponent.js +1 -1
  73. package/lib/maps/LeafletMapComponent.js +3 -1
  74. package/lib/maps/LegendComponent.d.ts +1 -0
  75. package/lib/maps/LegendComponent.js +9 -1
  76. package/lib/maps/MWaterServerLayer.d.ts +2 -2
  77. package/lib/maps/MWaterServerLayer.js +2 -2
  78. package/lib/maps/MapComponent.js +3 -3
  79. package/lib/maps/MapDesign.d.ts +2 -0
  80. package/lib/maps/MapDesignerComponent.d.ts +4 -3
  81. package/lib/maps/MapDesignerComponent.js +68 -74
  82. package/lib/maps/MapLayerViewDesignerComponent.js +2 -2
  83. package/lib/maps/MapUtils.d.ts +4 -0
  84. package/lib/maps/MapUtils.js +19 -0
  85. package/lib/maps/MapViewComponent.d.ts +8 -3
  86. package/lib/maps/MarkersLayer.d.ts +5 -4
  87. package/lib/maps/MarkersLayer.js +33 -7
  88. package/lib/maps/MarkersLayerDesign.d.ts +19 -16
  89. package/lib/maps/PopupFilterJoinsUtils.d.ts +6 -3
  90. package/lib/maps/PopupFilterJoinsUtils.js +0 -6
  91. package/lib/maps/RasterMapViewComponent.d.ts +3 -31
  92. package/lib/maps/RasterMapViewComponent.js +7 -2
  93. package/lib/maps/ServerMapDataSource.js +2 -1
  94. package/lib/maps/SwitchableTileUrlLayer.d.ts +3 -3
  95. package/lib/maps/SwitchableTileUrlLayer.js +2 -1
  96. package/lib/maps/TileUrlLayer.d.ts +4 -5
  97. package/lib/maps/TileUrlLayer.js +2 -1
  98. package/lib/maps/VectorMapViewComponent.d.ts +5 -37
  99. package/lib/maps/VectorMapViewComponent.js +19 -8
  100. package/lib/maps/maps.d.ts +3 -0
  101. package/lib/quickfilter/QuickfiltersComponent.d.ts +2 -0
  102. package/lib/quickfilter/QuickfiltersComponent.js +9 -7
  103. package/lib/quickfilter/QuickfiltersDesignComponent.d.ts +1 -1
  104. package/lib/quickfilter/QuickfiltersDesignComponent.js +19 -35
  105. package/lib/richtext/ExprItemsHtmlConverter.d.ts +5 -2
  106. package/lib/richtext/ExprItemsHtmlConverter.js +4 -4
  107. package/lib/richtext/ExprItemsTranslator.d.ts +5 -0
  108. package/lib/richtext/ExprItemsTranslator.js +149 -0
  109. package/lib/richtext/ItemsHtmlConverter.d.ts +1 -1
  110. package/lib/richtext/ItemsHtmlConverter.js +31 -15
  111. package/lib/wellknown.js +12 -9
  112. package/lib/widgets/IFrameWidget.d.ts +4 -4
  113. package/lib/widgets/ImageWidget.d.ts +7 -4
  114. package/lib/widgets/ImageWidget.js +9 -1
  115. package/lib/widgets/ImageWidgetComponent.d.ts +1 -0
  116. package/lib/widgets/ImageWidgetComponent.js +1 -1
  117. package/lib/widgets/MapWidget.d.ts +5 -48
  118. package/lib/widgets/MapWidget.js +26 -63
  119. package/lib/widgets/MarkdownWidget.d.ts +3 -0
  120. package/lib/widgets/MarkdownWidget.js +3 -0
  121. package/lib/widgets/TOCWidget.d.ts +15 -27
  122. package/lib/widgets/TOCWidget.js +107 -183
  123. package/lib/widgets/Widget.d.ts +18 -7
  124. package/lib/widgets/Widget.js +4 -0
  125. package/lib/widgets/WidgetScopesViewComponent.js +1 -1
  126. package/lib/widgets/charts/Chart.d.ts +10 -1
  127. package/lib/widgets/charts/Chart.js +22 -11
  128. package/lib/widgets/charts/ChartViewComponent.d.ts +4 -0
  129. package/lib/widgets/charts/ChartViewComponent.js +6 -3
  130. package/lib/widgets/charts/ChartWidget.d.ts +2 -0
  131. package/lib/widgets/charts/ChartWidget.js +9 -1
  132. package/lib/widgets/charts/ChartWidgetComponent.d.ts +4 -0
  133. package/lib/widgets/charts/ChartWidgetComponent.js +2 -2
  134. package/lib/widgets/charts/calendar/CalendarChart.d.ts +1 -0
  135. package/lib/widgets/charts/calendar/CalendarChart.js +26 -0
  136. package/lib/widgets/charts/calendar/CalendarChartViewComponent.js +3 -1
  137. package/lib/widgets/charts/imagemosaic/ImageMosaicChart.d.ts +1 -0
  138. package/lib/widgets/charts/imagemosaic/ImageMosaicChart.js +8 -0
  139. package/lib/widgets/charts/layered/LayeredChart.d.ts +2 -0
  140. package/lib/widgets/charts/layered/LayeredChart.js +63 -3
  141. package/lib/widgets/charts/layered/LayeredChartCompiler.d.ts +1 -1
  142. package/lib/widgets/charts/layered/LayeredChartCompiler.js +1 -1
  143. package/lib/widgets/charts/layered/LayeredChartDesignerComponent.js +2 -2
  144. package/lib/widgets/charts/layered/LayeredChartViewComponent.js +8 -3
  145. package/lib/widgets/charts/pivot/PivotChart.d.ts +1 -0
  146. package/lib/widgets/charts/pivot/PivotChart.js +63 -0
  147. package/lib/widgets/charts/pivot/PivotChartLayoutComponent.js +1 -1
  148. package/lib/widgets/charts/pivot/SegmentDesignerComponent.js +7 -4
  149. package/lib/widgets/charts/table/OrderingsComponent.js +1 -1
  150. package/lib/widgets/charts/table/TableChart.d.ts +1 -0
  151. package/lib/widgets/charts/table/TableChart.js +15 -0
  152. package/lib/widgets/text/TextComponent.d.ts +11 -4
  153. package/lib/widgets/text/TextComponent.js +11 -8
  154. package/lib/widgets/text/TextWidget.d.ts +6 -3
  155. package/lib/widgets/text/TextWidget.js +7 -1
  156. package/lib/widgets/text/TextWidgetComponent.d.ts +4 -0
  157. package/lib/widgets/text/TextWidgetComponent.js +7 -1
  158. package/lib/widgets/text/TextWidgetDesign.d.ts +2 -4
  159. package/lib/widgets/text/TextWidgetDesign.js +1 -1
  160. package/package.json +7 -8
  161. package/src/ColorComponent.tsx +1 -2
  162. package/src/IdSelection.ts +62 -0
  163. package/src/MWaterAddRelatedIndicatorComponent.ts +3 -2
  164. package/src/MWaterCompleteTableSelectComponent.tsx +36 -46
  165. package/src/MWaterLoaderComponent.ts +28 -26
  166. package/src/MWaterResponsesFilterComponent.ts +5 -2
  167. package/src/MWaterTableSelectComponent.tsx +5 -9
  168. package/src/autotranslate.ts +141 -0
  169. package/src/axes/AxisBuilder.ts +3 -3
  170. package/src/axes/AxisColorEditorComponent.tsx +5 -0
  171. package/src/axes/{AxisComponent.ts → AxisComponent.tsx} +106 -106
  172. package/src/axes/CategoryMapComponent.ts +4 -4
  173. package/src/axes/RangesComponent.ts +3 -2
  174. package/src/dashboards/DashboardComponent.tsx +79 -14
  175. package/src/dashboards/DashboardDesign.ts +9 -2
  176. package/src/dashboards/DashboardUtils.ts +39 -0
  177. package/src/dashboards/DashboardViewComponent.tsx +22 -3
  178. package/src/dashboards/ServerDashboardDataSource.ts +2 -1
  179. package/src/dashboards/SettingsModalComponent.tsx +450 -35
  180. package/src/dashboards/WidgetComponent.tsx +12 -6
  181. package/src/datagrids/CellEditor.tsx +354 -0
  182. package/src/datagrids/DatagridComponent.tsx +646 -0
  183. package/src/datagrids/DatagridViewComponent.tsx +539 -0
  184. package/src/datagrids/DirectDatagridDataSource.ts +2 -3
  185. package/src/datagrids/{ExprCellComponent.ts → ExprCellComponent.tsx} +28 -23
  186. package/src/datagrids/{FindReplaceModalComponent.ts → FindReplaceModalComponent.tsx} +109 -122
  187. package/src/index.css +1 -1
  188. package/src/index.ts +0 -1
  189. package/src/layouts/blocks/HorizontalBlockComponent.ts +2 -2
  190. package/src/mWaterLoader.ts +1 -1
  191. package/src/maps/BufferLayer.ts +83 -60
  192. package/src/maps/BufferLayerDesign.ts +20 -14
  193. package/src/maps/BufferLayerDesignerComponent.tsx +309 -0
  194. package/src/maps/ChoroplethLayer.ts +40 -19
  195. package/src/maps/ChoroplethLayerDesign.ts +4 -2
  196. package/src/maps/ChoroplethLayerDesigner.tsx +4 -2
  197. package/src/maps/ClusterLayer.ts +4 -10
  198. package/src/maps/DetailLevelSelectComponent.ts +1 -1
  199. package/src/maps/DirectMapDataSource.ts +2 -1
  200. package/src/maps/EditPopupComponent.ts +7 -3
  201. package/src/maps/GridLayer.ts +4 -10
  202. package/src/maps/GridLayerDesigner.tsx +5 -3
  203. package/src/maps/HoverContent.tsx +40 -16
  204. package/src/maps/Layer.ts +28 -10
  205. package/src/maps/LayerFactory.ts +0 -8
  206. package/src/maps/LayerLegendComponent.ts +2 -4
  207. package/src/maps/LayerSwitcherComponent.tsx +6 -2
  208. package/src/maps/LeafletMapComponent.tsx +3 -1
  209. package/src/maps/LegendComponent.tsx +10 -1
  210. package/src/maps/MWaterServerLayer.ts +3 -3
  211. package/src/maps/MapComponent.ts +3 -3
  212. package/src/maps/MapDesign.ts +3 -0
  213. package/src/maps/MapDesignerComponent.tsx +165 -162
  214. package/src/maps/MapLayerViewDesignerComponent.ts +2 -2
  215. package/src/maps/MapUtils.ts +24 -0
  216. package/src/maps/MapViewComponent.tsx +11 -3
  217. package/src/maps/MarkersLayer.ts +44 -18
  218. package/src/maps/MarkersLayerDesign.ts +19 -16
  219. package/src/maps/PopupFilterJoinsUtils.ts +6 -2
  220. package/src/maps/RasterMapViewComponent.ts +9 -45
  221. package/src/maps/ServerMapDataSource.ts +2 -2
  222. package/src/maps/SwitchableTileUrlLayer.tsx +4 -10
  223. package/src/maps/TileUrlLayer.tsx +4 -10
  224. package/src/maps/VectorMapViewComponent.tsx +28 -55
  225. package/src/maps/maps.ts +3 -0
  226. package/src/quickfilter/QuickfiltersComponent.ts +13 -7
  227. package/src/quickfilter/QuickfiltersDesignComponent.tsx +56 -74
  228. package/src/richtext/ExprItemsHtmlConverter.ts +9 -5
  229. package/src/richtext/ExprItemsTranslator.ts +176 -0
  230. package/src/richtext/ItemsHtmlConverter.ts +33 -18
  231. package/src/wellknown.ts +33 -30
  232. package/src/widgets/ImageWidget.ts +10 -1
  233. package/src/widgets/ImageWidgetComponent.ts +3 -2
  234. package/src/widgets/{MapWidget.ts → MapWidget.tsx} +90 -101
  235. package/src/widgets/MarkdownWidget.ts +3 -0
  236. package/src/widgets/TOCWidget.tsx +281 -0
  237. package/src/widgets/Widget.ts +25 -5
  238. package/src/widgets/WidgetScopesViewComponent.ts +2 -1
  239. package/src/widgets/charts/Chart.ts +31 -12
  240. package/src/widgets/charts/ChartViewComponent.ts +13 -3
  241. package/src/widgets/charts/ChartWidget.ts +11 -1
  242. package/src/widgets/charts/ChartWidgetComponent.tsx +9 -1
  243. package/src/widgets/charts/calendar/CalendarChart.ts +29 -0
  244. package/src/widgets/charts/calendar/CalendarChartViewComponent.tsx +3 -1
  245. package/src/widgets/charts/imagemosaic/ImageMosaicChart.ts +9 -0
  246. package/src/widgets/charts/layered/LayeredChart.ts +71 -3
  247. package/src/widgets/charts/layered/LayeredChartCompiler.ts +2 -2
  248. package/src/widgets/charts/layered/LayeredChartDesignerComponent.tsx +4 -2
  249. package/src/widgets/charts/layered/LayeredChartViewComponent.ts +10 -4
  250. package/src/widgets/charts/pivot/PivotChart.ts +73 -0
  251. package/src/widgets/charts/pivot/PivotChartLayoutComponent.tsx +1 -1
  252. package/src/widgets/charts/pivot/SegmentDesignerComponent.tsx +6 -4
  253. package/src/widgets/charts/table/OrderingsComponent.tsx +2 -1
  254. package/src/widgets/charts/table/TableChart.ts +17 -0
  255. package/src/widgets/text/TextComponent.tsx +22 -12
  256. package/src/widgets/text/TextWidget.ts +9 -2
  257. package/src/widgets/text/TextWidgetComponent.tsx +16 -1
  258. package/src/widgets/text/TextWidgetDesign.ts +4 -7
  259. package/test/IdSelectionTests.ts +54 -0
  260. package/test/LayeredChartCompilerTests.ts +0 -2
  261. package/test/richtext/ExprItemsTranslatorTests.ts +144 -0
  262. package/test/wellknownTests.ts +144 -0
  263. package/src/datagrids/DatagridComponent.ts +0 -478
  264. package/src/datagrids/DatagridViewComponent.ts +0 -464
  265. package/src/datagrids/EditExprCellComponent.tsx +0 -305
  266. package/src/datagrids/README.md +0 -3
  267. package/src/maps/BufferLayerDesignerComponent.ts +0 -311
  268. package/src/widgets/TOCWidget.ts +0 -326
  269. package/test/LegoLayoutEngineTests.ts +0 -69
@@ -11,27 +11,33 @@ export interface HoverContentProps {
11
11
  /** Schema to use */
12
12
  schema: Schema
13
13
  dataSource: DataSource
14
- /** Design of the marker layer */
15
- design: any
16
14
  filters?: JsonQLFilter[]
17
- /** Table that popup is for */
18
- // table: string
19
- // /** Table of the row that join is to. Usually same as table except for choropleth maps */
20
- // idTable: string
21
- // defaultPopupFilterJoins: any
15
+ /** Table that hover over is for */
16
+ table: string
17
+ /** Hover over items */
18
+ items: HoverOverItem[]
19
+ /** Locale to use */
20
+ locale: string
21
+ /** Translate function to use */
22
+ translate: (input: string) => string
22
23
  }
23
24
 
24
- const HoverContent: React.FC<HoverContentProps> = props => {
25
+ /** Component that displays hover over content */
26
+ const HoverContent = (props: HoverContentProps) => {
25
27
  const [values, setValues] = useState<{ [key: string]: string }>({})
28
+ const [error, setError] = useState<string | null>(null)
26
29
  const exprUtils = new ExprUtils(props.schema)
30
+
27
31
  useEffect(() => {
28
- const items = props.design.hoverOver?.items ?? []
32
+ let mounted = true
33
+ const items = props.items
34
+
29
35
  if (items.length > 0) {
30
36
  const exprCompiler = new ExprCompiler(props.schema)
31
37
  const query: JsonQLSelectQuery = {
32
38
  type: "query",
33
39
  selects: [],
34
- from: exprCompiler.compileTable(props.design.table, "main"),
40
+ from: exprCompiler.compileTable(props.table, "main"),
35
41
  limit: 1
36
42
  }
37
43
 
@@ -59,24 +65,42 @@ const HoverContent: React.FC<HoverContentProps> = props => {
59
65
  }
60
66
 
61
67
  props.dataSource.performQuery(query, (error: any, data: any) => {
68
+ if (!mounted) {
69
+ return
70
+ }
71
+
72
+ if (error) {
73
+ setError(props.translate("Error loading hover data"))
74
+ return
75
+ }
76
+
62
77
  setValues(data?.[0] ?? {})
63
78
  })
64
79
  }
80
+
81
+ return () => {
82
+ mounted = false
83
+ }
65
84
  }, [])
85
+
86
+ if (error) {
87
+ return <div className="text-danger">{error}</div>
88
+ }
89
+
66
90
  return (
67
91
  <div className="_mviz-map-hover-content">
68
- {props.design.hoverOver?.items.map((item: HoverOverItem) => {
92
+ {props.items.map((item: HoverOverItem) => {
69
93
  let value = values[item.id]
70
94
 
71
- if (value !== null && item.value) {
95
+ if (value != null && item.value) {
72
96
  // Get expression type
73
97
  const exprType = exprUtils.getExprType(item.value)
74
98
 
75
99
  // Format if can format
76
100
  if (exprType && canFormatType(exprType)) {
77
- value = formatValue(exprType, value, undefined)
101
+ value = formatValue(exprType, value, item.format, props.locale)
78
102
  } else {
79
- value = exprUtils.stringifyExprLiteral(item.value, value)
103
+ value = exprUtils.stringifyExprLiteral(item.value, value, props.locale)
80
104
  }
81
105
  } else {
82
106
  value = "■■■■"
@@ -84,8 +108,8 @@ const HoverContent: React.FC<HoverContentProps> = props => {
84
108
 
85
109
  return (
86
110
  <>
87
- <span>{item.label}:</span>
88
- <span className="text-muted">{values[item.id] === null ? "n/a" : values[item.id] ?? "■■■■"}</span>
111
+ <span>{props.translate(item.label)}:</span>
112
+ <span className="text-muted">{values[item.id] === null ? "n/a" : value}</span>
89
113
  </>
90
114
  )
91
115
  })}
package/src/maps/Layer.ts CHANGED
@@ -9,6 +9,7 @@ import { OnGridClickResults, OnGridHoverResults } from "./maps"
9
9
  import { ReactNode } from "react"
10
10
  import { JsonQLExpr, JsonQLQuery, JsonQLSelectQuery } from "@mwater/jsonql"
11
11
  import { LayerSpecification } from "maplibre-gl"
12
+ import { MapLayerDataSource } from "./MapLayerDataSource"
12
13
 
13
14
  export interface JsonQLCssLayerDefinition {
14
15
  layers: Array<{
@@ -37,11 +38,15 @@ export interface OnGridClickOptions<LayerDesign> {
37
38
  /** data source to use */
38
39
  dataSource: DataSource
39
40
  /** layer data source */
40
- layerDataSource: any // TODO
41
+ layerDataSource: MapLayerDataSource
41
42
  /** current scope data if layer is scoping */
42
43
  scopeData: any
43
44
  /** compiled filters to apply to the popup */
44
45
  filters: JsonQLFilter[]
46
+ /** Locale to use */
47
+ locale: string
48
+ /** Translate function to use */
49
+ translate: (input: string) => string
45
50
  }
46
51
 
47
52
  export interface OnGridHoverOptions<LayerDesign> {
@@ -52,11 +57,15 @@ export interface OnGridHoverOptions<LayerDesign> {
52
57
  /** data source to use */
53
58
  dataSource: DataSource
54
59
  /** layer data source */
55
- layerDataSource: any // TODO
60
+ layerDataSource: MapLayerDataSource
56
61
  /** current scope data if layer is scoping */
57
62
  scopeData: any
58
63
  /** compiled filters to apply to the popup */
59
64
  filters: JsonQLFilter[]
65
+ /** Locale to use */
66
+ locale: string
67
+ /** Translate function to use */
68
+ translate: (input: string) => string
60
69
  }
61
70
 
62
71
  /** Definition of a vector tile layer */
@@ -186,14 +195,7 @@ export default class Layer<LayerDesign> {
186
195
  }
187
196
 
188
197
  /** Get the legend to be optionally displayed on the map. Returns a React element */
189
- getLegend(
190
- design: LayerDesign,
191
- schema: Schema,
192
- name: string,
193
- dataSource: DataSource,
194
- locale: string,
195
- filters: JsonQLFilter[]
196
- ): ReactNode {
198
+ getLegend(options: LegendOptions<LayerDesign>): ReactNode {
197
199
  return null
198
200
  }
199
201
 
@@ -325,4 +327,20 @@ export default class Layer<LayerDesign> {
325
327
  }
326
328
  })
327
329
  }
330
+
331
+ /** Get strings to be translated */
332
+ getTranslatableStrings(design: LayerDesign, schema: Schema): string[] {
333
+ return []
334
+ }
335
+ }
336
+
337
+ export interface LegendOptions<LayerDesign> {
338
+ design: LayerDesign
339
+ schema: Schema
340
+ name: string
341
+ dataSource: DataSource
342
+ locale: string
343
+ filters: JsonQLFilter[]
344
+ /** Translate function to use */
345
+ translate: (input: string) => string
328
346
  }
@@ -14,36 +14,28 @@ export default class LayerFactory {
14
14
  switch (type) {
15
15
  case "MWaterServer":
16
16
  return new MWaterServerLayer()
17
- break
18
17
 
19
18
  case "Markers":
20
19
  return new MarkersLayer()
21
- break
22
20
 
23
21
  case "Buffer":
24
22
  return new BufferLayer()
25
- break
26
23
 
27
24
  // Uses a legacy type name
28
25
  case "AdminChoropleth":
29
26
  return new ChoroplethLayer()
30
- break
31
27
 
32
28
  case "Cluster":
33
29
  return new ClusterLayer()
34
- break
35
30
 
36
31
  case "TileUrl":
37
32
  return new TileUrlLayer()
38
- break
39
33
 
40
34
  case "SwitchableTileUrl":
41
35
  return new SwitchableTileUrlLayer()
42
- break
43
36
 
44
37
  case "Grid":
45
38
  return new GridLayer()
46
- break
47
39
  }
48
40
 
49
41
  throw new Error(`Unknown type ${type}`)
@@ -1,10 +1,8 @@
1
- import PropTypes from "prop-types"
2
1
  import React from "react"
3
2
  import _ from "lodash"
4
- const R = React.createElement
5
3
  import AxisBuilder from "../axes/AxisBuilder"
6
4
  import LegendGroup from "./LegendGroup"
7
- import { ExprUtils, Schema } from "@mwater/expressions"
5
+ import { Schema } from "@mwater/expressions"
8
6
  import { Axis } from "../axes/Axis"
9
7
 
10
8
  export interface LayerLegendComponentProps {
@@ -60,7 +58,7 @@ export default class LayerLegendComponent extends React.Component<LayerLegendCom
60
58
  return null
61
59
  }
62
60
 
63
- const label = axisBuilder.formatCategory(this.props.axis, category)
61
+ const label = axisBuilder.formatCategory(this.props.axis!, category)
64
62
  const color = _.find(this.props.axis!.colorMap!, { value: category.value })
65
63
  if (color) {
66
64
  return { color: color.color, name: label }
@@ -3,7 +3,11 @@ import React, { CSSProperties, Ref, useEffect, useRef, useState } from "react"
3
3
  import { MapDesign, MapLayerView } from "./MapDesign"
4
4
 
5
5
  /** Component to switch layers on a map */
6
- export function LayerSwitcherComponent(props: { design: MapDesign; onDesignChange: (design: MapDesign) => void }) {
6
+ export function LayerSwitcherComponent(props: {
7
+ design: MapDesign
8
+ onDesignChange: (design: MapDesign) => void
9
+ translate: (input: string) => string
10
+ }) {
7
11
  const [dropdownOpen, setDropdownOpen] = useState(false)
8
12
 
9
13
  const iconStyle: CSSProperties = {
@@ -45,7 +49,7 @@ export function LayerSwitcherComponent(props: { design: MapDesign; onDesignChang
45
49
  return (
46
50
  <div key={index} style={{ fontSize: 12, whiteSpace: "nowrap", cursor: "pointer" }} onClick={handleClick}>
47
51
  <i className={lv.visible ? "fa fa-fw fa-check-square text-primary" : "fa fa-fw fa-square text-muted"} />
48
- &nbsp;{lv.name}
52
+ &nbsp;{props.translate(lv.name)}
49
53
  </div>
50
54
  )
51
55
  }
@@ -221,7 +221,9 @@ export default class LeafletMapComponent extends Component<Props> {
221
221
  lBounds = lBounds.pad(pad)
222
222
  }
223
223
 
224
- this.map.fitBounds(lBounds, { animate: true })
224
+ if (lBounds.getEast() !== Infinity && lBounds.getWest() !== -Infinity && lBounds.getNorth() !== Infinity && lBounds.getSouth() !== -Infinity) {
225
+ this.map.fitBounds(lBounds, { animate: true })
226
+ }
225
227
  } else {
226
228
  // Fit world doesn't work sometimes. Make sure that entire left-right is included
227
229
  this.map.fitBounds([
@@ -15,6 +15,7 @@ export default function LegendComponent(props: {
15
15
  /** array of filters to apply. Each is { table: table id, jsonql: jsonql condition with {alias} for tableAlias. Use injectAlias to correct */
16
16
  filters: JsonQLFilter[]
17
17
  locale: string
18
+ translate: (input: string) => string
18
19
  onHide: () => void
19
20
  }) {
20
21
  const legendItems = _.compact(
@@ -53,7 +54,15 @@ export default function LegendComponent(props: {
53
54
 
54
55
  return {
55
56
  key: layerView.id,
56
- legend: layer.getLegend(design, props.schema, layerView.name, props.dataSource, props.locale, props.filters)
57
+ legend: layer.getLegend({
58
+ design,
59
+ schema: props.schema,
60
+ name: layerView.name,
61
+ dataSource: props.dataSource,
62
+ locale: props.locale,
63
+ filters: props.filters,
64
+ translate: props.translate
65
+ })
57
66
  }
58
67
  })
59
68
  )
@@ -1,5 +1,5 @@
1
1
  import $ from "jquery"
2
- import Layer from "./Layer"
2
+ import Layer, { LegendOptions } from "./Layer"
3
3
  import React from "react"
4
4
  import { Schema } from "@mwater/expressions"
5
5
  const R = React.createElement
@@ -46,11 +46,11 @@ export default class MWaterServerLayer extends Layer<any> {
46
46
 
47
47
  // Get the legend to be optionally displayed on the map. Returns
48
48
  // a React element
49
- getLegend(design: any, schema: Schema) {
49
+ getLegend(options: LegendOptions<any>) {
50
50
  // Create loading legend component
51
51
  // TODO hardcoded
52
52
  const apiUrl = "https://api.mwater.co/v3/"
53
- return React.createElement(LoadingLegend, { url: `${apiUrl}maps/legend?type=${design.type}` })
53
+ return React.createElement(LoadingLegend, { url: `${apiUrl}maps/legend?type=${options.design.type}` })
54
54
  }
55
55
 
56
56
  // Get a list of table ids that can be filtered on
@@ -133,7 +133,7 @@ export default class MapComponent extends React.Component<MapComponentProps, Map
133
133
  onClick: this.handleUndo
134
134
  },
135
135
  R("span", { className: "fas fa-caret-left" }),
136
- R("span", { className: "hide-600px" }, T` Undo`)
136
+ R("span", { className: "hide-600px" }, " ", T`Undo`)
137
137
  ),
138
138
  " ",
139
139
  R(
@@ -144,7 +144,7 @@ export default class MapComponent extends React.Component<MapComponentProps, Map
144
144
  onClick: this.handleRedo
145
145
  },
146
146
  R("span", { className: "fas fa-caret-right" }),
147
- R("span", { className: "hide-600px" }, T` Redo`)
147
+ R("span", { className: "hide-600px" }, " ", T`Redo`)
148
148
  )
149
149
  ]
150
150
  : undefined,
@@ -153,7 +153,7 @@ export default class MapComponent extends React.Component<MapComponentProps, Map
153
153
  "a",
154
154
  { key: "showQuickfilters", className: "btn btn-link btn-sm", onClick: this.handleShowQuickfilters },
155
155
  R("span", { className: "fa fa-filter" }),
156
- R("span", { className: "hide-600px" }, T` Show Quickfilters`)
156
+ R("span", { className: "hide-600px" }, " ", T`Show Quickfilters`)
157
157
  )
158
158
  : undefined,
159
159
  this.props.extraTitleButtonsElem,
@@ -25,6 +25,9 @@ export interface MapDesign {
25
25
  /** true to automatically zoom to bounds of data */
26
26
  autoBounds?: boolean
27
27
 
28
+ /** True to animate zoom to bounds of data. Default is true */
29
+ animateAutoBounds?: boolean
30
+
28
31
  /** maximum allowed zoom level */
29
32
  maxZoom?: number | null
30
33