Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
react-svg-pan-zoom
Advanced tools
A react component that adds pan and zoom features to SVG
npm install --save react-svg-pan-zoom
http://chrvadala.github.io/react-svg-pan-zoom/
git clone https://github.com/chrvadala/react-svg-pan-zoom.git
cd react-svg-pan-zoom
npm install
npm start
import React from 'react';
import ReactDOM from 'react-dom';
import {Viewer, ViewerHelper} from 'react-svg-pan-zoom';
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
value: ViewerHelper.getDefaultValue(),
tool: 'pan' //one of `none`, `pan`, `zoom`
};
}
handleChange(event) {
this.setState({value: event.value});
}
handleClick(event){
console.log('click', event.x, event.y, event.originalEvent);
}
render() {
return (
<div>
<Viewer width={400} height={400}
value={this.state.value} tool={this.state.tool}
onChange={event => this.handleChange(event)}
onClick={event => this.handleClick(event)}
onMouseMove={event => this.handleMouseMove(event)} >
<svg width={800} height={800} >
<rect x="30" y="50" width="100" height="70" fill="black"/>
<circle cx="210" cy="120" r="50" fill="blue"/>
</svg>
</Viewer>
</div>
);
}
}
width
– required – width of the viewer displayed on screen (if you want to omit this see below)height
– required – height of the viewer displayed on screen (if you want to omit this see below)background
– background of the viewer (default dark grey)style
- CSS style of the viewerSVGBackground
- background of the SVG (default white)value
- value of the viewer (current point of view)tool
- active tool ( one of none
, pan
, zoom
)onChange
- handler something changed fn(viewerEvent)
onClick
- handler click fn(viewerEvent)
onMouseUp
- handler mouseup fn(viewerEvent)
onMouseMove
- handler mousemove fn(viewerEvent)
onMouseDown
- handler mousedown fn(viewerEvent)
Your event handlers will be passed instances of ViewerEvent
. It has some useful attributes (See below). If, for your purpose, you need original React event instance (SyntheticEvent
), you can get it through event.originalEvent
.
SyntheticEvent originalEvent
- The original React eventnumber x
- x coordinate of the event mapped to SVG coordinatesnumber y
- y coordinate of the event mapped to SVG coordinatesnumber scaleFactor
- zoom levelnumber translationX
- x delta from the viewer originnumber translationY
- y delta from the viewer originSvgPanZoom requires width and height to work propertly. If you need a responsive component you can use ViewerResponsive
, a component that extends Viewer
and detects width and height trought its parent (See ReactDimension for details).
become
import {Viewer, ViewerHelper} from 'react-svg-pan-zoom';
import {ViewerResponsive, ViewerHelper} from 'react-svg-pan-zoom';
npm run build
Your contributions (issues and pull request) are appreciated!
MIT
FAQs
A React component that adds pan and zoom features to SVG
The npm package react-svg-pan-zoom receives a total of 61,506 weekly downloads. As such, react-svg-pan-zoom popularity was classified as popular.
We found that react-svg-pan-zoom demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.