cx-diagrams 22.3.2 → 22.3.5

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.5",
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 | "space-between";
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") {
@@ -73,11 +77,13 @@ export class Flow extends Node {
73
77
  if (!box) continue;
74
78
  if (height > pt) height += gap;
75
79
  height += box.mt;
80
+ height += box.ms;
76
81
  box.col += pl + box.ml;
77
82
  box.row += height;
78
83
  height += box.height;
79
84
  height += box.mb;
80
85
  width = Math.max(width, box.col + box.width + box.mr + pr);
86
+ if (box.selfAlign == "stretch") stretchItems.push(box);
81
87
  }
82
88
  height += pb;
83
89
  } else if (direction == "up") {
@@ -93,10 +99,17 @@ export class Flow extends Node {
93
99
  height += box.mt;
94
100
  height += box.me;
95
101
  width = Math.max(width, box.col + box.width + box.mr + pr);
102
+ if (box.selfAlign == "stretch") stretchItems.push(box);
96
103
  }
97
104
  height += pt;
98
105
  }
99
106
 
107
+ if (direction == "left" || direction == "right") {
108
+ for (let box of stretchItems) box.height = height - pt - pb;
109
+ } else if (direction == "up" || direction == "down") {
110
+ for (let box of stretchItems) box.width = width - pl - pr;
111
+ }
112
+
100
113
  instance.box = {
101
114
  row,
102
115
  col,
@@ -108,6 +121,7 @@ export class Flow extends Node {
108
121
  mt,
109
122
  ms,
110
123
  me,
124
+ selfAlign: this.selfAlign,
111
125
  };
112
126
 
113
127
  super.exploreCleanup(context, instance);
@@ -118,12 +132,39 @@ export class Flow extends Node {
118
132
  let innerWidth = box.width - data.pl - data.pr;
119
133
  let innerHeight = box.height - data.pt - data.pb;
120
134
 
135
+ let spacing = 0;
136
+
137
+ if (this.justify == "space-between") {
138
+ let contentSize = 0,
139
+ count = 0,
140
+ size = 0;
141
+ if (instance.direction == "left" || instance.direction == "right") {
142
+ for (let { box } of nodes) {
143
+ if (!box) continue;
144
+ contentSize += box.width;
145
+ count++;
146
+ }
147
+ size = innerWidth;
148
+ } else {
149
+ for (let { box } of nodes) {
150
+ if (!box) continue;
151
+ contentSize += box.height;
152
+ count++;
153
+ }
154
+ size = innerHeight;
155
+ }
156
+ spacing = (size - contentSize) / (count - 1) - data.gap;
157
+ }
158
+
159
+ let index = 0;
160
+
121
161
  for (let child of nodes) {
122
162
  if (!child.box) continue;
123
163
 
124
164
  switch (instance.direction) {
125
165
  case "right":
126
166
  child.box.col += box.col;
167
+ child.box.col += index * spacing;
127
168
  child.box.row += box.row;
128
169
 
129
170
  if (this.align == "center") child.box.row += (innerHeight - child.box.height) / 2;
@@ -133,12 +174,14 @@ export class Flow extends Node {
133
174
  case "down":
134
175
  child.box.col += box.col;
135
176
  child.box.row += box.row;
177
+ child.box.row += index * spacing;
136
178
 
137
179
  if (this.align == "center") child.box.col += (innerWidth - child.box.width) / 2;
138
180
  break;
139
181
 
140
182
  case "left":
141
183
  child.box.col += box.col + box.width;
184
+ child.box.col -= index * spacing;
142
185
  child.box.row += box.row;
143
186
 
144
187
  if (this.align == "center") child.box.row += (innerHeight - child.box.height) / 2;
@@ -147,10 +190,13 @@ export class Flow extends Node {
147
190
  case "up":
148
191
  child.box.col += box.col;
149
192
  child.box.row += box.row + box.height;
193
+ child.box.row -= index * spacing;
150
194
 
151
195
  if (this.align == "center") child.box.col += (innerWidth - child.box.width) / 2;
152
196
  break;
153
197
  }
198
+
199
+ index++;
154
200
  }
155
201
  super.prepare(context, instance);
156
202
  }
@@ -158,6 +204,8 @@ export class Flow extends Node {
158
204
 
159
205
  Flow.prototype.direction = "right";
160
206
  Flow.prototype.align = "start";
207
+ Flow.prototype.selfAlign = null;
208
+ Flow.prototype.justify = null;
161
209
  Flow.prototype.gap = 0;
162
210
  Flow.prototype.padding = 0;
163
211
  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
 
@@ -1,7 +1,7 @@
1
1
  import { NumberProp, StringProp, Widget } from "cx/src/core";
2
- import { Line, LineProps } from "cx/svg";
2
+ import { StraightLineProps } from "./StraightLine";
3
3
 
4
- interface ThreeSegmentLineProps extends LineProps {
4
+ interface ThreeSegmentLineProps extends StraightLineProps {
5
5
  startOffset?: NumberProp;
6
6
  direction?: StringProp;
7
7
  }
@@ -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
 
@@ -1,7 +1,7 @@
1
1
  import { NumberProp, StringProp, Widget } from "cx/src/core";
2
- import { Line, LineProps } from "cx/svg";
2
+ import { StraightLineProps } from "./StraightLine";
3
3
 
4
- interface TwoSegmentLineProps extends LineProps {
4
+ interface TwoSegmentLineProps extends StraightLineProps {
5
5
  startOffset?: NumberProp;
6
6
  direction?: StringProp;
7
7
  }
@@ -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