peity icon indicating copy to clipboard operation
peity copied to clipboard

React.js ?

Open vko-online opened this issue 9 years ago • 7 comments

Any react port?

vko-online avatar Sep 12 '15 18:09 vko-online

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.

benpickles avatar Sep 13 '15 07:09 benpickles

Cool Please Thanks

vko-online avatar Sep 13 '15 11:09 vko-online

@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.

austinpray avatar Nov 17 '15 23:11 austinpray

Is there still no way of using this with react?

mspe87 avatar Dec 27 '15 13:12 mspe87

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

nqbao avatar Jul 16 '16 09:07 nqbao

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)',
        ],
    } }
/>

nk-o avatar Oct 08 '19 10:10 nk-o

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

vko-online avatar Oct 09 '19 07:10 vko-online