-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrollFunctions.js
162 lines (130 loc) · 3.78 KB
/
scrollFunctions.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
import {
drawAxes,
drawSecondaryAxes,
drawBar,
removeBar,
stackedBarChart,
fadeBarsOut,
fadeBarsIn,
drawAllBars,
cleanupZeroBars,
fillMissingBars,
middleBarsDown,
middleBarsDownFinalState,
forceChart,
middleBarsDownReverse,
forceChartReverse,
} from "./graphFunctions.js";
import { totalMdVolume } from "./data/dataPrep.js";
import textStory from "./textStory.js";
import cra from "./data/craData.js";
import { changeEventsDownard } from "./stepFunctionsDownard.js";
import { changeEventsUpward } from "./stepFunctionsUpward.js";
let activateFunctions = [];
// activateFunctions[0] = drawBar();
// activateFunctions = [drawAxes, drawBar];
const scroller = scrollama();
let main = d3.select("main");
var scrolly = main.select("#scrolly");
var article = scrolly.select("article");
var step = article.selectAll(".step");
const allStepTriggers = [
"intro",
"year2006",
"year2008",
"year2009",
"year2010",
"year2011",
"year2012",
"year2013",
"year2014",
"year2015",
"year2016",
"year2017",
"year2018",
"year2019",
"year2020",
"classBreakdown",
"firstAndLast",
"productLevel",
];
// function currentStepVLastCalled(){
function eventDifferenceSnip(currentStepId, lastCalledEvent) {
let snipOutput;
const currentStepIndex = allStepTriggers.indexOf(currentStepId);
const lastCalledIndex = allStepTriggers.indexOf(lastCalledEvent);
console.log(currentStepId, lastCalledEvent);
// console.log(currentStepIndex, lastCalledIndex);
if (lastCalledIndex > currentStepIndex) {
snipOutput = allStepTriggers.slice(currentStepIndex, lastCalledIndex);
console.log(snipOutput);
}
if (lastCalledEvent < currentStepIndex) {
snipOutput = allStepTriggers.slice(lastCalledIndex, currentStepIndex);
snipOutput.reverse();
console.log(snipOutput);
}
}
scroller
.setup({
step: "#scrolly article .step",
offset: 0.55,
// debug: true,
})
.onStepEnter(handleStepEnter);
// d3 stack data
function handleStepEnter(resp) {
let lastCalledEvent = "bob";
const scrollPoz = window.scrollY;
let scrollDirection = resp.direction;
const currentStepId = resp.element.id;
const currentStepClass = resp.element.className;
const isYearElement = currentStepClass.includes("year");
let currentYear;
let dataToyear;
if (isYearElement) {
currentYear = parseInt(currentStepId.match(/\d+/g));
dataToyear = totalMdVolume.filter((row) => row.date <= currentYear);
}
if (scrollDirection === "down") {
if (currentStepId === "intro") {
changeEventsDownard.intro(totalMdVolume);
}
if (isYearElement) {
changeEventsDownard[currentStepId](totalMdVolume, currentYear);
// clearTimeout(t);
// t = setTimeout(() => {
// recordStep(lastCalledEvent, currentStepId);
// }, 1000);
// console.log(lastCalledEvent, currentStepId);
}
if (
["classBreakdown", "firstAndLast", "productLevel"].includes(currentStepId)
) {
changeEventsDownard[currentStepId]();
}
// if (currentStepId === "classBreakdown")
// // console.log("triggered atscroll functions ");
// // changeEventsDownard[`${classBreakdown}`]();
// changeEventsDownard[`classBreakdown`]();
}
if (scrollDirection === "up") {
if (currentStepId === "intro") {
changeEventsUpward.intro(totalMdVolume);
}
if (isYearElement) {
changeEventsUpward[currentStepId](totalMdVolume, currentYear);
}
if (
["classBreakdown", "firstAndLast", "productLevel"].includes(currentStepId)
) {
changeEventsUpward[currentStepId]();
}
}
const renderedText = document.querySelector("#renderedText");
renderedText.className = "fadeOut";
setTimeout(() => {
renderedText.className = "fadeIn";
renderedText.innerHTML = textStory[currentStepId];
}, 500);
}