cx-diagrams 22.3.2 → 22.3.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cx-diagrams",
3
- "version": "22.3.2",
3
+ "version": "22.3.3",
4
4
  "description": "A library for creating diagrams within CxJS applications",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -21,4 +21,8 @@ export class DiagramState {
21
21
  );
22
22
  return data;
23
23
  }
24
+
25
+ hasShape(id) {
26
+ return !!this.shapes[id];
27
+ }
24
28
  }
package/src/Flow.d.ts CHANGED
@@ -37,6 +37,12 @@ export interface FlowProps extends NodeProps {
37
37
 
38
38
  /** Alignment of items. */
39
39
  align?: "start" | "center";
40
+
41
+ /** Distribute items */
42
+ justify?: null | "stretch";
43
+
44
+ /** Change alignment of this particular item */
45
+ selfAlign?: null | "stretch";
40
46
  }
41
47
 
42
48
  export class Flow extends Widget<FlowProps> {}
package/src/Flow.js CHANGED
@@ -35,6 +35,8 @@ export class Flow extends Node {
35
35
  let direction = (instance.direction =
36
36
  context.rotateDirection && !data.fixed ? context.rotateDirection(this.direction) : this.direction);
37
37
 
38
+ let stretchItems = [];
39
+
38
40
  let { pl, pr, pt, pb, gap, ml, mr, mt, mb, ms, me } = data;
39
41
  if (direction == "right") {
40
42
  width += pl;
@@ -49,6 +51,7 @@ export class Flow extends Node {
49
51
  width += box.mr;
50
52
  width += box.me;
51
53
  height = Math.max(height, box.row + box.height + box.mb + pb);
54
+ if (box.selfAlign == "stretch") stretchItems.push(box);
52
55
  }
53
56
  width += pr;
54
57
  }
@@ -65,6 +68,7 @@ export class Flow extends Node {
65
68
  width += box.ml;
66
69
  width += box.me;
67
70
  height = Math.max(height, box.row + box.height + box.mb + pb);
71
+ if (box.selfAlign == "stretch") stretchItems.push(box);
68
72
  }
69
73
  width += pl;
70
74
  } else if (direction == "down") {
@@ -78,6 +82,7 @@ export class Flow extends Node {
78
82
  height += box.height;
79
83
  height += box.mb;
80
84
  width = Math.max(width, box.col + box.width + box.mr + pr);
85
+ if (box.selfAlign == "stretch") stretchItems.push(box);
81
86
  }
82
87
  height += pb;
83
88
  } else if (direction == "up") {
@@ -93,10 +98,17 @@ export class Flow extends Node {
93
98
  height += box.mt;
94
99
  height += box.me;
95
100
  width = Math.max(width, box.col + box.width + box.mr + pr);
101
+ if (box.selfAlign == "stretch") stretchItems.push(box);
96
102
  }
97
103
  height += pt;
98
104
  }
99
105
 
106
+ if (direction == "left" || direction == "right") {
107
+ for (let box of stretchItems) box.height = height - pt - pb;
108
+ } else if (direction == "up" || direction == "down") {
109
+ for (let box of stretchItems) box.width = width - pl - pr;
110
+ }
111
+
100
112
  instance.box = {
101
113
  row,
102
114
  col,
@@ -108,6 +120,7 @@ export class Flow extends Node {
108
120
  mt,
109
121
  ms,
110
122
  me,
123
+ selfAlign: this.selfAlign,
111
124
  };
112
125
 
113
126
  super.exploreCleanup(context, instance);
@@ -118,12 +131,39 @@ export class Flow extends Node {
118
131
  let innerWidth = box.width - data.pl - data.pr;
119
132
  let innerHeight = box.height - data.pt - data.pb;
120
133
 
134
+ let spacing = 0;
135
+
136
+ if (this.justify == "space-between") {
137
+ let contentSize = 0,
138
+ count = 0,
139
+ size = 0;
140
+ if (instance.direction == "left" || instance.direction == "right") {
141
+ for (let { box } of nodes) {
142
+ if (!box) continue;
143
+ contentSize += box.width;
144
+ count++;
145
+ }
146
+ size = innerWidth;
147
+ } else {
148
+ for (let { box } of nodes) {
149
+ if (!box) continue;
150
+ contentSize += box.height;
151
+ count++;
152
+ }
153
+ size = innerHeight;
154
+ }
155
+ spacing = (size - contentSize) / (count - 1) - data.gap;
156
+ }
157
+
158
+ let index = 0;
159
+
121
160
  for (let child of nodes) {
122
161
  if (!child.box) continue;
123
162
 
124
163
  switch (instance.direction) {
125
164
  case "right":
126
165
  child.box.col += box.col;
166
+ child.box.col += index * spacing;
127
167
  child.box.row += box.row;
128
168
 
129
169
  if (this.align == "center") child.box.row += (innerHeight - child.box.height) / 2;
@@ -133,12 +173,14 @@ export class Flow extends Node {
133
173
  case "down":
134
174
  child.box.col += box.col;
135
175
  child.box.row += box.row;
176
+ child.box.row += index * spacing;
136
177
 
137
178
  if (this.align == "center") child.box.col += (innerWidth - child.box.width) / 2;
138
179
  break;
139
180
 
140
181
  case "left":
141
182
  child.box.col += box.col + box.width;
183
+ child.box.col += index * spacing;
142
184
  child.box.row += box.row;
143
185
 
144
186
  if (this.align == "center") child.box.row += (innerHeight - child.box.height) / 2;
@@ -147,10 +189,13 @@ export class Flow extends Node {
147
189
  case "up":
148
190
  child.box.col += box.col;
149
191
  child.box.row += box.row + box.height;
192
+ child.box.row += index * spacing;
150
193
 
151
194
  if (this.align == "center") child.box.col += (innerWidth - child.box.width) / 2;
152
195
  break;
153
196
  }
197
+
198
+ index++;
154
199
  }
155
200
  super.prepare(context, instance);
156
201
  }
@@ -158,6 +203,8 @@ export class Flow extends Node {
158
203
 
159
204
  Flow.prototype.direction = "right";
160
205
  Flow.prototype.align = "start";
206
+ Flow.prototype.selfAlign = null;
207
+ Flow.prototype.justify = null;
161
208
  Flow.prototype.gap = 0;
162
209
  Flow.prototype.padding = 0;
163
210
  Flow.prototype.margin = 0;
package/src/Shape.d.ts CHANGED
@@ -3,6 +3,7 @@ import { BoundedObjectProps } from "cx/src/svg/BoundedObject";
3
3
  import { Instance } from "cx/src/ui/Instance";
4
4
 
5
5
  export interface ShapeProps extends BoundedObjectProps {
6
+ id?: StringProp;
6
7
  text?: StringProp;
7
8
  shape?: "rect" | "circle";
8
9
  tooltip?: StringProp | Config;
@@ -15,6 +15,8 @@ export class StraightLine extends Container {
15
15
 
16
16
  if (!data.from || !data.to || !context.diagram) return new Rect();
17
17
 
18
+ if (!context.diagram.hasShape(data.from) || !context.diagram.hasShape(data.to)) return new Rect();
19
+
18
20
  let { bounds: sb, shape: startShape } = context.diagram.getShape(data.from);
19
21
  let { bounds: eb, shape: endShape } = context.diagram.getShape(data.to);
20
22
 
@@ -26,6 +26,8 @@ export class ThreeSegmentLine extends Container {
26
26
 
27
27
  if (!data.from || !data.to || !context.diagram) return new Rect();
28
28
 
29
+ if (!context.diagram.hasShape(data.from) || !context.diagram.hasShape(data.to)) return new Rect();
30
+
29
31
  let { bounds: sb, shape: startShape } = context.diagram.getShape(data.from);
30
32
  let { bounds: eb, shape: endShape } = context.diagram.getShape(data.to);
31
33
 
@@ -26,6 +26,8 @@ export class TwoSegmentLine extends Container {
26
26
 
27
27
  if (!data.from || !data.to || !context.diagram) return new Rect();
28
28
 
29
+ if (!context.diagram.hasShape(data.from) || !context.diagram.hasShape(data.to)) return new Rect();
30
+
29
31
  let { bounds: sb, shape: startShape } = context.diagram.getShape(data.from);
30
32
  let { bounds: eb, shape: endShape } = context.diagram.getShape(data.to);
31
33