npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@asphalt-react/data-viz

v2.0.0-rc.11

Published

data-viz is a comprehensive charting library tailored to fulfill diverse visualization requirements.

Downloads

150

Readme

DataViz

npm

DataViz charts visually represent data to effectively communicate information and patterns. There are multiple charts availables like Bar, Grouped Bar, Stacked Bar, Line, and Donut. Use these charts to represent complex data in a visual format.

You can control whether to show legends, grid, tooltip, change the format of the tick labels, and change the position of the legend.

You can also customize the colors of the bars and lines.

The charts are all reponsive and adapts to the screen size seemlessly.

Usage

import React from "react"
import {
  BarChart
} from "@asphalt-react/data-viz"

const data = [
  {
    date: "2012-05-13",
    "New York": "65.3",
    "San Francisco": "52.0",
    Austin: "72.4",
  },
  {
    date: "2012-05-14",
    "New York": "64.2",
    "San Francisco": "56.0",
    Austin: "72.5",
  }
]

export const BasicBarChart = ({ ...props }) => {
  return (
    <div style={{ width: "100%", height: "400px" }}>
      <BarChart data={data} dataKey="date" />
    </div>
  )
}

Types

There are multiple types of data visualization components. You can use any of them as per your use-case.

  1. BarChart
  2. LineChart
  3. DonutChart

Responsive behavior

We set a minimum width of "312px" and a minimum height of "360px". The minimum height excludes the legends, as their wrapping behavior depends on the number of legends and available space.

All charts stretch to fit their container. Ensure you account for the legend height when defining the height of the container as the legend's height is dynamic becuse of it's wrapping behaviour.

BarChart

Bar chart which can display multiple data series, grouped, stack or side by side. Also supports both vertical and horizontal layout.

Props

data

Bar chart data.

Example:

[
  {
    month: "Jan",
    customers: 4350,
    attrition: 120
  },
  {
    month: "Feb",
    customers: 6600,
    attrition: 220
  }
]

To enhance the user experience, limit the number of bars to 20. In case of grouped, limit the sets to 8.

The data validation process verifies if all objects within the data array possess the identical set of keys, using the first object in the array as the reference point.

| type | required | default | | ------- | -------- | ------- | | arrayOf | true | N/A |

colors

Colors of individual bars in a grouped or stack bar chart. Use this prop to override the default set of colors. Accepts an object with the key mapped to the key of the bar, and the value mapped to the color value.

For instance:

const data = [
  {
    month: "Jan",
    customers: 4350,
    attrition: 120
  },
  {
    month: "Feb",
    customers: 6600,
    attrition: 220
  }
]

const colors = { customers: "#497aaa", attrition: "#666666" }

| type | required | default | | ------ | -------- | ------- | | object | false | N/A |

dataKey

Key of the datum to index the data.

For instance:

const data = [
  {
    month: "Jan",
    customers: 4350,
    attrition: 120
  },
  {
    month: "Feb",
    customers: 6600,
    attrition: 220
  }
]

Use "month" as the dataKey. This plots the "month" on x-axis, whereas in case of horizontal bar charts, plots the data on y-axis.

| type | required | default | | ------ | -------- | ------- | | string | true | N/A |

xAxisLabel

Label for X-axis.

| type | required | default | | ------ | -------- | ------- | | string | false | N/A |

yAxisLabel

Label for Y-axis.

| type | required | default | | ------ | -------- | ------- | | string | false | N/A |

showGrid

Show grid lines.

| type | required | default | | ---- | -------- | ------- | | bool | false | false |

showLegend

Show chart legend.

| type | required | default | | ---- | -------- | ------- | | bool | false | true |

legendTop

Position the legends at the top.

| type | required | default | | ---- | -------- | ------- | | bool | false | false |

xTickFormat

Formats the default x-axis tick label.

tickLabel - tick label value. return value should be string|number.

For instance:

(tickLabel) => {
 // return the formatted label
}

| type | required | default | | ---- | -------- | ------- | | func | false | N/A |

yTickFormat

Formats the default y-axis tick label.

tickLabel - tick label value. return value should be "string|number".

For instance:

(tickLabel) => {
 // return the formatted label
}

| type | required | default | | ---- | -------- | ------- | | func | false | N/A |

tooltip

React node to pass your own tooltip.

| type | required | default | | ---- | -------- | ------- | | node | false | null |

viewTooltip

Show tooltip.

| type | required | default | | ---- | -------- | ------- | | bool | false | true |

onMouseHover

Returns the value of the bar on mouse hover.

  • event - browser event.
  • currentData - the current data on which the mouse is hovering.
  • groupData - the entire group which the current data is part of.
(event, { currentData, groupData }) => {}

| type | required | default | | ---- | -------- | ------- | | func | false | N/A |

horizontal

Enable horizontal view.

| type | required | default | | ---- | -------- | ------- | | bool | false | false |

stack

Enable stack view.

| type | required | default | | ---- | -------- | ------- | | bool | false | false |

showLabel

Show label bar.

| type | required | default | | ---- | -------- | ------- | | bool | false | false |

formatLabel

Format the label value displayed on top of each bar.

totalValue - The total value represented by the bar. The value type is number. return value should be string|number.

For instance:

(totalValue) => {
 // Return the formatted value as needed
}

| type | required | default | | ---- | -------- | ------- | | func | false | N/A |

LineChart

These display data points connected by straight lines. They are commonly used to show trends over time.

Props

data

Line chart data.

Example:

[
  {
    month: "Jan",
    customers: 4350,
    attrition: 120
  },
  {
    month: "Feb",
    customers: 6600,
    attrition: 220
  }
]

To enhance the user experience, limit the number of lines to 20.

The data validation process verifies if all objects within the data array possess the identical set of keys, using the first object in the array as the reference point.

| type | required | default | | ------- | -------- | ------- | | arrayOf | true | N/A |

colors

Colors of individual lines. Use this prop to override the default set of colors. Accepts an object with the key mapped to the key of the point, and the value mapped to the color value.

For instance:

const data = [
  {
    month: "Jan",
    customers: 4350,
    attrition: 120
  },
  {
    month: "Feb",
    customers: 6600,
    attrition: 220
  }
]

const colors = { customers: "#497aaa", attrition: "#666666" }

| type | required | default | | ------ | -------- | ------- | | object | false | N/A |

dataKey

Key of the datum to index the data.

For instance:

const data = [
  {
    month: "Jan",
    customers: 4350,
    attrition: 120
  },
  {
    month: "Feb",
    customers: 6600,
    attrition: 220
  }
]

Use "month" as the dataKey. This plots the "month" on x-axis.

| type | required | default | | ------ | -------- | ------- | | string | true | N/A |

xAxisLabel

Label for X-axis.

| type | required | default | | ------ | -------- | ------- | | string | false | N/A |

yAxisLabel

Label for Y-axis.

| type | required | default | | ------ | -------- | ------- | | string | false | N/A |

showGrid

Show grid lines.

| type | required | default | | ---- | -------- | ------- | | bool | false | false |

showLegend

Show chart legend.

| type | required | default | | ---- | -------- | ------- | | bool | false | true |

legendTop

Position the legends at the top.

| type | required | default | | ---- | -------- | ------- | | bool | false | false |

xTickFormat

Formats the default x-axis tick label.

tickLabel - tick label value. return value should be "string|number".

For instance:

(tickLabel) => new Date(tickLabel)

| type | required | default | | ---- | -------- | ------- | | func | false | N/A |

yTickFormat

Formats the default y-axis tick label.

tickLabel - tick label value. return value should be "string|number".

For instance:

(tickLabel) => new Date(tickLabel)

| type | required | default | | ---- | -------- | ------- | | func | false | N/A |

tooltip

React node to pass your own tooltip.

| type | required | default | | ---- | -------- | ------- | | node | false | null |

viewTooltip

Show tooltip.

| type | required | default | | ---- | -------- | ------- | | bool | false | true |

onMouseHover

Returns the value of the point(s) on mouse hover.

  • event - browser event.
  • currentData - the current data on which the mouse is hovering.
(event, { currentData }) => {}

| type | required | default | | ---- | -------- | ------- | | func | false | N/A |

showPoints

Show data points(circles) on the lines.

| type | required | default | | ---- | -------- | ------- | | bool | false | false |

startFromZero

Starts from 0 in y-axis. Else, takes the minimum value available.

| type | required | default | | ---- | -------- | ------- | | bool | false | false |

DonutChart

Donut charts are probably the most commonly used charts. They are divided into segments, the arc of each segment shows the proportional value of each piece of data.

Props

data

Donut chart data. Accepts an object with the key mapped to an arc.

Example:

  {
    Cartography: 100,
    GoFood: 200,
    Transport: 250
  }

| type | required | default | | ------ | -------- | ------- | | object | true | N/A |

colors

Colors of individual arcs in a donut chart. Use this prop to override the default set of colors. Accepts an object with the key mapped to an arc, and the value mapped to the color value.

For instance:

const data =  {
    Cartography: 100,
    GoFood: 200,
    Transport: 250
}

const colors = { GoFood: "#497aaa", Transport: "#666666" }

| type | required | default | | ------ | -------- | ------- | | object | false | N/A |

showLegend

Show chart legend.

| type | required | default | | ---- | -------- | ------- | | bool | false | true |

legendTop

Position the legends at the top.

| type | required | default | | ---- | -------- | ------- | | bool | false | false |

tooltip

React node to pass your own tooltip.

| type | required | default | | ---- | -------- | ------- | | node | false | null |

viewTooltip

Show tooltip.

| type | required | default | | ---- | -------- | ------- | | bool | false | true |

onMouseHover

Returns the value of the arc on mouse hover.

  • event - browser event.
  • currentData - the current data on which the mouse is hovering.
(event, { currentData }) => {}

| type | required | default | | ---- | -------- | ------- | | func | false | N/A |