Giter Club home page Giter Club logo

react-raphael's Introduction

react-raphael

Version Downloads

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-raphael

Example

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

snapshot.png

API

All Element Props

  • Paper
    • width number width of the canvas.
    • height number height of the canvas.
    • container object props of the canvas's container.default value: { style:{}, className:"" }
  • Element
    • attr object Sets the attributes of the element.
    • animate object Creates and starts animation for given element.
    • animateWith object Acts similar to Element.animate, but ensure that given animation runs in sync with another given element.
    • click function Adds event handler for click for the element.
    • data object Adds or retrieves given value asociated with given key.
    • dblclick function Adds event handler for double click for the element.
    • drag object Adds event handlers for drag of the element. object {move,start,end,mcontext,scontext,econtext}
    • glow function Return set of elements that create glow-like effect around given element.
    • hover object Adds event handlers for hover for the element. object {in,out,icontext,ocontext}
    • hide boolean Makes element invisible.
    • mousedown function Adds event handler for mousedown for the element.
    • mousemove function Adds event handler for mousemove for the element.
    • mouseout function Adds event handler for mouseout for the element.
    • mouseover function Adds event handler for mouseover for the element.
    • mouseup function Adds event handler for mouseup for the element.
    • load function Adds event handler for load for the element.
    • rotate object Adds rotation by given angle around given point to the list of transformations of the element.
    • scale object Adds scale by given amount relative to given point to the list of transformations of the element.
    • stop boolen Stops animation for given element.
    • toBack boolean Moves the element so it is the furthest from the viewer’s eyes, behind other elements.
    • toFront boolean Moves the element so it is the closest to the viewer’s eyes, on top of other elements.
    • touchcancel function Adds event handler for touchcancel for the element.
    • touchend function Adds event handler for touchend for the element.
    • touchmove function Adds event handler for touchmove for the element.
    • touchstart function Adds event handler for touchstart for the element.
    • transform string or array Adds 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"
    • translate object Adds translation by given amount to the list of transformations of the element.
    • update function Adds event handler for update for the element.
  • Set Extends Element & Container Elements
  • Circle Extends Element & Draws a circle
    • x number x coordinate of the centre
    • y number y coordinate of the centre
    • r number radius
  • Ellipse Extends Element & Draws a ellipse
    • x number x coordinate of the centre
    • y number y coordinate of the centre
    • rx number horizontal radius
    • ry number vertical radius
  • Image Extends Element & Embeds an image into the surface
    • src string URI of the source image
    • x number x coordinate of the centre
    • y number y coordinate of the centre
    • width number width of the image
    • height number height of the image
  • Path Extends Element & Creates a path element by given path data string
    • d string path string in SVG format
  • Print Extends Element & Creates set of shapes to represent given font at given position with given size
    • x number x position of the text
    • y number y position of the text
    • text string text to print
    • font-family string family of font object
    • font-weight string weight of font object
    • font-style string style of font object
    • font-stretch string stretch of font object
    • font-size number size of the font, default is 16
    • origin string could be "baseline" or "middle", default is "middle"
    • letter-spacing number number in range -1..1, default is 0
  • Rect Extends Element & Draws a circle
    • x number x coordinate of the top left corner
    • y number y coordinate of the top left corner
    • width number width of the rect
    • height number height of the rect
    • r number radius for rounded corners, default is 0
  • Text Extends Element & Draws a text string & If you need line breaks, put “\n” in the string
    • x number x coordinate position
    • y number y coordinate position
    • text string The text string to draw
  • Line Extends Path & Draws a line
    • x1 number x coordinate of the start point
    • y1 number y coordinate of the start point
    • x2 number x coordinate of the end point
    • y2 number y coordinate of the end point

All Element Ref Function

  • Paper
    • getPaper function paper of the component
  • Set
    • getSet function set of the component
  • Element
    • getElement function element of the component

Raphael & Utils

  • Raphael you can see http://dmitrybaranovskiy.github.io/raphael/reference.html#Raphael
  • Utils
    • createPaper function create a paper by Raphael()
    • updatePaper function update a paper
    • removePaper function remove a paper
    • create function create elements or a set by paper.xxx
    • createElement function call create to create a element
    • createSet function call create to create a set
    • updateElement function update elements or a set
    • removeSet function remove a set from paper
    • removeElement function remove a element from paper
    • papers array all paper instance
    • elements array all elements or set of the only paper instance
    • findParentById function find parent of element by id

Contact

Email: [email protected]

react-raphael's People

Contributors

liuhong1happy avatar rohn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-raphael's Issues

update npm package?

May I ask if you might update the npm package with latest version of this GitHub repo?

I apologize for creating an issue to ask if you planned to do this, but I don't have another way to contact you.

I am very appreciative of this repo and am currently using it for a project 😄 Thank you for your awesome work and contributing to the open source community.

Raphael dependency not working

After installing react-raphael, when trying to use it, it does not find the module 'raphael'. I guess this is because it is specified as a 'devDependency' in package.json. It should be specified simply as a dependency instead. This means that in 'raphael-react' project, 'raphael' module should have been installed using 'npm install --save raphael' instead of '--save-dev'

Setting viewBox on svg element

Is there any way I can assign something to the svg element other than width and height?

<Paper width={800} height={600} container={{ viewBox: "0 0 800 400" }}>

This is not a solution since container prop assigns everything to the svg's parent div element, can I somehow add attribute to the svg itself? Thanks.

Drag function with state

How to use drag function with state? But when i use on move function i am guessing object will rerender and onmove is fired only once (checked with console.log). How to used it properly?

state = {
    x: 10,
    y: 10
}


onstart = (x, y) => {
    this.setState({x: x, y: y})
}

onMove = (dx, dy) => {
    let x = this.state.x;
    let y = this.state.y
    this.setState({x: x + dx, y: y + dy})
}


end = (x, y) => {
    this.setState({x: x, y: y})
}

render() {
    return (
        <div className="design_wrapper">
            <div className="svg_container">
                <Paper width={300} height={300}>
                    <Set>
                        <Circle key={"asdd"} x={this.state.x} y={this.state.y} r={15}
                                attr={{stroke: "#000", fill: "#000"}}
                                drag={{
                                    move: this.onMove,
                                    start: this.onstart,
                                    end: this.end
                                }}/>
                    </Set>
                </Paper>
            </div>
        </div>
    );
}

}`

Path transform attr not working. how to do that?

I have tried all methods, but not succeed,
<Path transform={"matrix(0.3536,0.3536,-0.3536,0.3536,287.4991,651.138)"} d={["M25.545,23.328L17.918,15.623L25.534,8.007L27.391,9.864L29.649,1.436L21.222,3.694L23.058,5.53L15.455,13.134L7.942,5.543L9.809,3.696L1.393,1.394L3.608,9.833L5.456,8.005L12.98,15.608L5.465,23.123L3.609,21.268L1.351,29.695L9.779,27.438L7.941,25.6L15.443,18.098L23.057,25.791L21.19,27.638L29.606,29.939L27.393,21.5Z"]} attr={{"stroke":"#000", "fill": "#cbcbcb"}}/>

or

Anything else?

Use tag not supported

I want to use some Icons from an existing SVG-Icons-Sprite by utilizing SVG's <use> tag.
Unfortunately this does not seem to work.

Instead of having the <use> at the correct position it gets moved up and out of the currrent paper and inserted in a Set's <div> tag. Which looses all relations, coordinates are not working, etc.

Animation not working on sets?

I can't seem to get animation to work for sets...

a simplest example:

const growAnimation = Raphael.animation({ transform:'"S5"' }, 300);

<Set animate={growAnimation} >
  <Circle x={100} y={200} r={5} />
  <Circle x={200} y={200} r={15} />
</Set>

but if I put the animate={growAnimation} direction on each of the <Circle>s then they do animate immediately on component load.

Set class to the SVG Element

I do not find how to se ta class directly to the svg element created by:

<Paper className="paper" width={300} height={500}>

is not working. Any solution ?

React v15

Thank you for this lib !

Using react v15.x, a warning comes up :
warning.js?8a56:36 Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead.

Here is a link for possible solution : https://facebook.github.io/react/warnings/dont-call-proptypes.html

Is your dependency on react v0.14 really necessary ? I could try to check this if you want ( though not really confident).

"Warning: A string ref...." in devTools console

Hi! I'm getting this warning when running my React Typescript project

image

---------------CODE------------------------------------------------------
import React from "react";

import { Paper, Set, Circle, Image, Path } from "react-raphael";
import { IWingMapViewerProps } from "../types";

const WingMapViewer = ({
points,
addPoint,
removePoint,
imageUrl,
svgPath,
viewWeight,
viewHeight,
}: IWingMapViewerProps) => {
return (



<Path
d={[svgPath]}
attr={{ fill: "transparent" }}
click={(e: Function) => addPoint(e)}
/>
{points.map(({ pointInfo }) => {
return (
<Circle
key={pointInfo.id}
x={pointInfo.x}
y={pointInfo.y}
r={5}
attr={{ fill: "green" }}
click={(e: Function) => removePoint(e, pointInfo.id)}
/>
);
})}


);
};

export default WingMapViewer;


Is this something anyone else is aware of? Any idea/comment?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.