Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/initial zoom #289

Merged
merged 5 commits into from
May 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
3 changes: 2 additions & 1 deletion docs/DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ const graph = {
- `highlightOpacity` **[number][96]** this value is used to highlight nodes in the network. The lower
the value the more the less highlighted nodes will be visible (related to _nodeHighlightBehavior_). (optional, default `1`)
- `maxZoom` **[number][96]** max zoom that can be performed against the graph. (optional, default `8`)
- `minZoom` **[number][96]** min zoom that can be performed against the graph. (optional, default `0.1`)
- `minZoom` **[number][96]** min zoom that can be performed
danielcaldas marked this conversation as resolved.
Show resolved Hide resolved
- `initialZoom` **[number][96]** initial zoom that can be performed against the graph. (optional, default `1`)
- `panAndZoom` **[boolean][97]** 🚅🚅🚅 pan and zoom effect when performing zoom in the graph,
a similar functionality may be consulted [here][104]. (optional, default `false`)
- `staticGraph` **[boolean][97]** when setting this value to true the graph will be completely static, thus
Expand Down
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-d3-graph",
"version": "2.3.0",
"version": "2.3.1",
danielcaldas marked this conversation as resolved.
Show resolved Hide resolved
"description": "React component to build interactive and configurable graphs with d3 effortlessly",
"author": "Daniel Caldas",
"license": "MIT",
Expand Down
2 changes: 2 additions & 0 deletions sandbox/graph-config-tooltips.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions src/components/graph/Graph.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,16 @@ export default class Graph extends React.Component {
* @returns {undefined}
*/
_zoomConfig = () => {
d3Select(`#${this.state.id}-${CONST.GRAPH_WRAPPER_ID}`)
.call(
d3Zoom()
.scaleExtent([this.state.config.minZoom, this.state.config.maxZoom])
.on("zoom", this._zoomed)
)
.on("dblclick.zoom", null);
const selector = d3Select(`#${this.state.id}-${CONST.GRAPH_WRAPPER_ID}`);

const zoomObject = d3Zoom()
.scaleExtent([this.state.config.minZoom, this.state.config.maxZoom])
.on("zoom", this._zoomed);

// set initial zoom
zoomObject.scaleTo(selector, this.state.config.initialZoom);
danielcaldas marked this conversation as resolved.
Show resolved Hide resolved

selector.call(zoomObject).on("dblclick.zoom", null);
};

/**
Expand Down
2 changes: 2 additions & 0 deletions src/components/graph/graph.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
* the value the more the less highlighted nodes will be visible (related to <i>nodeHighlightBehavior</i>).
* @param {number} [maxZoom=8] - max zoom that can be performed against the graph.
* @param {number} [minZoom=0.1] - min zoom that can be performed against the graph.
* @param {number} [initialZoom=1] - initial zoom that can be performed against the graph.
danielcaldas marked this conversation as resolved.
Show resolved Hide resolved
* @param {boolean} [panAndZoom=false] - 🚅🚅🚅 pan and zoom effect when performing zoom in the graph,
* a similar functionality may be consulted <a target="_blank" href="https://bl.ocks.org/mbostock/2a39a768b1d4bc00a09650edef75ad39">here</a>.
* @param {boolean} [staticGraph=false] - when setting this value to true the graph will be completely static, thus
Expand Down Expand Up @@ -229,6 +230,7 @@ export default {
linkHighlightBehavior: false,
maxZoom: 8,
minZoom: 0.1,
initialZoom: 1,
danielcaldas marked this conversation as resolved.
Show resolved Hide resolved
nodeHighlightBehavior: false,
panAndZoom: false,
staticGraph: false,
Expand Down