-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathDrawTreeItemsTask.js
More file actions
203 lines (184 loc) · 8.03 KB
/
Copy pathDrawTreeItemsTask.js
File metadata and controls
203 lines (184 loc) · 8.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import Point from '../../graphics/structs/Point';
import Size from '../../graphics/structs/Size';
import Rect from '../../graphics/structs/Rect';
import RenderEventArgs from '../../events/RenderEventArgs';
import { Layers, Visibility, AdviserPlacementType } from '../../enums';
export default function DrawTreeItemsTask(getGraphics, createTransformTask, applyLayoutChangesTask, scaleOptionTask,
itemsSizesOptionTask,
combinedContextsTask,
alignDiagramTask, centerOnCursorTask,
itemTemplateParamsTask,
cursorItemTask, selectedItemsTask,
groupTitleTemplateTask, checkBoxTemplateTask, buttonsTemplateTask) {
var _positions,
_graphics,
_transform,
_itemsSizesOptions,
_buttonsTemplate,
_checkBoxTemplate,
_groupTitleTemplate;
function process() {
_graphics = getGraphics();
_itemsSizesOptions = itemsSizesOptionTask.getOptions();
_positions = alignDiagramTask.getItemsPositions();
_transform = createTransformTask.getTransform();
_buttonsTemplate = buttonsTemplateTask.getTemplate();
_checkBoxTemplate = checkBoxTemplateTask.getTemplate();
_groupTitleTemplate = groupTitleTemplateTask.getTemplate();
_graphics.reset("placeholder", Layers.Item);
_graphics.reset("placeholder", Layers.Controls);
redrawTreeItems();
return false;
}
function redrawTreeItems() {
var uiHash,
element,
cursorItemId = cursorItemTask.getCursorTreeItem(),
treeItemPosition,
actualPosition,
viewPortPosition = getViewPortPosition();
for (var treeItemId in _positions) {
if (_positions.hasOwnProperty(treeItemId)) {
treeItemPosition = _positions[treeItemId],
actualPosition = treeItemPosition.actualPosition;
if (treeItemPosition.actualVisibility == Visibility.Normal) {
_transform.transformRect(actualPosition.x, actualPosition.y, actualPosition.width, actualPosition.height, true,
this, function (x, y, width, height) {
var nodePosition = new Rect(x, y, width, height);
if (viewPortPosition == null || viewPortPosition.overlaps(nodePosition)) {
var templateParams = itemTemplateParamsTask.getTemplateParams(treeItemId);
if(templateParams != null) {
var template = templateParams.template;
uiHash = new RenderEventArgs();
uiHash.id = treeItemId;
uiHash.context = combinedContextsTask.getConfig(treeItemId);
uiHash.isCursor = (treeItemId == cursorItemId);
uiHash.isSelected = selectedItemsTask.isSelected(treeItemId);
uiHash.templateName = template.templateConfig.name;
uiHash.template = templateParams.template;
uiHash.isActive = templateParams.isActive;
uiHash.hasSelectorCheckbox = templateParams.hasSelectorCheckbox;
uiHash.hasButtons = templateParams.hasButtons;
uiHash.hasGroupTitle = templateParams.hasGroupTitle;
uiHash.onButtonsRender = templateParams.onButtonsRender;
_graphics.activate("placeholder", Layers.Item);
element = _graphics.template(
x
, y
, width
, height
, treeItemPosition.contentPosition.x
, treeItemPosition.contentPosition.y
, treeItemPosition.contentPosition.width
, treeItemPosition.contentPosition.height
, template.itemTemplate.template()
, template.itemTemplate.getHashCode()
, template.itemTemplate.render
, uiHash
, { "borderWidth": template.templateConfig.itemBorderWidth }
);
if (templateParams.hasGroupTitle) {
var groupTitlePosition = 0;
switch (_itemsSizesOptions.groupTitlePlacementType) {
case AdviserPlacementType.Left:
case AdviserPlacementType.Auto:
groupTitlePosition = 2;
break;
case AdviserPlacementType.Right:
groupTitlePosition = width - (_itemsSizesOptions.groupTitlePanelSize - 4);
break;
default:
}
element = _graphics.template(
x,
y,
width,
height,
groupTitlePosition,
treeItemPosition.contentPosition.y,
_itemsSizesOptions.groupTitlePanelSize - 4,
treeItemPosition.contentPosition.height + 2,
_groupTitleTemplate.template(),
_groupTitleTemplate.getHashCode(),
_groupTitleTemplate.render,
uiHash,
null
);
}
if (templateParams.hasSelectorCheckbox) {
_graphics.activate("placeholder", Layers.Controls);
element = _graphics.template(
x,
y,
width,
height,
treeItemPosition.contentPosition.x,
height - (_itemsSizesOptions.checkBoxPanelSize - 4),
treeItemPosition.contentPosition.width,
_itemsSizesOptions.checkBoxPanelSize - 4,
_checkBoxTemplate.template(),
_checkBoxTemplate.getHashCode(),
_checkBoxTemplate.render,
uiHash,
null
);
}
if (templateParams.hasButtons) {
_graphics.activate("placeholder", Layers.Controls);
var buttonsPanelPosition = 0;
switch (_itemsSizesOptions.groupTitlePlacementType) {
case AdviserPlacementType.Left:
case AdviserPlacementType.Auto:
buttonsPanelPosition = width - (_itemsSizesOptions.buttonsPanelSize - 4);
break;
case AdviserPlacementType.Right:
buttonsPanelPosition = 2;
break;
default:
}
element = _graphics.template(
x,
y,
width,
height,
buttonsPanelPosition,
treeItemPosition.contentPosition.y,
_itemsSizesOptions.buttonsPanelSize - 4,
Math.max(treeItemPosition.contentPosition.height, height - treeItemPosition.contentPosition.y),
_buttonsTemplate.template(),
template.templateConfig.name + _buttonsTemplate.getHashCode(),
_buttonsTemplate.render,
uiHash,
null
);
}
}
}
});//ignore jslint
}
}
}
}
function getViewPortPosition() {
var result = null;
if (centerOnCursorTask != null) {
var scaleOptions = scaleOptionTask.getOptions(),
scale = scaleOptions.scale,
placeholderOffset = new Point(centerOnCursorTask.getPlaceholderOffset()),
panelSize = new Rect(alignDiagramTask.getContentSize()),
optimalPanelSize = new Size(applyLayoutChangesTask.getOptimalPanelSize());
placeholderOffset.scale(1.0 / scale);
optimalPanelSize.scale(1.0 / scale);
result = new Rect(
placeholderOffset.x,
placeholderOffset.y,
Math.min(optimalPanelSize.width, panelSize.width),
Math.min(optimalPanelSize.height, panelSize.height)
);
}
return result;
}
return {
process: process
};
};