Skip to content
Open
Changes from 1 commit
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
81 changes: 81 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Comment thread
anbcodes marked this conversation as resolved.
Outdated
this.addUpdateURLWatchers();
},

mounted() {
let b = 32000;
let bounds = {
Expand Down Expand Up @@ -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;
}
},
}
</script>
Expand Down