react-raphael v0.9.0
react-raphael
reactify raphael
Install
# or specify the externals in webpack config
npm install --save raphael
# install react-raphael in your react-raphael project
npm install --save react-raphaelExample
- react-raphael-example
- react-raphael-map
- react-raphael-chart
- react-raphael-workflow
- react-raphael-scrawl
- react-raphael-mine-sweeping
Quickly Start
var React = require('react');
var ReactDOM = require('react-dom');
const {Raphael,Paper,Set,Circle,Ellipse,Image,Rect,Text,Path,Line} = require('react-raphael');
class App extends React.Component{
render(){
var data = [
{x:50,y:50,r:40,attr:{"stroke":"#0b8ac9","stroke-width":5},animate:Raphael.animation({cx:60},500,"<>")},
{x:100,y:100,r:40,attr:{"stroke":"#f0c620","stroke-width":5},animate:Raphael.animation({cx:105},500,"<>")},
{x:150,y:50,r:40,attr:{"stroke":"#1a1a1a","stroke-width":5}},
{x:200,y:100,r:40,attr:{"stroke":"#10a54a","stroke-width":5},animate:Raphael.animation({cx:195},500,"<>")},
{x:250,y:50,r:40,attr:{"stroke":"#e11032","stroke-width":5},animate:Raphael.animation({cx:240},500,"<>")}
]
return (<Paper width={300} height={300}>
<Set>
{
data.map(function(ele,pos){
return (<Circle key={pos} x={ele.x} y={ele.y} r={ele.r} attr={ele.attr} animate={ele.animate}/>)
})
}
</Set>
<Set>
<Rect x={30} y={148} width={240} height={150} attr={{"fill":"#10a54a","stroke":"#f0c620","stroke-width":5}}/>
<Ellipse x={150} y={198} ry={40} rx={100} attr={{"fill":"#fff","stroke":"#e11032"}} glow={{width:10,fill:true,color:"#0b8ac9",opacity:1}}/>
<Image src="static/images/5circle.png" x={100} y={170} width={90} height={60} />
<Text x={150} y={258} text="同一个世界 同一个梦想" attr={{"fill":"#fff"}}/>
<Text x={150} y={273} text="One World One Dream" attr={{"fill":"#fff"}}/>
<Path d={["M150 287L150 287"]} animate={Raphael.animation({"path": ["M80 287L220 287"]},500,"<>")} attr={{"stroke":"#fff"}}/>
<Line x1={150} y1={290} x2={150} y2={290} animate={Raphael.animation({ x1:80, x2:220},500,"<>")} attr={{"stroke":"#fff"}}/>
</Set>
</Paper>)
}
}Snapshot
API
All Element Props
- Paper
- width
numberwidth of the canvas. - height
numberheight of the canvas. - containerobjectprops of the canvas's container.default value: { style:{}, className:"" }
- width
- Element
- attr
objectSets the attributes of the element. - animateobjectCreates and starts animation for given element. - animateWithobjectActs similar to Element.animate, but ensure that given animation runs in sync with another given element. - clickfunctionAdds event handler for click for the element. - dataobjectAdds or retrieves given value asociated with given key. - dblclickfunctionAdds event handler for double click for the element. - dragobjectAdds event handlers for drag of the element.object {move,start,end,mcontext,scontext,econtext}- glowfunctionReturn set of elements that create glow-like effect around given element. - hoverobjectAdds event handlers for hover for the element.object {in,out,icontext,ocontext}- hidebooleanMakes element invisible. - mousedownfunctionAdds event handler for mousedown for the element. - mousemovefunctionAdds event handler for mousemove for the element. - mouseoutfunctionAdds event handler for mouseout for the element. - mouseoverfunctionAdds event handler for mouseover for the element. - mouseupfunctionAdds event handler for mouseup for the element.- load
functionAdds event handler for load for the element. - rotateobjectAdds rotation by given angle around given point to the list of transformations of the element. - scaleobjectAdds scale by given amount relative to given point to the list of transformations of the element. - stop
boolenStops animation for given element. - toBackbooleanMoves the element so it is the furthest from the viewer’s eyes, behind other elements. - toFrontbooleanMoves the element so it is the closest to the viewer’s eyes, on top of other elements. - touchcancelfunctionAdds event handler for touchcancel for the element. - touchendfunctionAdds event handler for touchend for the element. - touchmovefunctionAdds event handler for touchmove for the element. - touchstartfunctionAdds event handler for touchstart for the element. - transformstringorarrayAdds transformation to the element which is separate to other attributes, i.e. translation doesn’t change x or y of the rectange. The format of transformation string is similar to the path string syntax:"t100,100r30,100,100s2,2,100,100r45s1.5"- translateobjectAdds translation by given amount to the list of transformations of the element. - updatefunctionAdds event handler for update for the element.
- load
- Set
Extends Element & Container Elements - Circle
Extends Element & Draws a circle- x
numberx coordinate of the centre - y
numbery coordinate of the centre - r
numberradius
- x
- Ellipse
Extends Element & Draws a ellipse- x
numberx coordinate of the centre - y
numbery coordinate of the centre - rx
numberhorizontal radius - rynumbervertical radius
- x
- Image
Extends Element & Embeds an image into the surface- srcstringURI of the source image- x
numberx coordinate of the centre - y
numbery coordinate of the centre - width
numberwidth of the image - heightnumberheight of the image
- x
- Path
Extends Element & Creates a path element by given path data string- d
stringpath string in SVG format
- d
- Print
Extends Element & Creates set of shapes to represent given font at given position with given size- x
numberx position of the text - y
numbery position of the text - text
stringtext to print - font-family
stringfamily of font object - font-weight
stringweight of font object - font-style
stringstyle of font object - font-stretch
stringstretch of font object - font-size
numbersize of the font, default is 16 - origin
stringcould be "baseline" or "middle", default is "middle" - letter-spacing
numbernumber in range -1..1, default is 0
- x
- Rect
Extends Element & Draws a circle- x
numberx coordinate of the top left corner - y
numbery coordinate of the top left corner - width
numberwidth of the rect - heightnumberheight of the rect - r
numberradius for rounded corners, default is 0
- x
- Text
Extends Element & Draws a text string & If you need line breaks, put “\n” in the string- x
numberx coordinate position - y
numbery coordinate position - text
stringThe text string to draw
- x
- Line
Extends Path & Draws a line- x1
numberx coordinate of the start point - y1
numbery coordinate of the start point x2
numberx coordinate of the end point - y2numbery coordinate of the end point
- x1
All Element Ref Function
- Paper
- getPaper
functionpaper of the component - Set
- getSet
functionset of the component - Element
- getElement
functionelement of the component
Raphael & Utils
- Raphael
you can seehttp://dmitrybaranovskiy.github.io/raphael/reference.html#Raphael - Utils
- createPaper
functioncreate a paper byRaphael()- updatePaper
functionupdate a paper - removePaper
functionremove a paper - createfunctioncreate elements or a set bypaper.xxx- createElementfunctioncall create to create a element - createSetfunctioncall create to create a set - updateElement
functionupdate elements or a set - removeSetfunctionremove a set from paper - removeElementfunctionremove a element from paper - papersarrayall paper instance - elementsarrayall elements or set of the only paper instance findParentById
functionfind parent of element by id
- updatePaper
Contact
Email: liuhong1.happy@163.com
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago