-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
2966 lines (2564 loc) · 114 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mental Load Dev</title>
<link rel="icon" type="image/x-icon" href="/images/favicon.ico">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Barlow:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<script src="https://d3js.org/d3.v7.min.js"></script>
</head>
<style>
html * {
font-family: "Barlow", sans-serif !important;
overflow: visible
}
h1 {
font-weight: 500;
line-height: 1.2;
letter-spacing: -1px;
font-size: 60px;
color: #003b5c;
margin-top: 0.75em;
margin-bottom: .75em;
}
h2 {
font-weight: 500;
line-height: 1;
letter-spacing: 0px;
font-size: 34px;
color: #0092bc;
margin-top: 0em;
margin-bottom: 1em;
}
h3 {
font-weight: 600;
line-height: 1.5;
letter-spacing: 0px;
font-size: 28px;
color: #003b5c;
margin-top: 1.4em;
margin-bottom: .75em;
}
h4 {
font-weight: 450;
line-height: 1.5;
letter-spacing: 0px;
font-size: 20px;
color: #003b5c;
margin-top: 1.33em;
margin-bottom: .75em;
}
body {
margin-left: 40px;
}
.tooltip {
position: absolute;
text-align: center;
width: auto;
height: auto;
padding: 5px;
font-size: 13px;
background: #F2F2F2;
border: 0px;
border-radius: 2px;
pointer-events: none;
visibility: hidden;
z-index: 1;
/* Initially hidden */
}
.axislabel,
.tick,
.annotation,
.label {
font-size: 14px;
}
.dashed_line {
stroke: black;
stroke-dasharray: 4 4;
stroke-width: 1;
}
.sum {
stroke:white;
stroke-width:0.5em;
fill:black;
paint-order:stroke;
stroke-linejoin:round;
font-size: 15px;
}
.chart_title {
font-size: 18px;
font-weight: 450;
}
.grid line {
stroke: lightgrey;
stroke-opacity: 0.7;
shape-rendering: crispEdges;
}
input, label {
display:block;
font-size: 14px;
}
p {
max-width: 850px;
font-size: 16px;
}
button {
font-size: 16px;
padding: 7px;
/* background-color: #C8532E; */
border: 0px;
border-radius: 2px;
cursor: pointer;
/* Initially hidden */
}
button:hover {
background-color: #C8532E;
}
button:active {
background-color: #cb846f;
}
/* .tick {
font-size: 13px;
} */
</style>
<body>
<script>
// Set up the SVG area and margins
var margin = { top: 50, right: 20, bottom: 20, left: 60 };
var width = 400 - margin.left - margin.right;
var height = 350 - margin.top - margin.bottom;
var language = "en"
// append the svg object to the body of the page
d3.json("data/test_json_en.json").then(function (data_raw) {
//#region ############### variables #################
var all_cats = [];
if (language == "de") {
var rhythms_points_mapping_de = {
"täglich": 4,
"wöchentlich": 3,
"monatlich": 2,
"jährlich": 1
}
var rhythms = Object.keys(rhythms_points_mapping_de);
}
else if (language == "en") {
var rhythms_points_mapping_en = {
"daily": 4,
"weekly": 3,
"monthly": 2,
"yearly": 1
}
var rhythms = Object.keys(rhythms_points_mapping_en);
}
const types = ["I_do_it", "I_remember"]
const partner_types = ["partner_does_it", "partner_remembers"]
//#endregion
//#region ############### prep and reshape data #################
var questions_final = []; //reshaped data
var quest_ID = 0;
// target data shape
// {
// "Wäsche waschen + aufhängen": {
// "Text": "Wäsche waschen + aufhängen",
// "ID": "2",
// "domain": "Alle Sorgegemeinschaften, z.B. Paare",
// "category":"Haushalt + Wohnen",
// "rhythm": "täglich",
// "points": "4.00",
// "I_do_it": true,
// "I_remember": false,
// "not_apply": false,
// "partner_does_it": false,
// "partner_remembers": true,
// "I_do_it_and_I_remember": false
// }
// }
let domains = Object.keys(data_raw);
//console.log(domains)
for (let i = 0; i < domains.length; i++) {
let obj_cats = data_raw[domains[i]]
let cats = Object.keys(obj_cats)
//console.log(obj_cats)
//console.log(cats)
for (let catId = 0; catId < cats.length; catId++) {
let obj_rhthm = obj_cats[cats[catId]]
let rhthms = Object.keys(obj_rhthm)
//console.log(obj_rhthm)
//console.log(rhthms)
//something[catId] = []
for (let rhtmID = 0; rhtmID < rhthms.length; rhtmID++) {
let obj_question = obj_rhthm[rhthms[rhtmID]]
let questions = Object.keys(obj_question)
//console.log(obj_question)
//console.log(questions)
for (let quesID = 0; quesID < questions.length; quesID++) {
let obj_ques_level_2 = obj_question[questions[quesID]]
let ques_level_2 = Object.keys(obj_ques_level_2)
let obj_arr_answers = obj_ques_level_2[ques_level_2[0]]
//console.log(obj_ques_level_2)
//console.log(ques_level_2[0])
//add question to final array, and some more infos we know
questions_final[quest_ID[0]] = []
questions_final.push({})
questions_final[quest_ID]["Text"] = ques_level_2[0]
questions_final[quest_ID]["ID"] = questions[quesID]
questions_final[quest_ID]["domain"] = domains[i].replace('... ', '')
questions_final[quest_ID]["category"] = cats[catId]
questions_final[quest_ID]["rhythm"] = rhthms[rhtmID]
if (language == "de") {
questions_final[quest_ID]["points"] = rhythms_points_mapping_de[rhthms[rhtmID]]
}
else if (language == "en") {
questions_final[quest_ID]["points"] = rhythms_points_mapping_en[rhthms[rhtmID]]
}
//either empty array: partner does it, or object with answers
if (Array.isArray(obj_arr_answers)) {
//console.log("partner does it")
questions_final[quest_ID]["I_do_it"] = false;
questions_final[quest_ID]["I_remember"] = false;
questions_final[quest_ID]["partner_does_it"] = true;
questions_final[quest_ID]["partner_remembers"] = true;
questions_final[quest_ID]["not_apply"] = false;
questions_final[quest_ID]["I_do_it_and_I_remember"] = false;
//"I_do_it_and_I_remember": false//partner +=1
//partner_rhm +=1
}
else {
let obj_answers = obj_arr_answers //now an object
let answers = Object.keys(obj_answers)
//console.log(answers)
//console.log(obj_answers)
if (answers.length == 2) { //no need to go into answers, this must be "done" and "I_remembered"
questions_final[quest_ID]["I_do_it"] = true;
questions_final[quest_ID]["I_remember"] = true;
questions_final[quest_ID]["not_apply"] = false;
questions_final[quest_ID]["partner_does_it"] = false;
questions_final[quest_ID]["partner_remembers"] = false;
questions_final[quest_ID]["I_do_it_and_I_remember"] = true;
}
else {
questions_final[quest_ID]["I_do_it_and_I_remember"] = false;
let obj_single_answer = obj_answers[answers[0]] //only answer
//console.log(obj_single_answer)
//console.log(obj_single_answer["answer_type"])
switch (obj_single_answer["answer_type"]) {
case "1": //"I_do_it"
questions_final[quest_ID]["I_do_it"] = true;
questions_final[quest_ID]["I_remember"] = false;
questions_final[quest_ID]["not_apply"] = false;
questions_final[quest_ID]["partner_does_it"] = false;
questions_final[quest_ID]["partner_remembers"] = true;
break;
case "2": //"I_remember"
questions_final[quest_ID]["I_do_it"] = false;
questions_final[quest_ID]["I_remember"] = true;
questions_final[quest_ID]["not_apply"] = false;
questions_final[quest_ID]["partner_does_it"] = true;
questions_final[quest_ID]["partner_remembers"] = false;
break;
case "3": //"not_apply"
questions_final[quest_ID]["I_do_it"] = false;
questions_final[quest_ID]["I_remember"] = false;
questions_final[quest_ID]["not_apply"] = true;
questions_final[quest_ID]["partner_does_it"] = false;
questions_final[quest_ID]["partner_remembers"] = false;
break;
}
}
}
quest_ID += 1;
}
}
}
}
//questions_final.forEach((element) => console.log(element));
//console.table(questions_final)
//console.table(questions_final.filter(function(d) {return d.I_remember == true}))
var valid_questions = questions_final.filter(function (d) { return d.not_apply == false })
//console.table(valid_questions)
let max_num_points = d3.sum(valid_questions, (d) => d.points)
//print some stats of points
let I_remembered_questions = questions_final.filter(function (d) { return d.I_remember == true })
let done_questions = questions_final.filter(function (d) { return d.I_do_it == true })
let not_apply_questions = questions_final.filter(function (d) { return d.not_apply == true })
let partner_does_it_questions = questions_final.filter(function (d) { return d.partner_does_it == true })
let partner_remembers_questions = questions_final.filter(function (d) { return d.partner_remembers == true })
let I_remembered_points = d3.sum(I_remembered_questions, (d) => d.points)
let done_points = d3.sum(done_questions, (d) => d.points)
let partner_done_points = d3.sum(partner_does_it_questions, (d) => d.points)
let partner_remembers_points = d3.sum(partner_remembers_questions, (d) => d.points)
let number_not_apply = d3.count(not_apply_questions, (d) => d.ID)
var questions_answered = d3.count(valid_questions, (d) => d.ID)
// group by daily, monthly etc. for plots and analysis
let grouped_by_rhythm = d3.group(valid_questions, d => d.rhythm)
const uniqueCategories = Array.from(new Set(valid_questions.map(d => d.category)));
const uniqueDomains = Array.from(new Set(valid_questions.map(d => d.domain)));
//console.log(uniqueDomains)
console.log("points done: " + done_points + ", points I_remembered: " + I_remembered_points +
", points done of partner: " + partner_done_points +
", points I_remembered of partner: " + partner_remembers_points +
", number not apply: " + number_not_apply +
", max sum of points reachable, for each category: " + max_num_points +
". Answered questions: " + questions_answered
)
// check validity of data
if (done_points + partner_done_points != I_remembered_points + partner_remembers_points ||
done_points + partner_done_points != max_num_points) {
throw "something is wrong with the dataset"
}
//#endregion
//#region ############ colours ##############
var mntlld_darkblue = "#0F3D5F"
var mntlld_lightblue = "#0A92BA"
var mntlld_green = "#7FB701"
var mntlld_grey = "#F2F2F2"
var mntlld_dark_grey = "#ABABAB"
var mntlld_red = "#C8532E"
var mntlld_lightred = "#cb846f"
var color = d3.scaleOrdinal()
.domain(rhythms)
.range([ //'#0d5f83',
'#0b81a8', '#38a5c5', '#95ccdc',
"#D6E4E9"])
var domainColor = d3.scaleOrdinal()
.domain(uniqueDomains)
.range([mntlld_darkblue, mntlld_green, mntlld_red])
//#endregion
//#region ########## main, structure and layout ##########
console.table(valid_questions)
var [formattedData, type, categories] = aggregate_data(valid_questions, grouping = "rhythm")
var stack = d3.stack()
.keys(categories)
.order(d3.stackOrderNone)
.offset(d3.stackOffsetNone);
var series = stack(formattedData);
// add text
d3.select("body").append("h2").html("Evaluation").style("margin-top", "30px")
d3.select("body").append("div").attr("class", "tooltip")
var tooltip = d3.select(".tooltip");
d3.select("body").append("p").html("Here's your score: You have " + done_points + " of " + max_num_points +
" I-do-it points and " + I_remembered_points + " of " + max_num_points + " I-remember-to-do-it points. " +
"<br> This means you carry " + Math.round(100*(done_points/max_num_points)) + "% of the phyiscal labour and " +
+ Math.round(100*(I_remembered_points/max_num_points)) + "% of the mental labour."
// "<br> <b> Your total score is " + (I_remembered_points + done_points) + "</b>."
)
d3.select("body").append("p").html("Keep in mind that your partner has probably a different view on the division of the tasks. " +
"<b> This is only a reflection of your perspective!</b> " +
"For a better comparison, your partner should also do the test to see where you might disagree on. ")
// build_overview_chart()
build_overview_percentage_chart()
d3.select("body").append("h3").html("How does the scoring work?")
d3.select("body").append("p").html("The tasks listed are weighted according to the frequency with which they need to be performed. " +
"Four points are awarded for tasks to be performed daily or more frequently. For weekly tasks, three points are awarded. " +
"For monthly tasks, two points are awarded. For annual tasks, one point is awarded. " +
"The subdivision into “Do I” and “Remember I” is done in order to map the mental load, i.e. the cognitive care work that takes place in the head, as well." +
"<br> <b> This is explained using your do-it checkmarks that you have set in the test: </b>")
build_explain_weights_chart()
build_stacked_chart(series, type)
d3.select("body").append("h3").html("Task comparisons")
d3.select("body").append("p").html("To better understand your scores and see in which areas you could be more helpful " +
"(or to see, which are your strongsuit), you can compare your points according to their different attributes.")
build_bar_comparison_charts(grouping = "rhythm")
build_categories_diverging()
d3.select("body").append("h3").html("Comparison to partner")
d3.select("body").append("p").html("For this comparison we assume that your partner does all the tasks that you don't do. " +
"And that they remember all the tasks you don't remember. " +
"But we know that in everyday life, this might not be the case. Some tasks might be left behind and be a source of stress." +
"<br> For this visualisation, each task is one circle and can be uniquely assigned to one of the four states: " +
"<br> I do it and I also remember to do it; I do it but my partner reminds me to do it; my partner does it but I remind them to do it; partner both does it and remembers to do it. " +
"<br> <b> Hover over the circles to see which task it is. </b> "
)
d3.select("body").append("p").html("Keep in mind that your partner has probably a different view on the division of the tasks. " +
"<b> This is only a reflection of your perspective!</b> " +
"For a better comparison, your partner should also do the test to see where you might disagree on. ")
build_confusion_matrix()
d3.select("body").append("h3").html("And now?")
d3.select("body").append("p").html(
"<br> If you and your partner find yourself in a traditional role distribution but would ideally want to have a more egalitarian " +
"division of household chores and mental load: You are not alone. " +
"Studies show that couples commonly justify their own household practices with the strive for efficiency ('it's faster when I do it'), " +
"individual characteristics of the partners ('I'm just a bit more chaotic and laid back') and circumstances beyond their control " +
"('my partner's work is just not as flexible so I pick up the children from childcare'). See Daminger (2020). ")
"It is not only your individual result, but also that of political and societal structures and role models that have existed for centuries." +
d3.select("body").append("p").html("So try looking less for culprits but rather look ahead. " +
"<br> Do all of your divisions need to serve efficiency? Maybe there is a division that is not even that efficient (e.g. double checking with your partner " +
"before entering something in the family calender because they are its sole master). " +
"<br> Question the personality traits you assign to yourself and your partner. Maybe the 'chaotic' partner is a project manager in their day job. " +
"Are those traits really innate qualities rather than learned skills? " +
"And acknowledge that many decisions formed today's situation (choice of job, distance to school) and are not set in stone. "
// "<br> But remember: An individual solution that fit your circumstances that both of you are happy with." +
// "<br> and 'How Egalitarian Couples Make Sense of Non-egalitarian Household Practices' by A. Daminger (2020)" +
// "<br> see affordance theory by McClelland & Sliwa (2023)"
)
d3.select("body").append("p").html("A redistribution takes effort for both parties in the relationship!" +
"<br> It might make sense to assign both the mental and physical load of one task to one person. You can find a minimum standard of completion both partners are happy with. " +
"Important: Once assigned, this person has to take on the sole responsibility for that task! They can delegate or ask for help, but they will carry the mental load. " +
"This means that the other person should (in the beginning) not issue reminders or ask about the progress of specific tasks. "
)
d3.select("body").append("h3").html("Redistribution tool")
build_restructuring()
// d3.select("body").append("h3").html("But what about the paid work?")
// build_working_time()
// d3.select("body").append("h2").html("Redistribution of Mental Load")
// d3.select("body").append("h3").html("Social Role Theory")
// d3.select("body").append("p").html("The unequal division of mental load is a product of social, political and economical circumstances. " +
// "The Social Role Theory, developed by Alice Eagly and Wendy Wood tries to explain the unequal division of labour " +
// "as well as the differences in affect and behaviour of men and women." +
// "<br> This infographic applies the theory to mental labour, have fun exploring!"
// )
// d3.select("body").append("img")
// .attr("src", "/images/political_combined.png")
// .attr("alt", "Social Role Theory and the Unequal division of Mental Labour")
// .style("width", "850px")
d3.select("body").append("div").style("height", "50px").attr("class", "spacing")
// build_multiples_chart(grouping = "rhythm")
// build_categories_chart()
//TODO: number of adults sharing responsibility in the household
// build_bar_comparison_charts(grouping = "domain")
//#endregion
//#region ##### build charts functions #####
function build_overview_chart() {
d3.select("body").append("div").attr("class", "overview_chart")
// svg for plotting
var svg = d3.select(".overview_chart")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")")
// X axis
var x = d3.scaleBand()
.range([0, width])
.domain(types)
.padding(0.2);
// Add Y axis
//initial with max number of points for daily tasks
var y = d3.scaleLinear()
.domain([0, 1.1 * max_num_points])
.range([height, 0]);
var yAxis = svg.append("g")
.attr("class", "myYaxis")
.call(d3.axisLeft(y));
//yAxis label
svg.append("text")
.attr("class", "y axislabel")
.attr("text-anchor", "end")
.attr("y", -20)
.attr("dy", ".75em")
//.attr("transform", "translate(-40," + height/2 + "),rotate(-90)")
.text("points");
let rolled_up_I_do_it = d3.rollup(valid_questions, v => d3.sum(v, d => d.points), d => d.I_do_it)
let rolled_up_I_remember = d3.rollup(valid_questions, v => d3.sum(v, d => d.points), d => d.I_remember)
let data_overview = [
{ "type": "I_do_it", "value": rolled_up_I_do_it.get(true) },
{ "type": "I_remember", "value": rolled_up_I_remember.get(true) },
];
//console.log(data_overview)
svg.append("g").attr("class", "bars")
.selectAll("rect")
.data(data_overview)
.enter().append("rect")
//.text(function (d) { console.log(d.type); })
.attr("x", function (d) { return x(d.type); })
.attr("y", function (d) { return y(d.value); })
//.text(function(d) {console.log(d.type);})
.attr("width", x.bandwidth())
.attr("height", function (d) { return height - y(d.value); })
.attr("fill", mntlld_lightblue)
.on("mouseover", function (event, d) {
tooltip.style("visibility", "visible").text(d.value + " Points");
d3.select(this).attr("fill", mntlld_red)
})
.on("mousemove", function (event, d) {
tooltip.style("top", (event.pageY - 10) + "px")
.style("left", (event.pageX + 10) + "px");
})
.on("mouseout", function (event, d) {
d3.select(this).attr("fill", mntlld_lightblue);
tooltip.style("visibility", "hidden");
});
//add 50% line
svg.selectAll(".dashed_line")
.data([max_num_points / 2, max_num_points])
.enter()
.append("line")
.attr("class", "dashed_line")
.attr("x1", 0)
.attr("x2", width)
.attr("y1", d => y(d))
.attr("y2", d => y(d));
//line labels
svg.append("g").attr("class", "line_labels")
.selectAll("label")
.data([
{ "value": max_num_points / 2, "text": "50% of reachable points" },
{ "value": max_num_points, "text": "reachable points: " + max_num_points }
])
.enter()
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", d => y(d.value))
.attr("dy", "-.35em")
.style("text-anchor", "end")
.text(d => d.text)
//add bar labels
svg.append("g").attr("class", "label")
.selectAll("text.sum")
.data([{ "sum": done_points, "type": "I_do_it" }, { "sum": I_remembered_points, "type": "I_remember" }])
.enter()
.append("text")
.attr("class", "sum")
//.text(function(d) {console.log(d)})
.attr("x", (d) => x(d.type) + x.bandwidth() / 2)
.attr("y", (d) => y(d.sum))
.attr("dy", "-1em")
.style("text-anchor", "middle")
.text(d => d.sum);
//x-Axis on top
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
}
function build_overview_percentage_chart() {
d3.select("body").append("div").attr("class", "overview_perc_chart")
// svg for plotting
var svg = d3.select(".overview_perc_chart")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")")
// X axis
var x = d3.scaleBand()
.range([0, width])
.domain(types)
.padding(0.2);
// Add Y axis
//initial with max number of points for daily tasks
var y = d3.scaleLinear()
.domain([0, 100])
.range([height, 0]);
var yAxis = svg.append("g")
.attr("class", "myYaxis")
.call(d3.axisLeft(y)
.tickFormat(d => (Math.abs(d) + "%")))
//yAxis label
svg.append("text")
.attr("class", "y axislabel")
.attr("text-anchor", "middle")
.attr("y", -30)
.attr("dy", ".75em")
// .attr("transform", "translate(-40," + 0 + "),rotate(-90)")
.text("share of points");
let rolled_up_I_do_it = d3.rollup(valid_questions, v => d3.sum(v, d => d.points), d => d.I_do_it)
let rolled_up_I_remember = d3.rollup(valid_questions, v => d3.sum(v, d => d.points), d => d.I_remember)
let data_overview = [
{ "type": "I_do_it", "value": 100 * (rolled_up_I_do_it.get(true) / max_num_points) },
{ "type": "I_remember", "value": 100 * (rolled_up_I_remember.get(true) / max_num_points)},
];
//console.log(data_overview)
svg.append("g").attr("class", "bars")
.selectAll("rect")
.data(data_overview)
.enter().append("rect")
//.text(function (d) { console.log(d.type); })
.attr("x", function (d) { return x(d.type); })
.attr("y", function (d) { return y(d.value); })
// .text(function(d) {return (Math.round(10*d.value)/10) + " %"})
.attr("width", x.bandwidth())
.attr("height", function (d) { return height - y(d.value); })
.attr("fill", mntlld_lightblue)
.on("mouseover", function (event, d) {
tooltip
.style("visibility", "visible")
.text(Math.round(d.value) + "%");
d3.select(this).attr("fill", mntlld_red)
})
.on("mousemove", function (event, d) {
tooltip.style("top", (event.pageY - 10) + "px")
.style("left", (event.pageX + 10) + "px");
})
.on("mouseout", function (event, d) {
d3.select(this).attr("fill", mntlld_lightblue);
tooltip.style("visibility", "hidden");
});
//add 50% line
svg.selectAll(".dashed_line")
.data([50])
.enter()
.append("line")
.attr("class", "dashed_line")
.attr("x1", 0)
.attr("x2", width)
.attr("y1", d => y(d))
.attr("y2", d => y(d));
//line labels
svg.append("g").attr("class", "line_labels")
.selectAll("label")
.data([
{ "value": 50, "text": "50% of reachable points" },
// { "value": 100, "text": "reachable points: " + max_num_points }
])
.enter()
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", d => y(d.value))
.attr("dy", "-.35em")
.style("text-anchor", "end")
.text(d => d.text)
//add bar labels
svg.append("g").attr("class", "label")
.selectAll("text.sum")
.data(data_overview)
// .data([{ "sum": done_points, "type": "I_do_it" }, { "sum": I_remembered_points, "type": "I_remember" }])
.enter()
.append("text")
.attr("class", "sum")
//.text(function(d) {console.log(d)})
.attr("x", (d) => x(d.type) + x.bandwidth() / 2)
.attr("y", (d) => y(d.value))
.attr("dy", "-1em")
.style("text-anchor", "middle")
.text(d => Math.round(d.value) + "%");
//x-Axis on top
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
}
function build_explain_weights_chart() {
d3.select("body").append("div").attr("class", "explain_weights")
var svg3 = d3.select(".explain_weights")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.attr("class", "explain_svg")
.attr("position", "absolute")
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")")
var x_explain = d3.scaleBand()
.range([0, width])
.domain(["I-do-it checkmarks", "I-do-it points"])
.paddingInner(0.5)
.paddingOuter(0.5)
var xAxis_explain = svg3.append("g")
//.attr("transform", "translate(0,)")
.call(d3.axisTop(x_explain))
xAxis_explain.selectAll("path")
.style("stroke", "none");
var y_explain = d3.scaleLinear()
.domain([done_points, 0])
.range([height, 0]);
svg3.append("g")
.attr("transform", "translate(" + (width - 0.8 * x_explain.paddingOuter() * x_explain.step()) + ",0)")
.call(d3.axisRight(y_explain));
//aggregate according to points
var [formattedData, type, categories] = aggregate_data(valid_questions, grouping = "rhythm")
var stack = d3.stack()
.keys(categories)
.order(d3.stackOrderReverse)
.offset(d3.stackOffsetNone);
// aggregate by number of checkmarks
var ticks_by_rhythm = d3.rollup(done_questions, v => v.length, d => d.rhythm)
let formatted_ticks = {};
let done_ticks = 0;
rhythms.forEach(rhythm => {
formatted_ticks[rhythm] = ticks_by_rhythm.get(rhythm) || 0;
done_ticks += ticks_by_rhythm.get(rhythm) || 0
});
//console.log(done_ticks)
//join checkmarks and points
formattedData[1] = formatted_ticks
var series = stack(formattedData) //stack data
series.forEach(item => {
item[0].data["type"] = "I-do-it points"
item[1].data["type"] = "I-do-it checkmarks"
})
// data for lines
var connection_lines = []
series.forEach((item, index) => {
connection_lines[index] = [item[1][1], item[0][1]]
})
var fraction_lines = []
let i = 0;
series.forEach((item, index) => {
switch (item.key) {
case rhythms[3]: //yearly
// fraction_lines[i] = item[0][1]
// i++;
break;
case rhythms[2]: //monthly
// fraction_lines[i] = item[0][1]
fraction_lines[i] = item[0][0] + (item[1][1] - item[1][0])
i += 1;
break;
case rhythms[1]: //weekly
// fraction_lines[i] = item[0][1]
fraction_lines[i] = item[0][0] + (item[1][1] - item[1][0])
fraction_lines[i + 1] = item[0][0] + 2 * (item[1][1] - item[1][0])
i += 2;
break;
case rhythms[0]: //daily
// fraction_lines[i] = item[0][1]
fraction_lines[i] = item[0][0] + (item[1][1] - item[1][0])
fraction_lines[i + 1] = item[0][0] + 2 * (item[1][1] - item[1][0])
fraction_lines[i + 2] = item[0][0] + 3 * (item[1][1] - item[1][0])
i += 3;
break;
default:
break;
}
//fraction_lines[i]=[item[1][1], item[0][1]]
})
//rectangles
svg3.append("g").attr("class", "rectangles")
.selectAll("g")
.data(series)
.enter().append("g")
.attr("class", d => "rects_" + d.key)
.each(function(parentData) {
d3.select(this)
.selectAll("rect")
.data(d => d)
.enter().append("rect")
.attr("fill", d => color(parentData.key))
.attr("x", d => x_explain(d.data.type))
.attr("y", d => y_explain(d[0]))
.attr("height", d => y_explain(d[1]) - y_explain(d[0]))
//.text(function(d) {console.log(parentData)})
.attr("width", x_explain.bandwidth())
.on("mouseover", function (event, d) {
tooltip.style("visibility", "visible").text(
d.data.type == "I-do-it checkmarks" ? (d[1] - d[0]) + " checkmarks" : (d[1] - d[0]) + " points");
d3.select(this)
.attr("fill", mntlld_red)
})
.on("mousemove", function (event, d) {
tooltip.style("top", (event.pageY - 10) + "px")
.style("left", (event.pageX + 10) + "px");
})
.on("mouseout", function (event, d) {
tooltip.style("visibility", "hidden");
d3.select(this)
.attr("fill", color(parentData.key));
})
});
//lines
svg3
.append("g").attr("class", "connection_lines")
.selectAll("line.connection_line")
.data(connection_lines)
.enter()
.append("line")
.attr("class", "connection_line")
//.text(function(d) {console.log(d)})
.style("stroke", "black")
.attr("x1", x_explain.paddingOuter() * x_explain.step() + x_explain.bandwidth())
.attr("x2", x_explain.paddingOuter() * x_explain.step() + x_explain.bandwidth() + x_explain.paddingInner() * x_explain.step())
.attr("y1", (d) => y_explain(d[0]))
.attr("y2", (d) => y_explain(d[1]));
svg3.append("g").attr("class", "fraction_lines")
.selectAll("line.fraction_line")
.data(fraction_lines)
.enter()
.append("line")
.attr("class", "dashed_line")
//.text(function(d) {console.log(d)})
// .style("stroke", "black")
// .style("stroke-dasharray", ("4, 4"))
// .style("stroke-width", 0.5)
// .attr("x1", x_explain.paddingOuter()*x_explain.step() + x_explain.bandwidth() + x_explain.paddingInner()*x_explain.step())
// .attr("x2", x_explain.paddingOuter()*x_explain.step() + 2*x_explain.bandwidth() + x_explain.paddingInner()*x_explain.step())
.attr("x1", x_explain.paddingOuter() * x_explain.step() + x_explain.bandwidth() + x_explain.bandwidth())
.attr("x2", x_explain.paddingOuter() * x_explain.step() + 2 * x_explain.bandwidth() + x_explain.paddingInner() * x_explain.step())
.attr("y1", (d) => y_explain(d))
.attr("y2", (d) => y_explain(d));
svg3.append("g").attr("class", "annotation")
.selectAll("text.multiplier")
.data(series)
.enter()
.append("text")
.attr("class", "multiplier")
.attr("x", width / 2)
.attr("y", (d) => y_explain(((d[1][0] + (d[1][1] - d[1][0]) / 2) + (d[0][0] + (d[0][1] - d[0][0]) / 2)) / 2))
.attr("dy", ".35em")
.style("text-anchor", "middle")
.html(d => "×" + (d.index + 1));
svg3.append("g").attr("class", "label")
.selectAll("text.legend")
.data(series)
.enter()
.append("text")
.attr("class", "legend")
//.text(function(d) {console.log(d)})
.attr("x", x_explain.paddingOuter() * x_explain.step())
.attr("y", (d) => y_explain(d[1][0] + (d[1][1] - d[1][0]) / 2))
.attr("dx", "-.35em")
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(d => d.key);
svg3.append("g").attr("class", "label")
.selectAll("text.sum")
.data([{ "sum": done_points, "type": "I-do-it points" }, { "sum": done_ticks, "type": "I-do-it checkmarks" }])
.enter()
.append("text")
.attr("class", "sum")
//.text(function(d) {console.log(d)})
.attr("x", (d) => x_explain(d.type) + x_explain.bandwidth() / 2)
.attr("y", (d) => y_explain(d.sum))
.attr("dy", "1.2em")
.style("text-anchor", "middle")
.text(d => d.sum);
}
function build_confusion_matrix() {
d3.select("body").append("div").attr("class", "confusion_matrix")
var conf_margin = { top: 30, right: 400, bottom: 20, left: 20 };
var conf_width = 1200 - conf_margin.left - conf_margin.right;
var conf_height = 400 - conf_margin.top - conf_margin.bottom;
const innerWidth = conf_width - conf_margin.left - conf_margin.right;
const innerHeight = conf_height - conf_margin.top - conf_margin.bottom;
const x_confusion = d3.scaleBand()
.domain(['I_remember', 'partner_remembers'])
.range([0, innerWidth]);
const y_confusion = d3.scaleBand()
.domain(['I_do_it', 'partner_does_it'])
.range([0, innerHeight]);
const svg_confusion = d3.select(".confusion_matrix")
.append("svg")
.attr("width", conf_width)
.attr("height", conf_height)
.append("g")
.attr("transform", `translate(${conf_margin.left},${conf_margin.top})`);
// Add column labels
svg_confusion.selectAll(".column-label")
.data(x_confusion.domain())
.enter().append("text")
.attr("class", "column-label")
.attr("x", d => x_confusion(d) + x_confusion.bandwidth() / 2)
.attr("y", -10) // Position above the grid
.attr("text-anchor", "middle")
.text(d => d);
// Add row labels
svg_confusion.selectAll(".row-label")
.data(y_confusion.domain())
.enter().append("text")
.attr("class", "row-label")
.attr('transform', d => 'translate(' + -10 + ',' + (y_confusion(d) + y_confusion.bandwidth() / 2) + '),' + 'rotate(-90)')
//.text(function(d) {console.log(y_confusion.bandwidth() / 2)})
.attr("text-anchor", "middle")
.attr("dy", "0.35em") // Vertical alignment
.text(d => d);
// calculate radius based on points
const radiusScale = d3.scaleSqrt()
.domain([0, d3.max(valid_questions, d => d.points)])
.range([0, 10]);
// Map data to cell positions
const mappedData = valid_questions.map(d => ({
...d,
x: x_confusion(d.I_remember ? "I_remember" : "partner_remembers") + x_confusion.bandwidth() / 2,
y: y_confusion(d.I_do_it ? "I_do_it" : "partner_does_it") + y_confusion.bandwidth() / 2,
r: radiusScale(d.points)
}));
// Create simulation
const simulation = d3.forceSimulation(mappedData)
.force("x", d3.forceX(d => d.x).strength(1))
.force("y", d3.forceY(d => d.y).strength(1))
.force("collide", d3.forceCollide(d => d.r))
.stop();
for (let i = 0; i < 500; ++i) simulation.tick(); // Run the simulation
// Draw points
svg_confusion.append("g").selectAll(".point")
.data(mappedData)
.enter().append("circle")
.attr("class", "point")
.attr("cx", d => d.x)