From 4a8aae110dfb4ad0af47b4e5610aacd18fca61e3 Mon Sep 17 00:00:00 2001 From: Andrew Baumes Date: Tue, 4 Feb 2020 20:09:55 -0500 Subject: [PATCH 1/2] added url param support --- src/App.vue | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/src/App.vue b/src/App.vue index 670faa0..cc6f531 100644 --- a/src/App.vue +++ b/src/App.vue @@ -330,8 +330,38 @@ export default { edgeCount: 0, colorScale: null, selected: null, + graphSettings: [ + 'markdown', + 'showEdges', + 'edgeOpacity', + 'nodeOpacity', + 'nodeStrokeWidth', + 'size', + 'sizeField', + 'colorField', + 'layoutRunning', + 'alpha', + 'chargeStrength', + 'theta', + 'collideStrength', + 'linkStrength', + 'center', + 'xField', + 'xStrength', + 'yField', + 'yStrength', + 'radialField', + 'radialStrength', + 'gravityStrength', + ], }; }, + + created() { + this.updateValuesBastedOnURLParams(); + this.addUpdateURLWatchers(); + }, + mounted() { let b = 32000; let bounds = { @@ -669,6 +699,57 @@ export default { this.$refs.downloadAnchor.setAttribute('download', 'graph.json'); this.$refs.downloadAnchor.click(); }, + + addUpdateURLWatchers() { + this.graphSettings.forEach((option) => { + this.$watch(`${option}.value`, () => this.updateURLParams()); + }); + }, + + updateURLParams() { + const url = []; + this.graphSettings.forEach((option) => { + url.push(`${option}=${encodeURI(this[option].value)}`) + }); + + const urlParams = this.getURLParams(); + + if (urlParams.config) { + url.push(`config=${urlParams.config}`); + } + + if (urlParams.graph) { + url.push(`graph=${urlParams.graph}`); + } + + window.history.replaceState(null, null, `?${url.join('&')}`); + }, + + updateValuesBastedOnURLParams() { + const urlParams = this.getURLParams(); + + this.graphSettings.forEach((option) => { + const tempValue = urlParams[option] || this[option].value; + if (typeof this[option].value === 'number') { + this[option].value = +decodeURI(tempValue); + } else { + this[option].value = decodeURI(tempValue); + if (this[option].value === 'false') { + this[option].value = false; + } else if (this[option].value === 'true') { + this[option].value = true; + } + } + }); + }, + + getURLParams() { + const urlParams = {}; + window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { + urlParams[key] = value; + }); + return urlParams; + } }, } From ac15de3ea2cc49e4913f23c8c4629cba28cf7101 Mon Sep 17 00:00:00 2001 From: anbcodes <31807975+anbcodes@users.noreply.github.com> Date: Tue, 18 Feb 2020 19:26:20 -0500 Subject: [PATCH 2/2] Fixed a typo --- src/App.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.vue b/src/App.vue index cc6f531..129ffac 100644 --- a/src/App.vue +++ b/src/App.vue @@ -358,7 +358,7 @@ export default { }, created() { - this.updateValuesBastedOnURLParams(); + this.updateValuesBasedOnURLParams(); this.addUpdateURLWatchers(); }, @@ -725,7 +725,7 @@ export default { window.history.replaceState(null, null, `?${url.join('&')}`); }, - updateValuesBastedOnURLParams() { + updateValuesBasedOnURLParams() { const urlParams = this.getURLParams(); this.graphSettings.forEach((option) => {