Skip to content

Commit 7f7ad36

Browse files
Reworked connector annotation control
1 parent cc4ee46 commit 7f7ad36

File tree

10 files changed

+206
-186
lines changed

10 files changed

+206
-186
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "basicprimitives",
33
"sideEffects": false,
44
"homepage": "https://www.basicprimitives.com/",
5-
"version": "6.6.0",
5+
"version": "6.6.1",
66
"author": "Basic Primitives Inc. <support@basicprimitives.com> (https://www.basicprimitives.com)",
77
"description": "Basic Primitives Diagrams for JavaScript - data visualization components library that implements organizational chart and multi-parent dependency diagrams, contains implementations of JavaScript Controls and PDF rendering plugins.",
88
"repository": {

src/ConnectorAnnotationControl.js

Lines changed: 9 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
import Rect from './graphics/structs/Rect';
2-
import PaletteItem from './graphics/structs/PaletteItem';
3-
import { ConnectorPlacementType } from './enums';
42
import createGraphics from './graphics/createGraphics';
5-
import { getFixOfPixelAlignment, getInnerSize, getElementOffset } from './graphics/dom';
3+
import { getFixOfPixelAlignment, getInnerSize } from './graphics/dom';
64
import JsonML from './common/jsonml-html';
7-
import Transform from './graphics/Transform';
8-
import PolylinesBuffer from './graphics/structs/PolylinesBuffer';
9-
import ConnectorAnnotationOffsetResolver from './tasks/renders/offsetResolver/ConnectorAnnotationOffsetResolver';
10-
import ConnectorOffbeat from './graphics/shapes/ConnectorOffbeat';
11-
import ConnectorStraight from './graphics/shapes/ConnectorStraight';
5+
import ConnectorAnnotation from './graphics/annotations/ConnectorAnnotation';
126
import AnnotationLabelTemplate from './templates/html/AnnotationLabelTemplate';
13-
import { isNullOrEmpty } from './common';
14-
import RenderEventArgs from './events/RenderEventArgs';
157

168
/**
179
* Creates JavaScript Connector Annotation Control
@@ -30,7 +22,8 @@ export default function ConnectorAnnotationControl(element, options) {
3022
placeholder: null,
3123
panelSize: null,
3224
graphics: null,
33-
labelTemplate: null
25+
labelTemplate: null,
26+
connector: null
3427
};
3528

3629
if(!element) {
@@ -70,6 +63,7 @@ export default function ConnectorAnnotationControl(element, options) {
7063
);
7164

7265
_data.graphics = createGraphics(_data.element);
66+
_data.connector = new ConnectorAnnotation();
7367
};
7468

7569
function cleanLayout() {
@@ -106,127 +100,19 @@ export default function ConnectorAnnotationControl(element, options) {
106100
_data.labelTemplate = AnnotationLabelTemplate(_data.options);
107101
cleanLayout();
108102
createLayout();
109-
redraw();
103+
_data.graphics.begin();
104+
_data.connector.draw(_data.options, _data.graphics, _data.panelSize, _data.labelTemplate);
105+
_data.graphics.end();
110106
}
111107
else {
112108
updateLayout();
113109
_data.graphics.resize("placeholder", _data.panelSize.width, _data.panelSize.height);
114110
_data.graphics.begin();
115-
redraw();
111+
_data.connector.draw(_data.options, _data.graphics, _data.panelSize, _data.labelTemplate);
116112
_data.graphics.end();
117113
}
118114
}
119115

120-
function redraw() {
121-
var annotationConfig = _data.options,
122-
shape,
123-
uiHash,
124-
transform = new Transform(),
125-
panel = _data.graphics.activate("placeholder"),
126-
buffer = new PolylinesBuffer(),
127-
connectorAnnotationOffsetResolver = ConnectorAnnotationOffsetResolver();
128-
129-
transform.size = new Size(_data.panelSize.width, _data.panelSize.height);
130-
transform.setOrientation(annotationConfig.orientationType);
131-
132-
if (annotationConfig.fromRectangle != null && annotationConfig.toRectangle != null) {
133-
var fromRect = annotationConfig.fromRectangle,
134-
toRect = annotationConfig.toRectangle;
135-
136-
/* translate rectangles to Top orientation */
137-
/* from rectangle */
138-
transform.transformRect(fromRect.x, fromRect.y, fromRect.width, fromRect.height, false,
139-
this, function (x, y, width, height) {
140-
fromRect = new Rect(x, y, width, height);
141-
});
142-
143-
/* to rectangle */
144-
transform.transformRect(toRect.x, toRect.y, toRect.width, toRect.height, false,
145-
this, function (x, y, width, height) {
146-
toRect = new Rect(x, y, width, height);
147-
});
148-
149-
switch (annotationConfig.connectorPlacementType) {
150-
case ConnectorPlacementType.Offbeat:
151-
shape = new ConnectorOffbeat();
152-
break;
153-
case ConnectorPlacementType.Straight:
154-
shape = new ConnectorStraight();
155-
break;
156-
}
157-
158-
/* rotate label size to user orientation */
159-
var labelSize;
160-
transform.transformRect(0, 0, annotationConfig.labelSize.width, annotationConfig.labelSize.height, false,
161-
this, function (x, y, width, height) {
162-
labelSize = new Size(width, height);
163-
});
164-
165-
/* rotate panel size to user orientation */
166-
var panelSize = null;
167-
transform.transformRect(0, 0, panel.size.width, panel.size.height, false,
168-
this, function (x, y, width, height) {
169-
panelSize = new Size(width, height);
170-
});
171-
172-
var linePaletteItem = new PaletteItem({
173-
lineColor: annotationConfig.color,
174-
lineWidth: annotationConfig.lineWidth,
175-
lineType: annotationConfig.lineType
176-
});
177-
178-
var hasLabel = !isNullOrEmpty(annotationConfig.label);
179-
180-
/* offset rectangles */
181-
fromRect = new Rect(fromRect).offset(annotationConfig.offset);
182-
toRect = new Rect(toRect).offset(annotationConfig.offset);
183-
184-
var linesOffset = annotationConfig.lineWidth * 6;
185-
186-
/* create connection lines */
187-
shape.draw(buffer, linePaletteItem, fromRect, toRect, linesOffset, 0, labelSize, panelSize,
188-
annotationConfig.connectorShapeType, annotationConfig.labelOffset, annotationConfig.labelPlacementType, hasLabel,
189-
connectorAnnotationOffsetResolver, function (labelPlacement, labelConfig) {
190-
var hasLabel = !isNullOrEmpty(labelConfig.label);
191-
if (hasLabel && labelPlacement != null) {
192-
/* translate result label placement back to users orientation */
193-
transform.transformRect(labelPlacement.x, labelPlacement.y, labelPlacement.width, labelPlacement.height, true,
194-
self, function (x, y, width, height) {
195-
labelPlacement = new Rect(x, y, width, height);
196-
});
197-
198-
uiHash = new RenderEventArgs();
199-
uiHash.context = labelConfig;
200-
201-
/* draw label */
202-
_data.graphics.template(
203-
labelPlacement.x
204-
, labelPlacement.y
205-
, 0
206-
, 0
207-
, 0
208-
, 0
209-
, labelPlacement.width
210-
, labelPlacement.height
211-
, _data.labelTemplate.template()
212-
, _data.labelTemplate.getHashCode()
213-
, _data.labelTemplate.render
214-
, uiHash
215-
, null
216-
);
217-
}
218-
}, annotationConfig);
219-
connectorAnnotationOffsetResolver.resolve();
220-
}
221-
222-
/* translate result polylines back to users orientation */
223-
buffer.transform(transform, true);
224-
/* draw background polylines */
225-
_data.graphics.polylinesBuffer(buffer);
226-
227-
_data.graphics.end();
228-
}
229-
230116
function destroy() {
231117
cleanLayout();
232118
};

src/RotatedTextControl.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import Rect from './graphics/structs/Rect';
22
import createGraphics from './graphics/createGraphics';
33
import { getFixOfPixelAlignment, getInnerSize } from './graphics/dom';
44
import JsonML from './common/jsonml-html';
5-
import Transform from './graphics/Transform';
6-
import Shape from './graphics/shapes/Shape';
75
import AnnotationLabelTemplate from './templates/html/AnnotationLabelTemplate';
8-
import { isNullOrEmpty } from './common';
9-
import RenderEventArgs from './events/RenderEventArgs';
106

117
/**
128
* Creates JavaScript Rotated Text Control

src/ShapeAnnotationControl.js

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ import Rect from './graphics/structs/Rect';
22
import createGraphics from './graphics/createGraphics';
33
import { getFixOfPixelAlignment, getInnerSize } from './graphics/dom';
44
import JsonML from './common/jsonml-html';
5-
import Transform from './graphics/Transform';
6-
import Shape from './graphics/shapes/Shape';
5+
import ShapeAnnotation from './graphics/annotations/ShapeAnnotation';
76
import AnnotationLabelTemplate from './templates/html/AnnotationLabelTemplate';
8-
import { isNullOrEmpty } from './common';
9-
import RenderEventArgs from './events/RenderEventArgs';
107

118
/**
129
* Creates JavaScript Shape Annotation Control
@@ -25,7 +22,8 @@ export default function ShapeAnnotationControl(element, options) {
2522
placeholder: null,
2623
panelSize: null,
2724
graphics: null,
28-
labelTemplate: null
25+
labelTemplate: null,
26+
shape: null
2927
};
3028

3129
if(!element) {
@@ -65,6 +63,7 @@ export default function ShapeAnnotationControl(element, options) {
6563
);
6664

6765
_data.graphics = createGraphics(_data.element);
66+
_data.shape = new ShapeAnnotation();
6867
};
6968

7069
function cleanLayout() {
@@ -101,64 +100,17 @@ export default function ShapeAnnotationControl(element, options) {
101100
_data.labelTemplate = AnnotationLabelTemplate(_data.options);
102101
cleanLayout();
103102
createLayout();
104-
redraw();
103+
_data.shape.draw(_data.options, _data.graphics, _data.panelSize, _data.labelTemplate);
105104
}
106105
else {
107106
updateLayout();
108107
_data.graphics.resize("placeholder", _data.panelSize.width, _data.panelSize.height);
109108
_data.graphics.begin();
110-
redraw();
109+
_data.shape.draw(_data.options, _data.graphics, _data.panelSize, _data.labelTemplate);
111110
_data.graphics.end();
112111
}
113112
}
114113

115-
function redraw() {
116-
var annotationConfig = _data.options,
117-
shape,
118-
uiHash,
119-
transform = new Transform(),
120-
panel = _data.graphics.activate("placeholder");
121-
122-
transform.size = new Size(_data.panelSize.width, _data.panelSize.height);
123-
transform.setOrientation(annotationConfig.orientationType);
124-
125-
if (annotationConfig.position != null) {
126-
shape = new Shape(_data.graphics);
127-
primitives.mergeObjects(shape, options);
128-
129-
/* rotate label size to user orientation */
130-
transform.transformRect(0, 0, annotationConfig.labelSize.width, annotationConfig.labelSize.height, false,
131-
this, function (x, y, width, height) {
132-
shape.labelSize = new Size(width, height);
133-
});
134-
135-
/* rotate panel size to user orientation */
136-
transform.transformRect(0, 0, panel.size.width, panel.size.height, false,
137-
this, function (x, y, width, height) {
138-
shape.panelSize = new Size(width, height);
139-
});
140-
141-
shape.hasLabel = !isNullOrEmpty(annotationConfig.label);
142-
143-
var position = annotationConfig.position;
144-
145-
/* translate position to Top orientation */
146-
transform.transformRect(position.x, position.y, position.width, position.height, false,
147-
this, function (x, y, width, height) {
148-
position = new Rect(x, y, width, height);
149-
});
150-
151-
/* offset position */
152-
position = new Rect(annotationConfig.position).offset(annotationConfig.offset);
153-
154-
shape.labelTemplate = _data.labelTemplate;
155-
156-
uiHash = new RenderEventArgs();
157-
uiHash.context = annotationConfig;
158-
shape.draw(position, uiHash);
159-
}
160-
}
161-
162114
function destroy() {
163115
cleanLayout();
164116
};

src/configs/RotatedTextControlConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {VerticalAlignmentType, TextOrientationType, HorizontalAlignmentType} from '../enums';
1+
import {VerticalAlignmentType, TextOrientationType, HorizontalAlignmentType, Colors} from '../enums';
22

33
/**
44
* @class RotatedTextControlConfig

0 commit comments

Comments
 (0)