4.4.0 • Published 1 month ago

chartjs-plugin-hierarchical v4.4.0

Weekly downloads
584
License
MIT
Repository
github
Last release
1 month ago

Chart.js Hierarchical Scale Plugin

datavisyn NPM Package Github Actions

Chart.js module for adding a new categorical scale which mimics a hierarchical tree.

Works only with Chart.js >= 3.0.0

hierarchy

Install

npm install --save chart.js@next chartjs-plugin-hierarchical@next

Usage

see Samples on Github

or at this Open in CodePen

Scale

a new scale type hierarchical.

Styling

The hierarchical axis scale has the following styling options

interface IHierarchicalScaleOptions {
  /**
   * ratio by which the distance between two elements shrinks the higher the level of the tree is. i.e. two two level bars have a distance of 1. two nested one just 0.75
   * @default 0.75
   */
  levelPercentage: number;
  /**
   * padding of the first collapse to the start of the x-axis
   * @default 25
   */
  padding: number;
  /**
   * position of the hierarchy label in expanded levels, null to disable
   * @default 'below'
   */
  hierarchyLabelPosition: 'below' | 'above' | null;

  /**
   * object of attributes that should be managed and extracted from the tree
   * data structures such as `backgroundColor` for coloring individual bars
   * the object contains the key and default value
   * @default {}
   */
  attributes: { [attribute: string]: any };
}

Data structure

interface ILabelNode {
  /**
   * label
   */
  label: string;
  /**
   * defines whether this node is collapsed (false) or expanded (true) or focussed ('focus')
   * @default false
   */
  expand?: boolean | 'focus';
  /**
   * list of children
   */
  children?: ISubLabelNode[];
}

/**
 * a label entry can be a single string or a complex ILabelNode
 */
declare type ISubLabelNode = ILabelNode | string;

interface IValueNode<T> {
  /**
   * the actual value of this node
   */
  value: T;
  /**
   * list of children
   */
  children?: ISubValueNode<T>[];
}

/**
 * a value entry can be a single value or a complex IValueNode
 */
declare type ISubValueNode<T> = IValueNode<T> | T;

ESM and Tree Shaking

The ESM build of the library supports tree shaking thus having no side effects. As a consequence the chart.js library won't be automatically manipulated nor new controllers automatically registered. One has to manually import and register them.

import Chart from 'chart.js';
import { HierarchicalScale } from 'chartjs-plugin-hierarchical';

// register scale in chart.js and ensure the defaults are set
HierarchicalScale.register();
...

Development Environment

npm i -g yarn
yarn set version 2
yarn
yarn pnpify --sdk

Building

yarn install
yarn build

developed by datavisyn.

4.4.0

1 month ago

4.3.6

3 months ago

4.3.5

6 months ago

4.3.2

9 months ago

4.3.1

9 months ago

4.3.4

6 months ago

4.3.3

7 months ago

4.3.0

12 months ago

4.1.2

1 year ago

4.2.0

12 months ago

4.1.0

1 year ago

4.0.0

1 year ago

4.1.1

1 year ago

4.0.0-alpha

1 year ago

3.10.1

1 year ago

3.10.0

2 years ago

3.9.0

2 years ago

3.8.0

2 years ago

3.7.1

2 years ago

3.7.0

2 years ago

3.6.0

2 years ago

3.5.0

3 years ago

3.1.0

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

3.0.0-rc.3

3 years ago

3.0.0-beta.9

3 years ago

3.0.0-beta.7

3 years ago

3.0.0-beta.6

3 years ago

3.0.0-beta.4

3 years ago

2.0.1

3 years ago

3.0.0-beta.3

4 years ago

3.0.0-beta.1

4 years ago

3.0.0-alpha.20

4 years ago

3.0.0-alpha.2

4 years ago

3.0.0-alpha.1

4 years ago

2.0.0

4 years ago