0.1.4 • Published 6 years ago
react-envelope-graph v0.1.4
react-envelope-graph
A drag-and-drop-enabled, responsive, envelope graph that allows to shape a wave with attack, decay, sustain and release.
Check out the Demo!
Installing
$ npm i --save react-envelope-graphor
$ yarn add react-envelope-graphUsage
Import the component
import EnvelopeGraph from "react-envelope-graph";and then use it:
function App() {
return (
<EnvelopeGraph
defaultXa={1}
defaultXd={0.5}
defaultYs={0.5}
defaultXr={0.7}
ratio={{
xa: 0.25,
xd: 0.25,
xr: 0.2
}}
style={{
backgroundColor: "black",
padding: "2.5%",
height: "100vh",
width: "20vw"
}}
styles={{
line: {
fill: "none",
stroke: "red",
strokeWidth: 2,
},
dndBox: {
fill: "none",
stroke: "blue",
strokeWidth: 0.1,
height: 1,
width: 1
},
dndBoxActive: {
fill: "blue",
}
}}
onChange={console.log}
/>
);
}Notes
- The
height/widthratio is preserved within the svg widthandheightcan be specified via thestylepropdefaultXa,defaultXd,defaultYsanddefaultXrneed to have a value between 0 and 1- In
ratio, the sum of the valuesxa,xdandxrneeds to remain below0.75.xsis internally set toxs === 0.25. - Most numeric values in the
stylesprop must not use a unit (e.g.pxorem) as they set values on SVG components (user units) - Note that
stylesis not a regularstyleprop, but a custom prop that additionally allows to configure interaction reactions too - To regularly style the component, use the
styleprop - When
defaultXa,defaultXd,defaultYsanddefaultXrprops are changed, noonChangeevent is fired and the graph is set to these values. - Optional props:
ratio,dndBox,onChange,style
Contributing
To try the component:
$ git clone git@github.com:TimDaub/react-envelope-graph.git
$ npm i
$ npm run devCurrent Limitations
Help is very much appreciated. I'll try to handle PRs as fast as I can. Below is a list of the current limitations:
- The
yavalue cannot be set via dragging - Touch listeners are not yet implemented
Changelog
0.1.4
defaultXa,defaultXd,defaultYsanddefaultXrcan now be used to continuously set the graphs values without anonChangeevent firing
0.1.3
- Bugfix: Dropped
getBoundingClientRectin favor ofgetComputedStylesfor measuring the svg's dimensions. Settingmarginandpaddingviastyleshould now be possible without problems.
0.1.2
- Bugfix: Properly fix ratio issues with
heightandwidth. They're now members of thestyleprop
0.1.1
- Hotfix: Set
height/widthof graph to100%to respect ratio. I'll have to go back on that fix later...
0.1.0
- Breaking change: Removed functions
onAttackChange,onDecayChange,onSustainChangeandonReleaseChangein favor ofonChange, which returns all values as an object
0.0.11
- When setting the props
heightandwidth, the graph's ratio is adjusts accordingly
0.0.10
- Bugfix: Remove
ratio.xsfrom configurable params
0.0.9
- Bugfix: Dragging the function works even thought the graph has any type of padding
0.0.8
- Bugfix: Yet fixing corner length another time...
0.0.7
- Bugfix: Left top corner same length as others
0.0.6
- Add cut corners to graph
- Allow definition of
paddingthrough nativestyleprop and removemarginTop,marginRight,marginBottom, andmarginRightprops
0.0.5
- Improve support for
stylesprop to allow to styling of the component - Move
dndBoxprop tostyles
0.0.4
- DnD box's size now configurable
0.0.3
- Bugfix: When mouse leaves graph, DnD stops
0.0.2
- Event subscriptions
- Improved props API
- Responsive
0.0.1
- Dragable ADSR graph
License
MIT