From 536c2220df35ecc7ceb1ecd8f2ececeb8d44b57f Mon Sep 17 00:00:00 2001 From: Alex de Mulder Date: Tue, 20 May 2014 10:46:47 +0200 Subject: [PATCH] added option to setOptions to avoid resetting view. --- HISTORY.md | 7 +++++++ dist/vis.js | 16 +++++++++++----- docs/graph.html | 4 ++-- src/graph/Graph.js | 14 ++++++++++---- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index b9a16d36..ea608cea 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,13 @@ http://visjs.org +## 2014-05-09, version 1.0.2 + +### Graph + +- added option to setOptions to avoid resetting view. + + ## 2014-05-09, version 1.0.1 ### Timeline diff --git a/dist/vis.js b/dist/vis.js index 5bc5eeb0..6ef01017 100644 --- a/dist/vis.js +++ b/dist/vis.js @@ -5,7 +5,7 @@ * A dynamic, browser-based visualization library. * * @version 1.0.2-SNAPSHOT - * @date 2014-05-13 + * @date 2014-05-20 * * @license * Copyright (C) 2011-2014 Almende B.V, http://almende.com @@ -16046,9 +16046,13 @@ Graph.prototype.setData = function(data, disableStart) { /** * Set options * @param {Object} options + * @param {Boolean} [initializeView] | set zoom and translation to default. */ -Graph.prototype.setOptions = function (options) { +Graph.prototype.setOptions = function (options, initializeView) { if (options) { + if (initializeView === undefined) { + initializeView = true; + } var prop; // retrieve parameter values if (options.width !== undefined) {this.width = options.width;} @@ -16275,9 +16279,11 @@ Graph.prototype.setOptions = function (options) { // bind keys. If disabled, this will not do anything; this._createKeyBinds(); - this.setSize(this.width, this.height); - this._setTranslation(this.frame.clientWidth / 2, this.frame.clientHeight / 2); - this._setScale(1); + if (initializeView == true) { + this.setSize(this.width, this.height); + this._setTranslation(this.frame.clientWidth / 2, this.frame.clientHeight / 2); + this._setScale(1); + } this._redraw(); }; diff --git a/docs/graph.html b/docs/graph.html index b2bcce53..eb7eedd0 100644 --- a/docs/graph.html +++ b/docs/graph.html @@ -2041,10 +2041,10 @@ var options: { - setOptions(options) + setOptions(options,[initializeView]) none Set options for the graph. The available options are described in - the section Configuration Options. + the section Configuration Options. The initializeView boolean parameter is optional and can be used to avoid the resetting of the view when loading the options. This is ment when changing the options of an already initialized graph. diff --git a/src/graph/Graph.js b/src/graph/Graph.js index d95cbe0f..095f93ec 100644 --- a/src/graph/Graph.js +++ b/src/graph/Graph.js @@ -502,9 +502,13 @@ Graph.prototype.setData = function(data, disableStart) { /** * Set options * @param {Object} options + * @param {Boolean} [initializeView] | set zoom and translation to default. */ -Graph.prototype.setOptions = function (options) { +Graph.prototype.setOptions = function (options, initializeView) { if (options) { + if (initializeView === undefined) { + initializeView = true; + } var prop; // retrieve parameter values if (options.width !== undefined) {this.width = options.width;} @@ -731,9 +735,11 @@ Graph.prototype.setOptions = function (options) { // bind keys. If disabled, this will not do anything; this._createKeyBinds(); - this.setSize(this.width, this.height); - this._setTranslation(this.frame.clientWidth / 2, this.frame.clientHeight / 2); - this._setScale(1); + if (initializeView == true) { + this.setSize(this.width, this.height); + this._setTranslation(this.frame.clientWidth / 2, this.frame.clientHeight / 2); + this._setScale(1); + } this._redraw(); };