@mwater/visualization 5.2.0 → 5.3.1

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 (254) hide show
  1. package/lib/ColorComponent.d.ts +10 -11
  2. package/lib/ColorComponent.js +78 -29
  3. package/lib/ColorSchemeFactory.d.ts +13 -2
  4. package/lib/ColorSchemeFactory.js +7 -5
  5. package/lib/CustomColorsContext.d.ts +6 -0
  6. package/lib/CustomColorsContext.js +6 -0
  7. package/lib/FiltersDesignerComponent.d.ts +1 -4
  8. package/lib/FiltersDesignerComponent.js +2 -3
  9. package/lib/LocaleContextInjector.d.ts +5 -11
  10. package/lib/LocaleContextInjector.js +4 -12
  11. package/lib/MWaterAddRelatedFormComponent.js +3 -3
  12. package/lib/MWaterAddRelatedIndicatorComponent.d.ts +1 -4
  13. package/lib/MWaterAddRelatedIndicatorComponent.js +6 -6
  14. package/lib/MWaterCompleteTableSelectComponent.d.ts +5 -16
  15. package/lib/MWaterCompleteTableSelectComponent.js +36 -36
  16. package/lib/MWaterContextComponent.d.ts +4 -6
  17. package/lib/MWaterContextComponent.js +4 -13
  18. package/lib/MWaterLoaderComponent.d.ts +5 -3
  19. package/lib/MWaterLoaderComponent.js +2 -1
  20. package/lib/MWaterTableSelectComponent.d.ts +1 -4
  21. package/lib/MWaterTableSelectComponent.js +10 -12
  22. package/lib/UIComponents.d.ts +2 -2
  23. package/lib/UIComponents.js +4 -12
  24. package/lib/axes/AxisBuilder.d.ts +7 -4
  25. package/lib/axes/AxisBuilder.js +3 -1
  26. package/lib/axes/AxisComponent.d.ts +2 -5
  27. package/lib/axes/AxisComponent.js +1 -2
  28. package/lib/axes/ColorPaletteCollectionComponent.d.ts +5 -12
  29. package/lib/axes/ColorPaletteCollectionComponent.js +67 -36
  30. package/lib/dashboards/DashboardComponent.d.ts +4 -12
  31. package/lib/dashboards/DashboardComponent.js +18 -38
  32. package/lib/dashboards/DashboardDesign.d.ts +3 -3
  33. package/lib/dashboards/DashboardUpgrader.js +36 -1
  34. package/lib/dashboards/DashboardViewComponent.d.ts +5 -34
  35. package/lib/dashboards/DashboardViewComponent.js +109 -132
  36. package/lib/dashboards/FontStyleEditor.d.ts +8 -0
  37. package/lib/dashboards/FontStyleEditor.js +130 -0
  38. package/lib/dashboards/LayoutOptionsComponent.d.ts +0 -1
  39. package/lib/dashboards/LayoutOptionsComponent.js +211 -42
  40. package/lib/dashboards/ServerDashboardDataSource.d.ts +1 -2
  41. package/lib/dashboards/ServerDashboardDataSource.js +52 -33
  42. package/lib/dashboards/WidgetComponent.d.ts +3 -3
  43. package/lib/dashboards/WidgetComponent.js +3 -6
  44. package/lib/dashboards/WidgetDataSourcePrioritizer.d.ts +20 -0
  45. package/lib/dashboards/WidgetDataSourcePrioritizer.js +72 -0
  46. package/lib/dashboards/layoutOptions.d.ts +83 -0
  47. package/lib/dashboards/layoutOptions.js +436 -10
  48. package/lib/datagrids/DatagridDesign.d.ts +7 -6
  49. package/lib/datagrids/ServerDatagridDataSource.d.ts +7 -6
  50. package/lib/datagrids/ServerDatagridDataSource.js +87 -33
  51. package/lib/demo.js +3 -3
  52. package/lib/index.css +5 -0
  53. package/lib/index.d.ts +1 -1
  54. package/lib/index.js +0 -1
  55. package/lib/layouts/LayoutManager.d.ts +33 -29
  56. package/lib/layouts/LayoutManager.js +2 -8
  57. package/lib/layouts/blocks/BlocksDisplayComponent.d.ts +26 -57
  58. package/lib/layouts/blocks/BlocksDisplayComponent.js +122 -205
  59. package/lib/layouts/blocks/BlocksLayoutManager.d.ts +6 -22
  60. package/lib/layouts/blocks/BlocksLayoutManager.js +5 -14
  61. package/lib/layouts/blocks/HorizontalBlockComponent.d.ts +5 -4
  62. package/lib/layouts/blocks/HorizontalBlockComponent.js +5 -5
  63. package/lib/mWaterLoader.d.ts +2 -0
  64. package/lib/mWaterLoader.js +2 -1
  65. package/lib/maps/AddLayerComponent.d.ts +6 -8
  66. package/lib/maps/AddLayerComponent.js +6 -6
  67. package/lib/maps/BingLayer.js +10 -20
  68. package/lib/maps/BufferLayer.js +2 -1
  69. package/lib/maps/ChoroplethLayer.js +2 -1
  70. package/lib/maps/DirectMapDataSource.d.ts +5 -2
  71. package/lib/maps/DirectMapDataSource.js +2 -1
  72. package/lib/maps/EditPopupComponent.js +2 -1
  73. package/lib/maps/MapComponent.d.ts +1 -4
  74. package/lib/maps/MapComponent.js +3 -3
  75. package/lib/maps/MarkersLayer.js +30 -25
  76. package/lib/maps/RasterMapViewComponent.d.ts +1 -4
  77. package/lib/maps/RasterMapViewComponent.js +3 -3
  78. package/lib/maps/ServerMapDataSource.d.ts +2 -3
  79. package/lib/maps/ServerMapDataSource.js +5 -5
  80. package/lib/maps/VectorMapViewComponent.js +2 -1
  81. package/lib/maps/mapSymbols.js +2 -0
  82. package/lib/maps/symbols/font-awesome/cloud-rain.png +0 -0
  83. package/lib/maps/vectorMaps.js +61 -55
  84. package/lib/quickfilter/QuickfiltersComponent.d.ts +1 -4
  85. package/lib/quickfilter/QuickfiltersComponent.js +3 -3
  86. package/lib/richtext/DropdownPaletteItem.d.ts +32 -0
  87. package/lib/richtext/DropdownPaletteItem.js +82 -0
  88. package/lib/richtext/FontColorPaletteItem.d.ts +1 -5
  89. package/lib/richtext/FontColorPaletteItem.js +32 -27
  90. package/lib/richtext/ItemsHtmlConverter.js +12 -3
  91. package/lib/richtext/RichTextComponent.d.ts +26 -52
  92. package/lib/richtext/RichTextComponent.js +166 -128
  93. package/lib/valueFormatter.js +6 -1
  94. package/lib/wellknown.d.ts +5 -0
  95. package/lib/wellknown.js +288 -0
  96. package/lib/widgets/DropdownWidgetComponent.d.ts +8 -25
  97. package/lib/widgets/DropdownWidgetComponent.js +48 -25
  98. package/lib/widgets/IFrameWidgetComponent.d.ts +1 -2
  99. package/lib/widgets/ImageWidgetComponent.d.ts +2 -3
  100. package/lib/widgets/MapWidget.d.ts +2 -0
  101. package/lib/widgets/MapWidget.js +2 -1
  102. package/lib/widgets/TOCWidget.js +2 -1
  103. package/lib/widgets/Widget.d.ts +2 -0
  104. package/lib/widgets/WidgetDataSource.d.ts +3 -1
  105. package/lib/widgets/charts/Chart.d.ts +0 -1
  106. package/lib/widgets/charts/ChartViewComponent.d.ts +4 -0
  107. package/lib/widgets/charts/ChartViewComponent.js +11 -3
  108. package/lib/widgets/charts/ChartWidget.d.ts +1 -62
  109. package/lib/widgets/charts/ChartWidget.js +4 -183
  110. package/lib/widgets/charts/ChartWidgetComponent.d.ts +51 -0
  111. package/lib/widgets/charts/ChartWidgetComponent.js +167 -0
  112. package/lib/widgets/charts/calendar/CalendarChartViewComponent.d.ts +1 -4
  113. package/lib/widgets/charts/calendar/CalendarChartViewComponent.js +4 -4
  114. package/lib/widgets/charts/layered/LayeredChart.d.ts +5 -10
  115. package/lib/widgets/charts/layered/LayeredChart.js +6 -7
  116. package/lib/widgets/charts/layered/LayeredChartCompiler.d.ts +4 -2
  117. package/lib/widgets/charts/layered/LayeredChartCompiler.js +46 -32
  118. package/lib/widgets/charts/layered/LayeredChartDesign.d.ts +4 -0
  119. package/lib/widgets/charts/layered/LayeredChartDesignerComponent.d.ts +3 -0
  120. package/lib/widgets/charts/layered/LayeredChartDesignerComponent.js +21 -3
  121. package/lib/widgets/charts/layered/LayeredChartLayerDesignerComponent.d.ts +1 -2
  122. package/lib/widgets/charts/layered/LayeredChartLayerDesignerComponent.js +2 -1
  123. package/lib/widgets/charts/layered/LayeredChartViewComponent.d.ts +1 -4
  124. package/lib/widgets/charts/layered/LayeredChartViewComponent.js +89 -38
  125. package/lib/widgets/charts/pivot/IntersectionDesignerComponent.d.ts +5 -112
  126. package/lib/widgets/charts/pivot/IntersectionDesignerComponent.js +122 -166
  127. package/lib/widgets/charts/pivot/PivotChart.d.ts +6 -0
  128. package/lib/widgets/charts/pivot/PivotChart.js +47 -17
  129. package/lib/widgets/charts/pivot/PivotChartDesign.d.ts +11 -0
  130. package/lib/widgets/charts/pivot/PivotChartDesignerComponent.d.ts +1 -1
  131. package/lib/widgets/charts/pivot/PivotChartDesignerComponent.js +1 -1
  132. package/lib/widgets/charts/pivot/PivotChartLayoutBuilder.d.ts +2 -2
  133. package/lib/widgets/charts/pivot/PivotChartLayoutBuilder.js +20 -36
  134. package/lib/widgets/charts/pivot/PivotChartLayoutComponent.js +0 -1
  135. package/lib/widgets/charts/pivot/PivotChartQueryBuilder.d.ts +23 -2
  136. package/lib/widgets/charts/pivot/PivotChartQueryBuilder.js +215 -181
  137. package/lib/widgets/charts/pivot/PivotChartUtils.d.ts +2 -2
  138. package/lib/widgets/charts/pivot/PivotChartViewComponent.d.ts +9 -28
  139. package/lib/widgets/charts/pivot/PivotChartViewComponent.js +20 -60
  140. package/lib/widgets/charts/table/TableChart.js +8 -4
  141. package/lib/widgets/charts/table/TableChartDesignerComponent.js +3 -3
  142. package/lib/widgets/charts/table/TableChartViewComponent.js +11 -11
  143. package/lib/widgets/text/TextComponent.d.ts +5 -12
  144. package/lib/widgets/text/TextComponent.js +19 -39
  145. package/lib/widgets/text/TextWidget.d.ts +2 -1
  146. package/lib/widgets/text/TextWidget.js +5 -1
  147. package/lib/widgets/text/TextWidgetComponent.d.ts +15 -3
  148. package/lib/widgets/text/TextWidgetComponent.js +76 -19
  149. package/lib/widgets/text/TextWidgetDesign.d.ts +13 -1
  150. package/lib/widgets/text/TextWidgetDesign.js +6 -0
  151. package/package.json +4 -4
  152. package/src/ColorComponent.tsx +177 -0
  153. package/src/ColorSchemeFactory.ts +12 -6
  154. package/src/CustomColorsContext.tsx +9 -0
  155. package/src/FiltersDesignerComponent.ts +3 -4
  156. package/src/LocaleContextInjector.tsx +14 -13
  157. package/src/MWaterAddRelatedFormComponent.ts +3 -3
  158. package/src/MWaterAddRelatedIndicatorComponent.ts +6 -6
  159. package/src/MWaterCompleteTableSelectComponent.tsx +36 -36
  160. package/src/MWaterContextComponent.tsx +8 -17
  161. package/src/MWaterLoaderComponent.ts +6 -3
  162. package/src/MWaterTableSelectComponent.tsx +11 -12
  163. package/src/{UIComponents.ts → UIComponents.tsx} +7 -15
  164. package/src/axes/AxisBuilder.ts +7 -5
  165. package/src/axes/AxisComponent.ts +3 -4
  166. package/src/axes/{ColorPaletteCollectionComponent.ts → ColorPaletteCollectionComponent.tsx} +87 -61
  167. package/src/dashboards/DashboardComponent.tsx +71 -107
  168. package/src/dashboards/DashboardDesign.ts +3 -3
  169. package/src/dashboards/DashboardUpgrader.ts +41 -1
  170. package/src/dashboards/DashboardViewComponent.tsx +313 -0
  171. package/src/dashboards/FontStyleEditor.tsx +166 -0
  172. package/src/dashboards/LayoutOptionsComponent.tsx +380 -75
  173. package/src/dashboards/ServerDashboardDataSource.ts +52 -33
  174. package/src/dashboards/WidgetComponent.tsx +6 -12
  175. package/src/dashboards/WidgetDataSourcePrioritizer.ts +82 -0
  176. package/src/dashboards/layoutOptions.tsx +581 -0
  177. package/src/datagrids/DatagridDesign.ts +8 -3
  178. package/src/datagrids/ServerDatagridDataSource.ts +106 -43
  179. package/src/demo.ts +3 -3
  180. package/src/index.css +5 -0
  181. package/src/index.ts +1 -1
  182. package/src/layouts/LayoutManager.ts +44 -42
  183. package/src/layouts/blocks/BlocksDisplayComponent.tsx +498 -0
  184. package/src/layouts/blocks/BlocksLayoutManager.ts +6 -15
  185. package/src/layouts/blocks/HorizontalBlockComponent.ts +9 -8
  186. package/src/mWaterLoader.ts +4 -1
  187. package/src/maps/AddLayerComponent.ts +9 -9
  188. package/src/maps/BingLayer.ts +16 -26
  189. package/src/maps/BufferLayer.ts +2 -1
  190. package/src/maps/ChoroplethLayer.ts +2 -1
  191. package/src/maps/DirectMapDataSource.ts +12 -3
  192. package/src/maps/EditPopupComponent.ts +2 -1
  193. package/src/maps/MapComponent.ts +3 -3
  194. package/src/maps/MarkersLayer.ts +38 -41
  195. package/src/maps/RasterMapViewComponent.ts +3 -3
  196. package/src/maps/ServerMapDataSource.ts +7 -7
  197. package/src/maps/VectorMapViewComponent.tsx +2 -1
  198. package/src/maps/mapSymbols.ts +2 -0
  199. package/src/maps/symbols/font-awesome/cloud-rain.png +0 -0
  200. package/src/maps/vectorMaps.tsx +79 -74
  201. package/src/quickfilter/QuickfiltersComponent.ts +3 -3
  202. package/src/richtext/DropdownPaletteItem.tsx +144 -0
  203. package/src/richtext/FontColorPaletteItem.tsx +160 -0
  204. package/src/richtext/ItemsHtmlConverter.ts +15 -5
  205. package/src/richtext/RichTextComponent.tsx +274 -232
  206. package/src/valueFormatter.ts +5 -1
  207. package/src/wellknown.ts +286 -0
  208. package/src/widgets/DropdownWidgetComponent.tsx +75 -0
  209. package/src/widgets/MapWidget.ts +5 -2
  210. package/src/widgets/TOCWidget.ts +2 -1
  211. package/src/widgets/Widget.ts +3 -0
  212. package/src/widgets/WidgetDataSource.ts +3 -1
  213. package/src/widgets/charts/Chart.ts +1 -1
  214. package/src/widgets/charts/ChartViewComponent.ts +16 -3
  215. package/src/widgets/charts/ChartWidget.ts +3 -275
  216. package/src/widgets/charts/ChartWidgetComponent.tsx +281 -0
  217. package/src/widgets/charts/calendar/CalendarChartViewComponent.tsx +4 -4
  218. package/src/widgets/charts/layered/LayeredChart.ts +4 -6
  219. package/src/widgets/charts/layered/LayeredChartCompiler.ts +80 -63
  220. package/src/widgets/charts/layered/LayeredChartDesign.ts +7 -1
  221. package/src/widgets/charts/layered/LayeredChartDesignerComponent.tsx +43 -10
  222. package/src/widgets/charts/layered/LayeredChartLayerDesignerComponent.tsx +6 -6
  223. package/src/widgets/charts/layered/LayeredChartViewComponent.ts +140 -88
  224. package/src/widgets/charts/pivot/IntersectionDesignerComponent.tsx +305 -221
  225. package/src/widgets/charts/pivot/PivotChart.ts +56 -18
  226. package/src/widgets/charts/pivot/PivotChartDesign.ts +12 -0
  227. package/src/widgets/charts/pivot/PivotChartDesignerComponent.tsx +4 -3
  228. package/src/widgets/charts/pivot/PivotChartLayoutBuilder.ts +39 -76
  229. package/src/widgets/charts/pivot/PivotChartLayoutComponent.tsx +0 -1
  230. package/src/widgets/charts/pivot/PivotChartQueryBuilder.ts +230 -189
  231. package/src/widgets/charts/pivot/PivotChartUtils.ts +4 -4
  232. package/src/widgets/charts/pivot/{PivotChartViewComponent.ts → PivotChartViewComponent.tsx} +86 -89
  233. package/src/widgets/charts/table/TableChart.ts +8 -4
  234. package/src/widgets/charts/table/TableChartDesignerComponent.ts +4 -4
  235. package/src/widgets/charts/table/TableChartViewComponent.ts +13 -14
  236. package/src/widgets/text/TextComponent.tsx +47 -49
  237. package/src/widgets/text/TextWidget.ts +8 -3
  238. package/src/widgets/text/TextWidgetComponent.tsx +249 -0
  239. package/src/widgets/text/TextWidgetDesign.ts +22 -1
  240. package/src/ColorComponent.ts +0 -117
  241. package/src/dashboards/DashboardViewComponent.ts +0 -303
  242. package/src/dashboards/layoutOptions.ts +0 -40
  243. package/src/layout-styles.css +0 -263
  244. package/src/layouts/blocks/BlocksDisplayComponent.ts +0 -461
  245. package/src/layouts/grid/GridLayoutComponent.ts +0 -67
  246. package/src/layouts/grid/GridLayoutManager.ts +0 -185
  247. package/src/layouts/grid/LegoLayoutEngine.ts +0 -142
  248. package/src/layouts/grid/PaletteItemComponent.ts +0 -28
  249. package/src/layouts/grid/README.md +0 -14
  250. package/src/layouts/grid/WidgetContainerComponent.ts +0 -420
  251. package/src/richtext/FontColorPaletteItem.ts +0 -172
  252. package/src/richtext/FontSizePaletteItem.ts +0 -110
  253. package/src/widgets/DropdownWidgetComponent.ts +0 -78
  254. package/src/widgets/text/TextWidgetComponent.ts +0 -120
@@ -1,4 +1,3 @@
1
- import PropTypes from "prop-types"
2
1
  import _ from "lodash"
3
2
  import React, { createContext } from "react"
4
3
  const R = React.createElement
@@ -11,6 +10,7 @@ import { DataSource, Schema, Section } from "@mwater/expressions"
11
10
  import { CustomTableSelectComponentFactoryContext, CustomTableSelectComponentFactoryOptions, DecorateScalarExprTreeSectionChildrenContext, DecorateScalarExprTreeSectionChildrenOptions } from "@mwater/expressions-ui"
12
11
  import { IsScalarExprTreeSectionInitiallyOpenContext, IsScalarExprTreeSectionMatchContext } from "@mwater/expressions-ui"
13
12
  import { GlobalFilter } from "./GlobalFilter"
13
+ import { AddLayerComponentProps } from "./maps/AddLayerComponent"
14
14
 
15
15
 
16
16
  export interface GlobalFiltersElementFactoryProps {
@@ -28,6 +28,9 @@ export type GlobalFiltersElementFactory = (props: GlobalFiltersElementFactoryPro
28
28
 
29
29
  export const GlobalFiltersElementFactoryContext = createContext<GlobalFiltersElementFactory | null>(null)
30
30
 
31
+ export type AddLayerElementFactory = (props: AddLayerComponentProps) => React.ReactElement | null
32
+
33
+ export const AddLayerElementFactoryContext = createContext<AddLayerElementFactory | undefined>(undefined)
31
34
 
32
35
  /**
33
36
  * Creates several contexts to allow selecting of a table in an mWater-friendly way
@@ -44,12 +47,8 @@ export default class MWaterContextComponent extends React.Component<{
44
47
  /** Called when extra tables are changed and schema will be reloaded */
45
48
  onExtraTablesChange?: (extraTables: string[]) => void
46
49
  /** Override default add layer component. See AddLayerComponent for details */
47
- addLayerElementFactory?: any
50
+ addLayerElementFactory?: AddLayerElementFactory
48
51
  }> {
49
- static childContextTypes = {
50
- addLayerElementFactory: PropTypes.func, // Call with props of AddLayerComponent
51
- }
52
-
53
52
  createTableSelectElementFactory = (options: CustomTableSelectComponentFactoryOptions) => {
54
53
  return (
55
54
  <MWaterTableSelectComponent
@@ -67,16 +66,6 @@ export default class MWaterContextComponent extends React.Component<{
67
66
  )
68
67
  }
69
68
 
70
- getChildContext() {
71
- const context: any = {}
72
-
73
- if (this.props.addLayerElementFactory) {
74
- context.addLayerElementFactory = this.props.addLayerElementFactory
75
- }
76
-
77
- return context
78
- }
79
-
80
69
  createGlobalFiltersElementFactory = (props: GlobalFiltersElementFactoryProps) => {
81
70
  if (props.nullIfIrrelevant && !_.any(props.filterableTables, (t: string) => t.match(/^entities./))) {
82
71
  return null
@@ -148,7 +137,9 @@ export default class MWaterContextComponent extends React.Component<{
148
137
  <IsScalarExprTreeSectionMatchContext.Provider value={this.isScalarExprTreeSectionMatch}>
149
138
  <IsScalarExprTreeSectionInitiallyOpenContext.Provider value={this.isScalarExprTreeSectionInitiallyOpen}>
150
139
  <DecorateScalarExprTreeSectionChildrenContext.Provider value={this.decorateScalarExprTreeSectionChildren}>
151
- {this.props.children}
140
+ <AddLayerElementFactoryContext.Provider value={this.props.addLayerElementFactory}>
141
+ {this.props.children}
142
+ </AddLayerElementFactoryContext.Provider>
152
143
  </DecorateScalarExprTreeSectionChildrenContext.Provider>
153
144
  </IsScalarExprTreeSectionInitiallyOpenContext.Provider>
154
145
 
@@ -6,7 +6,7 @@ import { DataSource, Schema } from "@mwater/expressions"
6
6
  import AsyncLoadComponent from "@mwater/react-library/lib/AsyncLoadComponent"
7
7
  import LoadingComponent from "@mwater/react-library/lib/LoadingComponent"
8
8
  import mWaterLoader from "./mWaterLoader"
9
- import MWaterContextComponent from "./MWaterContextComponent"
9
+ import MWaterContextComponent, { AddLayerElementFactory } from "./MWaterContextComponent"
10
10
 
11
11
  /**
12
12
  * Loads an mWater schema from the server and creates child with schema and dataSource
@@ -29,10 +29,12 @@ export default class MWaterLoaderComponent extends AsyncLoadComponent<
29
29
  /** Locales of the schema to load. Default is all. */
30
30
  locales?: string[]
31
31
  /** Override default add layer component. See AddLayerComponent for details */
32
- addLayerElementFactory?: any
32
+ addLayerElementFactory?: AddLayerElementFactory
33
33
  children: (error: any, config?: { schema: Schema; dataSource: DataSource }) => ReactElement<any>
34
34
  /** Custom error formatter that returns React node or string, gets passed the error response from server */
35
35
  errorFormatter?: (data: any, defaultError: string) => string
36
+ /** Origin of usage. e.g. "dashboards:43445364..." */
37
+ origin?: string
36
38
  },
37
39
  {
38
40
  error: any
@@ -73,7 +75,8 @@ export default class MWaterLoaderComponent extends AsyncLoadComponent<
73
75
  share: props.share,
74
76
  asUser: props.asUser,
75
77
  extraTables: props.extraTables,
76
- locales: props.locales
78
+ locales: props.locales,
79
+ origin: props.origin
77
80
  },
78
81
  (error: any, config: any) => {
79
82
  if (error) {
@@ -7,7 +7,7 @@ import { ExprUtils, Schema } from "@mwater/expressions"
7
7
  import MWaterResponsesFilterComponent from "./MWaterResponsesFilterComponent"
8
8
  import ModalPopupComponent from "@mwater/react-library/lib/ModalPopupComponent"
9
9
  import MWaterCompleteTableSelectComponent from "./MWaterCompleteTableSelectComponent"
10
- import { ActiveTablesContext } from "@mwater/expressions-ui"
10
+ import { ActiveTablesContext, LocaleContext } from "@mwater/expressions-ui"
11
11
 
12
12
  export interface MWaterTableSelectComponentProps {
13
13
  /** Url to hit api */
@@ -36,9 +36,7 @@ export default class MWaterTableSelectComponent extends React.Component<
36
36
  MWaterTableSelectComponentProps,
37
37
  MWaterTableSelectComponentState
38
38
  > {
39
- static contextTypes = {
40
- locale: PropTypes.string, // e.g. "en"
41
- }
39
+ static contextType = LocaleContext
42
40
 
43
41
  toggleEdit: any
44
42
 
@@ -139,9 +137,12 @@ export default class MWaterTableSelectComponent extends React.Component<
139
137
  },
140
138
  forceOpen: !this.props.table, // Must have table
141
139
  label: this.props.table
142
- ? ExprUtils.localizeString(this.props.schema.getTable(this.props.table)?.name, this.context.locale)
140
+ ? ExprUtils.localizeString(this.props.schema.getTable(this.props.table)?.name, this.context)
143
141
  : "",
144
- editor
142
+ editor,
143
+ onRemove: () => {
144
+ this.props.onChange(null)
145
+ }
145
146
  }),
146
147
 
147
148
  // Make sure table still exists
@@ -184,9 +185,7 @@ class EditModeTableSelectComponent extends React.Component<
184
185
  EditModeTableSelectComponentProps,
185
186
  EditModeTableSelectComponentState
186
187
  > {
187
- static contextTypes = {
188
- locale: PropTypes.string, // e.g. "en"
189
- }
188
+ static contextType = LocaleContext
190
189
 
191
190
  constructor(props: any) {
192
191
  super(props)
@@ -237,7 +236,7 @@ class EditModeTableSelectComponent extends React.Component<
237
236
 
238
237
  // Sort by name
239
238
  tables = _.sortBy(tables, (tableId) =>
240
- ExprUtils.localizeString(this.props.schema.getTable(tableId)!.name, this.context.locale)
239
+ ExprUtils.localizeString(this.props.schema.getTable(tableId)!.name, this.context)
241
240
  )
242
241
 
243
242
  return tables
@@ -279,8 +278,8 @@ class EditModeTableSelectComponent extends React.Component<
279
278
  <OptionListComponent items={this.getTableShortlist(activeTables).map((tableId) => {
280
279
  const table = this.props.schema.getTable(tableId)!
281
280
  return {
282
- name: ExprUtils.localizeString(table.name, this.context.locale),
283
- desc: ExprUtils.localizeString(table.desc, this.context.locale),
281
+ name: ExprUtils.localizeString(table.name, this.context),
282
+ desc: ExprUtils.localizeString(table.desc, this.context),
284
283
  onClick: () => this.props.onChange(table.id)
285
284
  }
286
285
  })} />
@@ -9,6 +9,7 @@ import { Radio } from "@mwater/react-library/lib/bootstrap"
9
9
  export interface SectionComponentProps {
10
10
  icon?: string
11
11
  label?: any
12
+ required?: boolean
12
13
  }
13
14
 
14
15
  // Miscellaneous ui components
@@ -28,7 +29,8 @@ export class SectionComponent extends React.Component<SectionComponentProps> {
28
29
  this.props.icon && this.props.icon.match(/^glyphicon-/)
29
30
  ? [R("span", { className: `glyphicon ${this.props.icon}` }), " "]
30
31
  : undefined,
31
- this.props.label
32
+ this.props.label,
33
+ this.props.required ? <span style={{ color: "red" }}> *</span> : undefined
32
34
  ),
33
35
  R("div", { style: { marginLeft: 10 } }, this.props.children)
34
36
  )
@@ -205,7 +207,7 @@ export interface ToggleEditComponentProps {
205
207
  initiallyOpen?: boolean
206
208
  label: any
207
209
  editor: any
208
- onRemove?: any
210
+ onRemove?: () => void
209
211
  }
210
212
 
211
213
  interface ToggleEditComponentState {
@@ -221,25 +223,15 @@ export class ToggleEditComponent extends React.Component<ToggleEditComponentProp
221
223
  }
222
224
 
223
225
  close = () => {
224
- // Save height of editor
225
- if (this.editorComp) {
226
- this.editorHeight = ReactDOM.findDOMNode(this.editorComp).clientHeight
227
- }
228
-
229
- return this.setState({ open: false })
226
+ this.setState({ open: false })
230
227
  }
231
228
 
232
229
  open = () => {
233
- return this.setState({ open: true })
230
+ this.setState({ open: true })
234
231
  }
235
232
 
236
233
  handleToggle = () => {
237
- return this.setState({ open: !this.state.open })
238
- }
239
-
240
- // Save editor comp
241
- editorRef = (editorComp: any) => {
242
- return (this.editorComp = editorComp)
234
+ this.setState({ open: !this.state.open })
243
235
  }
244
236
 
245
237
  render() {
@@ -949,8 +949,10 @@ export default class AxisBuilder {
949
949
  return []
950
950
  }
951
951
 
952
- // Get type of axis output
953
- getAxisType(axis: any): LiteralType | null {
952
+ /**
953
+ * Get type of axis output
954
+ */
955
+ getAxisType(axis: Axis | null | undefined): LiteralType | null {
954
956
  if (!axis) {
955
957
  return null
956
958
  }
@@ -971,19 +973,19 @@ export default class AxisBuilder {
971
973
  }
972
974
 
973
975
  // Determines if axis is aggregate
974
- isAxisAggr(axis: any) {
976
+ isAxisAggr(axis: Axis | null | undefined) {
975
977
  // Legacy support of axis.aggr
976
978
  return axis != null && (axis.aggr || this.exprUtils.getExprAggrStatus(axis.expr) === "aggregate")
977
979
  }
978
980
 
979
981
  // Determines if axis supports cumulative values (number, date or year-quarter)
980
- doesAxisSupportCumulative(axis: any) {
982
+ doesAxisSupportCumulative(axis: Axis) {
981
983
  const axisType = this.getAxisType(axis)
982
984
  return axisType == "date" || axisType == "number" || axis.xform?.type === "yearquarter"
983
985
  }
984
986
 
985
987
  // Converts a category to a string (uses label or override)
986
- formatCategory(axis: any, category: any) {
988
+ formatCategory(axis: Axis, category: any) {
987
989
  const categoryLabel = axis.categoryLabels ? axis.categoryLabels[JSON.stringify(category.value)] : undefined
988
990
  if (categoryLabel) {
989
991
  return categoryLabel
@@ -1,10 +1,9 @@
1
1
  import _ from "lodash"
2
- import PropTypes from "prop-types"
3
2
  import React from "react"
4
3
  const R = React.createElement
5
4
  import uuid from "uuid"
6
5
  import AsyncLoadComponent from "@mwater/react-library/lib/AsyncLoadComponent"
7
- import { ExprComponent } from "@mwater/expressions-ui"
6
+ import { ExprComponent, LocaleContext } from "@mwater/expressions-ui"
8
7
  import { AggrStatus, DataSource, ExprUtils, LiteralType, OpExpr, Schema } from "@mwater/expressions"
9
8
  import AxisBuilder from "./AxisBuilder"
10
9
  import update from "update-object"
@@ -29,7 +28,7 @@ export interface AxisComponentProps {
29
28
  /** Optional types to limit to */
30
29
  types?: LiteralType[]
31
30
  aggrNeed: "none" | "optional" | "required"
32
- value?: Axis
31
+ value?: Axis | null
33
32
  onChange: (axis: Axis | null) => void
34
33
  /** Makes this a required value */
35
34
  required?: boolean
@@ -63,7 +62,7 @@ export default class AxisComponent extends AsyncLoadComponent<
63
62
  autosetColors: true
64
63
  }
65
64
 
66
- static contextTypes = { locale: PropTypes.string }
65
+ static contextType = LocaleContext
67
66
 
68
67
  constructor(props: any) {
69
68
  super(props)
@@ -1,20 +1,26 @@
1
1
  import _ from "lodash"
2
- import PropTypes from "prop-types"
3
- import React from "react"
4
- const R = React.createElement
2
+ import React, { useContext } from "react"
5
3
 
6
4
  import ColorSchemeFactory from "../ColorSchemeFactory"
7
- import { Axis, AxisCategory } from "./Axis"
5
+ import { Axis, AxisCategory, ColorMap } from "./Axis"
6
+ import { CustomColorsContext } from "../CustomColorsContext"
8
7
 
9
8
  export interface ColorPaletteCollectionComponentProps {
10
- onPaletteSelected: any
11
9
  axis: Axis
12
10
  categories: AxisCategory[]
13
- onCancel: any
11
+ onPaletteSelected: (colorMap: ColorMap) => void
12
+ onCancel: () => void
14
13
  }
15
14
 
16
- export default class ColorPaletteCollectionComponent extends React.Component<ColorPaletteCollectionComponentProps> {
17
- static palettes = [
15
+ interface Palette {
16
+ type: string
17
+ reversed: boolean
18
+ /** Override colors if type is "custom" */
19
+ colors?: string[]
20
+ }
21
+
22
+ function ColorPaletteCollectionComponent(props: ColorPaletteCollectionComponentProps) {
23
+ const palettes: Palette[] = [
18
24
  { type: "schemeSet1", reversed: false },
19
25
  { type: "schemeSet2", reversed: false },
20
26
  { type: "schemeSet3", reversed: false },
@@ -79,85 +85,105 @@ export default class ColorPaletteCollectionComponent extends React.Component<Col
79
85
  { type: "interpolateRdYlGn", reversed: true }
80
86
  ]
81
87
 
82
- onPaletteSelected = (index: any) => {
83
- // Generate color map
84
- const scheme = ColorSchemeFactory.createColorScheme({
85
- type: ColorPaletteCollectionComponent.palettes[index].type,
86
- // Null doesn't count to length
87
- number: _.any(this.props.categories, (c) => c.value == null)
88
- ? this.props.categories.length - 1
89
- : this.props.categories.length,
90
- reversed: ColorPaletteCollectionComponent.palettes[index].reversed
88
+ // Get custom colors
89
+ const customColorsContext = useContext(CustomColorsContext)
90
+
91
+ // Number of colors needed. Null doesn't count to length
92
+ const numColors = props.categories.filter((c) => c.value != null).length
93
+
94
+ if (customColorsContext && customColorsContext.customColors.filter((c) => c != null).length > 0) {
95
+ const customPalettes: Palette[] = []
96
+ for (let i = 0; i < customColorsContext.customColors.length; i += 6) {
97
+ const customPalette = customColorsContext.customColors.slice(i, i + 6)
98
+ customPalettes.push({ type: "custom", reversed: false, colors: customPalette.filter((c) => c != null) as string[] })
99
+ }
100
+ palettes.unshift(...customPalettes)
101
+ }
102
+
103
+ function generatePaletteColors(palette: Palette, numColors: number) {
104
+ if (palette.type === "custom") {
105
+ return palette.colors!
106
+ }
107
+
108
+ return ColorSchemeFactory.createColorScheme({
109
+ type: palette.type,
110
+ number: numColors,
111
+ reversed: palette.reversed
91
112
  })
113
+ }
92
114
 
93
- const colorMap = _.map(this.props.categories, (category, i) => ({
115
+ const onPaletteSelected = (index: number) => {
116
+ // Generate color map
117
+ const scheme = generatePaletteColors(palettes[index], Math.min(numColors, 6))
118
+
119
+ const colorMap = _.map(props.categories, (category, i) => ({
94
120
  value: category.value,
95
121
  color: category.value === null ? "#aaaaaa" : scheme[i % scheme.length]
96
122
  }))
97
- return this.props.onPaletteSelected(colorMap)
123
+ return props.onPaletteSelected(colorMap)
98
124
  }
99
125
 
100
- renderCancel = () => {
101
- if (this.props.axis.colorMap) {
102
- return R(
103
- "div",
104
- null,
105
- R("a", { className: "link-plain", onClick: this.props.onCancel, key: "cancel-customize" }, "Cancel")
126
+ const renderCancel = () => {
127
+ if (props.axis.colorMap) {
128
+ return (
129
+ <div>
130
+ <a className="link-plain" onClick={props.onCancel} key="cancel-customize">
131
+ Cancel
132
+ </a>
133
+ </div>
106
134
  )
107
135
  }
108
136
  return null
109
137
  }
110
138
 
111
- render() {
112
- return R(
113
- "div",
114
- null,
115
- R("p", null, "Please select a color scheme"),
116
- _.map(ColorPaletteCollectionComponent.palettes, (config, index) => {
117
- return R(ColorPaletteComponent, {
118
- key: index,
119
- index,
120
- colorSet: ColorSchemeFactory.createColorScheme({
121
- type: config.type,
122
- number: Math.min(this.props.categories.length - 1, 6),
123
- reversed: config.reversed
124
- }),
125
- onPaletteSelected: this.onPaletteSelected,
126
- number: this.props.categories.length
127
- })
128
- }),
129
- this.renderCancel()
139
+ function renderPalette(palette: Palette, index: number) {
140
+ return (
141
+ <ColorPaletteComponent
142
+ key={index}
143
+ index={index}
144
+ colorSet={generatePaletteColors(palette, 6)}
145
+ onPaletteSelected={onPaletteSelected}
146
+ />
130
147
  )
131
148
  }
149
+
150
+
151
+ return (
152
+ <div>
153
+ <p>Please select a color scheme</p>
154
+ {palettes.map((palette, index) => renderPalette(palette, index))}
155
+ {renderCancel()}
156
+ </div>
157
+ )
132
158
  }
133
159
 
160
+ export default ColorPaletteCollectionComponent
161
+
134
162
  interface ColorPaletteComponentProps {
135
163
  index: number
136
- colorSet: any
137
- onPaletteSelected: any
138
- number?: number
164
+ colorSet: string[]
165
+ onPaletteSelected: (index: number) => void
139
166
  }
140
167
 
141
168
  class ColorPaletteComponent extends React.Component<ColorPaletteComponentProps> {
142
- static defaultProps = { number: 6 }
143
-
144
169
  handleSelect = () => {
145
170
  return this.props.onPaletteSelected(this.props.index)
146
171
  }
147
172
 
148
173
  render() {
149
- return R(
150
- "div",
151
- { onClick: this.handleSelect, className: "axis-palette" },
152
- _.map(this.props.colorSet.slice(0, this.props.number), (color, i) => {
153
- const cellStyle = {
154
- display: "inline-block",
155
- height: 20,
156
- width: 20,
157
- backgroundColor: color
158
- }
159
- return R("div", { style: cellStyle, key: i }, " ")
160
- })
174
+ return (
175
+ <div onClick={this.handleSelect} className="axis-palette">
176
+ {_.range(Math.max(6, this.props.colorSet.length)).map((i) => {
177
+ const color = this.props.colorSet[i]
178
+ const cellStyle: React.CSSProperties = {
179
+ display: "inline-block",
180
+ height: 20,
181
+ width: 20,
182
+ backgroundColor: color ?? "transparent"
183
+ }
184
+ return <div style={cellStyle} key={i}> </div>
185
+ })}
186
+ </div>
161
187
  )
162
188
  }
163
189
  }