-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add x and y to SVG * initialise to zero, because not mandatory * Update translations in fitToViewer * bugfix in setting new SVG x and y * Set default value for SVG x and y * Merge PR #88 from @kheyse-oqton with current version * stylistic changes * Update fit to viewer as switch statement More explicit handling of the translations as a function of alignment options * Cleaning up of the constructor and componentDidUpdate functions * using destructured values in Miniature * small scaling bugfix * small scale fix: scaling should be with viewer scaleLevel, not scaleY * adds ViewboxStory * minor ViewboxStory fix * rename SVGViewBoxXY to SVGMinXY * in order to reuse the standard name as defined in SVG RFC https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute, please rename SVGViewBoxX and SVGViewBoxY with SVGMinX and SVGMinY #150 (comment) * Move viewbox parser to separate file * please move the ViewBox parser in a new file called utils/ViewBoxParser.js #150 (comment) * make ViewBox parser W3C compliant This should do the trick and is more readable than a regex, IMO #150 (comment) * replace `withViewBox` by `viewBox` #150 (comment)
- Loading branch information
1 parent
334de3a
commit c69b899
Showing
9 changed files
with
159 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function parseViewBox(viewBoxString) { | ||
// viewBox specs: https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute | ||
return viewBoxString | ||
.split(/[ ,]/) // split optional comma | ||
.filter(Boolean) // remove empty strings | ||
.map(Number); // cast to Number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, {StrictMode} from 'react'; | ||
import {action} from '@storybook/addon-actions'; | ||
import {noArgsDecorator, viewerMouseEventDecorator} from './actions-decorator'; | ||
|
||
import {UncontrolledReactSVGPanZoom} from '../../src/index'; | ||
import {boolean} from "@storybook/addon-knobs"; | ||
|
||
export default class ViewboxStory extends React.Component { | ||
constructor(props) { | ||
super(props) | ||
this.Viewer = null; | ||
} | ||
|
||
componentDidMount() { | ||
this.Viewer.fitToViewer(); | ||
} | ||
|
||
render() { | ||
return ( | ||
<StrictMode> | ||
|
||
<UncontrolledReactSVGPanZoom | ||
width={400} height={400} | ||
|
||
ref={Viewer => this.Viewer = Viewer} | ||
|
||
onClick={viewerMouseEventDecorator('onClick')} | ||
|
||
onChangeValue={noArgsDecorator('onChangeValue')} | ||
onChangeTool={action('onChangeTool')} | ||
|
||
detectAutoPan={boolean('detectAutoPan', false)} | ||
detectWheel={boolean('detectWheel', false)} | ||
detectPinchGesture={boolean('detectPinchGesture', false)} | ||
> | ||
|
||
<svg | ||
width={100} height={100} | ||
withViewBox="10 10 80 80" | ||
> | ||
|
||
<rect x="20" y="20" width="60" height="60" fill="yellow"/> | ||
<circle cx="20" cy="20" r="4" fill="red"/> | ||
<circle cx="80" cy="80" r="4" fill="red"/> | ||
|
||
<circle cx="0" cy="0" r="4" fill="blue"/> | ||
<circle cx="100" cy="100" r="4" fill="blue"/> | ||
|
||
<circle cx="50" cy="50" r="2" fill="black"/> | ||
</svg> | ||
</UncontrolledReactSVGPanZoom> | ||
</StrictMode> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters