Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cb-charts

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cb-charts

Sparrow Marketing custom charts library.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-75%
Maintainers
1
Weekly downloads
 
Created
Source

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.

FAQs

Package last updated on 14 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc