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

@codedown/react-d3-treemap

v1.0.31

Published

Integrating D3 Treemap with React

Downloads

8

Readme

react-d3-treemap

TreeMap component built with D3 Treemap and React based on Mike Bostock´s Treemap.

npm version Code Climate PRs Welcome

React-d3-treemap-gif

DEMO

React D3 Treemap demo

Features

  • React for painting SVG
  • D3 for doing the maths calculations

Installation

Steps to use react-d3-treemap in your React project

1.Install from NPM

npm install --save react-d3-treemap

2. Import and use in your application

import TreeMap from "react-d3-treemap";
// Include its styles in you build process as well
import "react-d3-treemap/dist/react.d3.treemap.css";

3. Usage

interface TreeMapInPutData {
  name: string;
  value?: number;
  children?: Array<TreeMapInPutData>;
  className?: string;
}

<TreeMap<TreeMapInPutData>
    id="myTreeMap"
    width={500}
    height={400}
    data={<my data matching TreeMapInputData interface>}
    valueUnit={"MB"}
/>

Props

  /**
   * TreeMap id, will be use for create customId for each node
   */
  id: string;

  /**
   * TreeMap width
   */
  width: number;

  /**
   * TreeMap height
   */
  height: number;

  /**
   * TreeMap data. Normally should have at least name, value and children.
   *
   * Example:
   *  interface TreeMapInPutData {
   *      name: string;
   *      value?: number;
   *      children?: Array<TreeMapInPutData>;
   *      className?: string;
   *  }
   */
  data: TreeMapInputData;

  /*
        Unit for values. For example MB
    */
  valueUnit?: string;

  /*
   * Format for the values
   * https://github.com/d3/d3-format#format
   */
  valueFormat?: string;

  /**
   * Hide breadcrumb.
   *
   * If you app doesn't use breadcrumb, you can pass down a ref
   * and use the methods: zoomOut, resetZoom
   */
  disableBreadcrumb?: boolean;

  /**
   * There are few color strategies for nodes:
   *    Depth: different color per depth
   *    Value: different color depends on how big / small is the value
   *    NumberOfChildren: different color depends on how many children node has
   *    OneEachChildren: one color per each top children, then range of colors from white to that one
   */
  colorModel?: ColorModel;

  /**
   * Don't show the top right corner box indicating number of children
   */
  hideNumberOfChildren?: boolean;

  /**
   * Don't show the value
   */
  hideValue?: boolean;

  /**
   * Overrides top div main class
   */
  className?: string;

  /**
   * Overrides svg class
   */
  svgClassName?: string;

  /**
   * Overrides node class
   */
  nodeClassName?: string;

  /**
   * Overrides breadcrumb class
   */
  breadCrumbClassName?: string;

  /**
   * Overrides svg style
   */
  svgStyle?: React.CSSProperties;

  /**
   * Overrides node style
   */
  nodeStyle?: React.CSSProperties;

  /**
   * Padding between nodes ( calculated by D3 )
   */
  paddingInner?: number;

  /**
   * Custom ScaleSequential from D3
   */
  customD3ColorScale?: ScaleSequential<string>;

  /**
   * Name for the property `name` included in data
   *
   * @default "name"
   */
  namePropInData?: string;

  /**
   * Name for the property `link` included in data
   *
   * @default "link"
   */
  linkPropInData?: string;

  /**
   * Name for the property `value` included in data
   *
   * @default "value"
   */
  valuePropInData?: string;

  /**
   * Name for the property `children` included in data
   *
   * @default "children"
   */
  childrenPropInData?: string;

  /**
   * Captures on zoom event
   */
  onZoom?: (
    zoomLevel: number,
    zoomId: number,
    breadcrumbItems: IBreadcrumbItem[]
  ) => void;

  /**
   * Triggers when TreeMap is mounted
   */
  onTreeMapDidMount?: (treeMap: TreeMap<TreeMapInputData>) => void;

  /**
   * Indicates where to place NumberOfChildren box
   *
   * @default NumberOfChildrenPlacement.BottomRight
   */
  numberOfChildrenPlacement: NumberOfChildrenPlacement;

  /**
   * Color for text and children counter when background is dark
   *
   * @default white
   */
  darkNodeTextColor?: string;

  /**
   * Color for node border when background is dark
   *
   * @default white
   */
  darkNodeBorderColor?: string;

  /**
   * Color for text and children counter when background is light
   *
   * @default black
   */
  lightNodeTextColor?: string;

  /**
   * Color for node border when background is dark
   *
   * @default black
   */
  lightNodeBorderColor?: string;
  
  /**
   * Override value text for node 
   */
  valueFn?: (value: number) => string

  /**
   * Tooltip placement. If none is specified then is automatic depending on
   * the quadrant of the treeMap
   */
  tooltipPlacement?: TooltipPlacement;

  /**
   * Tooltip custom css class
   */
  tooltipClassName?: string;

  /**
   * Disable custom tooltip
   * 
   * @default false
   */
  disableTooltip?: boolean

  /**
   * Tooltip offset X
   *
   * @default 0
   */
  tooltipOffsetX?: number;

  /**
   * Tooltip offset Y
   *
   * @default 0
   */
  tooltipOffsetY?: number;

  /**
   * Number of levels to display in TreeMap
   *
   * @default 1
   */
  levelsToDisplay?: number;

App sample

You can see an example of App here.

Data sample

You can see an example of data here.

TypeScript sample

I created a TypeScript consume sample for React D3 Treemap.

License

BSD 3-Clause License

Copyright (c) 2021, José Quinto All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.