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

cb-charts

v1.0.0

Published

Sparrow Marketing custom charts library.

Downloads

18

Readme

Sparrow Charts

Custom charts library for sparrow marketing

Why

The Sparrow Storybook was built with the purpose of holding tye design system required by the various projects under Sparrow Marketing. Example being Sparrow Frontend and Sparrow Report Generator

Architecture

Under the hood, Sparrow Storybook uses the following:

  1. Typescript
  2. React Storybook - For displaying the components
  3. Rollup - For bundling

Code quality control

  1. Eslint - Linting Typescript
  2. Stylelint - Linting CSS
  3. Prettier - Code formatting
  4. Husky & Lint staged - Precommit hook to execute commands and do fixes before the file is committed

Testing

  1. Jest(https://jestjs.io/) - Test runner
  2. React Testing Library(https://testing-library.com/docs/react-testing-library/intro)

Development

Usage

Depending on chart, it accepts different type of data and config. All config values can be found in documentation. Here are some examples how to create basic chart of each type:

Bar Chart

// array of labels for x axis
const labels = [
  'Date 1',
  'Date 2',
  'Date 3',
  'Date 4'
]

const data = {
  labels,
  datasets: [
    {
      label: 'Followers',
      data: [1, 2, 3, 4],
      backgroundColor: '#c12382',
    }
  ]
}

<Chart type="bar" data={data} />

Multiple Bar Chart

// array of labels for x axis
const labels = [
  'Date 1',
  'Date 2',
  'Date 3',
  'Date 4'
]

const data = {
  labels,
  datasets: [
    //pass multiple dataset objects
    {
      label: 'Followers',
      data: [1, 2, 3, 4],
      backgroundColor: '#c12382',
    },
    {
      label: 'Followers',
      data: [1, 2, 3, 4],
      backgroundColor: '#c12382',
    },
    {
      label: 'Followers',
      data: [1, 2, 3, 4],
      backgroundColor: '#c12382',
    }
  ]
}

<Chart type="bar" data={data} />

Stacked Bar Chart

// array of labels for x axis
const labels = [
  'Date 1',
  'Date 2',
  'Date 3',
  'Date 4'
]

const data = {
  labels,
  datasets: [
    //pass multiple dataset objects
    {
      label: 'Followers',
      data: [1, 2, 3, 4],
      backgroundColor: '#c12382',
    },
    {
      label: 'Followers',
      data: [1, 2, 3, 4],
      backgroundColor: '#c12382',
    },
    {
      label: 'Followers',
      data: [1, 2, 3, 4],
      backgroundColor: '#c12382',
    }
  ]
}

// pass in the config.chart property stacked
<Chart type="bar" data={data} config={{chart: {stacked: true}}} />

Area Chart

// array of labels for x axis
const labels = [
  'Date 1',
  'Date 2',
  'Date 3',
  'Date 4'
]

const data = {
  labels,
  datasets: [
    {
      label: 'Followers',
      data: [1, 2, 3, 4],
      backgroundColor: '#c12382',
    }
  ]
}

<Chart type="area" data={data} />

Multiple Area Chart

// array of labels for x axis
const labels = [
  'Date 1',
  'Date 2',
  'Date 3',
  'Date 4'
]

const data = {
  labels,
  datasets: [
    //pass multiple dataset objects
    {
      label: 'Followers',
      data: [1, 2, 3, 4],
      backgroundColor: '#c12382',
    },
    {
      label: 'Followers',
      data: [1, 2, 3, 4],
      backgroundColor: '#c12382',
    },
    {
      label: 'Followers',
      data: [1, 2, 3, 4],
      backgroundColor: '#c12382',
    }
  ]
}

<Chart type="area" data={data} />

Curve Chart

const data = {
  // labels for boundary values
  labels: ['Bellow average', 'Average', 'Above average'],
  // boundary values
  datasets: [0, 35, 70],
  // value for point on curve chart
  value: state
}

<Chart type="curve" data={data} />

Donut Chart

const data = {
  datasets: [
    { label: 'Slice 1', data: 1, color: '#00c9dd' },
    { label: 'Slice 2', data: 2, color: '#1d9dee' },
    { label: 'Slice 3', data: 3, color: '#ff9600' }
  ]
}

<Chart type="new-donut" data={data} />

Diverging Chart

// array of labels for x axis
const labels = [
  'Strongly disagree',
  'Disagree',
  'Not Sure',
  'Agree',
  'Strongly agree'
]

const data = {
  labels,
  datasets: [
    {
      total: 282 // optional value to provide total value for chart by x axis
      label: 'Question 1',
      data: [1,2,3,4,5],
      backgroundColor: ['#FF5860', '#FFCDCF', '#BEC4CD', '#C2EEC2', '#33C635']
    }
  ]
}

<Chart type="diverging" data={data} />

Polar Area Chart

const labels = ['Slice 1','Slice 2','Slice 3','Slice 4','Slice 5']

const data = {
  labels,
  datasets: {
    data: [1,2,3,4,5],
    backgroundColor: ['red', 'green', 'blue', 'purple', 'orange']
  }
}

<Chart type="polar-area" data={data} />

Prerequisites

NodeJS & NPM - Use NVM as mentioned here

Developement

To start the storybook development server, execute npm run dev To build storybook, execute npm run build-storybook

Build

To build the component library, execute npm run build. This would use rollup under the hood to build the component library

Working

The storybook internally uses the prepare script from npm which helps us to build the package in the target repository once it is being updated/installed there. Hence every time a change happens and something new is added to storybook,

Release management

In order to be used effectively in other projects relying on storybook, we found it necessary to have a release management process. Each time a new change is merged to master branch, the developer can release the changes by checking out to a new release branch from the master branch by executing git checkout -b release/<version_no> and then pushing it to upstream using git push -u origin release/<version_no>. This can then be used in other projects by using: "storybook": "git+https://sparrow+storybook-deploy-token:<token>@gitlab.com/sparrow-marketing/storybook.git#release/<version_no></version_no>". Please make sure the version number is always incremented.

Integration with other projects

Since we dont have a private NPM registry at the moment, we rely on building the storybook at the installation target. This is made possible by using the npm prepare script which gets executed every time storybook is installed in a different project as a dependency. We are currently facing issues with the same when doing installations in gitlab and fixing this is a work in progress.