Giter Site home page Giter Site logo

overlap-bar's Introduction

Overlap Bar

A ReactJS component for a stacked fillable gauge where each bar is overlapped to the others.

Overlap Bar

Installation

Install with npm install overlap-bar and import in your project.

Usage

This component accepts the following properties:

  • data (mandatory): the data used to draw the gauges. It can either be an array of numbers or an array of objects (see the examples below);
  • max: the full scale used to draw the gauges. Defaults to the highest value passed in the data property, but can be manually set;
  • showLabels: a boolean value that controls the visibility of the labels within the gauges. Defaults to false;
  • formatLabel: a function that returns the rendered label. Use this to change how your label appears within the gauge. Defaults to (value) => value

Examples

To draw a simple gauge just pass an array of numbers:

import React from 'react'
import OverlapBar from 'overlap-bar'

class MyComponent extends React.Component {
    render() {
        let data = [10, 40, 100]

        return (
            <OverlapBar data={data} />
        )
    }
}

export default MyComponent

To draw a gauge with custom colors you can pass data like in this example:

import React from 'react'
import OverlapBar from 'overlap-bar'

class MyComponent extends React.Component {
    render() {
        let data = [{
            value: 30,
            backgroundColor: '#ff0000'
        }, {
            value: 80,
            backgroundColor: '#00ff00'
        }]

        return (
            <OverlapBar data={data} max={100} />
        )
    }
}

export default MyComponent

You can also show some labels:

import React from 'react'
import OverlapBar from 'overlap-bar'

class MyComponent extends React.Component {
    formatLabel(value) {
        return `${value} %`
    }

    render() {
        let data = [{
            value: 30,
            backgroundColor: '#ff0000',
            color: '#fff'
        }, {
            value: 80,
            backgroundColor: '#00ff00',
            color: '#fff'
        }]

        return (
            <OverlapBar
                data={data}
                max={100}
                showLabels={true}
                formatLabel={this.formatLabel}
            />
        )
    }
}

export default MyComponent

The component includes some default CSS, but you can change the way it looks by overriding the .overlap-bar, .bar and .bar-label classes.

Demo

Coming as soon as I figure out how to work with React and GH Pages :)

Contributing

Clone the repository, run npm install, hack away and add your tests. Run npm test to check that everything is good, and then build with npm run build-dist. If you want a non minified bundled version with source maps, run npm run build-dev, it will be placed in the dev directory.

Pull requests and issues are welcome!

License

MIT

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.