From a91c4670de5516750a482860c73ca8ac835e6831 Mon Sep 17 00:00:00 2001 From: schneefux Date: Sat, 2 Apr 2016 10:58:55 +0200 Subject: that was close - add weightsVisWrapperWrapper and fix reloading page inits --- code/weightviswrapper.js | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'code') diff --git a/code/weightviswrapper.js b/code/weightviswrapper.js index 74ae622..aa18ae1 100644 --- a/code/weightviswrapper.js +++ b/code/weightviswrapper.js @@ -9,6 +9,7 @@ var WeightVisWrapper = (function() { this.svg = this.svgContainer.append("svg"); this.netVisualizer = new NetVisualizer(this.svg); this.resizeHooks = []; + this.readyHooks = []; this.ready = false; this.svgContainer @@ -18,7 +19,7 @@ var WeightVisWrapper = (function() { .style("width", "100%"); this.spinner = this.container.append("div") - .attr("class", "mdl-spinner mdl-js-spinner mdl-spinner--single-color is-active visContainer") + .attr("class", "mdl-spinner mdl-js-spinner mdl-spinner--single-color is-active spinner") .style("position", "absolute") .style("left", "50%") .style("top", "50%"); @@ -96,10 +97,19 @@ var WeightVisWrapper = (function() { }); self.ready = true; callback(); + self.readyHooks.forEach(function(hook) { hook(); }); console.log("ready"); // DEBUG }); }; + WeightVisWrapper.prototype.afterLoad = function(cb) { + if (!this.ready) { + this.readyHooks.push(cb); + } else { + cb(); + } + }; + var attrFontSize = 20; WeightVisWrapper.prototype.placeAttributes = function() { var inputNodes = this.svg.selectAll(".layer-1")[0]; @@ -113,14 +123,13 @@ var WeightVisWrapper = (function() { }; WeightVisWrapper.prototype.addPlaceholder = function(el) { - el.node().parentNode.appendChild(this.spinner.node().cloneNode(true)); - el.remove(); + el.appendChild(this.spinner.node().cloneNode(true)); }; WeightVisWrapper.prototype.openIn = function(el) { - el.node().parentNode.appendChild(this.svgContainer.node()); - el.node().parentNode.appendChild(this.controlContainer.node()); - el.remove(); + d3.select(el).select(".spinner").remove(); + el.appendChild(this.svgContainer.node()); + el.appendChild(this.controlContainer.node()); this.reposition(); }; @@ -151,3 +160,21 @@ var WeightVisWrapper = (function() { return WeightVisWrapper; })(); + +/* helps with impress.js' stepenter/stepleave events */ +var VisIntegrater = (function() { + function VisIntegrater(enterCb, leaveCb) { + var self = this; + this.slide = document.currentScript.parentElement; + this.container = d3.select(this.slide).select(".visContainer"); + console.log(this.slide); + this.slide.addEventListener("impress:stepenter", function() { + enterCb(self.slide); + }); + this.slide.addEventListener("impress:stepleave", function() { + leaveCb(self.slide); + }); + } + + return VisIntegrater; +})(); -- cgit v1.3.1