forked from drahoslove/pianco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.html
812 lines (742 loc) · 22.9 KB
/
stats.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
<!DOCTYPE html>
<meta charset="utf-8">
<title>Pianoteq Stats</title>
<link rel="stylesheet" href="lib/dc.css" />
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>📊</text></svg>">
<style>
html, body {
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
font-family: Arial, sans-serif;
}
body {
width: 1500px;
}
*[hidden] {
display: none !important;
}
svg {
overflow: visible;
margin: 0 auto;
}
#charts, .chart, .loader {
display: flex;
flex-direction: column;
justify-items: center;
}
.loader {
font-family: 'Courier New', Courier, monospace;
font-size: 150%;
}
.row {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-bottom: 2em;
}
.dc-chart g.row rect {
fill-opacity: 1;
}
.totals {
background: #1f77b41d;
padding: 0 1em;
}
.totals p {
display: flex;
justify-content: space-between;
gap: 0.5em;
}
.filters {
width: 450px;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr 1fr 1fr;
gap: 0.25em;
}
.filters label {
background-color: #1f77b40d;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}
.filters label:last-child {
grid-column: span 3;
}
.filters label:hover {
background-color: #1f77b41d;
}
.filters input:checked + label {
background-color: #1f77b42d;
}
.filters input {
visibility: hidden;
position: absolute;
pointer-events: none;
}
#all-keys {
width: 1500px;
display: flex;
flex-direction: row;
align-items: flex-end;
margin: 2em 0;
background-color: #eee;
}
.key {
display: bloc;
width: calc(1500px / 88);
height: 40px;
position: relative;
}
.key::before,
.key::after {
font-size: 18px;
opacity: 0;
transition: 0.2s all ease;
pointer-events: none;
white-space: nowrap;
position: absolute;
top: 40px;
}
.key::before {
content: attr(data-key-name) ' ⬏';
right: calc(1500px / 88 / 2);
}
.key::after {
content: '⬑' attr(data-key-count);
left: calc(1500px / 88 / 2);
}
.key:hover::after,
.key:hover::before {
opacity: 1;
}
.key .sub {
display: block;
height: 25px;
}
.key .bar {
display: flex;
width: 100%;
height: calc(var(--height) * 1.5);
background-color: #1f77b4dd;
/* border-bottom: 1px solid transparent; */
transition: 0.15s all linear;
transform-origin: top;
position: absolute;
bottom: 40px;
}
.key:hover .bar {
filter: brightness(0.25);
}
#all-keys:hover .key .bar {
/* border-bottom: 1px solid red; */
/* scale: 1 5; */
}
/* black keys */
.key:nth-child(12n+2) .sub,
.key:nth-child(12n+5) .sub,
.key:nth-child(12n+7) .sub,
.key:nth-child(12n+10) .sub,
.key:nth-child(12n+12) .sub {
background-color: #555a;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
/* white keys */
/*
.key:nth-child(12n+1) .sub,
.key:nth-child(12n+3) .sub,
.key:nth-child(12n+4) .sub,
.key:nth-child(12n+6) .sub,
.key:nth-child(12n+8) .sub,
.key:nth-child(12n+9) .sub,
.key:nth-child(12n+11) .sub{
background-color: #ccca;
} */
:is(#month-chart, #week-chart) svg .x.axis .tick text {
transform: translateY(5px) rotate(-20deg);
}
</style>
<div id="charts" hidden="true">
<div calss="row">
<div id="all-keys" class=""></div>
</div>
<div class="row">
<div class="totals">
<p>
total: <b> <span id="total-duration">0 ?</span></b>
</p>
<p>
daily avg: <b> <span id="avg-daily">0 ?</span></b>
</p>
<p>
notes: <b> <span id="total-notes">0 ?</span></b>
</p>
<p>
<span id="max-note-name"></span> <b> <span id="max-note-count">0 ?</span></b>
</p>
<p>
<span id="min-note-name"></span> <b> <span id="min-note-count">0 ?</span></b>
</p>
<p>
midi files: <b> <span id="total-count">0 ?</span></b>
</p>
</div>
<div class="filters" id="filters">
<input type="radio" name="filter" id="this_day" value="this_day">
<label for="this_day">today</label>
<input type="radio" name="filter" id="prev_day" value="prev_day">
<label for="prev_day">yesterday</label>
<input type="radio" name="filter" id="last_day" value="last_day">
<label for="last_day">last 24 h</label>
<input type="radio" name="filter" id="this_week" value="this_week">
<label for="this_week">this week</label>
<input type="radio" name="filter" id="prev_week" value="prev_week">
<label for="prev_week">previous week</label>
<input type="radio" name="filter" id="last_week" value="last_week">
<label for="last_week">last 7 days</label>
<input type="radio" name="filter" id="this_month" value="this_month">
<label for="this_month">this month</label>
<input type="radio" name="filter" id="prev_month" value="prev_month">
<label for="prev_month">previous month</label>
<input type="radio" name="filter" id="last_month" value="last_month">
<label for="last_month">last 30 days</label>
<input type="radio" name="filter" id="this_year" value="this_year">
<label for="this_year"> this year</label>
<input type="radio" name="filter" id="prev_year" value="prev_year">
<label for="prev_year">previous year</label>
<input type="radio" name="filter" id="last_year" value="last_year">
<label for="last_year">last 365 days</label>
<input type="radio" name="filter" id="all" value="all" checked>
<label for="all"> all time</label>
</div>
<div id="activity-pie" class="chart">
<div class="title">Days spent playing</div>
</div>
</div>
<div class="row">
<div id="hour-chart" class="chart">
<div class="title">Time of Day (avg)</div>
</div>
<div id="weekday-chart" class="chart">
<div class="title">Day of week (avg)</div>
</div>
<div id="delay-chart" class="chart">
<div class="title">Notes per second</div>
</div>
</div>
<div class="row">
<div id="day-chart" class="chart">
<div class="title">Days</div>
</div>
</div>
<div class="row">
<div id="week-chart" class="chart">
<div class="title">Weeks</div>
</div>
<div id="month-chart" class="chart">
<div class="title">Months</div>
</div>
</div>
</div>
<div class="loader">Loading...</div>
<script src="lib/luxon.min.js"></script>
<script src="lib/crossfilter.v1.min.js"></script>
<script src="lib/d3.v6.min.js"></script>
<script src="lib/dc.js"></script>
<script>
const { DateTime } = luxon
const zeroedList = (n) => Array.from({ length: n }).map(() => 0)
// key index (0..87) to note name (A0 to C8)
const keyToNote = (n) => {
return [
["A"],
["A♯", "B♭"],
["B"],
["C"],
["C♯", "D♭"],
["D"],
["D♯", "E♭"],
["E"],
["F"],
["F♯", "G♭"],
["G"],
["G♯", "A♭"],
][n%12][0] + ((n-(n%12))/12 + (n%12 >= 3 ? 1 : 0))
}
;[
[0, 'A0'],
[2, 'B0'],
[3, 'C1'],
[87, 'C8'],
].forEach(([n, name]) => {
const res = keyToNote(n)
console.assert(res === name, n, name, res)
})
window.onload = async () => {
const response = await fetch('https://local.pian.co/archive.json')
const rawData = await response.json()
const data = rawData.map(({ t: timestamp, d: duration, n: notes, k: keys }) => ({
date: new Date(timestamp*1000),
duration: new Date((duration+0.5)*1000), // add half second to compensate for rounding
notes,
keys,
tempo: notes/(duration+0.5),
}))
const numberFormat = (n) => Intl.NumberFormat('cs').format(n)
const dayString = (date) => date.toLocaleDateString() // .toISOString().substr(0,10) // any uniq string for each day
const hourString = (date) => date.toISOString().substr(0,13) // any unique string for each hour
// fill missing days with empty data
// {
// const includedDays = {}
// data.forEach(({ date }) => {
// includedDays[dayString(date)] = true
// })
const startDate = new Date(+data[0].date)
const endDate = new Date(+data[data.length-1].date)
for (let d = new Date(startDate); d <= endDate; d.setHours(d.getHours () + 1)) {
data.push({ // insert empty data
date: new Date(+d), // must clone the date - it is modified in the loop
duration: new Date(0),
notes: 0,
tempo: 0,
keys: zeroedList(88)
})
}
data.sort(({ date: a }, { date: b }) => +a - +b) // older first, newest last
// }
const selectAll = () => {
selectInterval(data)
}
;[...document.querySelectorAll('#filters input')].forEach(input => {
input.onchange = ({ target }) => {
if (target.checked) {
const [which, duration] = target.value.split('_')
document.getElementById('day-chart').hidden = ['day'].includes(duration)
document.getElementById('week-chart').hidden = ['day', 'week'].includes(duration)
document.getElementById('month-chart').hidden = ['day', 'week', 'month'].includes(duration)
if (target.value === 'all') {
return selectAll()
}
let [start, end] = [startDate, endDate]
if (which === 'this' || which === 'prev') {
const dateTime = DateTime.now().plus({
[`${duration}s`]: which === 'prev' ? -1 : 0
})
start = dateTime.startOf(duration).toJSDate()
end = dateTime.endOf(duration).toJSDate()
}
if (which === 'last') {
const dateTime = DateTime.now()
start = dateTime.plus({
days: -({ day: 1, week: 7, month: 30, year: 365 }[duration]),
}).endOf(duration === 'day' ? 'hour' : 'day').toJSDate()
end = dateTime.endOf(duration === 'day' ? 'hour' : 'day').toJSDate()
}
const filteredDate = data.filter(({ date }) => (
+date >= +start &&
+date <= +end
))
filteredDate.push({
date: new Date(+end),
duration: new Date(0),
notes: 0,
tempo: 0,
keys: zeroedList(88),
})
return selectInterval(filteredDate, duration)
}
}
})
let cleanup = () => {}
selectAll()
document.querySelector('#charts').hidden=false
document.querySelector('.loader').hidden=true
async function selectInterval(data, duration) {
cleanup()
const startDate = new Date(+data[0].date)
const endDate = new Date(+data[data.length-1].date)
const histDomain = [startDate, endDate]
const totalNotes = data.reduce((sum, { notes }) => sum + notes, 0)
const totalDuration = data.reduce((sum, { duration }) => sum + +duration/1000)
const roundTo = (n=1) => (x) => Math.floor(x / n) * n
const avgReducers = (batchDefiner) => [
(p, v) => {
const batchKey = batchDefiner(v)
if (!p.batchCounted[batchKey]) {
++p.count
p.batchCounted[batchKey] = 0
}
p.batchCounted[batchKey]++
p.durationSumMs += +v.duration
p.avgDuration = new Date(p.count ? Math.round(p.durationSumMs / p.count) : 0)
return p
},
(p, v) => {
const batchKey = batchDefiner(v)
p.batchCounted[batchKey]--
if (!p.batchCounted[batchKey]) {
--p.count
}
p.durationSumMs -= +v.duration
p.avgDuration = new Date(p.count ? Math.round(p.durationSumMs / p.count) : 0)
return p
},
() => ({ durationSumMs: 0, count: 0, avgDuration: new Date(0), batchCounted: {} })
]
const archive = crossfilter(data)
const allCount = archive.groupAll().reduceSum((d) => d.notes ? 1 : 0) // midi files with notes
const allNotes = archive.groupAll().reduceSum(d => d.notes)
const allDuration = archive.groupAll().reduceSum(d => +d.duration)
const allDays = archive.groupAll().reduce(...avgReducers(d => dayString(d.date)))
/// 3 main time histgrams
const dateDim1 = archive.dimension(d => d.date)
const dateDim2 = archive.dimension(d => d.date)
const dateDim3 = archive.dimension(d => d.date)
const days = dateDim1.group(d3.timeDay).reduceSum(d => d.duration)
const weeks = dateDim2.group(d3.timeWeek).reduceSum(d => d.duration)
const months = dateDim3.group(d3.timeMonth).reduceSum(d => d.duration)
const activeDay = archive.dimension(d => d.notes ? true : false)
const activeDays = activeDay.group().reduce(...avgReducers(d => dayString(d.date)))
// by day hour
const dayHour = archive.dimension(d => roundTo(1)(d.date.getHours() + d.date.getMinutes()/60))
const dayHours = dayHour.group().reduce(...avgReducers(d => hourString(d.date))) // count all dates in same hour only as one
// by week day
const weekDay = archive.dimension(d => d.date.getDay())
const weekDays = weekDay.group().reduce(...avgReducers(d => dayString(d.date))) // count all dates in same day only as one
const tempo = archive.dimension(d => d.tempo)
const tempos = tempo.group(roundTo(1/2)).reduceSum(d => d.duration)
const durationScale = d3.scaleTime()
// .domain([0, 60*60*1000])
.domain([new Date(0), new Date(60 * 60 *1000)])
.range([0, 100])
const durationFormat = (ms) => {
const t = typeof ms === 'number' ? new Date(ms) : ms
const d = +t.toISOString().substr(8,2)-1
const h = +t.toISOString().substr(11,2)
const m = +t.toISOString().substr(14,2)
const s = +t.toISOString().substr(17,2)
return d !== 0
? `${+d}d ${+h}h`
: h !== 0
? `${+h}h ${+m}m`
: `${+m}m ${+s}s`
}
// keys
const allKeys = archive.groupAll().reduce(
(p, v) => { // add
(v.keys||[]).forEach((val, i) => {
p[i] += val
})
return p
},
(p, v) => { // remove
(v.keys||[]).forEach((val, i) => {
p[i] -= val
})
return p
},
() => { // init
return zeroedList(88)
}
)
// const keysDimension = archive.dimension(d => true)
// const keysGroup = keysDimension.group()
const chartDefs = [
// chart => {
// chart
// .width(1000)
// .height(100)
// .dimension(keysDimension)
// .group(keysGroup)
// .x(d3.scaleLinear()
// .domain([1, 88])
// .range([0, 87])
// )
// chart
// .valueAccessor((d, ...x) => {
// console.log('ddd', d, x)
// return d.keys
// } )
// return chart
// },
chart => {
chart
.width(500)
.dimension(activeDay)
.group(activeDays)
.ordering(d => +d.key)
.label(d => (d.key ? 'Days Played' : 'Days Counted'))
.title((d) => {
const [all, played] = activeDays.all()
const percentage = d.key === false
? 100
: Math.round(100 * played.value.count / all.value.count)
return `${percentage} % (${d.value.count})`
})
.valueAccessor(d => d.value.count)
.elasticX(true)
chart.ordinalColors(['#d7e7f2', '#1f77b4'])
chart.xAxis().ticks(8)
return chart
},
chart => { // hour of day avg
chart
.width(500)
.height(200)
.gap(2)
.dimension(dayHour)
.group(dayHours)
.round(roundTo(1))
.x(d3.scaleLinear()
.domain([0, 24])
.range([0, 24])
)
chart
// .valueAccessor(d => +d.value.durationSumMs)
.valueAccessor(d => + d.value.avgDuration)
.elasticY(true)
.y(durationScale)
chart
chart.xAxis().ticks(24)
chart.yAxis().ticks(5)
chart.yAxis().tickFormat(durationFormat)
return chart
},
chart => { // day of week avg
chart
.width(500)
.height(200)
.gap(2)
.dimension(weekDay)
.group(weekDays)
.ordering(d => (d.key+6)%7)
.label(d => ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][(d.key+6)%7])
.title(d => `${durationFormat(d.value.avgDuration)} spend on average\n${durationFormat(d.value.durationSumMs)} in total`)
chart
.ordinalColors(['rgb(31, 119, 180)'])
chart
.valueAccessor(d => +d.value.avgDuration)
.elasticX(true)
.x(durationScale)
chart.xAxis().ticks(8)
chart.xAxis().tickFormat(durationFormat)
// chart.xAxis().label('Avg time spent')
return chart
},
chart => { // tempo
chart
.width(500)
.height(200)
.gap(2)
.dimension(tempo)
.group(tempos)
.round(roundTo(1/2))
.xUnits(() => 2 * 12)
.x(d3.scaleLinear()
.domain([0, 12])
.range([0, 12])
)
chart
.elasticY(true)
.y(durationScale)
chart.xAxis().ticks(16)
chart.yAxis().ticks(5)
chart.yAxis().tickFormat(durationFormat)
return chart
},
// histograms
chart => {
chart
.width(1500)
.gap(2)
.dimension(dateDim1)
.group(days)
.round(d3.timeDay.floor)
.xUnits(d3.timeDays)
.x(d3.scaleTime()
.domain(histDomain)
.range([0, 100])
.nice(d3.timeMonth.every(1))
)
chart
.elasticY(true)
.y(durationScale)
// chart.yAxis().scale(durationScale)
chart.yAxis().tickFormat(durationFormat)
return chart
},
chart => {
chart
.width(930)
.height(200)
.gap(2)
.dimension(dateDim2)
.group(weeks)
.round(d3.timeWeek.floor)
.xUnits(d3.timeWeeks)
.x(d3.scaleTime()
.domain(histDomain)
.range([0, 100])
.nice(d3.timeMonth.every(1))
)
chart
.elasticY(true)
.y(durationScale)
// chart.yAxis().scale(durationScale)
chart.yAxis().tickFormat(durationFormat)
return chart
},
chart => {
chart
.width(570)
.height(200)
// .gap(2)
.dimension(dateDim3)
.group(months)
.round(d3.timeMonth.floor)
.xUnits(d3.timeMonths)
.x(d3.scaleTime()
.domain(histDomain)
.range([0, 6])
.nice(d3.timeMonth.every(1))
)
chart
.elasticY(true)
.y(durationScale)
// chart.xAxis().tickFormat((v,x, y) => { console.log(v, x, y); return v})
// chart.yAxis().scale(durationScale)
chart.yAxis().tickFormat(durationFormat)
chart.title(d => `${durationFormat(d.value)} played`)
return chart
},
]
const charts = Array.from(document.querySelectorAll('.chart'))
.filter((div) => ({
'day-chart': !['day'].includes(duration),
'week-chart': !['day', 'week'].includes(duration),
'month-chart': !['day', 'week', 'month'].includes(duration),
}[div.id] || true))
.map((div, i) => new dc[{
'weekday-chart' : 'RowChart',
'activity-pie' : 'RowChart',
}[div.id] || 'BarChart'](div, 'chartgroup'))
.map((chart, i) => chartDefs[i](chart))
.map(chart => (chart.render(), chart))
// Whenever the brush moves, re-rendering everything.
function renderAll(noadjust) {
const sumNotes = data.reduce((sum, { notes }) => (sum + notes), 0)
const sumDuration = data.reduce((sum, { duration }) => (sum + +duration), 0)
const sumCount = data.filter(({ notes }) => notes > 0).length
d3.select("#total-notes").text(
numberFormat(allNotes.value()) ||
`${numberFormat(allNotes.value())} / ${numberFormat(sumNotes)}`
)
d3.select("#total-duration").text(
durationFormat(allDuration.value()) ||
`${durationFormat(allDuration.value())} / ${durationFormat(sumDuration)}`
)
d3.select("#total-count").text(
numberFormat(allCount.value()) ||
`${numberFormat(allCount.value())} / ${numberFormat(sumCount)}`
)
d3.select("#avg-daily").text(
durationFormat(allDays.value().avgDuration)// + ' ' + allDays.value().count
)
const notes = allNotes.value()
const keys = allKeys.value()
const maxKey = Math.max(...keys)
const minKey = Math.min(...keys)
const keySel = d3.select('#all-keys')
.selectAll('.key')
.data(keys)
.join('span')
.attr('class', 'key')
// .attr('title', d => numberFormat(d))
.attr('data-key-name', (d, i) => keyToNote(i))
.attr('data-key-count', d => numberFormat(d))
keySel.selectAll('.sub')
.data(d => [d])
.join('span')
.attr('class', 'sub')
keySel.selectAll('.bar')
.data(d => [d])
.join('span')
.attr('class', 'bar')
.style('--height', d => `${(d / maxKey)*100}%`)
const maxKeyName = keyToNote(keys.indexOf(maxKey))
const minKeyName = keyToNote(87-[...keys].reverse().indexOf(minKey))
d3.select('#min-note-count').text(numberFormat(minKey))
d3.select('#max-note-count').text(numberFormat(maxKey))
d3.select('#min-note-name').text(
minKeyName + (
keys.filter(v => v == minKey).length > 1
? '+'
: ''
)
)
d3.select('#max-note-name').text(
maxKeyName + (
keys.filter(v => v == maxKey).length > 1
? '+'
: ''
)
)
if (!noadjust) {
return
}
// adjust widths of months columns
d3.selectAll('#month-chart .chart-body .bar')
.transition()
.duration(500)
.attr('width', function (_, i, list) {
const gap = 2
const rect = d3.select(this)
const nextRect = list[i+1]
const currentWidth = rect.attr('width')
if (nextRect) {
const width = nextRect.getAttribute('x') - rect.attr('x') - gap
return width < 1.2 * currentWidth // ignore if bar is missing
? width
: currentWidth
}
return currentWidth
})
}
charts.forEach((chart) => {
chart.on('renderlet', renderAll)
})
renderAll() // render immideately
let broadcasting = false // don't repropogate (infinite loop)
charts.slice(-3).forEach((chart, i, charts) => {
chart.on('filtered', (chart, filter) => {
if (broadcasting) {
return
}
broadcasting = true
charts.filter(ch => ch !== chart).forEach(chart => {
chart.replaceFilter(filter)
})
broadcasting = false
})
})
cleanup = () => {
charts.forEach(chart => { // clear the old charts
chart.resetSvg()
})
d3.selectAll("svg").remove()
dateDim1.dispose()
dateDim2.dispose()
dateDim3.dispose()
activeDay.dispose()
dayHour.dispose()
weekDay.dispose()
tempo.dispose()
allKeys.dispose()
}
}
}
</script>