@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,185 +0,0 @@
1
- import _ from "lodash"
2
- import React from "react"
3
- const R = React.createElement
4
-
5
- import uuid from "uuid"
6
- import LayoutManager from "../LayoutManager"
7
- import LegoLayoutEngine from "./LegoLayoutEngine"
8
- import AutoSizeComponent from "@mwater/react-library/lib/AutoSizeComponent"
9
-
10
- export default class GridLayoutManager extends LayoutManager {
11
- renderPalette(width: any) {
12
- const PaletteItemComponent = require("./PaletteItemComponent").default
13
-
14
- const createWidgetItem =
15
- (
16
- type: any,
17
- design: any // Add unique id
18
- ) =>
19
- () => ({
20
- id: uuid(),
21
- widget: { type, design },
22
- bounds: { x: 0, y: 0, width: width / 3, height: width / 4 }
23
- })
24
-
25
- return R(
26
- "div",
27
- {
28
- className: "mwater-visualization-palette",
29
- style: { position: "absolute", top: 0, left: 0, bottom: 0, width: 185 }
30
- },
31
- R(PaletteItemComponent, {
32
- createItem: createWidgetItem("Text", { style: "title" }),
33
- title: R("i", { className: "fa fa-font" }),
34
- subtitle: "Title"
35
- }),
36
- R(PaletteItemComponent, {
37
- createItem: createWidgetItem("Text", {}),
38
- title: R("i", { className: "fa fa-align-left" }),
39
- subtitle: "Text"
40
- }),
41
- R(PaletteItemComponent, {
42
- createItem: createWidgetItem("LayeredChart", {}),
43
- title: R("i", { className: "fa fa-bar-chart" }),
44
- subtitle: "Chart"
45
- }),
46
- R(PaletteItemComponent, {
47
- createItem: createWidgetItem("Image", {}),
48
- title: R("i", { className: "fa fa-image" }),
49
- subtitle: "Image"
50
- }),
51
- R(PaletteItemComponent, {
52
- createItem: createWidgetItem("Map", {
53
- baseLayer: "bing_road",
54
- layerViews: [],
55
- filters: {},
56
- bounds: { w: -40, n: 25, e: 40, s: -25 }
57
- }),
58
- title: R("i", { className: "fa fa-map-o" }),
59
- subtitle: "Map"
60
- }),
61
- R(PaletteItemComponent, {
62
- createItem: createWidgetItem("TableChart", {}),
63
- title: R("i", { className: "fa fa-table" }),
64
- subtitle: "Table"
65
- }),
66
- R(PaletteItemComponent, {
67
- createItem: createWidgetItem("CalendarChart", {}),
68
- title: R("i", { className: "fa fa-calendar" }),
69
- subtitle: "Calendar"
70
- }),
71
- R(PaletteItemComponent, {
72
- createItem: createWidgetItem("ImageMosaicChart", {}),
73
- title: R("i", { className: "fa fa-th" }),
74
- subtitle: "Mosaic"
75
- }),
76
- R(PaletteItemComponent, {
77
- createItem: createWidgetItem("IFrame", {}),
78
- title: R("i", { className: "fa fa-youtube-play" }),
79
- subtitle: "Video"
80
- })
81
- )
82
- }
83
-
84
- // Renders the layout as a react element
85
- // options:
86
- // items: opaque items object that layout manager understands
87
- // onItemsChange: Called when items changes
88
- // renderWidget: called with ({ id:, type:, design:, onDesignChange:, width:, height: })
89
- renderLayout(options: any) {
90
- const GridLayoutComponent = require("./GridLayoutComponent").default
91
-
92
- return R(AutoSizeComponent, { injectWidth: true, injectHeight: true } as any, (size: any) => {
93
- if (options.onItemsChange != null) {
94
- return R(
95
- "div",
96
- { style: { position: "relative", height: "100%", overflow: "hidden" } },
97
- this.renderPalette(size.width),
98
- R(
99
- "div",
100
- { style: { position: "absolute", left: 185, top: 0, right: 0, bottom: 0, overflow: "scroll" } },
101
- R(
102
- "div",
103
- { style: { position: "absolute", left: 20, top: 20, right: 20, bottom: 20 } },
104
- R(GridLayoutComponent, {
105
- width: size.width - 40 - 185,
106
- items: options.items,
107
- onItemsChange: options.onItemsChange,
108
- renderWidget: options.renderWidget
109
- })
110
- )
111
- )
112
- )
113
- } else {
114
- return R(
115
- "div",
116
- { style: { position: "relative", height: "100%", width: size.width, padding: 20 } },
117
- R(GridLayoutComponent, {
118
- width: size.width - 40,
119
- items: options.items,
120
- onItemsChange: options.onItemsChange,
121
- renderWidget: options.renderWidget
122
- })
123
- )
124
- }
125
- })
126
- }
127
-
128
- // Tests if dashboard has any items
129
- isEmpty(items: any) {
130
- return _.isEmpty(items)
131
- }
132
-
133
- // Gets { type, design } of a widget
134
- getWidgetTypeAndDesign(items: any, widgetId: any) {
135
- return items[widgetId]?.widget
136
- }
137
-
138
- // Gets all widgets in items as array of { type, design }
139
- getAllWidgets(items: any) {
140
- const widgets = []
141
- for (let id in items) {
142
- const item = items[id]
143
- widgets.push({ id, type: item.widget.type, design: item.widget.design })
144
- }
145
-
146
- return widgets
147
- }
148
-
149
- // Add a widget to the items
150
- addWidget(items: any, widgetType: any, widgetDesign: any) {
151
- // Find place for new item
152
- const layout = this.findOpenLayout(items, 12, 12)
153
-
154
- // Create item
155
- const item = {
156
- layout,
157
- widget: {
158
- type: widgetType,
159
- design: widgetDesign
160
- }
161
- }
162
-
163
- const id = uuid()
164
-
165
- // Add item
166
- items = _.clone(items)
167
- items[id] = item
168
-
169
- return items
170
- }
171
-
172
- // Find a layout that the new widget fits in. width and height are in 24ths
173
- findOpenLayout(items: any, width: any, height: any) {
174
- // Create layout engine
175
- // TODO create from design
176
- // TODO uses fake width
177
- const layoutEngine = new LegoLayoutEngine(100, 24)
178
-
179
- // Get existing layouts
180
- const layouts = _.pluck(_.values(items) as any, "layout")
181
-
182
- // Find place for new item
183
- return layoutEngine.appendLayout(layouts, width, height)
184
- }
185
- }
@@ -1,142 +0,0 @@
1
- import _ from "lodash"
2
-
3
- // Layout engine that places blocks like lego and displaces others out of the way
4
- export default class LegoLayoutEngine {
5
- width: any
6
- blocksAcross: any
7
- scale: number
8
-
9
- constructor(width: any, blocksAcross: any) {
10
- this.width = width
11
- this.blocksAcross = blocksAcross
12
- this.scale = this.width / this.blocksAcross
13
- }
14
-
15
- // Calculate the total height needed to fit all layouts plus one row
16
- calculateHeight(layouts: any) {
17
- const bottom = _.max(_.map(layouts, (l) => this.getLayoutBounds(l).y + this.getLayoutBounds(l).height))
18
- return bottom + this.scale
19
- }
20
-
21
- // Get the bounds of a layout (x, y, width, height)
22
- getLayoutBounds(layout: any) {
23
- return {
24
- x: this.scale * layout.x,
25
- y: this.scale * layout.y,
26
- width: this.scale * layout.w,
27
- height: this.scale * layout.h
28
- }
29
- }
30
-
31
- // Converts a rectangle to a layout
32
- rectToLayout(rect: any) {
33
- // Get snapped approximate location
34
- let x = Math.round(rect.x / this.scale)
35
- let y = Math.round(rect.y / this.scale)
36
- let w = Math.round(rect.width / this.scale)
37
- let h = Math.round(rect.height / this.scale)
38
-
39
- // Clip
40
- if (x < 0) {
41
- x = 0
42
- }
43
- if (y < 0) {
44
- y = 0
45
- }
46
- if (x >= this.blocksAcross) {
47
- x = this.blocksAcross - 1
48
- }
49
-
50
- if (w < 1) {
51
- w = 1
52
- }
53
- if (x + w > this.blocksAcross) {
54
- w = this.blocksAcross - x
55
- }
56
-
57
- if (h < 1) {
58
- h = 1
59
- }
60
-
61
- return { x, y, w, h }
62
- }
63
-
64
- // Arranges a layout, making all blocks fit. Optionally prioritizes
65
- // a particular item.
66
- // layouts is lookup of id -> layout
67
- // priority is optional id to layout first
68
- // Returns layout lookup of id -> layout
69
- performLayout(layouts: any, priority: any) {
70
- // Create list of placed layouts to avoid as placing new ones
71
- const placedLayouts: any[] = []
72
- const results: any = {}
73
-
74
- // Add priority first to displace others
75
- if (priority) {
76
- placedLayouts.push(layouts[priority])
77
- results[priority] = layouts[priority]
78
- }
79
-
80
- // Order all by reading order (l->r, top->bottom)
81
- const toProcess = _.sortBy(_.keys(layouts), (id) => {
82
- const l = layouts[id]
83
- return l.x + l.y * this.blocksAcross
84
- })
85
-
86
- // Process each layout, avoiding all previous
87
- for (let id of toProcess) {
88
- // Skip priority one
89
- if (id === priority) {
90
- continue
91
- }
92
-
93
- // Check if overlaps
94
- var layout = layouts[id]
95
- while (_.any(placedLayouts, (pl) => this.overlaps(pl, layout))) {
96
- // Move around until fits
97
- layout = this.shiftLayout(layout)
98
- }
99
-
100
- placedLayouts.push(layout)
101
- results[id] = layout
102
- }
103
-
104
- return results
105
- }
106
-
107
- // Adds a layout with the w and h (width and height in blocks)
108
- appendLayout(layouts: any, w: any, h: any) {
109
- // Check if overlaps
110
- let layout = { x: 0, y: 0, w, h }
111
- while (_.any(_.values(layouts), (pl) => this.overlaps(pl, layout))) {
112
- // Move around until fits
113
- layout = this.shiftLayout(layout)
114
- }
115
- return layout
116
- }
117
-
118
- // Check if layouts overlap
119
- overlaps(a: any, b: any) {
120
- if (a.x + a.w <= b.x) {
121
- return false
122
- }
123
- if (a.y + a.h <= b.y) {
124
- return false
125
- }
126
- if (a.x >= b.x + b.w) {
127
- return false
128
- }
129
- if (a.y >= b.y + b.h) {
130
- return false
131
- }
132
- return true
133
- }
134
-
135
- // Shifts layout right or down if no more room
136
- shiftLayout(layout: any) {
137
- if (layout.x + layout.w < this.blocksAcross) {
138
- return { x: layout.x + 1, y: layout.y, w: layout.w, h: layout.h }
139
- }
140
- return { x: 0, y: layout.y + 1, w: layout.w, h: layout.h }
141
- }
142
- }
@@ -1,28 +0,0 @@
1
- import PropTypes from "prop-types"
2
- import React from "react"
3
- const R = React.createElement
4
-
5
- const DragSourceComponent = require("../DragSourceComponent").default("block-move")
6
-
7
- export interface PaletteItemComponentProps {
8
- /** Create the drag item */
9
- createItem: any
10
- title?: any
11
- subtitle?: any
12
- }
13
-
14
- // Item in a palette that can be dragged to add a widget or other item
15
- export default class PaletteItemComponent extends React.Component<PaletteItemComponentProps> {
16
- render() {
17
- return R(
18
- DragSourceComponent,
19
- { createDragItem: this.props.createItem },
20
- R(
21
- "div",
22
- { className: "mwater-visualization-palette-item" },
23
- R("div", { className: "title", key: "title" }, this.props.title),
24
- R("div", { className: "subtitle", key: "subtitle" }, this.props.subtitle)
25
- )
26
- )
27
- }
28
- }
@@ -1,14 +0,0 @@
1
- Items is:
2
-
3
- `dashboard items, indexed by id. Each item contains:
4
-
5
- `layout`: layout-engine specific data for layout of item
6
- `widget`: details of the widget (see below)
7
-
8
- ### Widget data
9
-
10
- `widget` contains:
11
-
12
- `type`: type string of the widget. Understandable by widget factory
13
- `version`: version of the widget. semver string
14
- `design`: design of the widget as a JSON object