Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React.js ? #75

Open
vko-online opened this issue Sep 12, 2015 · 7 comments
Open

React.js ? #75

vko-online opened this issue Sep 12, 2015 · 7 comments

Comments

@vko-online
Copy link

Any react port?

@benpickles
Copy link
Owner

I do actually have an unpushed branch building support for a React-based version. I can let you know when there's something more to look at.

@vko-online
Copy link
Author

Cool
Please
Thanks

@austinpray
Copy link

@benpickles maybe just push the WIP and let me do some polishing? Created a little proprietary component that approximates peity but would rather just contribute upstream.

@mspe87
Copy link

mspe87 commented Dec 27, 2015

Is there still no way of using this with react?

@nqbao
Copy link

nqbao commented Jul 16, 2016

There is an attempt to port to react here https://www.npmjs.com/package/react-peity

@nk-o
Copy link

nk-o commented Oct 8, 2019

react-peity is limited to Line and Bar charts. For our new React project we needed Pie Peity, so created a simple Component. Hope it will be helpful for someone.

p.s. Including jQuery globally is required.

/**
 * External Dependencies
 */
import 'peity';
import React, { Component } from 'react';

const $ = window.jQuery;

/**
 * Component
 */
class Peity extends Component {
    constructor( props ) {
        super( props );

        this.$chartRef = React.createRef();
        this.$chart = false;
    }

    componentDidMount() {
        const {
            type = 'line',
            options = {},
        } = this.props;

        this.$chart = $( this.$chartRef.current ).peity( type, options );
    }

    componentDidUpdate( prevProps ) {
        // nothing changed
        if ( JSON.stringify( prevProps.data ) === JSON.stringify( this.props.data ) ) {
            return false;
        }

        if ( this.$chart ) {
            this.$chart
                .change();
        }
    }

    render() {
        const {
            data = '',
        } = this.props;

        return (
            <span
                ref={ this.$chartRef }
                className="peity"
            >
                { data.join( ',' ) }
            </span>
        );
    }
}

export default Peity;

Usage example:

<Peity
    type="line"
    data={ [ 5, 3, 9, 6, 5, 9, 7, 3, 5, 2 ] }
    options={ {
        height: 16,
        strokeWidth: 0,
        fill: 'rgba(114, 94, 195, 0.8)',
    } }
/>

<Peity
    type="pie"
    data={ [ 5, 3, 4 ] }
    options={ {
        height: 16,
        strokeWidth: 0,
        fill: [
            'rgba(114, 94, 195, 0.8)',
            'rgba(114, 94, 195, 0.6)',
            'rgba(114, 94, 195, 0.4)',
        ],
    } }
/>

@vko-online
Copy link
Author

I ended up creating port for react-native https://github.com/vko-online/react-native-peity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants