-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparcial.js
1294 lines (1072 loc) · 40.5 KB
/
parcial.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
/* This file is released under the GNU General Public License, version 3
* */
'use strict';
var svg;
var root;
var mappging = [];
var selected_object = null;
var dataA;
function SdosSheetController($rootScope, $state, $scope, $mdDialog, $http) {
var jsonFile = "cascadeData.json";
var icon_file = "/angular/icons/d3/plusfile.svg";
var icon_key = "/angular/icons/d3/key.svg";
var icon_key_closed = "/angular/icons/d3/key_closed.svg";
var icon_masterkey = "/angular/icons/d3/masterkey_test.svg";
var icon_masterkey_pass = "/angular/icons/d3/masterkey_password.svg";
var icon_masterkey_TPM = "/angular/icons/d3/masterkey_TPM.svg";
var icon_masterkey_new = "/angular/icons/d3/masterkey_test_new.svg";
var icon_masterkey_pass_new = "/angular/icons/d3/masterkey_password_new.svg";
var icon_masterkey_TPM_new = "/angular/icons/d3/masterkey_TPM_new.svg";
var icon_plusfile = "/angular/icons/d3/pluskey_object.svg";
var icon_pluskey = "/angular/icons/d3/pluskey.svg";
var icon_object = "/angular/icons/d3/key_object.svg";
var icon_selectedfile = "/angular/icons/d3/selected_file.svg";
var icon_selectedkey = "/angular/icons/d3/selected_key.svg";
var icon_key_delete = "/angular/icons/d3/key_object_delete.svg";
var icon_file_delete = "/angular/icons/d3/plusfile_delete.svg";
var dataset;
var dataP;
var inicialTree = [];
var text;
var animation = 0;
var cascadeData;
// this is how the UI knows which explain-text to highlight
//$scope.current_animation_step = 0;
/*
$scope.hide = function () {
$mdDialog.hide();
};
$scope.cancel = function () {
$mdDialog.cancel();
};
*/
var margin = {top: 20, right: 120, bottom: 20, left: 120},
width = 1000 - margin.right - margin.left,
height = 800 - margin.top - margin.bottom;
var i = 0,
duration = 750
;
var tree = d3.layout.tree()
.size([height, width]);
var diagonal = d3.svg.diagonal()
.projection(function (d) {
return [d.y, d.x];
});
var zoom = d3.behavior.zoom().scaleExtent([0, 1]).translate([120, 20]).on("zoom", zoomed);
/*
*
* Rendering functions
*
* */
d3.json(jsonFile, function (error, data) {
if (error) {
console.log(error);
} else {
console.log(data);
dataA = data;
renderTree(data);
}
});
function objMapping(root, deletableObjejects) {
if(root.type == "object") {
if(root.parent != null)
if(deletableObjejects.indexOf(root.name) > -1)
mappging.push(root);
}
else{
if(root.children){
root.children.forEach(function (d) {
objMapping(d, deletableObjejects);
});
}
if(root._children){
root._children.forEach(function (d) {
objMapping(d, deletableObjejects);
});
}
if(root.siblings_up){
root.siblings_up.forEach(function (d) {
objMapping(d, deletableObjejects);
});
}
if(root.siblings_down){
root.siblings_down.forEach(function (d) {
objMapping(d, deletableObjejects);
});
}
}
}
function renderTree(data) {
cascadeData = data;
dataset = jsonToFlare(data);
root = dataset[0];
root.x0 = height / 2;
root.y0 = 0;
d3.select(self.frameElement).style("height", "500px");
svg = d3.select("#cascadeRendering").append("svg")
.attr("width", width + margin.right + margin.left)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
.call(zoom);
var open = [];
/* For the start configuration of the tree
* takes the first node of each level and let
* their open
* */
for (var i = 0; i < data.levels - 1; i++) {
open.push(pidFop(data.partitionSize, i));
}
inicialTree = open;
closeTree(root, open);
update(root);
if(data.sdos_batch_delete_log.length){
loadNode(root, data.sdos_batch_delete_log, data);
}
d3.select("#cascadeRendering").append("input")
.attr("type", "checkbox")
.attr("id", "autoAnimation")
.attr("checked", "checked");
d3.select("#cascadeRendering").append("span")
.text("Automatic animation ");
d3.select("#cascadeRendering").append("input")
.attr("type", "button")
.attr("value", "next")
.on("click", function (){
if(selected_object.length == 1)
stepAnimation(selected_object);
else if(selected_object.length > 1)
stepAnimationMultiple(selected_object, 1);
});
d3.select("#cascadeRendering").append("input")
.attr("type", "button")
.attr("value", "delete")
.on("click", function (){
deleteAnimation(selected_object);
});
var delete_text = d3.select("#cascadeRendering").append("input")
.attr("type", "text")
.attr("disabled", "disabled")
.attr("id", "delete_text")
.attr("size", 100);
d3.select("#cascadeRendering").append("br");
/*
* Bellow are the buttons to "Reset tree" and "Search Node"
* used only in the development file
* */
/* "Reset Tree" button using the open list configuration
* */
d3.select("#cascadeRendering").append("input")
.attr("type", "button")
.attr("value", "Reset Tree")
.on("click", function () {
closeTree(root, open);
update(root);
});
/* "Search Node" button and selection list
* Create the select list for the objects names
* */
text = d3.select("#cascadeRendering").append("select")
.attr('id', "valueText");
/* add to the objects from the objectsMapping
* a link to their father in order to find the path
* for then later when the user selects an object
* */
var optionList = [];
for (i in data.objectMapping) {
for (var j = 0; j < data.objectMapping[i].length; j++) {
if (data.objectMapping[i][j] != null)
data.objectMapping[i][j]['parent'] = i;
}
optionList = optionList.concat(data.objectMapping[i]);
}
/* The value of an <option> is the parent number
* */
text.selectAll('option')
.data(optionList).enter()
.append('option').text(function (d) {
return d.objName
})
.attr('value', function (d) {
return d.parent + "|" + d.objName
});
/* By clicking the search button it calls the leafPath function
* with the value of the option selected
* */
d3.select("#cascadeRendering").append("input")
.attr("type", "button")
.attr("value", "Search Node")
.on("click", function () {
searchNode(root, text, data);
});
/*
* Button and camp text delete
* */
}
/*
* Ends rendering functions
* */
/* Zoom functions area
*
* Note: the var zoom is created to be called by the svg --> line 33
* */
function zoomed() {
svg.attr("transform",
"translate(" + zoom.translate() + ")" +
"scale(" + zoom.scale() + ")"
);
}
function interpolateZoom(translate, scale) {
var self = this;
return d3.transition().duration(duration).tween("zoom", function () {
var iTranslate = d3.interpolate(zoom.translate(), translate),
iScale = d3.interpolate(zoom.scale(), scale);
return function (t) {
zoom
.scale(iScale(t))
.translate(iTranslate(t));
zoomed();
};
});
}
function zoomClick(id) {
var factor = 0.5,
center = [width / 2, height / 2],
extent = zoom.scaleExtent(),
translate = zoom.translate(),
view = {x: translate[0], y: translate[1], k: zoom.scale()};
d3.event.preventDefault();
var direction = (id === 'zoom_in') ? 2 : -1;
var target_zoom = zoom.scale() * (1 + factor * direction);
var translate0 = [(center[0] - view.x) / view.k, (center[1] - view.y) / view.k];
view.k = target_zoom;
var l = [translate0[0] * view.k + view.x, translate0[1] * view.k + view.y];
view.x += center[0] - l[0];
view.y += center[1] - l[1];
interpolateZoom([120, 20], view.k);
}
function buttonClick() {
if (this.id == 'zoom_in' || this.id == 'zoom_out') {
return zoomClick(this.id);
}
else {
animateClick(this.id);
}
}
d3.selectAll('button').on('click', buttonClick);
/* Ends zoom functions */
/*
*
* Selecting path and objects functions
*
* */
function loadNode(source, objects, data) {
var path = [];
var aux;
aux = searchParent(objects, data.objectMapping);
multipleLeafsPath(source,aux, data.partitionSize, path);
closeTree(source, path);
update(root);
objMapping(root, data.sdos_batch_delete_log);
selected_object = mappging;
//console.log(mappging);
}
function searchParent(objects, objMapping){
var parentsChildren = [];
var i = 0;
for(var parent in objMapping){
objMapping[parent].forEach(function (d) {
if(objects.indexOf(d.objName) > -1){
parentsChildren[i] = parent.toString() + "|" + d.objName.toString();
i++;
}
})
}
return parentsChildren;
}
/* text is a string in the format "parent|object_name"
* source is the root tree
* data is the raw data from the json file
* */
function searchNode(source, text, data) {
var path = [];
var aux = text.property("value").toString();
multipleLeafsPath(source,[aux], data.partitionSize, path);
closeTree(source, path);
update(root);
objMapping(root, data.sdos_batch_delete_log);
selected_object = mappging;
}
function multipleLeafsPath(source,list, ps, path) {
var multiplePath = [];
var objects = [];
var open = [];
//list = ["4369|0", "4369|2", "4369|9", "4373|66"];
list.forEach(function (d) {
var aux = d.split("|");
leafPath(parseInt(aux[0]), ps, path);
multiplePath = multiplePath.concat(path.filter(function (item) {
return multiplePath.indexOf(item) < 0;
}));
objects.push(aux[1]);
});
//select all nodes
rightChildren(source, multiplePath, objects, open);
console.log(open);
// if(objects.length == 1){ //Search one just object
open.forEach(function (op) {
console.log(op);
var found = 0;
var down = 1;
while(!found) {
//look if the object is in children
op[1].children.forEach(function (d) {
if (d.name == op[0].name) {
found = 1;
}
});
if(!found){
//go siblings down
if (down) {
siblingsDown(op[1].children[op[1].children.length - 1], op[1]);
if (op[1].siblings_down.length == 0) {
down = 0;
}
}
else {
siblingsUp(op[1].children[0], op[1]);
if (op[1].siblings_up.length == 0) {
down = 1;
}
}
}
}
});
//}
}
function leafPath(value, ps, path) {
var number = value;
/* By the number/key node name, finds all the path
* from the root to this current number
* returning it in a list
* */
if (number > 0) {
var parent = parseInt((number - 1) / ps);
if(path.indexOf(number) < 0)
path.push(number);
leafPath(parent, ps, path);
} else {
if(path.indexOf(0) < 0)
path.push(0);
}
}
function rightChildren(source, openNodes, object, open) {
/* Go through all children
* */
var next = null;
/* Testes if the node is not closed, then open it
* */
if (source._children != null) {
//console.log(source);
changeChildren(source);
}
// take all children to be selected
var uz = [];
if(source.children != null)
uz = uz.concat(source.children);
if(source.siblings_down != null)
uz = uz.concat(source.siblings_down);
if(source.siblings_up != null)
uz = uz.concat(source.siblings_up);
if (uz != null) {
uz.forEach(function (d) {
/* See if this node is in the OpenNodes list
* if it is and it is a "key" type, goes to the next node
* if it is a "key_object" type
* */
/*
* NOTE: assume that this function will be use to mark all nodes
* once and will be not another "search"
* if it is, probably will be in the case of "else"
* */
if (openNodes.indexOf(d.name) > -1 && (d.type == "key")) {
d.operation = "selected";
next = d;
open.push([d, source]);
rightChildren(next, openNodes, object, open);
}
else if (d.type == "key_object") {
if(d.children != null) {
changeChildren(d);
}
if(d._children[0] && object.indexOf(d._children[0].name) > -1) {
d.operation = "selected";
changeChildren(d);
open.push([d, source]);
}
else{
d.operation = "none";
}
}
else{
d.operation = "none";
}
});
}
return open; //in case of one
}
function closeTree(source, openNodes) {
/* Uses the click function to let just the nodes
* in the array openNodes open in the tree. the remain
* do not show its children
* */
var nodes = tree.nodes(source).reverse();
nodes.forEach(function (d) {
/* The actual node d is the node tested to be in the path
* So to open & show the path, the node d have to be in its parent children
* */
if (d.type != "key_object") {
if (d.children != null && openNodes.indexOf(d.name) < 0) {
changeChildren(d);
//console.log(d);
}
else if (d._children != null && openNodes.indexOf(d.name) > -1) {
changeChildren(d);
}
}
/*else{
if(d._children != null){
changeChildren(d);
}
}*/
});
}
/*
* ends Selecting path and objects functions
* */
/*
*
* Animation functions
*
* */
function newAnimation(d, visited_keys, callback) {
setTimeout(function () {
d3.select("#delete_text").attr("value", "Inputing new key");
// New key
if(d.type == "master"){
//$scope.current_animation_step = 7;
//$scope.$apply();
}
else { // key_object and object do not call newAnimation
//$scope.current_animation_step = 3;
//$scope.$apply();
}
d.operation = "new";
update(d);
if(callback) {
// remove next node from visited nodes
var next = visited_keys.shift();
callback(next, visited_keys, newAnimation);
}
}, 750);
}
function fadingAnimation(d, visited_keys, callback) {
setTimeout(function () {
d3.select("#delete_text").attr("value", "Deleting old key");
// Remove OLD key
if(d.type == "master"){
//$scope.current_animation_step = 4;
//$scope.$apply();
}
else if(d.type == "key") {
//$scope.current_animation_step = 2;
//$scope.$apply();
}
else if(d.type == "key_object") {
//$scope.current_animation_step = 5;
//$scope.$apply();
}
else{ //remove object
//$scope.current_animation_step = 6;
//$scope.$apply();
}
d.operation = "fade";
update(d);
if(d.type == "object"){
var parent = d.parent;
parent.children = null;
update(parent);
}
// remove next node from visited nodes
if (visited_keys.length > 0) {
if (visited_keys[0].type != "object") {
callback(d, visited_keys, fadingAnimation);
}
else {
var next = visited_keys.shift();
fadingAnimation(next, visited_keys, newAnimation);
// should not have the case of trying call the callback from this point, since order
}
}else if(visited_keys.length == 0 && callback){
if(d.type != "key_object" && d.type != "object") {
callback(d, visited_keys);
}
}
}, 750);
}
function changingKeysAnimation(d, visited_keys) {
console.log("changing",d);
visited_keys.reverse();
var list = visited_keys;
fadingAnimation(d, list, newAnimation);
}
function selectingAnimation(d, visited_keys, callback) {
setTimeout(function () {
if (d.parent) {
d3.select("#delete_text").attr("value", "Selecting path from leaf to root");
//$scope.current_animation_step = 1;
//$scope.$apply();
d.operation = "selecting";
update(d);
visited_keys.push(d);
selectingAnimation(d.parent, visited_keys, callback);
}
else {
if(callback)
callback(d, visited_keys);
else{
// case when the step animation called, need put key master in the array
var last = visited_keys.pop();
visited_keys.push(last);
visited_keys.push(last.parent);
}
}
}, 750);
}
var step = 0;
var keys = [];
// "Next" button calls this function directly
function stepAnimation(d){
if(step == 0){
// selecting step
selectingAnimation(d[0],keys);
step = 1;
}
else{
if(keys != []){
var node = keys.pop();
console.log("steo",d[0]);
changingKeysAnimation(node, []);
}
}
}
function selectingAnimationMultiple(d, visited_keys, multiples, step, callback) {
setTimeout(function () {
if (d.parent && d.operation != "selecting") {
d3.select("#delete_text").attr("value", "Selecting path from leaf to root");
//$scope.current_animation_step = 1;
//$scope.$apply();
d.operation = "selecting";
update(d);
visited_keys.push(d);
selectingAnimationMultiple(d.parent, visited_keys, multiples, step, callback);
}
else {
if(callback) {
//add master key
if(visitedMultiple.length == 0){
visitedMultiple[0] = d;
}
visited_keys.reverse();
visitedMultiple = visitedMultiple.concat(visited_keys);
callback(multiples, step);
}
else{
console.log("no callback");
}
}
}, 750);
}
var mulCont = 0;
var visitedMultiple = [];
var waitOne = 1;
function stepAnimationMultiple(d, doStep){
if(step == 0) {
selectingAnimationMultiple(d[mulCont], [], d, doStep, stepAnimationMultiple);
mulCont = mulCont + 1;
if(mulCont == d.length)
step = 1;
}
else{
if(visitedMultiple != []) {
if(doStep){
if(waitOne){
waitOne = 0;
}
else {
var node = visitedMultiple.shift();
fadingAnimation(node, [], newAnimation);
}
}
else {
var master = visitedMultiple.shift();
fadingAnimation(master, visitedMultiple, newAnimation);
}
}
}
}
function deleteAnimation(d) {
var auto = d3.select("#autoAnimation").property("checked");
if (!animation) {
if (auto) {
waitOne = 0;
stepAnimationMultiple(d, 0);
}
}
}
/*
* End animations functions
*
* */
/*
* Drawing function
* */
function update(source) {
// Compute the new tree layout.
var nodes = tree.nodes(root).reverse(); // list of the nodes objects, descending
var links = tree.links(nodes);
// Normalize for fixed-depth.
nodes.forEach(function (d) {
d.y = d.depth * 100;
}); // the distance between nodes
tree.separation(separation);
function separation(a, b) {
return a.parent == b.parent ? 0.8 : 2;
}
// Update the nodes…
var node = svg.selectAll("g.node")
.data(nodes, function (d) {
return d.id || (d.id = ++i);
});
// Enter any new nodes at the parent's previous position.
var nodeEnter = node.enter().append("g")
.attr("class", "node")
.attr("transform", function () {
return "translate(" + source.y0 + "," + source.x0 + ")";
})
.on("click", function (d) {
if (d.type == "down" || d.type == "object_down")
return clickDown(d);
else if (d.type == "up" || d.type == "object_up")
return clickUp(d);
else if (d.type == "object")
return clickOpenObject(d);
else return click(d)
});
// append svg and rectangles to the nodes
function rectHeight(d) {
var inicial = d.x;
var final;
var next = false;
d.parent.children.forEach(function (e) {
if (e.name == d.name + 1) {
final = e.x;
next = true;
}
});
if (!next) {
if (d.parent.children[d.parent.children.length - 1].type == "down")
final = d.parent.children[d.parent.children.length - 1].x;
else final = inicial + 60;
}
return final - inicial + 2;
}
nodeEnter.append("rect")
.attr("width", function (d) {
return (d.type == "key" || d.type == "key_object") ? 40 : null
})
.attr("height", function (d) {
return (d.type == "key" || d.type == "key_object") ? rectHeight(d) : null;
})
.attr("class", function (d) {
return (d.type == "key" ) ? "key" : "object";
})
.attr("x", "-10px")
.attr("y", "-24px")
.style("fill-opacity", 1e-6);
nodeEnter.append("svg:image")
.attr("xlink:href", function (d) {
return d.type == "key" ? (d._children ? icon_key_closed :icon_key) : (
d.type == "master" ?
(d.key_type == "static" ? icon_masterkey :
(d.key_type == "tpm" ? icon_masterkey_TPM : icon_masterkey_pass ) )
: ( d.type == "object" ? icon_file :
(d.type == "key_object" ? icon_object : (d.type == "up" || d.type == "down" ? icon_pluskey : icon_plusfile) )));
})
.attr("x", function (d) {
return d.type == "master" && d.operation == null ? "-30px" : "-19px"
})
.attr("y", function (d) {
return d.type == "master" && d.operation == null ? "-120px" : "-24px"
})
.attr("width", function (d) {
return d.type == "master" && d.operation == null ? "130px" : "37px"
})
.attr("height", function (d) {
return d.type == "master" && d.operation == null ? "150px" : "37px"
});
// the label of the node
nodeEnter.append("text")
.attr("x", 13)
.attr("dy", "1.5em")
.attr("text-anchor", function (d) {
return d.children || d._children ? "end" : "start";
})
.text(function (d) {
return d.name;
})
.style("fill-opacity", 1e-6);
// Transition nodes to their new position.
var nodeUpdate = node.transition()
.duration(duration)
.attr("transform", function (d) {
return "translate(" + (d.y) + "," + d.x + ")";
});
// the new style after the transition
nodeUpdate.select("image")
.attr("xlink:href", function (d) {
if((d.type == "object" || d.type == "key_object") && d.operation == "selecting"){
return d.type == "object" ? icon_file_delete : icon_key_delete;
}
if(d.type == "object" && d.parent.operation == "selected")
return icon_selectedfile;
return d.operation == "selected" ? icon_selectedkey :
(d.operation == "new" ? ( d.type == "master" ? (
d.key_type == "static" ? icon_masterkey_new :
(d.key_type == "tpm" ? icon_masterkey_TPM_new : icon_masterkey_pass_new )
) : icon_pluskey) :
(d.operation == "fade" ? "" : ( d.type == "key" ?
(d._children ? icon_key_closed :icon_key) : ( d.type == "master" ?
(d.key_type == "static" ? icon_masterkey :
(d.key_type == "tpm" ? icon_masterkey_TPM : icon_masterkey_pass ) ) : ( d.type == "object" ? icon_file :
(d.type == "key_object" ? icon_object : (d.type == "up" || d.type == "down" ? icon_pluskey : icon_plusfile) ))))));
})
.attr("x", function (d) {
return d.type == "master" ? "-30px" : "-19px"
})
.attr("y", function (d) {
return d.type == "master" ? "-120px" : "-24px"
})
.attr("width", function (d) {
return d.type == "master" ? "130px" : "37px"
})
.attr("height", function (d) {
return d.type == "master" ? "150px" : "37px"
});
nodeUpdate.select("rect")
.attr("width", function (d) {
return (d.type == "key" || d.type == "key_object") ? 40 : null
})
.attr("height", function (d) {
return (d.type == "key" || d.type == "key_object") ? rectHeight(d) : null;
})
.attr("class", function (d) {
return (d.type == "key") ? "key" : "object";
})
.attr("x", "-20px")
.attr("y", "-24px")
.style("fill", function (d) {
return "lightsteelblue";
//return d._children ? (d.type == "key" ? "lightsteelblue" : "#c3c3c3" ) : "#fff"
})
.style("fill-opacity", 1)
.style("stroke", function (d) {
return "none";
//return d.operation == "selected" ? "#DA6B03" : ( d.operation == "selecting"? "#B83737" :"steelblue")
})
;
nodeUpdate.select("text")
.style("fill", function (d) {
if(d.type == "object" && d.parent.operation == "selected")
return "#DA6B03";
})
.style("fill-opacity", function (d) {
return d.operation == "fade" && (d.type == "key_object" || d.type == "object" ) ? 0 : 1;
});
// Transition exiting nodes to the parent's new position.
var nodeExit = node.exit().transition()
.duration(duration)
.attr("transform", function () {
return "translate(" + source.y + "," + source.x + ")";
})
.remove();
nodeExit.select("text")
.style("fill-opacity", 1e-6);
// Update the links…
var link = svg.selectAll("path.link")
.data(links, function (d) {
return d.target.id;
});
// Enter any new links at the parent's previous position.
link.enter().insert("path", "g")
/*.filter(function (d) {
console.log(d);
if (d.target.type != "down" && d.target.type != "up"){
return true;
}
else this.remove();
})*/
.attr("class", "link")
.attr("d", function () {
var o = {x: source.x0, y: source.y0};
return diagonal({source: o, target: o});