Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stack.v1.js and index.html updated to use d3.v4.min.js #25

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions d3.v4.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
<p><a style="color:#777;text-decoration:none;" href="https://github.com/mbostock/stack">View source to get started.</a>
</section>

<script src="d3.v3.min.js"></script>
<script src="stack.v1.min.js"></script>
<script src="d3.v4.min.js"></script>
<script src="stack.v1.js"></script>
<script>

var mystack = stack()
Expand All @@ -123,8 +123,8 @@
follow = d3.select("#follow"),
followAnchor = d3.select("#follow-anchor"),
lorenz = d3.select("#lorenz"),
followIndex = section[0].indexOf(follow.node()),
lorenzIndex = section[0].indexOf(lorenz.node());
followIndex = section.nodes().indexOf(follow.node()),
lorenzIndex = section.nodes().indexOf(lorenz.node());

function refollow() {
followAnchor.style("top", (followIndex + (1 - mystack.scrollRatio()) / 2 - d3.event.offset) * 100 + "%");
Expand Down Expand Up @@ -164,7 +164,7 @@
.attr("width", width)
.attr("height", height);

var color = d3.scale.linear()
var color = d3.scaleLinear()
.domain([0, 20, 30, 50])
.range(["yellow", "orange", "brown", "purple"])
.interpolate(d3.interpolateHcl);
Expand Down
31 changes: 17 additions & 14 deletions stack.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function stack() {
.style("opacity", 0)
.style("z-index", 0);

var sectionAndBackground = d3.selectAll(section[0].concat(background.node()))
var sectionAndBackground = d3.selectAll(section.nodes().concat(background.node()))
.style("position", "fixed")
.style("left", 0)
.style("top", 0)
Expand All @@ -62,8 +62,8 @@ function stack() {
.style("background", "linear-gradient(to top,black,white)");

var sectionPrevious = d3.select(null),
sectionCurrent = d3.select(section[0][0]),
sectionNext = d3.select(section[0][1]);
sectionCurrent = d3.select(section.nodes()[0]),
sectionNext = d3.select(section.nodes()[1]);

d3.select(window)
.on("resize.stack", resize)
Expand All @@ -78,10 +78,10 @@ function stack() {
}

function dispatchEvent(event, i) {
var target = section[0][i], sourceEvent = event.sourceEvent = d3.event;
var target = section.nodes()[i], sourceEvent = event.sourceEvent = d3.event;
try {
d3.event = event;
dispatch[event.type].call(target, target.__data__, i);
dispatch.call(event.type, target, target.__data__, i);
} finally {
d3.event = sourceEvent;
}
Expand Down Expand Up @@ -151,24 +151,24 @@ function stack() {
if (i1 === i + 1) { // advance one
sectionPrevious.interrupt().style("display", "none").style("opacity", 0).style("z-index", 0).each(deactivate);
sectionPrevious = sectionCurrent.interrupt().style("opacity", 1).style("z-index", 1);
sectionPrevious.transition().each("end", deactivate);
sectionPrevious.transition().on("end", deactivate);
sectionCurrent = sectionNext.interrupt().style("opacity", 0).style("z-index", 2).each(activate);
sectionCurrent.transition().style("opacity", 1);
sectionNext = d3.select(section[0][i1 + 1]).interrupt().style("display", "block").style("opacity", 0).style("z-index", 0);
sectionNext = d3.select(section.nodes()[i1 + 1]).interrupt().style("display", "block").style("opacity", 0).style("z-index", 0);
} else if (i1 === i - 1) { // rewind one
sectionNext.interrupt().style("display", "none").style("opacity", 0).style("z-index", 0).each(deactivate);
sectionNext = sectionCurrent.interrupt().style("opacity", 1).style("z-index", 1);
sectionNext.transition().each("end", deactivate);
sectionNext.transition().on("end", deactivate);
sectionCurrent = sectionPrevious.interrupt().style("opacity", 0).style("z-index", 2).each(activate);
sectionCurrent.transition().style("opacity", 1);
sectionPrevious = d3.select(section[0][i1 - 1]).interrupt().style("display", "block").style("opacity", 0).style("z-index", 0);
sectionPrevious = d3.select(section.nodes()[i1 - 1]).interrupt().style("display", "block").style("opacity", 0).style("z-index", 0);
} else { // skip
sectionPrevious.interrupt().style("display", "none").style("opacity", 0).style("z-index", 0).each(deactivate);
sectionCurrent.interrupt().style("display", "none").style("opacity", 0).style("z-index", 0).each(deactivate);
sectionNext.interrupt().style("display", "none").style("opacity", 0).style("z-index", 0).each(deactivate);
sectionPrevious = d3.select(section[0][i1 - 1]).interrupt().style("display", "block").style("opacity", 0).style("z-index", 0).each(deactivate);
sectionCurrent = d3.select(section[0][i1]).interrupt().style("display", "block").style("opacity", 1).style("z-index", 2).each(activate);
sectionNext = d3.select(section[0][i1 + 1]).interrupt().style("display", "block").style("opacity", 0).style("z-index", 0).each(deactivate);
sectionPrevious = d3.select(section.nodes()[i1 - 1]).interrupt().style("display", "block").style("opacity", 0).style("z-index", 0).each(deactivate);
sectionCurrent = d3.select(section.nodes()[i1]).interrupt().style("display", "block").style("opacity", 1).style("z-index", 2).each(activate);
sectionNext = d3.select(section.nodes()[i1 + 1]).interrupt().style("display", "block").style("opacity", 0).style("z-index", 0).each(deactivate);
}
i = i1;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ function stack() {
var i = d3.interpolateNumber(pageYOffset, yt * windowHeight);
return function(t) { scrollTo(0, i(t)); };
})
.each("end", function() { yt = NaN; });
.on("end", function() { yt = NaN; });

d3.event.preventDefault();
}
Expand All @@ -226,7 +226,10 @@ function stack() {
return arguments.length ? (fontSize = +_, resize(), stack) : fontSize;
};

d3.rebind(stack, dispatch, "on");
stack.on = function() {
var value = dispatch.on.apply(dispatch, arguments);
return value === dispatch ? stack : value;
};

return stack;
}
1 change: 0 additions & 1 deletion stack.v1.min.js

This file was deleted.