-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathpanelController.js
299 lines (284 loc) · 8.55 KB
/
panelController.js
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
const { editDocument } = require("application");
const application = require("application");
let panel;
const defaultParms = {
leftEdgeType: "none",
rightEdgeType: "arrow1",
lineWidth: 1,
edgeScale: 100,
color: "#666666"
}
const labels = {
default:{
menu:{
straight: "Straight",
curve: "Curve",
snake: "Snake"
},
edit:{
title: "Edit",
lineWidth: "Line Width",
edgeScale: "Edge Scale",
leftEdge: "Left",
rightEdge: "Right",
color: "Color",
default: "Reset to default",
edgeType:{
none: "none",
arrow1: "arrow1",
arrow2: "arrow2",
arrow3: "arrow3",
circle1: "circle1",
circle2: "circle2",
square1: "square1",
square2: "square2",
bar: "bar"
}
}
},
ja:{
menu:{
straight: "直線",
curve: "折れ線",
snake: "カギ線"
},
edit:{
title: "編集",
lineWidth: "先の太さ",
edgeScale: "ポイントの大きさ",
leftEdge: "左端",
rightEdge: "右端",
color: "着色",
default: "初期値に戻す",
edgeType:{
none: "無し",
arrow1: "矢印1",
arrow2: "矢印2",
arrow3: "矢印3",
circle1: "円形1",
circle2: "円形2",
square1: "四角1",
square2: "四角2",
bar: "縦線"
}
}
}
}
function create(onActionButton, onChangeProperty) {
let _labels;
if(application.appLanguage == 'ja'){
_labels = labels.ja;
}else{
_labels = labels.default;
}
const html = `
<style>
.actionButton {
width: 100%;
background: #fff;
padding: 10px;
border-radius: 4px;
display: block;
border: 1px solid #fff;
margin-bottom: 4px;
}
.actionButton:hover{
border: 1px solid #999;
}
.actionButton span{
font-size: 108%;
line-height: 24px;
display: inline-block;
color: #333;
text-decoration: none;
}
.actionButton img{
width: 24px; height: 24px;
margin-right: 16px;
}
.hide {
display: none;
}
.show{
display: block;
}
.row {
align-items: center;
}
.spread {
justify-content: space-between;
width: 100%;
}
.edge{
display: inlineBlock;
width: 50%;
}
input[type="range"]{
width: 100%;
}
label{
margin: 0.2em 0;
width: 100%;
}
.propertyBox{
background: rgba(0,0,0,0.025);
padding: 4px;
}
h2{
font-size: 140%;
margin: 12px 0;
padding: 0 4px;
}
.footer{
text-align:right;
margin: 4px 0;
}
</style>
<div id="toolPanel" class="show">
<a href="#" data-action="straight" class="actionButton">
<img src="assets/icon_straight.png" />
<span>${_labels.menu.straight}</span>
</a>
<a href="#" data-action="curve" class="actionButton">
<img src="assets/icon_curve.png" />
<span>${_labels.menu.curve}</span>
</a>
<a href="#" data-action="snake" class="actionButton">
<img src="assets/icon_snake.png" />
<span>${_labels.menu.snake}</span>
</a>
</div>
<div id="propertyPanel" class="hide">
<h2>${_labels.edit.title}</h2>
<div class="propertyBox">
<div><label>
<div class="row spread">
<span>${_labels.edit.lineWidth}</span>
<span class="lineWidthValue">1</span>
</div>
<input type="range" id="lineWidth" min=0.5 max=5 value=1 step=0.5 />
</label></div>
<div><label>
<div class="row spread">
<span>${_labels.edit.edgeScale}</span>
<span class="edgeScaleValue">100%<span>
</div>
<input type="range" id="edgeScale" min=0 max=200 value=100 step=25 />
</label></div>
<div>
<label class="edge">
<span>${_labels.edit.leftEdge}</span>
<select id="leftEdge">
<option value="none" selected>${_labels.edit.edgeType.none}</option>
<option value="arrow1">${_labels.edit.edgeType.arrow1}</option>
<option value="arrow2">${_labels.edit.edgeType.arrow2}</option>
<option value="arrow3">${_labels.edit.edgeType.arrow3}</option>
<option value="circle1">${_labels.edit.edgeType.circle1}</option>
<option value="circle2">${_labels.edit.edgeType.circle2}</option>
<option value="square1">${_labels.edit.edgeType.square1}</option>
<option value="square2">${_labels.edit.edgeType.square2}</option>
<option value="bar">${_labels.edit.edgeType.bar}</option>
</select>
</label>
<label class="edge">
<span>${_labels.edit.rightEdge}</span>
<select id="rightEdge">
<option value="none">${_labels.edit.edgeType.none}</option>
<option value="arrow1" selected>${_labels.edit.edgeType.arrow1}</option>
<option value="arrow2">${_labels.edit.edgeType.arrow2}</option>
<option value="arrow3">${_labels.edit.edgeType.arrow3}</option>
<option value="circle1">${_labels.edit.edgeType.circle1}</option>
<option value="circle2">${_labels.edit.edgeType.circle2}</option>
<option value="square1">${_labels.edit.edgeType.square1}</option>
<option value="square2">${_labels.edit.edgeType.square2}</option>
<option value="bar">${_labels.edit.edgeType.bar}</option>
</select>
</label>
</div>
<label>
<span>${_labels.edit.color}</span>
<input type="text" id="color" value="#666666" />
</label>
<input type="hidden" id="lineType" value="straight" style="display:none" />
</div>
<div class="footer">
<button id="defaultButton">${_labels.edit.default}</button>
</div>
</div>
`;
panel = document.createElement("div");
panel.innerHTML = html;
const buttons = panel.querySelectorAll(".actionButton");
for(let i = 0; i < buttons.length; i++){
buttons[i].addEventListener("click", _onActionButton);
}
const inputs = panel.querySelectorAll("#propertyPanel input, #propertyPanel select");
for(let i = 0; i < inputs.length; i++){
inputs[i].addEventListener("change", _onChangeProperty);
}
const sliders = panel.querySelectorAll("#edgeScale, #lineWidth");
for(let i = 0; i < sliders.length; i++){
sliders[i].addEventListener("input", _onInputSlider);
}
const defaultButton = panel.querySelector("#defaultButton");
defaultButton.addEventListener("click", _onDefaultButton);
function _onChangeProperty(e=null){
onChangeProperty(getParms());
}
function _onActionButton(e){
const actionName = e.currentTarget.getAttribute('data-action');
onActionButton(actionName);
}
function _onInputSlider(e){
const input = e.currentTarget;
let label;
if(input.id == "lineWidth"){
label = input.parentNode.querySelector(".lineWidthValue");
label.innerHTML = input.value + "";
}else if(input.id == "edgeScale"){
label = input.parentNode.querySelector(".edgeScaleValue");
label.innerHTML = input.value + "%";
}
}
function _onDefaultButton(e){
updateToolPanel(defaultParms);
_onChangeProperty();
}
return panel;
}
function show(event, onActionButton, onChangeProperty) {
if (!panel) event.node.appendChild(create(onActionButton, onChangeProperty));
}
function showPropertyPanel(parms){
updateToolPanel(parms);
panel.querySelector("#toolPanel").className = "hide";
panel.querySelector("#propertyPanel").className = "show";
}
function hidePropertyPanel(){
panel.querySelector("#toolPanel").className = "show";
panel.querySelector("#propertyPanel").className = "hide";
}
function updateToolPanel(parms){
panel.querySelector("#propertyPanel #lineWidth").value = parms.lineWidth;
panel.querySelector("#propertyPanel #leftEdge").value = parms.leftEdgeType;
panel.querySelector("#propertyPanel #rightEdge").value = parms.rightEdgeType;
if(parms.lineType) panel.querySelector("#propertyPanel #lineType").value = parms.lineType;
panel.querySelector("#propertyPanel #color").value = parms.color;
panel.querySelector("#propertyPanel #edgeScale").value = parms.edgeScale;
panel.querySelector("#propertyPanel .lineWidthValue").innerHTML = parms.lineWidth + "";
panel.querySelector("#propertyPanel .edgeScaleValue").innerHTML = parms.edgeScale + "%";
}
function getParms(){
return {
lineWidth: document.querySelector("#lineWidth").value - 0,
leftEdgeType: document.querySelector("#leftEdge").value,
rightEdgeType: document.querySelector("#rightEdge").value,
edgeScale: document.querySelector("#edgeScale").value - 0,
lineType: document.querySelector("#lineType").value,
color: document.querySelector("#color").value
};
}
module.exports.getParms = getParms;
module.exports.show = show;
module.exports.showPropertyPanel = showPropertyPanel;
module.exports.hidePropertyPanel = hidePropertyPanel;