forked from xavierlp/SenseSankey
-
Notifications
You must be signed in to change notification settings - Fork 3
/
SenseColorableSankey.js
1557 lines (1461 loc) · 54.8 KB
/
SenseColorableSankey.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
/**
* Jonathan Vitale
* Major code changes from Xavier Le Pitre's version 2.31
*
* v0.5
* - New options in "Sankey Settings" to disable selecting on nodes or flow.
* - Tooltips are now differentiated by id of containing object, that way multiple sankeys on the same page should work.
* v0.5.1: Changed import of js/qlik to qlik. ht mindspank
* v0.5.2: Updated for September 2018 release
* v0.5.3: Calculation Condition message (in Add-Ons) now allow for an expression.
* v0.4:
* - if data is very large will incrementally grow data (using backend api to grow hypercube in callback paint functions).
* - Make show null nodes default setting so users can see all of data, selection box is in Node Options
* - Also in Node Options, allow users to hide nodes with a given text, e.g., "Not Yet", separate multiple by ";"
* - Finally, in Node Options, allow users to select minimum size of a null
* - Similarly, in Link Options, allow users to hide links with < minimum size
* v0.4.1:
* - terminal nodes no longer pushed to edge of display
* v0.4.2:
* - Reduced # of rows called in initialProperties (to 1000 from 10,000)
* v0.4.3:
* - Can use the function RGB instead of a string for a color
*
* v0.3:
* - updated flow coloring to be dimension based. We now calculate the outflow for each dimension. Will ignore the final dimension
* - ignores null dimensions - skips over them. Good for data that will be loaded in the future.
* - should export to image and pdf
* - Label dimensions on Sankey
* v0.2:
* - You can now sort each dimension by expression. Simply assign a numeric value to the dimension value
* and then you can sort on and switch whether you are ascending or descending
* - slightly smarter checking for pictures on measures (but still not really tested)
* v0.1:
* - In the definition of dimensions, we now include options for coloring. Users first have the option of "auto" coloring.
* The auto color is random (not persistent). If auto is switched off a drop-down with several options appears, including
* random, single color, and expression. For random, persistence means that a node will always
* have the same color based upon its text and position. For expression, you can use the dimension names, like
* If(D1 = 10, '#FF0000', '#00000'). Set different expressions for each dimension.
* - The Sankey Settings area of the panel, now separates Flow Options (e.g. max flow) and Flow Colors. The flow colors
* works in the same way as the dimensions, but creates a new measure. Use expressions like the following to color
* If(D1 = 10 and D2 = 20, '#FF0000', '#00000')
* - Turned on the exporting option.
**/
// Is this necessary? It was in the original.
/*
requirejs.config({
shim : {
"extensions/SenseColorableSankey/sankeymore" : {
deps : ["extensions/SenseColorableSankey/d3.min"],
exports: 'd3.sankey'
}
}
});
*/
define(
[
"jquery",
"qlik",
"text!./style.css",
"text!./theme.json",
"./md5.min",
"./d3.min",
"./colorsankeymore"
],
function($, qlik, cssContent, Theme, md5) {
'use strict';
Theme = JSON.parse(Theme);
var SenseColorableSankeyVersion = "0.5.2";
var runningTick = 1;
$( "<style>" ).html( cssContent ).appendTo( "head" );
return {
initialProperties: {
version: SenseColorableSankeyVersion,
qHyperCubeDef: {
qDimensions: [],
qMeasures: [],
qInitialDataFetch: [{
qWidth: 10,
qHeight: 1000
}]
}
, selectionMode: "QUICK"
},
definition: {
type: "items",
component: "accordion",
items: {
dimensions: {
uses: "dimensions",
min: 2,
max: 6,
items: {
colorSectionText:{
type:"string",
component:"text",
label:" "
},
colorSwitch:{
type: "boolean",
component: "switch",
label: "Colors",
ref:"qDef.myColorSelection.auto",
options: [
{
value: true,
label: "Auto"
}, {
value: false,
label: "Custom"
}
],
defaultValue: true
},
colorChoice:{
type:"string",
component:"dropdown",
label:"",
ref:"qDef.myColorSelection.choice",
options: [
{label: "Random", value:"random"},
{label: "Single color", value:"single"},
{label: "By expression", value:"expression"}
],
show : function(layout) {
if (typeof layout === 'object'){
if (typeof layout.qDef.myColorSelection === 'object' && typeof layout.qDef.myColorSelection.auto !== 'undefined'){
return !layout.qDef.myColorSelection.auto;
} else {
return false;
}
} else {
return false;
}
}
},
// the following two objects are moved from the "Sankey Settings" section to here.
colorPalette:{
type:"string",
component: "dropdown",
label : "Palette",
ref:"qDef.myColorSelection.displayPalette",
options:
[
{
value: "D3-20",
label: "Ordinal Palette 20 colors"
},
{
value: "D3-20c",
label: "Blue-Grey Palette 20 colors"
},
{
value: "D3-20b",
label: "Blue-Purple Palette 20 colors"
},
{
value: "20",
label: "Palette 20 colors"
},
{
value: "20a",
label: "Other Palette 20 colors"
}
],
defaultValue: "D3-20",
show : function(layout) {
if (typeof layout === 'object'){
if (typeof layout.qDef.myColorSelection === 'object' && typeof layout.qDef.myColorSelection.choice !== 'undefined'){
return !layout.qDef.myColorSelection.auto && layout.qDef.myColorSelection.choice === 'random';
} else {
return false;
}
} else {
return false;
}
}
},
colorPersistence:{
ref: "qDef.myColorSelection.colorPersistence",
component: "switch",
type: "boolean",
translation: "Persistence",
defaultValue: false,
trueOption: {
value: true,
translation: "properties.on"
},
falseOption: {
value: false,
translation: "properties.off"
},
show : function(layout) {
if (typeof layout === 'object'){
if (typeof layout.qDef.myColorSelection === 'object' && typeof layout.qDef.myColorSelection.choice !== 'undefined'){
return !layout.qDef.myColorSelection.auto && layout.qDef.myColorSelection.choice === 'random';
} else {
return false;
}
} else {
return false;
}
}
},
colorSingle:{
type: "integer",
component: "color-picker",
label: "Color",
ref: "qDef.myColorSelection.single",
dualOutput: true,
defaultValue: 1,
show : function(layout) {
if (typeof layout === 'object'){
if (typeof layout.qDef.myColorSelection === 'object' && typeof layout.qDef.myColorSelection.choice !== 'undefined'){
return !layout.qDef.myColorSelection.auto && layout.qDef.myColorSelection.choice === 'single';
} else {
return false;
}
} else {
return false;
}
}
},
colorExpression:{
type: "string",
label: "Enter color expression",
ref: "qAttributeExpressions.0.qExpression",
component: "expression",
show : function(layout) {
if (typeof layout === 'object'){
if (typeof layout.qDef.myColorSelection === 'object' && typeof layout.qDef.myColorSelection.choice !== 'undefined'){
return !layout.qDef.myColorSelection.auto && layout.qDef.myColorSelection.choice === 'expression';
} else {
return false;
}
} else {
return false;
}
}
},
// JV Update v0.3: make flow color part of the dimension
flowColorSectionText:{
type:"string",
component:"text",
label:" "
},
flowColorSwitch:{
type: "boolean",
component: "switch",
label: "Outflow Colors",
ref:"qDef.myFlowColorSelection.auto",
options: [
{
value: true,
label: "Auto"
}, {
value: false,
label: "Custom"
}
]
,defaultValue: true
},
flowColorChoice:{
type:"string",
component:"dropdown",
label:"Choose an outflow color method",
ref:"qDef.myFlowColorSelection.choice",
options: [
{label: "Random", value:"random"},
{label: "Single color", value:"single"},
{label: "By expression", value:"expression"}
],
show : function(layout) {
if (typeof layout === 'object'){
if (typeof layout.qDef.myFlowColorSelection === 'object' && typeof layout.qDef.myFlowColorSelection.auto !== 'undefined'){
return !layout.qDef.myFlowColorSelection.auto;
} else {
return false;
}
} else {
return false;
}
}
},
// the following two objects are moved from the "Sankey Settings" section to here.
flowColorPalette:{
type:"string",
component: "dropdown",
label : "Outflow Palette",
ref:"qDef.myFlowColorSelection.displayPalette",
options:
[
{
value: "D3-20",
label: "Ordinal Palette 20 colors"
},
{
value: "D3-20c",
label: "Blue-Grey Palette 20 colors"
},
{
value: "D3-20b",
label: "Blue-Purple Palette 20 colors"
},
{
value: "20",
label: "Palette 20 colors"
},
{
value: "20a",
label: "Other Palette 20 colors"
},
],
defaultValue: "D3-20",
show : function(layout) {
if (typeof layout === 'object'){
if (typeof layout.qDef.myFlowColorSelection === 'object' && typeof layout.qDef.myFlowColorSelection.choice !== 'undefined'){
return !layout.qDef.myFlowColorSelection.auto && layout.qDef.myFlowColorSelection.choice === 'random';
} else {
return false;
}
} else {
return false;
}
}
},
flowColorPersistence:{
component: "switch",
type: "boolean",
translation: "Persistence",
ref: "qDef.myFlowColorSelection.colorPersistence",
defaultValue: false,
trueOption: {
value: true,
translation: "properties.on"
},
falseOption: {
value: false,
translation: "properties.off"
},
show : function(layout) {
if (typeof layout === 'object'){
if (typeof layout.qDef.myFlowColorSelection === 'object' && typeof layout.qDef.myFlowColorSelection.choice !== 'undefined'){
return !layout.qDef.myFlowColorSelection.auto && layout.qDef.myFlowColorSelection.choice === 'random';
} else {
return false;
}
} else {
return false;
}
}
},
flowColorSingle:{
type: "integer",
component: "color-picker",
label: "Outflow Color",
ref: "qDef.myFlowColorSelection.single",
dualOutput: true,
defaultValue: 1,
show : function(layout) {
if (typeof layout === 'object'){
if (typeof layout.qDef.myFlowColorSelection === 'object' && typeof layout.qDef.myFlowColorSelection.choice !== 'undefined'){
return !layout.qDef.myFlowColorSelection.auto && layout.qDef.myFlowColorSelection.choice === 'single';
} else {
return false;
}
} else {
return false;
}
}
},
flowColorExpression:{
type: "string",
label: "Enter outflow color expression",
ref: "qAttributeExpressions.1.qExpression",
component: "expression",
show : function(layout) {
if (typeof layout === 'object'){
if (typeof layout.qDef.myFlowColorSelection === 'object' && typeof layout.qDef.myFlowColorSelection.choice !== 'undefined'){
return !layout.qDef.myFlowColorSelection.auto && layout.qDef.myFlowColorSelection.choice === 'expression';
} else {
return false;
}
} else {
return false;
}
}
},
sortSectionText:{
type:"string",
component:"text",
label:" "
},
sortSwitch:{
type: "boolean",
component: "switch",
label: "Sort",
ref:"qDef.mySortSelection.auto",
options: [
{
value: true,
label: "Auto"
}, {
value: false,
label: "Expression"
}
],
defaultValue: true
},
sortExpression:{
type: "string",
label: "Enter sorting expression",
ref: "qAttributeExpressions.2.qExpression",
component: "expression",
show : function(layout) {
if (typeof layout === 'object'){
if (typeof layout.qDef.mySortSelection === 'object' && typeof layout.qDef.mySortSelection.auto !== 'undefined'){
return !layout.qDef.mySortSelection.auto;
} else {
return false;
}
} else {
return false;
}
}
},
sortAscending:{
type: "boolean",
component: "switch",
label: "Sort Direction",
ref:"qDef.mySortSelection.ascending",
options: [
{
value: true,
label: "Ascending"
}, {
value: false,
label: "Descending"
}
],
defaultValue: true,
show : function(layout) {
if (typeof layout === 'object'){
if (typeof layout.qDef.mySortSelection === 'object' && typeof layout.qDef.mySortSelection.auto !== 'undefined'){
return !layout.qDef.mySortSelection.auto;
} else {
return false;
}
} else {
return false;
}
}
}
}
},
measures: {
uses: "measures",
min: 1,
max: 4
},
SankeyGroup: {
label: "Sankey Settings",
component:"expandable-items",
items : {
NodeOpts: {
label: "Node Options",
type: "items",
items : {
enableNodeSelectionsSwitch:{
type: "boolean",
component: "switch",
label: "Enable node selections",
ref:"enableNodeSelections",
options: [
{
value: true,
label: "Enabled"
}, {
value: false,
label: "Disabled"
}
],
defaultValue: true
},
sortSwitch:{
type: "boolean",
component: "switch",
label: "Show dimension labels",
ref:"displayDimensionLabels",
options: [
{
value: true,
label: "Show"
}, {
value: false,
label: "Hide"
}
],
defaultValue: false
},
nodeMin:{
type: "integer",
label: "Minimum Node Size",
ref: "nodeMinSize",
defaultValue: 1,
min : 1,
max : 200000
},
removeNullNodes:{
type:"boolean",
label:"Remove Empty Nodes",
ref:"nodeRemoveEmpty",
defaultValue: false
},
removeTextNodes:{
type:"string",
expression:"",
label:"Remove with text (separate by ;)",
ref:"nodeRemoveText"
}
}
},
FlowOps: {
label : "Flow Options",
type:"items",
items : {
enableFlowSelectionsSwitch:{
type: "boolean",
component: "switch",
label: "Enable flow selections",
ref:"enableFlowSelections",
options: [
{
value: true,
label: "Enabled"
}, {
value: false,
label: "Disabled"
}
],
defaultValue: true
},
limitFlow:{
ref: "limitFlow",
type: "boolean",
label: "Limit path combinations?",
default: true
},
flowMax:{
type: "integer",
label: "# of unique path combos",
ref: "flowMax",
defaultValue: 1000,
min : 1,
show: function(layout) { if( layout.limitFlow ){ return true } else { return false } }
},
nodeMin:{
type: "integer",
label: "Minimum Link Size",
ref: "linkMinSize",
defaultValue: 1,
min : 1,
max : 200000
},
Separateur:{
ref: "displaySeparateur",
type: "string",
component: "dropdown",
label: "Pop-up Separator",
options:
[
{
value:" - ",
label:"-"
},
{
value:" <-> ",
label:"<->"
},
{
value: " → ",
label: " → "
},
],
defaultValue: " - "
},
Format:{
ref: "displayFormat",
type: "string",
component: "dropdown",
label: "Pop-up Format",
options:
[
{
value: "Number2",
label: "1000.12"
},
{
value: "Number1",
label: "1000.1"
},
{
value: "Number",
label: "1000"
},
],
defaultValue: "Number"
},
currencySymbol:{
type: "string",
label: "Currency Symbol",
ref: "currencySymbol",
defaultValue: "€"
}
},
},
manageImages: {
type:"items",
label:"Images (beta)",
items: {
useImage: {
ref: "useImage",
type: "boolean",
label : "Display Image for 1st and last Dimension",
defaultValue: false,
},
useMeasure : {
ref: "useMeasure",
type: "boolean",
component: "buttongroup",
label: "Dimension or Measure",
options: [
{
value: false,
label: "Dimensions",
tooltip: "1st and last dimensions will be used to build the image"
},
{
value: true,
label: "Measures",
tooltip: "Last and 2nd to last Measures contain the image"
}],
defaultValue: true,
show : function(layout) {return layout.useImage}
},
dimensionImageDescDim:{
ref: "dimensionImageDescD",
type: "string",
component: "text",
label: "1st and last dimensions will be used to build the image",
show: function(layout) { if( layout.useMeasure == true ){ return false } else { return true } }
},
dimensionImageDescMeasure:{
ref: "dimensionImageDescM",
type: "string",
component: "text",
label: "Last and 2nd to last Measures contain the image",
show: function(layout) { if( layout.useMeasure == true ){ return true } else { return false } }
},
extensionImage:{
ref:"extensionImage",
type: "string",
label: "Extension of the image file",
defaultValue: "png",
show: function(layout) {
if (layout.useImage) {
if (layout.useMeasure) { return false } else { return true }
}
}
},
imageLeft:{
ref: "imageLeft",
component: "switch",
type: "boolean",
label: "Image Left",
translation: "Use image left",
defaultValue: true,
trueOption: {
value: true,
translation: "properties.on"
},
falseOption: {
value: false,
translation: "properties.off"
},
show: function(layout) { if( layout.useImage ){ return true } else { return false } }
},
imageRight:{
ref: "imageRight",
component: "switch",
type: "boolean",
label: "Image Right",
translation: "Use image right",
defaultValue: true,
trueOption: {
value: true,
translation: "properties.on"
},
falseOption: {
value: false,
translation: "properties.off"
},
show: function(layout) { if( layout.useImage ){ return true } else { return false } }
},
urlImage:{
ref: "urlImage",
type: "string",
label: "Full URL to online image folder",
expression: "optional",
defaultValue: "",
show: function(layout) { if( layout.useImage ){ return true } else { return false } }
},
sizeImage:{
ref: "sizeImage",
type: "integer",
label: "Image width & height (px)",
defaultValue: 80,
min : 10,
max : 100,
show: function(layout) { if( layout.useImage ){ return true } else { return false } }
}
}
},
managemoreDimension:{
type:"items",
label:"Manage 7 and more Dimensions",
items: {
moreDimension:{
ref: "moreDimension",
component: "switch",
type: "boolean",
label: "Manage more than 4 dimensions",
defaultValue: false,
trueOption: {
value: true
},
falseOption: {
value: false
},
show: true
},
descriptionSeparateur:{
ref: "separateur",
label: "Define the separator to use between dimensions i.e ([dimension4] & '§' & [dimension5] & '§' & [dimension6]",
type: "string",
component: "text",
show: function(layout) { return layout.moreDimension }
},
separateur:{
ref: "separateur",
label: "Add this separator",
//in the last dimension i.e ([dimension4] & '§' & [dimension5] & '§' & [dimension6]",
type: "string",
defaultValue: "§",
show: function(layout) { return layout.moreDimension }
}
}
}
}
},
addons: {
uses: "addons",
items: {
dataHandling: {
uses: "dataHandling",
items: {
calcCond: {
uses: "calcCond"
}
}
}
}
},
settings: {
uses: "settings"
}
}
},
snapshot: {
canTakeSnapshot: true
},
support : {
export: true
},
paint: function ( $element, layout ) {
// Fonction format pop-up
function formatMoney(n, c, d, t, m, l){
var c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "." : d,
t = t == undefined ? "," : t,
s = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return l + ' \n ' + s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "")+ m;
};
function formatNumber(displayFormat, value, context,currencySymbol){
if (displayFormat === "Number"){
return formatMoney(value, 0, '.', ',',currencySymbol, context);
}
if (displayFormat === "Number1"){
return formatMoney(value, 1, '.', ',',currencySymbol,context);
}
if (displayFormat === "Number2"){
return formatMoney(value, 2, '.', ',',currencySymbol,context);
}
}
// Persistent color function
var hashScale = d3.scale.linear().domain([1, 4294967295]).range([ 0, 19.9999 ]);
function hashL(str) {
var hashL = 5381,
i = str.length
while(i)
hashL = (hashL * 33) ^ str.charCodeAt(--i)
//hash = md5(str)
return hashL >>> 0;
}
// JV Update v0.4: Nulls and alternative text may remove nodes
function isValidNode(str){
var excludeWords = [""];
if (layout.nodeRemoveText != null){
// the user is told to separate by ';'
excludeWords = layout.nodeRemoveText.split(";").map(function(word, index){
return word.trim();
});
}
if (layout.nodeRemoveEmpty != null && layout.nodeRemoveEmpty && str === "-"
||
excludeWords.indexOf(str) >= 0
){
return false;
} else {
return true;
}
}
var _this = this;
var displayDimensionLabels = layout.displayDimensionLabels;
var displayFormat = layout.displayFormat;
var currencySymbol = " " + layout.currencySymbol;
var displaySeparateur = layout.displaySeparateur;
var displayPalette = layout.displayPalette;
var colorPersistence = layout.colorPersistence;
var useImage = layout.useImage;
var useMeasure = (layout.useMeasure === undefined ? true : layout.useMeasure);
var imageRight = (layout.imageRight === undefined ? true : layout.imageRight);
var imageLeft = layout.imageLeft;
var urlImage = layout.urlImage;
var urlImageDesc = layout.urlImageDesc;
var sizeImage = (layout.sizeImage === undefined ? 80 : layout.sizeImage);
var extensionImage = (layout.extensionImage === undefined ? "png" : layout.extensionImage);
var dimImageRight = (layout.dimImageRight === undefined ? "" : layout.dimImageRight);
var offset = $element.offset();
var separator = (layout.separateur === undefined ? "§" : layout.separateur);
var nbImageDrawn = 0;
var enableNodeSelections = layout.enableNodeSelections === undefined ? true : layout.enableNodeSelections;
var enableFlowSelections = layout.enableFlowSelections === undefined ? true : layout.enableFlowSelections;
//var flowColor = (layout.flowChoice == 2) ? layout.flowColorCustom : Theme.palette[layout.flowColor];
//var flowColor = layout.flowColorCustom.color;
var qData = layout.qHyperCube.qDataPages[0];
// create a new array that contains the dimension labels
var qDim = layout.qHyperCube.qDimensionInfo.map(function(d) {
return d.qFallbackTitle;
});
var divName = layout.qInfo.qId;
var qMatrix = qData.qMatrix.sort();
// JV Update v.1: create a new object array with user defined color and sort parameters for dimension
var qDimColorUser = layout.qHyperCube.qDimensionInfo.map(function(d){
var m = typeof d.myColorSelection !== "undefined" ? d.myColorSelection : {};
return {
auto: typeof m.auto !== "undefined" ? m.auto : true,
choice: typeof m.choice !== "undefined" ? m.choice : "random",
colorPersistence: typeof m.colorPersistence !== "undefined" ? m.colorPersistence : false,
displayPalette: typeof m.displayPalette !== "undefined" ? m.displayPalette : "D3-20c",
single: typeof m.single !== "undefined" ? m.single : "#4477aa"
}
});
// JV Update v.1: create a new object array with user defined color parameters for flow
// JV Update v.3: each dimension will now have an attribute for outflow color
var qFlowUser = layout.qHyperCube.qDimensionInfo.map(function(d){
var m = typeof d.myFlowColorSelection !== "undefined" ? d.myFlowColorSelection : {};
return {
auto: typeof m.auto !== "undefined" ? m.auto : true,
choice: typeof m.choice !== "undefined" ? m.choice : "random",
colorPersistence: typeof m.colorPersistence !== "undefined" ? m.colorPersistence : false,
displayPalette: typeof m.displayPalette !== "undefined" ? m.displayPalette : "D3-20c",
single: typeof m.single !== "undefined" ? m.single : "#4477aa"
}
});
// JV Update v.2: same for sorting
var qDimSortUser = layout.qHyperCube.qDimensionInfo.map(function(d){
var m = typeof d.mySortSelection !== "undefined" ? d.mySortSelection : {};
return {
auto: typeof m.auto !== "undefined" ? m.auto : true,
ascending: typeof m.ascending !== "undefined" ? m.ascending : true
}
});
// iterate through each row of the hypercube data
var source = [];
var lastrow = 0, me = this;
// JV Update v0.4: Use the backendApi to iterate through AVAILABLE rows
this.backendApi.eachDataRow(function(rownum, row){
lastrow = rownum;
var path = "";
var sep = "";
var nbDimension = qDim.length;
var nbMesures = qMatrix[0].length - nbDimension;
var nbTotal = nbMesures + nbDimension;
var labels = [];
var colors = [];
var flowColors = [];
var sortVals = [];
var sortDirs = [];
// only bother if the size of the measure is greater than zero
if (row[nbDimension].qNum > 0){
for (var i = 0; i < nbDimension ; i++) {
var label = row[i].qText;
labels = labels.concat(label);
path += sep + (label.replace('|', ' ')) + '|' + (row[i].qElemNumber);
sep = separator;
// JV UPDATE v0.1: This now does the work of coloring the nodes
// I removed the function "getColorForNode"
if (qDimColorUser[i].auto==true || qDimColorUser[i].choice == "random"){
//strValue = row[i].qText;
if (qDimColorUser[i].displayPalette === "D3-20") {
var colours = ['#1f77b4','#aec7e8','#ff7f0e','#ffbb78','#2ca02c','#98df8a','#d62728','#ff9896','#9467bd','#c5b0d5','#8c564b',
'#c49c94','#e377c2','#f7b6d2','#7f7f7f','#c7c7c7','#bcbd22','#dbdb8d','#17becf','#9edae5' ];
}
else if (qDimColorUser[i].displayPalette === "D3-20b") {
var colours = ['#393b79','#5254a3','#6b6ecf','#9c9ede','#637939','#8ca252','#b5cf6b','#cedb9c','#8c6d31','#bd9e39',
'#e7ba52','#e7cb94','#843c39','#ad494a','#d6616b','#e7969c','#7b4173','#a55194','#ce6dbd','#de9ed6'];
}
else if (qDimColorUser[i].displayPalette === "D3-20c") {
var colours = ['#3182bd','#6baed6', '#9ecae1','#c6dbef','#e6550d','#fd8d3c','#fdae6b','#fdd0a2','#31a354',
'#74c476','#a1d99b','#c7e9c0','#756bb1','#9e9ac8','#bcbddc','#dadaeb','#636363','#969696','#bdbdbd','#d9d9d9' ];
}
else if (qDimColorUser[i].displayPalette === "20") {
var colours = [ '#1abc9c','#7f8c8d','#2ecc71','#bdc3c7','#3498db','#c0392b','#9b59b6','#d35400','#34495e','#f39c12',
'#16a085','#95a5a6','#27ae60','#ecf0f1','#2980b9','#e74c3c','#8e44ad','#e67e22','#2c3e50','#f1c40f' ];
}
else if (qDimColorUser[i].displayPalette === "20a") {
var colours = [ '#023FA5','#7D87B9','#BEC1D4','#D6BCC0','#BB7784','#FFFFFF','#4A6FE3','#8595E1','#B5BBE3','#E6AFB9',
'#E07B91','#D33F6A','#11C638','#8DD593','#C6DEC7','#EAD3C6','#F0B98D','#EF9708','#0FCFC0','#9CDED6'];
}
if (qDimColorUser[i].auto==true || !qDimColorUser[i].colorPersistence){
colors = colors.concat(colours[Math.floor(Math.random() * (19))]);
} else {
colors = colors.concat(colours[parseInt(Math.floor(hashScale(hashL(md5(path)))))]);
}
} else if (qDimColorUser[i].choice == "single"){
colors = colors.concat(typeof qDimColorUser[i].single === "object" ? qDimColorUser[i].single.color : qDimColorUser[i].single);
} else if (qDimColorUser[i].choice == "expression" && typeof row[i].qAttrExps.qValues !== "undefined" && row[i].qAttrExps.qValues.length >= 0){
if (typeof row[i].qAttrExps.qValues[0].qText === "string") {
colors = colors.concat(row[i].qAttrExps.qValues[0].qText);
} else if (typeof row[i].qAttrExps.qValues[0].qNum === "number") {
var colHex = row[i].qAttrExps.qValues[0].qNum.toString(16);
// for some reason the alpha comes first, so let's remove those values
colHex = "#" + colHex.substr(2, 6); // + colHex.substr(0, 2);
colors = colors.concat(colHex);
}
} else {
colors = colors.concat("#888888"); //may happen if expression fails
}
// JV UPDATE v0.2: same with sorting
// first we check if we are doing expression-based sorting
if (qDimSortUser[i].auto==true || row[i].qAttrExps.qValues.length < 3){
sortVals = sortVals.concat(null); // will use default