1.0.0 • Published 6 months ago

@lg-charts/series-provider v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
6 months ago

Charts Series Provider

The Series Provider package is a part of the LeafyGreen UI library. It provides context and utilities for managing series data in chart components.

Installation

PNPM

pnpm add @lg-charts/series-provider

Yarn

yarn add @lg-charts/series-provider

NPM

npm install @lg-charts/series-provider

Example

To use the SeriesContext, wrap your chart components with the SeriesProvider component. This will provide the necessary context for managing series data.

import { ChartCard } from '@lg-charts/chart-card';
import { Chart } from '@lg-charts/core';
import { Legend } from '@lg-charts/legend';
import { SeriesProvider } from '@lg-charts/series-provider';

const App = () => {
  const lineData = getLineData();
  const series = lineData.map(({ name }) => name);

  return (
    <SeriesProvider series={series}>
      <Legend series={series}>
      <Chart>
        {lineData.map(({ data, name }) => (
          <Line key={name} data={data} name={name} />
        ))}
      </Chart>
    </SeriesProvider>
  );
};

Props

NameDescriptionTypeDefault
customColorsAn optional object mapping each theme to an array of custom colors for the series. If not provided, default colors based on the current theme will be usedArray<string>
seriesAn array of series names representing the data series to be displayed in the descendant charts componentsArray<string>

useSeriesContext

The useSeriesContext hook provides access to the series data within the SeriesProvider context.

Example

import { useSeriesContext } from '@leafygreen-ui/series-provider';

const ChartComponent = () => {
  const {
    getColor,
    getSeriesIndex,
    isChecked,
    isSelectAllChecked,
    isSelectAllIndeterminate,
    toggleSeries,
    toggleSelectAll,
  } = useSeriesContext();

  // Use the series context data
};
1.0.0

6 months ago

0.2.2

7 months ago

0.2.1

8 months ago

0.2.0

8 months ago

0.1.0

8 months ago