diff --git a/dist/app.js b/dist/app.js index f1bcd5b..90264aa 100644 --- a/dist/app.js +++ b/dist/app.js @@ -3156,6 +3156,12 @@ var app = (function (exports) { var identity$1 = new Transform(1, 0, 0); + transform.prototype = Transform.prototype; + + function transform(node) { + return node.__zoom || identity$1; + } + function nopropagation$1() { event.stopImmediatePropagation(); } @@ -5164,8 +5170,8 @@ var app = (function (exports) { var width = 600, height = 600; + this.zoom_level = opts.zoom || 1.5; this.apiurl = opts.apiurl; - this.init_svg(opts.svg); this.categorylabel = opts.categorylabel || "Category"; this.symbols_src = opts.symbols; this.categorydiv = select(opts.categorydiv); @@ -5178,6 +5184,7 @@ var app = (function (exports) { // this.net = new ForceNet({}); // this.net.on("nodeclick", this.nodeclick.bind(this)); this.svg = null; + this.init_svg(opts.svg); this.historylinks = {}; this.links = null; this.highlight_category = null; @@ -5263,9 +5270,9 @@ var app = (function (exports) { this.rect = this.svg.append("rect") .attr("width", 1000) .attr("height", 1000) - .style("fill", "none") - .style("pointer-events", "all") - .call(this.zoom); + .style("fill", "none"); + // .style("pointer-events", "all") + // .call(this.zoom); this.content = this.svg.append("g") .attr("id", "content"), this.linksg = this.content.append("g") @@ -5354,11 +5361,17 @@ var app = (function (exports) { this.categorydiv .selectAll("div.cat") .classed("highlight", d=> d.page ? d.page.highlight : false); - var data = {nodes: this.wiki.get_nodes(), links: values(this.all_links_by_key)}; + var data = {nodes: this.get_nodes(), links: values(this.all_links_by_key)}; this.update_node_counts(); this.update_graph(data); } + get_nodes () { + var nodes = this.wiki.get_nodes(); + nodes = nodes.filter(d => d.linked || d.active || d.active2 || d.highlight); + return nodes; + } + async set_active_page (page) { console.log("wikimap: set_active_page:", page.title); if (page === this.active_page) { @@ -5403,7 +5416,7 @@ var app = (function (exports) { // return; } else if (page.ns !== 0) { console.log("SPECIAL PAGE", page); - + } else { // LOAD/ENSURE PAGE LINKS var links_out = await page.get_links(); @@ -5420,15 +5433,17 @@ var app = (function (exports) { }); } - this.active_page = page; this.active_page.active = true; this.linked_nodes_set_active(this.active_page, true); + + setTimeout(() => { + this.centerOnItem(page, 1000); + }, 1000); this.events.emit("page", this.active_page); - - var data = {nodes: this.wiki.get_nodes(), links: values(this.all_links_by_key)}; + var data = {nodes: this.get_nodes(), links: values(this.all_links_by_key)}; this.update_node_counts(); this.update_graph(data); // this.update_nodes(); @@ -5623,7 +5638,44 @@ var app = (function (exports) { this.simulation.alpha(0.5).restart(); } + centerOnItem(item, duration) { + var bounds = this.svg.node().getBoundingClientRect(); + var curt = transform(this.rect.node()); + console.log("centerOnItem", this.zoom_level, "item", item); + var zoom_level = this.zoom_level ? this.zoom_level : curt.k; + if (item && item.x !== undefined) { + var transform$1 = function () { + return identity$1 + .translate(bounds.width / 2, bounds.height / 2) + .scale(zoom_level) + .translate(-item.x, -item.y); + }; + if (duration) { + this.rect.transition().duration(duration).call(this.zoom.transform, transform$1); + } else { + this.rect.call(this.zoom.transform, transform$1); + } + } else { + console.log("NO ITEM"); + var transform$1 = function () { + return identity$1 + .scale(1); + }; + this.rect.call(this.zoom.transform, transform$1); + } + } + do_zoom (f, transition) { + this.rect.call(this.zoom.scaleBy, f); + } + + zoom_in () { + this.do_zoom(1.25); + } + + zoom_out () { + this.do_zoom(1/1.25); + } } exports.Map = Map$2; diff --git a/dist/index.js b/dist/index.js index dfa4e5c..6f1ddf8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,17 +1,17 @@ var svg = document.querySelector("#svg"), - page = document.querySelector("#page"), iframe = document.querySelector("iframe#wikiframe"), - cats = document.querySelector("#cats"), - cats_contents = document.querySelector("#cats .body"), - // cats_thumb = document.querySelector("#cats .thumb"), - allcatscb = document.querySelector("input#allcats"), - historycb = document.querySelector("input#history"), - // current_title = null, - // loaded = false, - wikibaseurl, - wikibasepat; - + map = new app.Map({ + apiurl: "/mw/api.php", + symbols: "src/legend.json", + svg: "#svg", + categorylabel: "Catégorie", + categorydiv: "#cats .body", + zoom: 2.0 + }), + zoom_in = document.querySelector(".leaflet-control-zoom-in"), + zoom_out = document.querySelector(".leaflet-control-zoom-out"), + cats = document.querySelector("#cats"); window.addEventListener("resize", resize); function resize() { @@ -28,29 +28,14 @@ function resize() { // Match size of parent svg.setAttribute("width", page.clientWidth); svg.setAttribute("height", page.clientHeight); - } -resize(); - -var map = new app.Map({ - apiurl: "/mw/api.php", - symbols: "src/legend.json", - svg: "#svg", - categorylabel: "Catégorie", - categorydiv: "#cats .body" -}); async function doload () { + resize(); console.log("map.init"); await map.init(); console.log("map.init: done"); - // await map.load_json("data/sitemap.json"); - // console.log("loading categories"); - // await map.load_cats("data/cats.json", cats_contents); - // await map.load_legend("src/legend.json", cats_contents); - // loaded = true; - map.on("page", function (page) { // console.log("map.page", page.title); var url = page.url(); @@ -59,8 +44,18 @@ async function doload () { iframe.src = url; } }) + zoom_in.addEventListener("click", (e) => { + map.zoom_in(); + }) + zoom_out.addEventListener("click", (e) => { + map.zoom_out(); + }) } window.addEventListener("DOMContentLoaded", doload); iframe.addEventListener("load", function () { map.set_active_url(iframe.contentWindow.location.href); }); + +cats.addEventListener("click", e => { + cats.classList.toggle("expanded"); +}) \ No newline at end of file diff --git a/index.html b/index.html index 60ab9e2..f242c7a 100644 --- a/index.html +++ b/index.html @@ -8,36 +8,26 @@
+