-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathmain.js
384 lines (312 loc) · 10.7 KB
/
main.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
'use strict';
const { alert, error } = require("./lib/dialogs.js");
const { Line, Rectangle, Ellipse, Text, Color, Path } = require("scenegraph");
const commands = require("commands");
let scenegraph = require("scenegraph");
const CSV = require("./lib/csv");
const fs = require("uxp").storage.localFileSystem;
var assets = require("assets");
const palette = [
["Side Panel", '#6F777B'],
["Side Text", '#DEE0E2'],
["Tasks", '#A7488C'],
["Personas", '#35C0BD'],
["Touch Points", '#2C3E50'],
["Pain Points", '#F15159'],
["Dark Text", '#4C4743']
];
const sidePanelFill = palette[0][1];
const sidePanelText = palette[1][1];
const titleText = '#ffffff';
const defaultText = palette[6][1];
var ht_row = 170;
const wd_row = 30;
var wd_full = 1920;
const wd_offset = 330;
const ht_offset = 170;
const ht = 150;
const wd = 160;
const gutter = 10;
const gutterX = 5;
const gutterY = 32;
var row_x;
var row_y;
var offsetX = 2 * wd + gutterX;
var offsetY = 110;
var fontSize = 12;
var fontHeaderSize = 18;
var fontLargeSize = 48;
var allColors;
var rowHts = [190, 370, 550, 900, 870];
async function createUserJourney(selection) {
var i, j;
const aFile = await fs.getFileForOpening({ types: ["txt", "csv"] });
if (!aFile) {
return;
}
const contents = await aFile.read();
const arr = CSV.parse(contents);
if(arr.length<6 ){
showError('Not enough Data');
}else if(arr.length>20 ){
showError('Too Many Rows');
}else{
drawSidePanel(arr.slice(0,5), selection);
drawJourney(arr.slice(5), selection);
}
}
function drawJourney(arr, selection) {
var rows = arr.length;
var cols;
var text;
var i,j;
// draw background rows and title blocks
var str = " ";
row_x = wd_offset + gutter + wd_row;
// split out the emotion row
let emotionArray = arr.splice(2,1)[0];
rows = arr.length;
wd_full = arr[0].length * wd;
for (j = 0; j < rows; j++) {
ht_row = 170;
if (j === 2){
ht_row = 340;
}
row_y = rowHts[j];
// Do not draw a box for the Time
if(arr[j][0]!=="Timeline"){
// draw row
var rect = new Rectangle();
rect.width = wd_full;
rect.height = ht_row;
rect.fill = new Color(palette[j+2][1], 0.1);
rect.stroke = null;
selection.insertionParent.addChild(rect);
rect.moveInParentCoordinates(row_x, row_y );
// draw header
var rect = new Rectangle();
rect.width = wd_row;
rect.height = ht_row;
rect.fill = new Color(palette[j+2][1]);
rect.stroke = null;
selection.insertionParent.addChild(rect);
// NB x position of title block is offset
rect.moveInParentCoordinates(wd_offset, row_y);
// row title text
if (arr[j][0] !== null && arr[j][0] !== ""){
str = String(arr[j][0]);
}
let text = new scenegraph.Text();
text.rotateAround(270, text.localCenterPoint);
text.text = str;
text.textAlign = Text.ALIGN_RIGHT;
text.styleRanges = [{
length: str.length,
fill: new Color(titleText),
fontSize: fontHeaderSize
}];
selection.insertionParent.addChild(text);
let x = wd_offset + gutter + 5;
let y = rowHts[j] + gutter;
text.moveInParentCoordinates(x, y);
}
// add the text blocks
str = " ";
cols = arr[j].length;
var xOffset = 0;
for (i = 0; i < cols; i++) {
if (arr[j][i] !== null && i > 0 ) {
if (arr[j][i] !== "") {
var str = String(arr[j][i]); // cast to string so we can get length
text = new Text();
if(arr[j][0]!=="Timeline"){
text.areaBox = { width: wd - gutterX * 3, height: ht };
}else{
xOffset = (wd - gutterX * 3)/2;
}
text.text = str;
text.styleRanges = [{
length: str.length,
fill: new Color(defaultText),
fontSize: fontSize
}];
// set yPos of TOUCH POINTS based on emotion point
var correction = 0;
if (j === 2){
let value = 1;
//check the "emotion" row
if(emotionArray[i]!==null){
value = parseInt(emotionArray[i]);
}
if(value<3){
correction = 170;
}
}
selection.insertionParent.addChild(text);
let x = row_x + (i - 1) * (wd + gutter) + gutter + xOffset;
let y = row_y + gutter + correction;
text.moveInParentCoordinates(x, y);
}
}
}
row_y = row_y + ht_row + gutter;
}
drawEmotions(emotionArray, selection);
}
// do two loops one to set line beneath all circles
function drawEmotions(arr, selection) {
var i, j;
var x, y;
var lastX = null;
var lastY = null;
var value;
var len = arr.length;
var offsetChart = (wd - gutterX * 3)/2;
var padding = 40;
var ht_range = ht_row*2 - padding*2;
var ht_step = parseInt(ht_range/4);
var points = [];
var startY, endY = 0;
for (i = 1; i < len; i++) {
// default value
value = 1;
if(arr[i]!==null){
value = parseInt(arr[i]);
}
x = row_x + ((i - 1) * (wd + gutter)) + wd/2;
y = rowHts[2] + (value - 1) * ht_step + padding;
// draw point
const circ = new Ellipse();
circ.radiusX = 6;
circ.radiusY = 6;
circ.fill = new Color(defaultText);
circ.strokeWidth = 1;
selection.insertionParent.addChild(circ);
circ.moveInParentCoordinates(x, y);
points.push([x+6, y+6]);
//draw vert line
const line = new Line();
// determine direction of line
if(value<3){
startY = y + 10;
endY = 710;
}else{
startY = y - 10;
endY = 600;
}
line.setStartEnd(
x + 6,
startY + 6,
x + 6,
endY + 6 // correct for anchor point of ellipse
);
line.strokeEnabled = true;
line.stroke = new Color(defaultText);
line.strokeWidth = 1;
selection.insertionParent.addChild(line);
}
//draw a path between points
len = points.length;
let pathData = 'M' + points[0][0] +',' + points[0][1];
for (i = 1; i < len; i++) {
pathData += ' L' + points[i][0] +',' + points[i][1];
}
const curve = new Path();
curve.pathData = pathData;
curve.strokeEnabled = true;
curve.strokeDashArray = [3, 10];
curve.stroke = new Color("black");
curve.strokeWidth = 3
selection.insertionParent.addChild(curve);
}
function drawSidePanel(arr, selection) {
const len = 5; // get first four rows to use as side-bar content
const rect = new Rectangle();
rect.width = wd * 2;
rect.height = 1080;
rect.fill = new Color(sidePanelFill);
rect.stroke = null;
rect.opacity = 1;
selection.insertionParent.addChild(rect);
//persona icon placeholder
const circ = new Ellipse();
circ.radiusX = wd/2 - gutter;
circ.radiusY = wd/2 - gutter;
circ.fill = null;
circ.stroke = new Color(sidePanelText);
circ.strokeWidth = 3;
selection.insertionParent.addChild(circ);
circ.moveInParentCoordinates(gutter + wd/2, gutter*2);
// use Persona value as page title
var str = "Default Persona title";
if(arr[0][1]!==null && arr[0][1]!==""){
str = String(arr[0][1]);
}
var text = new Text();
text.text = str;
text.styleRanges = [{
length: str.length,
fill: new Color(defaultText),
fontSize: fontLargeSize
}];
selection.insertionParent.addChild(text);
let x = offsetX + gutter;
let y = wd/2 + gutter*3; // match the center of the circle
text.moveInParentCoordinates(x, y);
var i, j, displayFont;
var rowLength = 0;
str = "";
for (j = 1; j < len; j++) {
// add title
if (arr[j][0] !== null && arr[j][0] !== "") {
str = String(arr[j][0]);
}
text = new Text();
text.text = str;
text.styleRanges = [{
length: str.length,
fill: new Color(sidePanelText),
fontSize: fontHeaderSize
}];
selection.insertionParent.addChild(text);
let xTitle = gutter;
let yTitle = rowHts[0] + (j-1)*(ht_row + gutter) + gutter;
text.moveInParentCoordinates(xTitle, yTitle);
// loop though and build single string
str = "";
rowLength = arr[j].length;
for (i = 1; i < rowLength; i++) {
if (arr[j][i] !== null && arr[j][i] !== "") {
str += String(arr[j][i]) +"\n";
}
}
// check for empty string
if(str===""){
str = " ";
}
text = new Text();
text.areaBox = { width: wd*2 - gutterX * 3, height: ht };
text.text = str;
text.styleRanges = [{
length: str.length,
fill: new Color(sidePanelText),
fontSize: fontSize
}];
selection.insertionParent.addChild(text);
let x = gutter;
let y = rowHts[0] + (j-1)*(ht_row + gutter) + 16 + gutter; // +16px to account for title
text.moveInParentCoordinates(x, y);
}
}
async function showError(header) {
/* we'll display a dialog here */
await error("CSV File Import Failed: " + header,
"Failed to load the selected file. Please check the file format:",
"* There needs to be 5 rows: for Persona, Roles, Goals, Needs and Expectations",
"* Then there needs to be 6 rows: for Tasks, Persona, Emotion, Touch points and Pain points",
"* See the plugin help page for more information");}
module.exports = {
commands: {
"createUserJourney": createUserJourney
}
};