Skip to content

Commit

Permalink
Added zoomScaleExtent method
Browse files Browse the repository at this point in the history
Closes #71
  • Loading branch information
Magnus Jacobsson authored and Magnus Jacobsson committed Jun 20, 2018
1 parent cf00633 commit e5f28a6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Returns a new graphviz renderer instance on the first element in the given *sele
| useWorker¹ | true |
| [width](#graphviz_width) | null |
| [zoom](#graphviz_zoom) | true |
| [zoomScaleExtent](#graphviz_zoomScaleExtent) | [0.1, 10] |

¹ Only has effect when the graphviz renderer instance is created.

Expand Down Expand Up @@ -332,6 +333,10 @@ A demo of shape tweening can be seen [here](http://bl.ocks.org/magjac/69dc955a2e

If *enable* is true (default), enables panning and zooming, else disables panning and zooming. The zoom behavior is applied to the graph's top level <b>svg</b> element.

<a name="graphviz_zoomScaleExtent" href="#graphviz_zoomScaleExtent">#</a> <i>graphviz</i>.<b>zoomScaleExtent</b>([<i>extent</i>]) [<>](https://github.com/magjac/d3-graphviz/blob/master/src/zoom.js "Source")

Sets the scale extent to the specified array of numbers [k0, k1] where k0 is the minimum allowed scale factor and k1 is the maximum allowed scale factor. The scale extent restricts zooming in and out. For details see [*zoom*.scaleExtent](https://github.com/d3/d3-zoom#zoom_scaleExtent).

<a name="graphviz_resetZoom" href="#graphviz_resetZoom">#</a> <i>graphviz</i>.<b>resetZoom</b>([<i>transition</i>]) [<>](https://github.com/magjac/d3-graphviz/blob/master/src/zoom.js "Source")

Restores the original graph by resetting the transformation made by panning and zooming. If *transition* is specified and not null, it is taken to be a transition instance which is applied during zoom reset.
Expand Down
1 change: 1 addition & 0 deletions examples/basic-zoom-fit-window.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
margin = 20; // to avoid scrollbars

graphviz = d3.select("#graph").graphviz()
.zoomScaleExtent([0.5, 2])
.attributer(attributer)
.renderDot('digraph {a -> b}');

Expand Down
3 changes: 3 additions & 0 deletions src/graphviz.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import tweenPrecision from "./tweenPrecision";
import growEnteringEdges from "./growEnteringEdges";
import zoom from "./zoom";
import {resetZoom} from "./zoom";
import {zoomScaleExtent} from "./zoom";
import on from "./on";
import onerror from "./onerror";
import logEvents from "./logEvents";
Expand All @@ -50,6 +51,7 @@ export function Graphviz(selection, options) {
tweenPrecision: 1,
growEnteringEdges: true,
zoom: true,
zoomScaleExtent: [0.1, 10],
width: null,
height: null,
scale: 1,
Expand Down Expand Up @@ -167,6 +169,7 @@ Graphviz.prototype = graphviz.prototype = {
growEnteringEdges: growEnteringEdges,
zoom: zoom,
resetZoom: resetZoom,
zoomScaleExtent: zoomScaleExtent,
render: render,
dot: dot,
renderDot: renderDot,
Expand Down
9 changes: 8 additions & 1 deletion src/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function createZoomBehavior() {
return this;
}
this._zoomSelection = svg;
var extent = [0.1, 10];
var extent = this._options.zoomScaleExtent;
var zoomBehavior = zoom()
.scaleExtent(extent)
.interpolate(interpolate)
Expand Down Expand Up @@ -89,3 +89,10 @@ export function resetZoom(transition) {

return this;
}

export function zoomScaleExtent(extent) {

this._options.zoomScaleExtent = extent;

return this;
}
14 changes: 14 additions & 0 deletions test/zoom-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,17 @@ tape("zooming rescales transforms during transitions.", function(test) {
test.end();
}
});

tape("zoomScaleExtent() sets zoom scale extent.", function(test) {
var window = global.window = jsdom('<div id="graph"></div>');
var document = global.document = window.document;
var graphviz = d3_graphviz.graphviz("#graph");
var extent = [0.5, 4];
graphviz
.zoomScaleExtent(extent)
.renderDot('digraph {a -> b;}');

test.equal(graphviz.options().zoomScaleExtent, extent, '.zoomScaleExtent(...) sets zoom scale extent');

test.end();
});

0 comments on commit e5f28a6

Please sign in to comment.