1.0.0 • Published 4 years ago

univariate-infographics v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

univariate-infographics

React component library of SVG info-graphics for displaying uni-variate data

NPM JavaScript Style Guide

github hackersupreme.com

Install

npm install --save univariate-infographics

Components

  • <PieChart data={data} />
  • <PieSlice data={data} />
  • <BarChart data={data} />
  • <HorizontalBar data={data} />
  • <VerticalBar data={data} />

All Components

Usage

import React from 'react'

import { PieChart, BarChart, PieSlice, HorizontalBar, VerticalBar } from 'univariate-infographics'

Data Config

Each component takes in an array of objects called data. Each object must have a value property that represents the value of the item in the data set. You can also include other properties if you want to use them in a component's legend or as an overlay on some of the components.

// this is all that's required for the components to work
const data = [
  {
    value: 1
  },
  {
    value: 2
  }
]

/*
=== BUT ===
*/

// you can also add more fields
const data = [
  {
    value: 3,
    label: 'Plot A',
    unit: 'acres',
    ...
  },
  {
    value: 5,
    label: 'Plot B',
    unit: 'acres',
    ...
  }
]

PieChart

Pie Chart

How to use

const data = [
  {
    value: 1
  },
  {
    value: 2
  }
]

const Example = () => (
  <PieChart
    data={data}
  />
)

Props

PropertyTypeDefaultDescription
data (required)array-Data to be represented by component
widthnumber200Pixel width of component
heightnumber200Pixel height of component
baseColorstring'#4095bf'Starting color for component's gradient. Accepts rgb, hsl, and hex color formats
titlestringnullTitle of component
titleColorstring'#1d3940'Text color of title. Accepts any color format
highlightColorstring'#884ca1'Hover color of component. Accepts any color format
donutbooleanfalseTurns the pie chart into a donut chart
donutColorstring'white'Color of inner donut circle. Accepts any color format
legendbooleanfalseIncludes a legend for the component.
legendColorstring'#1d3940'Text color of legend. Accepts any color format
legendDataTypestring'value'Selects the property of the objects in the data array to display in the legend
orientationnumber (0-1)0Where the start of the piechart is on the circle. eg, 0, 1, 0.25, 0.5, etc
circleAreanumber (0-1)1What percentage of the circle should the pie chart fill
gradientDirectionstringnullSet to 'reverse' to reverse the gradient in the component
styleobjnullStyle object passed to the component
classNamestringnullClass names to be added to the component

Examples

Donut

Pie Chart With Legend

PieSlice

Pie Slice

How to use

const data = [
  {
    value: 1
  },
  {
    value: 2
  }
]

const Example = () => (
  <PieSlice
    data={data}
   />
)

Props

PropertyTypeDefaultDescription
data (required)array-Data to be represented by component
slicenumber0Index of data array that is going to displayed
widthnumber200Pixel width of component
heightnumber200Pixel height of component
baseColorstring'#4095bf'Color of slice
secondaryColorstring'#e9ecef'Background color of pie chart
titlestringnullTitle of component
titleColorstring'#1d3940'Text color of title. Accepts any color format
donutbooleanfalseTurns the pie chart into a donut chart
donutColorstring'white'Color of inner donut circle. Accepts any color format
legendbooleanfalseIncludes a legend for the component.
legendColorstring'#1d3940'Text color of legend. Accepts any color format
legendDataTypestring'value'Selects the property of the objects in the data array to display in the legend
orientationnumber (0-1)0Where the start of the piechart is on the circle. eg, 0, 1, 0.25, 0.5, etc
circleAreanumber (0-1)1What percentage of the circle should the pie chart fill
gradientDirectionstringnullSet to 'reverse' to reverse the gradient in the component
styleobjnullStyle object passed to the component
classNamestringnullClass names to be added to the component

Examples

Pie Slice with Legend

BarChart

Bar Chart

How to use

const data = [
  {
    value: 1
  },
  {
    value: 4
  },
  {
    value: 2
  }
]


const Example = () => (
  <BarChart
    data={data}
   />
)

Props

PropertyTypeDefaultDescription
data (required)array-Data to be represented by component
widthnumber200Pixel width of component
heightnumber200Pixel height of component
barWidthnumber20Pixel width of individual bars
baseColorstring'#4095bf'Starting color for component's gradient. Accepts rgb, hsl, and hex color formats
titlestringnullTitle of component
titleColorstring'#1d3940'Text color of title. Accepts any color format
highlightColorstring'#884ca1'Hover color of component. Accepts any color format
legendbooleanfalseIncludes a legend for the component.
legendColorstring'#1d3940'Text color of legend. Accepts any color format
legendDataTypestring'value'Selects the property of the objects in the data array to display in the legend
overlaybooleanfalseInclude an overlay value on the bars of the component
overlayColorstring'#1d3940'Text color of overlay. Accepts any color format
overlayDataTypestring'value'Selects the property of the objects in the data array to display in the overlay
gradientDirectionstringnullSet to 'reverse' to reverse the gradient in the component
styleobjnullStyle object passed to the component
classNamestringnullClass names to be added to the component

Examples

Bar Chart with Legend

Bar Chart with Overlay

HorizontalBar

Horizontal Bar

How to use

const data = [
  {
    value: 1
  },
  {
    value: 4
  },
  {
    value: 2
  }
]

const Example = () => (
  <HorizontalBar
    width={400}
    height={50}
    data={data}
   />
)

Props

PropertyTypeDefaultDescription
data (required)array-Data to be represented by component
widthnumber200Pixel width of component
heightnumber200Pixel height of component
baseColorstring'#4095bf'Starting color for component's gradient. Accepts rgb, hsl, and hex color formats
titlestringnullTitle of component
titleColorstring'#1d3940'Text color of title. Accepts any color format
highlightColorstring'#884ca1'Hover color of component. Accepts any color format
legendbooleanfalseIncludes a legend for the component.
legendColorstring'#1d3940'Text color of legend. Accepts any color format
legendDataTypestring'value'Selects the property of the objects in the data array to display in the legend
overlaybooleanfalseInclude an overlay value on the bars of the component
overlayColorstring'#1d3940'Text color of overlay. Accepts any color format
overlayDataTypestring'value'Selects the property of the objects in the data array to display in the overlay
gradientDirectionstringnullSet to 'reverse' to reverse the gradient in the component
styleobjnullStyle object passed to the component
classNamestringnullClass names to be added to the component

Examples

Horizontal Bar with Overlay

Horizontal Bar with Legend

VerticalBar

const data = [
  {
    value: 1
  },
  {
    value: 4
  },
  {
    value: 2
  }
]

const Example = () => (
  <VerticalBar
    width={50}
    height={200}
    data={data}
   />
)

Vertical Bar

Props

PropertyTypeDefaultDescription
data (required)array-Data to be represented by component
widthnumber200Pixel width of component
heightnumber200Pixel height of component
baseColorstring'#4095bf'Starting color for component's gradient. Accepts rgb, hsl, and hex color formats
titlestringnullTitle of component
titleColorstring'#1d3940'Text color of title. Accepts any color format
highlightColorstring'#884ca1'Hover color of component. Accepts any color format
legendbooleanfalseIncludes a legend for the component.
legendColorstring'#1d3940'Text color of legend. Accepts any color format
legendDataTypestring'value'Selects the property of the objects in the data array to display in the legend
overlaybooleanfalseInclude an overlay value on the bars of the component
overlayColorstring'#1d3940'Text color of overlay. Accepts any color format
overlayDataTypestring'value'Selects the property of the objects in the data array to display in the overlay
gradientDirectionstringnullSet to 'reverse' to reverse the gradient in the component
styleobjnullStyle object passed to the component
classNamestringnullClass names to be added to the component

Examples

Vertical Bar with Legend

Vertical Bar with Overlay

License

MIT © hackersupreme