@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,420 +0,0 @@
1
- import React, { CSSProperties } from "react"
2
- import ReactDOM from "react-dom"
3
- import _ from "lodash"
4
- const R = React.createElement
5
- import { DragSource, DropTarget } from "react-dnd"
6
- import DecoratedBlockComponent from "../DecoratedBlockComponent"
7
-
8
- export interface LayoutComponentProps {
9
- /** Opaque information to be used when a block is dragged */
10
- dragInfo: any
11
- canDrag: boolean
12
- connectMoveHandle: any
13
- connectResizeHandle: any
14
- }
15
-
16
- // Render a child element as draggable, resizable block, injecting handle connectors
17
- // to child element
18
- class LayoutComponent extends React.Component<LayoutComponentProps> {
19
- render() {
20
- if (this.props.canDrag) {
21
- return React.cloneElement(React.Children.only(this.props.children!) as any, {
22
- connectMoveHandle: this.props.connectMoveHandle,
23
- connectResizeHandle: this.props.connectResizeHandle
24
- })
25
- } else {
26
- return this.props.children
27
- }
28
- }
29
- }
30
-
31
- const moveSpec = {
32
- beginDrag(props: any, monitor: any, component: any) {
33
- return props.dragInfo
34
- },
35
- canDrag(props: any, monitor: any) {
36
- return props.canDrag
37
- }
38
- }
39
-
40
- function moveCollect(connect: any, monitor: any) {
41
- return {
42
- connectMoveHandle: connect.dragSource()
43
- }
44
- }
45
-
46
- const MoveLayoutComponent = DragSource("block-move", moveSpec, moveCollect)(LayoutComponent)
47
-
48
- const resizeSpec = {
49
- beginDrag(props: any, monitor: any, component: any) {
50
- return props.dragInfo
51
- },
52
- canDrag(props: any, monitor: any) {
53
- return props.canDrag
54
- }
55
- }
56
-
57
- function resizeCollect(connect: any, monitor: any) {
58
- return {
59
- connectResizeHandle: connect.dragSource()
60
- }
61
- }
62
-
63
- const MoveResizeLayoutComponent = DragSource("block-resize", resizeSpec, resizeCollect)(MoveLayoutComponent)
64
-
65
- interface ContainerProps {
66
- layoutEngine: any
67
- /** Lookup of id -> { widget:, layout: } */
68
- items: any
69
- /** Called with lookup of id -> { widget:, layout: } */
70
- onItemsChange?: any
71
- /** Renders a widget */
72
- renderWidget: any
73
- /** width in pixels */
74
- width: number
75
- connectDropTarget: any
76
- }
77
-
78
- interface ContainerState {
79
- moveHover: any
80
- resizeHover: any
81
- }
82
-
83
- // Container contains layouts to layout. It renders widgets at the correct location.
84
- class Container extends React.Component<ContainerProps, ContainerState> {
85
- constructor(props: any) {
86
- super(props)
87
- this.state = { moveHover: null, resizeHover: null }
88
- }
89
-
90
- setMoveHover(hoverInfo: any) {
91
- return this.setState({ moveHover: hoverInfo })
92
- }
93
-
94
- setResizeHover(hoverInfo: any) {
95
- return this.setState({ resizeHover: hoverInfo })
96
- }
97
-
98
- dropLayout(id: any, droppedRect: any, widget: any) {
99
- // Stop hover
100
- this.setState({ moveHover: null, resizeHover: null })
101
-
102
- // Convert rect to layout
103
- const droppedLayout = this.props.layoutEngine.rectToLayout(droppedRect)
104
-
105
- // Insert dropped layout
106
- let items = _.clone(this.props.items)
107
- items[id] = { layout: droppedLayout, widget }
108
-
109
- let layouts: any = {}
110
- for (id in items) {
111
- const item = items[id]
112
- layouts[id] = item.layout
113
- }
114
-
115
- // Perform layout
116
- layouts = this.props.layoutEngine.performLayout(layouts, id)
117
-
118
- // Update item layouts
119
- items = _.mapValues(items, (item, id) => {
120
- return _.extend({}, item, { layout: layouts[id!] })
121
- })
122
-
123
- return this.props.onItemsChange(items)
124
- }
125
-
126
- // Called when a block is dropped
127
- dropMoveLayout(dropInfo: any) {
128
- // Get rectangle of dropped block
129
- const droppedRect = {
130
- x: dropInfo.x,
131
- y: dropInfo.y,
132
- width: dropInfo.dragInfo.bounds.width, // width and height are from drop info
133
- height: dropInfo.dragInfo.bounds.height
134
- }
135
-
136
- return this.dropLayout(dropInfo.dragInfo.id, droppedRect, dropInfo.dragInfo.widget)
137
- }
138
-
139
- dropResizeLayout(dropInfo: any) {
140
- // Get rectangle of hovered block
141
- const droppedRect = {
142
- x: dropInfo.dragInfo.bounds.x,
143
- y: dropInfo.dragInfo.bounds.y,
144
- width: dropInfo.width,
145
- height: dropInfo.height
146
- }
147
-
148
- return this.dropLayout(dropInfo.dragInfo.id, droppedRect, dropInfo.dragInfo.widget)
149
- }
150
-
151
- componentWillReceiveProps(nextProps: any) {
152
- // Reset hover if not over
153
- if (!nextProps.isOver && (this.state.moveHover || this.state.resizeHover)) {
154
- // Defer to prevent "Cannot dispatch in the middle of a dispatch." error
155
- _.defer(() => {
156
- this.setState({ moveHover: null, resizeHover: null })
157
- })
158
- }
159
- }
160
-
161
- handleRemove = (id: any) => {
162
- // Update item layouts
163
- const items = _.omit(this.props.items, id)
164
- return this.props.onItemsChange(items)
165
- }
166
-
167
- handleWidgetDesignChange = (id: any, widgetDesign: any) => {
168
- let { widget } = this.props.items[id]
169
- widget = _.extend({}, widget, { design: widgetDesign })
170
-
171
- let item = this.props.items[id]
172
- item = _.extend({}, item, { widget })
173
-
174
- const items = _.clone(this.props.items)
175
- items[id] = item
176
-
177
- return this.props.onItemsChange(items)
178
- }
179
-
180
- renderPlaceholder(bounds: any) {
181
- return R("div", {
182
- key: "placeholder",
183
- style: {
184
- position: "absolute",
185
- left: bounds.x,
186
- top: bounds.y,
187
- width: bounds.width,
188
- height: bounds.height,
189
- border: "dashed 3px #AAA",
190
- borderRadius: 5,
191
- padding: 5
192
- }
193
- })
194
- }
195
-
196
- // Render a particular layout. Allow visible to be false so that
197
- // dragged elements can retain state
198
- renderItem = (id: any, item: any, layout: any, visible = true) => {
199
- // Calculate bounds
200
- const bounds = this.props.layoutEngine.getLayoutBounds(layout)
201
-
202
- // Position absolutely
203
- const style: CSSProperties = {
204
- position: "absolute",
205
- left: bounds.x,
206
- top: bounds.y
207
- }
208
-
209
- if (!visible) {
210
- style.display = "none"
211
- }
212
-
213
- // Create dragInfo which is all the info needed to drop the layout
214
- const dragInfo = {
215
- id,
216
- bounds,
217
- widget: item.widget
218
- }
219
-
220
- let elem = this.props.renderWidget({
221
- id,
222
- type: item.widget.type,
223
- design: item.widget.design,
224
- onDesignChange: this.props.onItemsChange != null ? this.handleWidgetDesignChange.bind(null, id) : undefined,
225
- width: bounds.width - 10,
226
- height: bounds.height - 10
227
- })
228
-
229
- // Render decorated if editable
230
- if (this.props.onItemsChange) {
231
- elem = React.createElement(
232
- DecoratedBlockComponent,
233
- // style: { width: bounds.width, height: bounds.height }
234
- { onBlockRemove: this.handleRemove.bind(null, id) },
235
- elem
236
- )
237
- } else {
238
- elem = R(
239
- "div",
240
- { className: "mwater-visualization-block-view" },
241
- // style: { width: bounds.width, height: bounds.height },
242
- elem
243
- )
244
- }
245
-
246
- // Clone element, injecting width, height and enclosing in a dnd block
247
- return R(
248
- "div",
249
- { style, key: id },
250
- React.createElement(MoveResizeLayoutComponent, { dragInfo, canDrag: this.props.onItemsChange != null }, elem)
251
- )
252
- }
253
-
254
- // Calculate a lookup of layouts incorporating hover info
255
- calculateLayouts(props: any, state: any) {
256
- // Get hovered block if present
257
- let hoveredRect, id
258
- let hoveredDragInfo = null
259
- let hoveredLayout = null // Layout of hovered block
260
- if (state.moveHover) {
261
- hoveredDragInfo = state.moveHover.dragInfo
262
- hoveredRect = {
263
- x: state.moveHover.x,
264
- y: state.moveHover.y,
265
- width: state.moveHover.dragInfo.bounds.width,
266
- height: state.moveHover.dragInfo.bounds.height
267
- }
268
- hoveredLayout = props.layoutEngine.rectToLayout(hoveredRect)
269
- }
270
-
271
- if (state.resizeHover) {
272
- hoveredDragInfo = state.resizeHover.dragInfo
273
- hoveredRect = {
274
- x: state.resizeHover.dragInfo.bounds.x,
275
- y: state.resizeHover.dragInfo.bounds.y,
276
- width: state.resizeHover.width,
277
- height: state.resizeHover.height
278
- }
279
- hoveredLayout = props.layoutEngine.rectToLayout(hoveredRect)
280
- }
281
-
282
- let layouts: any = {}
283
- for (id in props.items) {
284
- const item = props.items[id]
285
- layouts[id] = item.layout
286
- }
287
-
288
- // Add hovered layout
289
- if (hoveredDragInfo) {
290
- layouts[hoveredDragInfo.id] = hoveredLayout
291
- }
292
-
293
- // Perform layout
294
- layouts = props.layoutEngine.performLayout(layouts, hoveredDragInfo ? hoveredDragInfo.id : undefined)
295
- return layouts
296
- }
297
-
298
- renderItems(items: any) {
299
- let id
300
- const layouts = this.calculateLayouts(this.props, this.state)
301
-
302
- const renderElems = []
303
- const hover = this.state.moveHover || this.state.resizeHover
304
-
305
- // Render blocks in their adjusted position
306
- const ids = []
307
- for (id in items) {
308
- ids.push(id)
309
- }
310
- if (hover && !ids.includes(hover.dragInfo.id)) {
311
- ids.push(hover.dragInfo.id)
312
- }
313
-
314
- for (id of _.sortBy(ids)) {
315
- const item = items[id]
316
- if (!hover || id !== hover.dragInfo.id) {
317
- renderElems.push(this.renderItem(id, item, layouts[id]))
318
- } else {
319
- // Render it anyway so that its state is retained
320
- if (item) {
321
- renderElems.push(this.renderItem(id, item, layouts[id], false))
322
- }
323
- renderElems.push(this.renderPlaceholder(this.props.layoutEngine.getLayoutBounds(layouts[id])))
324
- }
325
- }
326
-
327
- return renderElems
328
- }
329
-
330
- // This gets called 100s of times when dragging
331
- shouldComponentUpdate(nextProps: any, nextState: any) {
332
- if (this.props.width !== nextProps.width) {
333
- return true
334
- }
335
-
336
- if (this.props.layoutEngine !== nextProps.layoutEngine) {
337
- return true
338
- }
339
-
340
- const layouts = this.calculateLayouts(this.props, this.state)
341
- const nextLayouts = this.calculateLayouts(nextProps, nextState)
342
-
343
- if (!_.isEqual(layouts, nextLayouts)) {
344
- return true
345
- }
346
-
347
- return false
348
- }
349
-
350
- render() {
351
- // Determine height using layout engine
352
- const style = {
353
- width: this.props.width,
354
- height: "100%", // @props.layoutEngine.calculateHeight(layouts)
355
- position: "relative"
356
- }
357
-
358
- // Connect as a drop target
359
- return this.props.connectDropTarget(R("div", { style }, this.renderItems(this.props.items)))
360
- }
361
- }
362
-
363
- const targetSpec = {
364
- drop(props: any, monitor: any, component: any) {
365
- if (monitor.getItemType() === "block-move") {
366
- const rect = (ReactDOM.findDOMNode(component) as Element).getBoundingClientRect()
367
- component.dropMoveLayout({
368
- dragInfo: monitor.getItem(),
369
- x:
370
- monitor.getClientOffset().x -
371
- (monitor.getInitialClientOffset().x - monitor.getInitialSourceClientOffset().x) -
372
- rect.left,
373
- y:
374
- monitor.getClientOffset().y -
375
- (monitor.getInitialClientOffset().y - monitor.getInitialSourceClientOffset().y) -
376
- rect.top
377
- })
378
- }
379
- if (monitor.getItemType() === "block-resize") {
380
- component.dropResizeLayout({
381
- dragInfo: monitor.getItem(),
382
- width: monitor.getItem().bounds.width + monitor.getDifferenceFromInitialOffset().x,
383
- height: monitor.getItem().bounds.height + monitor.getDifferenceFromInitialOffset().y
384
- })
385
- }
386
- },
387
- hover(props: any, monitor: any, component: any) {
388
- if (monitor.getItemType() === "block-move") {
389
- const rect = (ReactDOM.findDOMNode(component) as Element).getBoundingClientRect()
390
- component.setMoveHover({
391
- dragInfo: monitor.getItem(),
392
- x:
393
- monitor.getClientOffset().x -
394
- (monitor.getInitialClientOffset().x - monitor.getInitialSourceClientOffset().x) -
395
- rect.left,
396
- y:
397
- monitor.getClientOffset().y -
398
- (monitor.getInitialClientOffset().y - monitor.getInitialSourceClientOffset().y) -
399
- rect.top
400
- })
401
- }
402
- if (monitor.getItemType() === "block-resize") {
403
- component.setResizeHover({
404
- dragInfo: monitor.getItem(),
405
- width: monitor.getItem().bounds.width + monitor.getDifferenceFromInitialOffset().x,
406
- height: monitor.getItem().bounds.height + monitor.getDifferenceFromInitialOffset().y
407
- })
408
- }
409
- }
410
- }
411
-
412
- function targetCollect(connect: any, monitor: any) {
413
- return {
414
- connectDropTarget: connect.dropTarget(),
415
- isOver: monitor.isOver(),
416
- clientOffset: monitor.getClientOffset()
417
- }
418
- }
419
-
420
- export default DropTarget(["block-move", "block-resize"], targetSpec, targetCollect)(Container)
@@ -1,172 +0,0 @@
1
- import React from "react"
2
- const R = React.createElement
3
- import _ from "lodash"
4
- import ClickOutHandler from "react-onclickout"
5
- import Color from "color"
6
-
7
- export interface FontColorPaletteItemProps {
8
- /** Called with "#FF8800", etc. */
9
- onSetColor: any
10
- /** should the popup be under or over? */
11
- position?: string
12
- }
13
-
14
- interface FontColorPaletteItemState {
15
- open: any
16
- }
17
-
18
- // Palette item that allows picking a color
19
- export default class FontColorPaletteItem extends React.Component<
20
- FontColorPaletteItemProps,
21
- FontColorPaletteItemState
22
- > {
23
- static defaultProps = { position: "under" }
24
-
25
- constructor(props: any) {
26
- super(props)
27
- this.state = {
28
- open: false
29
- }
30
- }
31
-
32
- handleMouseDown = (ev: any) => {
33
- // Don't lose focus from editor
34
- ev.preventDefault()
35
- return this.setState({ open: !this.state.open })
36
- }
37
-
38
- render() {
39
- const popupPosition: React.CSSProperties = {
40
- position: "absolute",
41
- left: 0,
42
- zIndex: 1000,
43
- backgroundColor: "white",
44
- border: "solid 1px #AAA",
45
- borderRadius: 3
46
- }
47
-
48
- if (this.props.position === "under") {
49
- popupPosition["top"] = 26
50
- } else {
51
- popupPosition["bottom"] = 26
52
- }
53
-
54
- return R(
55
- ClickOutHandler,
56
- { onClickOut: () => this.setState({ open: false }) },
57
- R(
58
- "div",
59
- {
60
- className: "mwater-visualization-text-palette-item",
61
- onMouseDown: this.handleMouseDown,
62
- style: { position: "relative" }
63
- },
64
- this.state.open
65
- ? R(
66
- "div",
67
- { style: popupPosition },
68
- R(ColorPaletteComponent, {
69
- onSetColor: (color: any) => {
70
- this.props.onSetColor(color)
71
- return this.setState({ open: false })
72
- }
73
- })
74
- )
75
- : undefined,
76
-
77
- R("i", { className: "fa fa-tint" })
78
- )
79
- )
80
- }
81
- }
82
-
83
- interface ColorPaletteComponentProps {
84
- onSetColor: any
85
- }
86
-
87
- class ColorPaletteComponent extends React.Component<ColorPaletteComponentProps> {
88
- renderColor(color: any) {
89
- return R(
90
- "td",
91
- null,
92
- R("div", {
93
- style: { width: 16, height: 15, backgroundColor: color, margin: 1 },
94
- onMouseDown: (ev: any) => {
95
- ev.preventDefault()
96
- return this.props.onSetColor(color)
97
- }
98
- })
99
- )
100
- }
101
-
102
- render() {
103
- const baseColors = [
104
- "#FF0000", // red
105
- "#FFAA00", // orange
106
- "#FFFF00", // yellow
107
- "#00FF00", // green
108
- "#00FFFF", // cyan
109
- "#0000FF", // blue
110
- "#9900FF", // purple
111
- "#FF00FF" // magenta
112
- ]
113
- return R(
114
- "div",
115
- { style: { padding: 5 } },
116
- R(
117
- "table",
118
- null,
119
- R(
120
- "tbody",
121
- null,
122
- // Grey shades
123
- R(
124
- "tr",
125
- null,
126
- _.map(_.range(0, 8), (i) => {
127
- return this.renderColor(Color({ r: (i * 255) / 7, g: (i * 255) / 7, b: (i * 255) / 7 }).hex())
128
- })
129
- ),
130
- R("tr", { style: { height: 5 } }),
131
- // Base colors
132
- R(
133
- "tr",
134
- null,
135
- _.map(baseColors, (c) => this.renderColor(c))
136
- ),
137
- R("tr", { style: { height: 5 } }),
138
- R(
139
- "tr",
140
- null,
141
- _.map(baseColors, (c) => this.renderColor(Color(c).lighten(0.7).hex()))
142
- ),
143
- R(
144
- "tr",
145
- null,
146
- _.map(baseColors, (c) => this.renderColor(Color(c).lighten(0.5).hex()))
147
- ),
148
- R(
149
- "tr",
150
- null,
151
- _.map(baseColors, (c) => this.renderColor(Color(c).lighten(0.3).hex()))
152
- ),
153
- R(
154
- "tr",
155
- null,
156
- _.map(baseColors, (c) => this.renderColor(Color(c).darken(0.3).hex()))
157
- ),
158
- R(
159
- "tr",
160
- null,
161
- _.map(baseColors, (c) => this.renderColor(Color(c).darken(0.5).hex()))
162
- ),
163
- R(
164
- "tr",
165
- null,
166
- _.map(baseColors, (c) => this.renderColor(Color(c).darken(0.7).hex()))
167
- )
168
- )
169
- )
170
- )
171
- }
172
- }
@@ -1,110 +0,0 @@
1
- import React from "react"
2
- const R = React.createElement
3
- import _ from "lodash"
4
- import ClickOutHandler from "react-onclickout"
5
-
6
- export interface FontSizePaletteItemProps {
7
- /** Called with "125%", etc. */
8
- onSetSize: any
9
- /** should the popup be under or over? */
10
- position?: string
11
- }
12
-
13
- interface FontSizePaletteItemState {
14
- open: any
15
- }
16
-
17
- // Palette item that allows picking a size from dropdown
18
- export default class FontSizePaletteItem extends React.Component<FontSizePaletteItemProps, FontSizePaletteItemState> {
19
- static defaultProps = { position: "under" }
20
-
21
- constructor(props: any) {
22
- super(props)
23
- this.state = {
24
- open: false
25
- }
26
- }
27
-
28
- handleMouseDown = (ev: any) => {
29
- // Don't lose focus from editor
30
- ev.preventDefault()
31
- return this.setState({ open: !this.state.open })
32
- }
33
-
34
- renderSize(label: any, value: any) {
35
- return R(
36
- "div",
37
- {
38
- className: "font-size-palette-menu-item",
39
- onMouseDown: (ev) => {
40
- ev.preventDefault()
41
- this.props.onSetSize(value)
42
- return this.setState({ open: false })
43
- },
44
- key: value
45
- },
46
- label
47
- )
48
- }
49
-
50
- renderSizes() {
51
- return R(
52
- "div",
53
- null,
54
- this.renderSize("Tiny", "50%"),
55
- this.renderSize("Small", "66%"),
56
- this.renderSize("Normal", "100%"),
57
- this.renderSize("Large", "150%"),
58
- this.renderSize("Huge", "200%")
59
- )
60
- }
61
-
62
- render() {
63
- const popupPosition: React.CSSProperties = {
64
- position: "absolute",
65
- left: 0,
66
- zIndex: 1000,
67
- backgroundColor: "white",
68
- border: "solid 1px #AAA",
69
- borderRadius: 3
70
- }
71
-
72
- if (this.props.position === "under") {
73
- popupPosition["top"] = 26
74
- } else {
75
- popupPosition["bottom"] = 26
76
- }
77
-
78
- return R(
79
- ClickOutHandler,
80
- { onClickOut: () => this.setState({ open: false }) },
81
- R(
82
- "div",
83
- {
84
- className: "mwater-visualization-text-palette-item",
85
- onMouseDown: this.handleMouseDown,
86
- style: { position: "relative" }
87
- },
88
- R(
89
- "style",
90
- null,
91
- `\
92
- .font-size-palette-menu-item {
93
- color: black;
94
- background-color: white;
95
- text-align: left;
96
- padding: 5px 15px 5px 15px;
97
- cursor: pointer;
98
- }
99
- .font-size-palette-menu-item:hover {
100
- background-color: #DDD;
101
- }\
102
- `
103
- ),
104
- this.state.open ? R("div", { style: popupPosition }, this.renderSizes()) : undefined,
105
-
106
- R("i", { className: "fa fa-arrows-v" })
107
- )
108
- )
109
- }
110
- }