Coder Social home page Coder Social logo

React.js ? about peity HOT 7 OPEN

benpickles avatar benpickles commented on May 18, 2024
React.js ?

from peity.

Comments (7)

nk-o avatar nk-o commented on May 18, 2024 1

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

from peity.

benpickles avatar benpickles commented on May 18, 2024

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.

from peity.

vko-online avatar vko-online commented on May 18, 2024

Cool
Please
Thanks

from peity.

austinpray avatar austinpray commented on May 18, 2024

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

from peity.

mspe87 avatar mspe87 commented on May 18, 2024

Is there still no way of using this with react?

from peity.

nqbao avatar nqbao commented on May 18, 2024

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

from peity.

vko-online avatar vko-online commented on May 18, 2024

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

from peity.

Related Issues (20)

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.