Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
react-svg-pan-zoom
Advanced tools
react-svg-pan-zoom is a React component that adds pan and zoom features to the SVG images. It helps to display big SVG images in a small space.
available at http://chrvadala.github.io/react-svg-pan-zoom/
This component can work in three different modes depending on the selected tool:
##Additional Features
npm install --save react-svg-pan-zoom
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`, `zoom-in`, `zoom-out`
};
}
handleChange(event) {
this.setState({value: event.value});
}
handleClick(event){
console.log('click', event.x, event.y, event.originalEvent);
}
render() {
return (
<Viewer width={400} height={400} value={this.state.value}
tool={this.state.tool} onChange={this.handleChange} onClick={this.handleClick}>
<svg width={800} height={800} >
<-- put here your SVG content -->
</svg>
</Viewer>
);
}
}
width
– required – width of the viewer displayed on screen (if you want to omit this see Autosize)height
– required – height of the viewer displayed on screen (if you want to omit this see Autosize)background
– background of the viewer (default color: dark grey)style
- CSS style of the viewerspecialKeys
- array of keys used in zoom mode to switch between zoom-in and zoom-out (default binding: Win/Cmd, Ctrl)detectPinch
- detect zoom operation performed trough pinch gesture or mouse scrolldetectAutoPan
- perform PAN if the mouse is on the border of the viewerSVGBackground
- background of the SVG (default color: white)value
- value of the viewer (current point of view)tool
- active tool ( one of none
, pan
, zoom
, zoom-in
, zoom-out
)onChange
- handler for changes fn(viewerEvent)
onClick
- handler for click fn(viewerEvent)
onMouseUp
- handler for mouseup fn(viewerEvent)
onMouseMove
- handler for mousemove fn(viewerEvent)
onMouseDown
- handler for mousedown fn(viewerEvent)
Your event handlers will be passed instances of ViewerEvent
. It has some useful attributes (See below). If your purpose demands you to have the original React event instance (SyntheticEvent
), it is provided by event.originalEvent
.
SyntheticEvent originalEvent
- The original React eventSVGSVGElement SVGViewer
- Reference to SVGViewerobject
- coordinate (x,y) of the event mapped to SVG coordinatesnumber 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 originReact SVG Pan Zoom requires the properties width
and height
to be set in order to work properly. If you need an autosized component you can use ReactDimension to get the dimensions of a wrapper element and pass them as properties to its/the child element.
git clone https://github.com/chrvadala/react-svg-pan-zoom.git
cd react-svg-pan-zoom
npm install && npm start
Your contributions (issues and pull request) are much 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 62,949 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
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.