-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstate.js
1919 lines (1716 loc) · 49.8 KB
/
state.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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { encode } from './render'
import { decode } from './render'
import { unpackGrid } from './render'
import { remove_undefined } from './render'
import { toTileKey, GLState, toDistance } from './channel'
import LZString from "lz-string"
const yaml = require('js-yaml');
/*
* Hard-coded authentication for optional OMERO connection
*/
const omero_authenticate = function(username, pass) {
return pass.then(function(password) {
return fetch('https://omero.hms.harvard.edu/api/v0/token/',
{mode: 'no-cors'}
).then(function(token){
return fetch('https://omero.hms.harvard.edu/api/v0/login/', {
method: 'POST',
body: JSON.stringify({
csrfmiddlewaretoken: token.data,
username: username,
password: password,
server: 1
})
}).then(function(session){
return 'csrftoken=' + token.data + ';sessionid=' + session.eventContext.sessionUuid + ';';
})
})
});
}
const pos_modulo = function(i, n) {
return ((i % n) + n) % n;
};
// Define d url parameter (description)
const dFromWaypoint = function(waypoint) {
return encode(waypoint.Description);
};
// Define n url parameter (name)
const nFromWaypoint = function(waypoint) {
return encode(waypoint.Name);
};
// Define m url parameter (active mask indices)
const mFromWaypoint = function(waypoint, masks) {
const names = waypoint.ActiveMasks || [];
const m = names.map(name => index_name(masks, name));
if (m.length < 2) {
return [-1].concat(m);
}
return m;
};
// Define a url parameter (arrow)
const aFromWaypoint = function(waypoint, masks) {
const arrows = waypoint.Arrows || [{}]
const arrow = arrows[0].Point;
if (arrow) {
return arrow
}
return [-100, -100];
};
// Define g url parameter (channel group index)
const gFromWaypoint = function(waypoint, cgs) {
const cg_name = waypoint.Group;
return index_name(cgs, cg_name);
};
// Define v url parameter (viewport)
const vFromWaypoint = function(waypoint) {
return [
waypoint.Zoom,
waypoint.Pan[0],
waypoint.Pan[1],
];
};
// Define p url parameter (polygon)
const pFromWaypoint = function(waypoint) {
const p = waypoint.Polygon;
return p? p: toPolygonURL([]);
};
// Define o url parameter (overlay)
const oFromWaypoint = function(waypoint) {
return [
waypoint.Overlays[0].x,
waypoint.Overlays[0].y,
waypoint.Overlays[0].width,
waypoint.Overlays[0].height,
];
};
// Convert a polygon to a url parameter
var toPolygonURL = function(polygon){
var pointString='';
polygon.forEach(function(d){
pointString += d.x.toFixed(5) + "," + d.y.toFixed(5) + ",";
})
pointString = pointString.slice(0, -1); //removes "," at the end
var result = LZString.compressToEncodedURIComponent(pointString);
return result;
}
// Convert a url parameter to a polygon
var fromPolygonURL = function(polygonString){
var decompressed = LZString.decompressFromEncodedURIComponent(polygonString);
if (!decompressed){
return [];
}
var xArray = [], yArray = [];
//get all values out of the string
decompressed.split(',').forEach(function(d,i){
if (i % 2 == 0){ xArray.push(parseFloat(d)); }
else{ yArray.push(parseFloat(d)); }
});
//recreate polygon data structure
var newPolygon = [];
if (xArray.length == yArray.length) {
xArray.forEach(function(d, i){
newPolygon.push({x: d, y: yArray[i]});
});
}
return newPolygon;
}
// Serialize state to url
const serialize = function(keys, state, delimit) {
return keys.reduce(function(h, k) {
var value = state[k] || 0;
// Array separated by underscore
if (value.constructor === Array) {
value = value.join('_');
}
return h + delimit + k + '=' + value;
}, '').slice(1);
};
// Deserialize url to state
const deserialize = function(entries) {
const query = entries.reduce(function(o, entry) {
if (entry) {
const kv = entry.split('=');
const val = kv.slice(1).join('=') || '1';
const vals = val.split('_');
const key = kv[0];
// Handle arrays or scalars
o[key] = vals.length > 1? vals: val;
}
return o;
}, {});
return query;
};
/*
* Return an anonymous totken for any username and password
*/
const anon_authenticate = function(username, pass) {
return pass.then(function(password) {
return "Anonymous";
})
}
const to_subgroups = (subpath_map, rendered_map, group, all) => {
const used = new Set();
const shown = group.Shown;
const n_color = group.Colors.length;
const channels = group.Channels.slice(0, n_color);
const zipped = channels.reduce((o, Name, idx) => {
o.set(Name, {
Format: group.Format || 'jpg',
Colors: [ group.Colors[idx] ],
Description: (group.Descriptions || [])[idx] || ''
});
return o;
}, new Map());
// Return single-channel subpaths to render
if (subpath_map.size > 0) {
return channels.filter((n, i) => {
if (!all && !shown[i]) return false;
if (!subpath_map.has(n)) return false;
return true;
}).reduce((out, Name) => {
// Disallow duplicate subpaths
const Path = subpath_map.get(Name);
if (used.has(Path)) return out;
used.add(Path);
const Colorize = !rendered_map.get(Name);
const { Colors, Description } = zipped.get(Name);
const { Format } = zipped.get(Name);
return [...out, {
Name, Path, Colors, Format,
Colorize, Description
}];
}, []);
}
// Return group subpath
const { Name, Path, Colors } = group;
const Format = group.Format || 'jpg';
return [{
Name, Path, Colors, Format,
Colorize: false, Description: ''
}];
}
const is_active = ({ masks, subgroups, key, match }) => {
const mask_list = masks.map(m => m[key]);
const group_list = subgroups.map(g => g[key]);
const mask_index = mask_list.indexOf(match);
const group_index = group_list.indexOf(match);
const active = group_index >= 0 || mask_index >= 0;
return { active, group_index, mask_index };
}
const can_mutate_group = (old, group) => {
// Don't copy a copy, don't copy if same
if ('OriginalGroup' in group) return true;
if (old === group) return true;
const old_c = old.Channels;
const new_c = group.Channels;
// Check if channel names are the same
if (old_c.length === new_c.length) {
return new_c.every((c, i) => c === old_c[i]);
}
return false;
}
const add_mask_visibility = (masks) => {
return masks.map((mask) => {
mask.Shown = true;
return mask;
});
}
const add_visibility = (cgs) => {
return cgs.map((group) => {
group.Shown = group.Channels.map(() => true);
return group;
});
}
/*
* The HashState contains all state variables in sync with url hash
*/
export const HashState = function(exhibit, options) {
this.trackers = [];
this.pollycache = {};
this.embedded = options.embedded || false;
this.authenticate = options.authenticate || anon_authenticate;
this.speech_bucket = options.speech_bucket || "";
this.marker_links_map = options.marker_links_map;
this.marker_alias_map = options.marker_alias_map;
this.cell_type_links_map = options.cell_type_links_map;
this.cell_type_alias_map = options.cell_type_alias_map;
this.exhibit = exhibit;
this.el = options.el;
this.id = options.id;
this.customPopState = options.customPopState || false;
this.customPushState = options.customPushState || false;
this.customWelcome = options.customWelcome || "";
this.hideWelcome = options.hideWelcome || false;
this.noHome = options.noHome || false;
this._gl_state = null;
this.state = {
buffer: {
waypoint: undefined
},
lensUI: null,
lensRad: 100,
lensAlpha: 1,
eventPoint: [0, 0],
lensResizeBasis: null,
lensAlphaBasis: null,
lensHeld: true,
lensAlphaHeld: true,
lensResizeHeld: true,
lensResizeMin: 60,
lensResizeMax: 600,
lensResizeSpeed: 1,
lensInsideBorder: 20,
lensResizeThickness: 60,
activeChannel: -1,
drawType: "lasso",
addingOpen: false,
infoOpen: false,
changed: false,
design: {},
m: [-1],
w: [0],
g: 0,
s: 0,
a: [-100, -100],
v: [1, 0.5, 0.5],
o: [-100, -100, 1, 1],
p: [],
name: '',
description: '',
edit: false,
drawing: 0
};
this.newExhibit();
this._gl_state = new GLState(this)
};
const toClipPath = (rad, nav_gap) => {
const norm = 100*(2*rad) / nav_gap;
const arc = Math.asin(nav_gap/(2*rad));
const c = [...Array(32)].map((_, _i, _a) => {
const diff = _i*arc/(_a.length-1)+Math.PI/2;
const angle = (arc/2 - diff);
const x = Math.round(Math.cos(angle)*norm*10)/10;
const y = Math.round(Math.sin(angle)*norm*10)/10;
return `${y+50+norm}% ${x+50}%`;
}).join(',');
return `polygon(100% 0, 0 0, 0 100%, 100% 100%, ${c})`;
}
const to_container = (nav_gap) => {
const container = document.createElement('div');
container.setAttribute('class', `minerva-lens-ui-wrapper`);
container.setAttribute('style', `
display: grid;
position: absolute;
pointer-events: none;
grid-template-columns: ${nav_gap}px auto ${nav_gap}px;
grid-template-rows: ${nav_gap}px auto ${nav_gap}px;
justify-content: center;
align-content: center;
`);
const padding = document.createElement('div');
padding.setAttribute('style', `
grid-column: 2; grid-row: 2;
justify-content: center;
align-content: center;
display: grid;
`);
const alpha_handle = document.createElement('div');
alpha_handle.setAttribute('style', `
grid-column: 2; grid-row: 2;
color: rgba(0, 123, 255, 1);
grid-template-columns: 1fr auto 1fr;
grid-template-rows: 1fr auto 1fr;
justify-content: center;
align-content: center;
display: grid;
`);
const alpha_label = document.createElement('span');
alpha_label.setAttribute('class', `bg-trans`);
alpha_label.setAttribute('style', `
border-radius: ${nav_gap/2}px;
border: 2px solid white;
padding-top: 5px;
height: ${nav_gap}px;
width: ${nav_gap}px;
grid-column: 2;
grid-row: 2;
`);
const size_handle = document.createElement('div');
size_handle.setAttribute('class', `bg-trans`);
size_handle.setAttribute('style', `
grid-column: 3; grid-row: 3;
border-radius: ${nav_gap/2}px;
border: 2px solid white;
grid-template-columns: 1fr auto 1fr;
grid-template-rows: 1fr auto 1fr;
justify-content: center;
align-content: center;
display: grid;
`);
const size_label = document.createElement('span');
size_label.setAttribute('style', `
font-family: Arial;
padding-top: 5px;
grid-column: 2;
grid-row: 2;
`);
const size_svg = (new DOMParser()).parseFromString(`
<svg fill="#007bff" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 358.666 358.666" xml:space="preserve" transform="rotate(-45)"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <g> <g> <polygon points="190.367,316.44 190.367,42.226 236.352,88.225 251.958,72.619 179.333,0 106.714,72.613 122.291,88.231 168.302,42.226 168.302,316.44 122.314,270.443 106.708,286.044 179.333,358.666 251.958,286.056 236.363,270.432 "></polygon> </g> </g> </g></svg>
`, "image/svg+xml").children[0];
size_svg.style = `
width: ${nav_gap-5}px;
margin-top: -6px;
`;
size_label.appendChild(size_svg);
size_handle.append(size_label);
alpha_handle.append(alpha_label);
container.append(padding);
container.append(size_handle);
container.append(alpha_handle);
return { container, padding, alpha_label, alpha_handle };
}
const to_pad = (rad, nav_gap) => {
return Math.ceil(2*rad / Math.sqrt(2)) - 20;
}
const update_container = ({
alpha_handle, alpha_label, container, padding, nav_gap,
alpha, rad, x, y, no_lens
}) => {
const alpha_angle = 3 * (alpha - 0.03);
const pad = to_pad(rad, nav_gap);
const css_x = Math.round(x - rad) + 'px';
const css_y = Math.round(y - rad) + 'px';
container.style.border = "2px solid white";
container.style.borderRadius = rad + "px";
container.style.display = ['grid', 'none'][+no_lens];
alpha_handle.style.transform = `rotate(${alpha_angle}rad)`;
alpha_label.style.clipPath = toClipPath(rad, nav_gap);
alpha_label.style.translate = `-${rad}px 0px`;
container.style.height = 2*rad + 'px';
container.style.width = 2*rad + 'px';
padding.style.height = pad + 'px';
padding.style.width = pad + 'px';
container.style.left = css_x;
container.style.top = css_y;
}
const toReferenceVector = (origin, point) => {
return [0,1].map(i => point[i] - origin[i]);
}
const resizeDirection = (ref, vec) => {
const dot = (a,b) => a[0]*b[0] + a[1]*b[1];
return -1 * Math.sign(dot(ref, vec));
}
const toAngleTrajectory = (ref, vec) => {
const diff = ref[1]*vec[0] - ref[0]*vec[1];
const sum = ref[0]*vec[0] + ref[1]*vec[1];
return Math.atan2(diff, sum);
}
const toTrajectory = (ref, vec) => {
const dot = (a,b) => a[0]*b[0] + a[1]*b[1];
const scalar = dot(ref,vec) / dot(ref,ref);
return ref.map(x => scalar * x);
}
const toAngle = (vec) => {
return Math.atan2(vec[1], vec[0]);
}
// Set the opacity of active masks
const newMasks = function(active_masks, viewer) {
const { world } = viewer;
const n_items = world.getItemCount();
const indices = [...Array(n_items).keys()];
// Full list of tiled image masks
const mask_t = indices.map(i => {
const tiledImage = world.getItemAt(i);
const tileSource = tiledImage.source;
return { tiledImage, tileSource };
}).filter(t => t.tileSource.is_mask);
// Map tile source paths to tiled images
const mask_map = new Map(mask_t.map(t => {
return [t.tileSource.path, t.tiledImage];
}));
// Hide hidden masks
mask_t.forEach(t => {
t.tiledImage.setOpacity(0);
});
// Organize active masks
active_masks.forEach((m, i) => {
const order = n_items - 1 - i;
if (!mask_map.has(m.Path)) return;
const tiledImage = mask_map.get(m.Path);
world.setItemIndex(tiledImage, Math.max(order, 0));
tiledImage.setOpacity(1);
});
};
HashState.prototype = {
newMasks(viewer) {
newMasks(this.active_masks, viewer);
},
createLens (viewer) {
const vp = viewer.viewport;
const first_point = vp.viewportToViewerElementCoordinates(
vp.getCenter(true)
);
const first_center = [first_point.x, first_point.y];
this.createLensUI(viewer);
this.updateLensUI(first_center);
viewer.addHandler('canvas-release', (e) => {
this.state.lensHeld = false;
this.state.lensAlphaHeld = false;
this.state.lensResizeHeld = false;
this.state.lensResizeBasis = null;
this.state.lensAlphaBasis = null;
});
viewer.addHandler('canvas-press', (e) => {
const [x, y] = [Math.round(e.position.x), Math.round(e.position.y)];
this.state.lensHeld = this.isWithinLens([x, y]);
if (this.isWithinResizeRing([x, y])) {
this.state.lensResizeBasis = toReferenceVector([x, y], this.lensCenter);
this.state.lensAlphaBasis = toReferenceVector(this.lensCenter, [x, y]);
const basis_y = this.state.lensAlphaBasis[1];
const control_alpha = Math.sign(basis_y) === -1;
const control_resize = basis_y > this.lensRad / 4;
if (control_resize) this.state.lensResizeHeld = true;
else if (control_alpha) this.state.lensAlphaHeld = true;
}
});
viewer.addHandler('canvas-drag', (e) => {
const { lensResizeBasis, lensAlphaBasis } = this.state;
const [x, y] = [Math.round(e.position.x), Math.round(e.position.y)];
const resizing = (lensResizeBasis !== null && lensAlphaBasis !== null);
if (this.state.lensHeld) {
e.preventDefaultAction = true;
this.updateLensUI([x, y]);
}
else if (this.state.lensResizeHeld || this.state.lensAlphaHeld) {
e.preventDefaultAction = true;
if (this.state.lensAlphaHeld && this.state.lensAlphaBasis) {
const ref = this.state.lensAlphaBasis;
const new_ref = toReferenceVector(this.lensCenter, [x, y]);
const alpha_angle = toAngleTrajectory(ref, new_ref);
const alpha_arc = this.lensRad * alpha_angle;
const max_arc = this.lensRad * Math.PI;
const new_alpha = ((alpha, change) => {
return Math.min(Math.max(alpha - change, 0.1), 1);
})(this.lensAlpha, alpha_arc / max_arc)
this.state.lensAlphaBasis = new_ref;
this.updateLensAlpha(new_alpha);
}
else if (this.state.lensResizeHeld && this.state.lensResizeBasis) {
const ref = this.state.lensResizeBasis;
const resize_dir = resizeDirection(ref, [e.delta.x, e.delta.y]);
const resize_vector = toTrajectory(ref, [e.delta.x, e.delta.y]);
const resize_mag = toDistance([0, 0], resize_vector);
const resize_speed = this.state.lensResizeSpeed;
const new_rad = ((rad, scale) => {
const min = this.state.lensResizeMin;
const max = this.state.lensResizeMax;
if (isNaN(scale)) return rad;
return Math.min(Math.max(rad + scale, min), max);
})(this.lensRad, resize_speed * resize_dir * resize_mag);
this.updateLensRadius(new_rad);
}
else {
return;
}
this.updateLensUI(this.lensCenter);
}
});
},
createLensUI (viewer) {
const nav_gap = this.state.lensResizeThickness * .75;
const {
container, padding, alpha_handle, alpha_label
} = to_container(nav_gap);
this.state.lensUI = {
container, padding, alpha_handle, alpha_label, nav_gap
};
const { parentElement } = viewer.element;
parentElement.append(container);
},
updateLensUI (newLensCenter) {
const rad = this.lensRad;
const alpha = this.lensAlpha;
if (!this.state.lensUI) return;
if (newLensCenter) {
this.lensCenter = newLensCenter;
}
const [x, y] = this.lensCenter;
const no_lens = this.lensing === null;
const { lensUI } = this.state;
update_container({ ...lensUI, alpha, rad, x, y, no_lens });
this.gl_state.redrawLensTiles();
},
updateLensAlpha (newAlpha) {
this.state.lensAlpha = newAlpha;
},
updateLensRadius (newRad) {
this.state.lensRad = newRad;
},
get lensAlpha () {
return this.state.lensAlpha;
},
get lensRad () {
return this.state.lensRad;
},
get lensCenter () {
return this.state.eventPoint;
},
set lensCenter (xy) {
this.state.eventPoint = xy;
},
isWithinLens (xy) {
const lens_border = this.state.lensInsideBorder;
if (this.lensing === null) {
return false;
}
const center = this.lensCenter;
const dist = toDistance(center, xy);
const rad = this.lensRad - lens_border;
return (dist < rad);
},
isWithinResizeRing (xy) {
if (this.lensing === null) {
return false;
}
const rad = this.lensRad;
const center = this.lensCenter;
const ring = rad + this.state.lensResizeThickness;
const dist = toDistance(center, xy);
return dist < ring;
},
/*
* Editor buffers
*/
get bufferWaypoint() {
if (this.state.buffer.waypoint === undefined) {
const viewport = this.viewport;
return remove_undefined({
Zoom: viewport.scale,
Pan: [
viewport.pan.x,
viewport.pan.y
],
Arrows: [{
Point: this.a,
Text: '',
HideArrow: false
}],
ActiveMasks: undefined,
Masks: undefined,
Polygon: this.p,
Group: this.group.Name,
Groups: undefined,
Description: '',
Name: 'Untitled',
Overlays: [this.overlay]
});
}
return this.state.buffer.waypoint;
},
set bufferWaypoint(bw) {
this.state.buffer.waypoint = bw;
},
/*
* URL History
*/
location: function(key) {
return decodeURIComponent(location[key]);
},
get search() {
const search = this.location('search').slice(1);
const entries = search.split('&');
return deserialize(entries);
},
get hash() {
const hash = this.location('hash').slice(1);
const entries = hash.split('#');
return deserialize(entries);
},
get url() {
const root = this.location('pathname');
const search = this.location('search');
const hash = this.location('hash');
return root + search + hash;
},
get searchKeys() {
const search_keys = Object.keys(this.search);
return ['edit'].filter(x => search_keys.includes(x))
},
/*
* A shared link includes the "d" key for description,
* Otherwise, hash keys always include
* s: story index
* w: waypoint index
* g: channel group index
* m: mask indices
* a: arrow coordinates
* v: viewport coordinates
* o: overlay coordinates
* p: polygon definition
*/
get hashKeys() {
const oldTag = this.waypoint.Mode == 'tag';
if (oldTag || this.isSharedLink) {
return ['d', 's', 'w', 'g', 'm', 'a', 'v', 'o', 'p'];
}
else {
return ['s', 'w', 'g', 'm', 'a', 'v', 'o', 'p', 'r'];
}
},
/*
* Search Keys
*/
set edit(_edit) {
this.state.edit = !!_edit;
},
get edit() {
return !!this.state.edit;
},
get gl_state() {
return this._gl_state;
},
/*
* Control keys
*/
// Used only for optional OMERO support
get omero_cookie() {
const HS = this;
const username = 'jth30';
const pass = new Promise(function(resolve, reject) {
const selector = '.minerva-password_modal';
$(HS.el).find(selector).modal('show');
$(HS.el).find(selector).find('form').submit(function(e){
$(HS.el).find(selector).find('form').off();
$(this).closest('.modal').modal('hide');
const formData = parseForm(e.target);
// Get password from form
const p = formData.p;
resolve(p);
return false;
});
});
return omero_authenticate(username, pass);
},
// Used only for optional Cloud login support
get token() {
const HS = this;
const username = '[email protected]'
const pass = new Promise(function(resolve, reject) {
// Hard code password for public account
resolve('MEETING@lsp2');
/*
const selector = '.minerva-password_modal';
$(HS.el).find(selector).modal('show');
$(HS.el).find(selector).find('form').submit(function(e){
$(HS.el).find(selector).find('form').off();
$(this).closest('.modal').modal('hide');
const formData = parseForm(e.target);
// Get password from form
const p = formData.p;
resolve(p);
return false;
});
*/
});
return this.authenticate(username, pass);
},
// drawType is lasso, arrow, or box
get drawType() {
return this.state.drawType;
},
set drawType(_l) {
this.state.drawType = _l;
},
// Stage in multi-step overlay drawing process
get drawing() {
return this.state.drawing;
},
set drawing(_d) {
const d = parseInt(_d, 10);
this.state.drawing = pos_modulo(d, 3);
},
get singleChannelInfoOpen () {
return [
this.infoOpen, this.allowSingleChannels
].every(x => x)
},
get allowInfoIcon () {
if (this.allowSingleChannels) return true;
if (this.allowInfoLegend) return true;
return false;
},
get allowSingleChannels () {
return this.subpath_map.size > 0;
},
get allowInfoLegend () {
return !!this.channel_legend_lines.find(line => {
return line.description !== '';
});
},
get infoOpen() {
if (this.allowInfoIcon) {
return this.state.infoOpen;
}
return false;
},
set infoOpen(b) {
if (this.allowInfoIcon) {
this.state.infoOpen = !!b;
}
},
toggleInfo() {
this.infoOpen = !this.infoOpen;
},
get addingOpen() {
return this.state.addingOpen;
},
set addingOpen(b) {
this.state.addingOpen = !!b;
},
toggleAdding() {
this.addingOpen = !this.addingOpen;
},
/*
* Hash Keys
*/
// Viewport
get v() {
return this.state.v;
},
set v(_v) {
this.state.v = _v.map(parseFloat);
},
// Arrow
get a() {
return this.state.a;
},
set a(_a) {
this.state.a = _a.map(parseFloat);
},
// Mask indices
get m() {
const m = this.state.m;
const count = this.masks.length;
if (count == 0) {
return [-1]
}
return m;
},
set m(_m) {
if (Array.isArray(_m)) {
this.state.m = _m.map(i => parseInt(i, 10));
}
else {
this.state.m = [-1];
}
},
// Overlay coordinates
get g() {
const g = this.state.g;
const count = this.cgs.length;
return g < count ? g : 0;
},
set g(_g) {
const g = parseInt(_g, 10);
const count = this.cgs.length;
this.state.g = pos_modulo(g, count);
// Dispatch color event
this.activeChannel = -1;
},
/*
* Exhibit Hash Keys
*/
// Lens radius
get r() {
return Math.round(this.lensRad);
},
set r(_r) {
const r = parseInt(_r, 10);
this.updateLensRadius(r);
},
// Waypoint index
get w() {
const w = this.state.w[this.s] || 0;
const count = this.waypoints.length;
return w < count ? w : 0;
},
set w(_w) {
const w = parseInt(_w, 10);
const count = this.waypoints.length;
this.state.w[this.s] = pos_modulo(w, count);
// Set group, viewport from waypoint
const waypoint = this.waypoint;
if (waypoint.Lensing?.Rad) {
this.updateLensRadius(waypoint.Lensing.Rad);
}
// this.slower();
this.m = mFromWaypoint(waypoint, this.masks);
this.g = gFromWaypoint(waypoint, this.cgs);
this.v = vFromWaypoint(waypoint);
if (this.waypoint.Mode == 'tag') {
this.o = oFromWaypoint(waypoint);
this.a = aFromWaypoint(waypoint);
}
else {
this.o = [-100, -100, 1, 1];
this.a = [-100, -100];
}
this.p = pFromWaypoint(waypoint);
this.d = dFromWaypoint(waypoint);
this.n = nFromWaypoint(waypoint);
},
// Story index
get s() {
const s = this.state.s;
const count = this.stories.length;
return s < count ? s : 0;
},
set s(_s) {
const s = parseInt(_s, 10);
const count = this.stories.length;
this.state.s = pos_modulo(s, count);
// Update waypoint
this.w = this.w;
},
/*
* Tag Hash Keys
* for sharable tagged regions
*/
// Overlay coordinates
get o() {
return this.state.o;
},
set o(_o) {
this.state.o = _o.map(parseFloat);
},
// Polygon definition
get p() {
return toPolygonURL(this.state.p);
},
set p(_p) {
this.state.p = fromPolygonURL(_p);