File size: 3,972 Bytes
30e9731
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
window.makeGS = function(){
  var prevSlideIndex = -1
  function updateSlide(i){
    var slide = slides[i]
    if (!slide) return

    d3.select('.tooltip').classed('tooltip-hidden', true)

    var dur = 500

    sel.student.transition('xKey').duration(dur).delay(dur ? slide.circleDelayFn : 0)
      .translate(d => (d.isAdditionalStudent && slide.xKey != 'plagerizedShifted') ? [0,0]: d.pos[slide.xKey])

      
    if (sel.rectAt[slide.xKey]){
      sel.uniqueBox.transition('at').duration(dur)
        .delay(d => dur ? slide.circleDelayFn(d.d0) : 0)
        .at(sel.rectAt[slide.xKey])
        .translate(d => d.d0.group[slide.xKey].pos)
    }

    sel.uniqueBox.transition().duration(dur)
      .st({opacity: slide.showUniqueBox ? 1 : 0})
    
    sel.uniqueSeasonBox.transition()
      .delay((d, i) => slide.showUniqueSeasonBox ? dur*2 + i*40 : 0).duration(slide.showUniqueSeasonBox ? 0 : dur)
      .st({opacity: slide.showUniqueSeasonBox ? 1 : 0})


    if (sliders.headsProb != slide.headsProbTarget && slide.animateHeadsProbSlider != -1){
      var headI = d3.interpolate(sliders.headsProb, slide.headsProbTarget)
      if (window.headSliderTimer) window.headSliderTimer.stop()
      window.headSliderTimer = d3.timer(ms => {
        var dur = slide.animateHeadsProbSlider ? 2000 : 1
        var t = d3.easeCubicInOut(d3.clamp(0, ms/dur, 1))
        sliders.updateHeadsProb(headI(t))
        if (t == 1) headSliderTimer.stop()
      })
    }

    if (sliders.population != slide.populationTarget){
      var popI = d3.interpolate(sliders.population, slide.populationTarget)
      if (window.popSliderTimer) window.popSliderTimer.stop()
      window.popSliderTimer = d3.timer(ms => {
        var dur = slide.animatePopulationSlider ? 2000 : 1
        var t = d3.easeCubicInOut(d3.clamp(0, ms/dur, 1))
        sliders.updatePopulation(Math.round(popI(t)/2)*2)
        if (t == 1) popSliderTimer.stop()
      })
    }

    axii.stateAxis.transition().duration(dur/2)
      .st({opacity: slide.showStateAxis ? 1 : 0})
    axii.ageAxis.transition().duration(dur/2)
      .st({opacity: slide.showAgeAxis ? 1 : 0})
    axii.seasonAxis.transition().duration(dur/2)
      .st({opacity: slide.showSeasonAxis ? 1 : 0})
    axii.headAxis.transition().duration(dur/2)
      .st({opacity: slide.showHeadAxis ? 1 : 0})
    axii.headCaptionAxis.transition().duration(dur/2)
      .st({opacity: slide.showHeadCaptionAxis ? 1 : 0})
    estimates.axisSel.transition().delay(dur).duration(dur/2)
      .st({opacity: slide.showHistogramAxis ? 1 : 0})
    estimates.activeSel.transition().delay(dur).duration(dur/2)
      .st({opacity: slide.showHistogramAxis ? 1 : 0})
    // axii.estimateAxis.transition().delay(dur).duration(dur/2)
    //   .st({opacity: slide.showEstimate && !slide.enterHistogram ? 1 : 0})
    // axii.plagerizedAxis.transition().delay(dur).duration(dur/2)
    //   .st({opacity: slide.showPlagerizedAxis ? 1 : 0})


    annotationSel.transition().duration(dur/2)
      .st({opacity: d => i == d.slide ? 1 : 0})

    estimates.containerSel.transition('xKey').duration(dur/2)
      .st({opacity: slide.showHistogram ? 1 : 0})
    
    if (slide.enterHistogram){
      estimates.render(true)
    } else {
      window.flipAllCoinsTimer._time = Infinity
    }
    if (slide.enterHistogram === 0) estimates.estimateSel.classed('active', 1)


    // Display the default coin flip state if the histogram is not visible.
    sel.flipCircle.transition().duration(dur)
      .at({transform: d => {
        return slide.showFlipCircle && d.coinVals[estimates.active.index] < sliders.headsProb ? 'scale(1)' : 'scale(.1)'}})
    
    prevSlideIndex = i
    slides.curSlide = slide
  }

  var gs = d3.graphScroll()
    .container(d3.select('.container-1'))
    .graph(d3.selectAll('container-1 #graph'))
    .eventId('uniqueId1')
    .sections(d3.selectAll('.container-1 #sections > div'))
    .offset(300)
    .on('active', updateSlide)
}


if (window.init) window.init()