GithubHelp home page GithubHelp logo

vasturiano / icicle-chart Goto Github PK

View Code? Open in Web Editor NEW
36.0 3.0 11.0 596 KB

A partition / icicle interactive chart web component for visualizing hierarchical data

Home Page: https://vasturiano.github.io/icicle-chart/example/flare/

License: MIT License

HTML 22.96% JavaScript 73.56% CSS 3.48%
icicle partition chart data-visualization d3js hierarchical-data

icicle-chart's Introduction

icicle-chart

NPM package Build Size NPM Downloads

Also called a partition chart or a flame chart, an icicle chart visualizes a hierarchical data structure where nodes of a tree are represented by adjacent rectangles layed out progressively according to their depth.

Four orientation modes are supported for the axial direction of the nodes level: top-down, bottom-up, left-to-right and right-to-left.

Zooming interaction is available in the nodes cross-axis direction via mouse-wheel events or by clicking on a node, enabling a gradual exploration of the data. Clicking on a node zooms the view so that the node occupies the full width available. Clicking in the chart's background resets the zoom to its initial position. The chart also responds to data changes by animating the dimensions of each of the nodes into their new positions.

For improved performance, nodes with width smaller than a given threshold (minSegmentWidth) are excluded from the DOM, allowing for representation of large data sets while maintaining a smooth interaction. See here for an example of a randomly generated large data structure.

See also the Sunburst, Circle Pack and Treemap charts.

Quick start

import Icicle from 'icicle-chart';

or using a script tag

<script src="//unpkg.com/icicle-chart"></script>

then

const myChart = Icicle();
myChart
  .data(<myData>)
  (<myDOMElement>);

API reference

Method Description Default
orientation([string]) Getter/setter for the orientation of the chart. Choice between td (top-down), bu (bottom-up), lr (left-to-right), rl (right-to-left). lr
data([object]) Getter/setter for chart data (see below for syntax details).
width([number]) Getter/setter for the chart width in px. <window width>
height([number]) Getter/setter for the chart height in px. <window height>
children([string or fn]) Getter/setter for a data node's children accessor, used to establish the hierarchical relationship between nodes. Supports either a string indicating the object's property name, or a function(node) which should return an array of nodes. children
label([string or fn]) Getter/setter for a node object label accessor, used to display labels on the segments and their tooltips. name
size([string or fn]) Getter/setter for a node object size accessor, used to compute the widths of the segments. value
color([string or fn]) Getter/setter for a node object color accessor, used to color the segments. grey
nodeClassName([string or fn]) Getter/setter for a node object classname accessor. Determines the CSS class(es) to apply to each segment node.
minSegmentWidth([number]) Getter/setter for the minimum width of a segment (in px) required for it to be rendered in the DOM. 0.8
excludeRoot([boolean]) Getter/setter for whether to exclude the root node from the representation. false
sort([fn]) Getter/setter for the compare method used to sort sibling segments. A value of null (default) maintains the existing order found in the input data structure. This method is equivalent to d3-hierarchy's sort, it receives two arguments representing two sibling nodes and expects a numeric return value (-1, 0 or 1) indicating the order. Each element is an instance of d3-hierarchy node and has several useful properties to specify order: data (the corresponding data object), value (summed value of node and all its descendants) and depth (layer degree). For example, to order segments by size, use: (a, b) => b.value - a.value. <existing order>
showLabels([boolean]) Getter/setter for whether to show labels in the nodes. Regardless of this setting, labels too large to fit within a segment's width are automatically hidden. true
showTooltip([fn]) Getter/setter to specify a node object tooltip's visibility. If this function returns false for a particular node, that node's tooltip will not display at all. If unspecified, all nodes' tooltips will display. () => true
tooltipTitle([fn]) Getter/setter for a node object tooltip title. The function should return a string to be displayed in bold in the first line of the tooltip. If unspecified, the full hierarchical name will be displayed.
tooltipContent([fn]) Getter/setter for a node object tooltip content. Use this to specify extra content in each of the segment's tooltips in addition to the title set in tooltipTitle.
zoomToNode([node]) Programmatically zoom the chart to a particular node.
zoomBy([number]) Programmatically zoom the chart by a specific amount. 1 is unity, above one indicates a zoom-in and below a zoom-out.
zoomReset() Programmatically reset the zoom to the global view.
onHover([fn]) Callback function for mouse hover events. Includes the data node object (or null if hovering on background) as single argument.
onClick([fn]) Callback function for click events. Includes the data node object (or null if clicking on background) as single argument. A falsy value (default) automatically zooms on clicked nodes, equivalent to myChart.onClick(myChart.zoomToNode).
transitionDuration([number]) Getter/setter for the animation duration of transitions between states (opening, zoom in/out) in milliseconds. Enter 0 to disable animations. 800

Data syntax

{
  name: "root",
  children: [
    {
      name: "leafA",
      value: 3
    },
    {
      name: "nodeB",
      children: [
        {
          name: "leafBA",
          value: 5
        },
        {
          name: "leafBB",
          value: 1
        }
      ]
    }
  ]
}

Giving Back

paypal If this project has helped you and you'd like to contribute back, you can always buy me a โ˜•!

icicle-chart's People

Contributors

cantasura avatar vasturiano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

icicle-chart's Issues

Blurred text

The text in the slices blur when the cursor moves between levels. The blur get worse the more you are zoomed in.

This appears most prevalent in Chrome.

Setting the Size of the Node

Describe the bug
I am building an icicle chart, with 4 to 5 levels (columns), from left to right. The labels on the first 3 columns are much shorter (all <30 characters) than the labels on the 4th and 5th column (can be > 100 characters). I would like to adjust the width of these columns, by setting the first 3 column to have much less width than the 4th and 5th column.

Setting the width using a function in the .size() parameter does not seem to work as I expected. It changes the height of the cell in LR orientation, and not the width.

To Reproduce
Steps to reproduce the behavior:

  1. For ease, create a 3 (no need 5) column icicle chart. You can use my data sample
let data =  {
    "name": "root",
    "children": [
        {
            "name": "First Col",
            "children": [
                {
                    "name": "Second Col", 
                    "children": [
                        {"name": "Third Col 1", "value": 1}, 
                        {"name": "Third Col 2", "value": 1}, 
                        {"name": "Third Col 3", "value": 1}
                ]
            }
        ]
    }
]
}
  1. In the JavaScript script, put size parameter, a function that returns value according to which column it is, for example
Icicle()
    .data(data)
    .size(d =>  {
        if (d.name.substring(0,5) == 'First') {
            return 10
        } else if (d.name.substring(0, 5) == 'Secon') {
            return 10
        } else {
            return 300
        }
    })
    (document.getElementById('myDiv'));

Expected behavior
The width of the first and second column should be much less than the third column.

Screenshots
However, instead of changing the width, the height change.
This is the sizes without setting the .size() parameter
tmp_6snYCunvtr

This is the sizes after setting the .size() parameter
tmp_Dotl2Lw54k

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Safari, Chrome

Your help will be very appreciated! :)

Migration to ES Modules broke Jest unit testing

Describe the bug

The most recent change to this and other packages like kapsule, accessor-fn, float-tooltip, and probably some more, broke my unit-tests pipeline that uses Jest. Jest support for ES Modules is still in experimental phase so things are expected to break.

Details:

    /home/user/code/app/node_modules/float-tooltip/dist/float-tooltip.mjs:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { select, pointer } from 'd3-selection';
                                                                                      ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      3 | import React, { useEffect, useRef, useState } from "react";
      4 | import PropTypes from "prop-types";
    > 5 | import Icicle from "icicle-chart";
        | ^
      6 | import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
      7 | import {

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1605:14)
      at Object.<anonymous> (node_modules/icicle-chart/dist/icicle-chart.common.js:12:15)
      at Object.<anonymous> (lib/components/TreeMap/TreeMap.tsx:5:1)
      at Object.<anonymous> (lib/components/TreeMap/TreeMap.stories.tsx:6:1)
      at Object.<anonymous> (lib/components/TreeMap/TreeMap.test.tsx:5:1)

It's okay to migrate to ES Modules but if you are dropping support for CommonJS I believe that the best thing to do is to publish a new major version since this is most likely a breaking change.

Also, if someone knows how to fix this so that Jest is able to process these modules, please let me know.

Enable Normal Scrolling

Is your feature request related to a problem? Please describe.
The current behavior of the chart in Mac is that when there is a 'wheel' event, the chart will either zoom in or zoom out. 'Wheel'ing is usually used for scrolling in Mac laptop. Thus, I cannot scroll, I can only zoom in and out of the chart.

Describe the solution you'd like
I would like the chart to be able to support scrolling. What I have done is I change the 'wheeling' listener. If it is wheeled and the 'Ctrl' key is pressed, it will zoom in or out. Otherwise, it will scroll as per normal. In the code of 'wheeling', I just added a
if (even.ctrlKey) { _wheel implementation_ }
However, after zooming, I am unable to scroll around, I can only see several nodes, the nodes that are in the current zoom view.

I want it such that when I zoom in, the other node that are not in the view are still there and I can still scroll around it. I have been looking at the implementation but I cannot clearly find which part of the code sets and update the width of the nodes to 0 after the node has been kicked out from the current view.

Describe alternatives you've considered
Currently, after zooming in to a certain section, I need to zoom out, then scroll around again.

If you like the feature request, I can help to implement and change for you!

Thank you for your kind help!

Reset zoom on zoomed Node click

Hi there,
first of all thank you very much for this framework and also for the suburst-chart ๐Ÿ˜ ๐Ÿ‘
I would like to be able to reset the zoom when I click the same node again (see link below).

Maybe you could create a function where the return type is the zoomed node, then we could accomplish this feature with the click method.

Additional context
https://observablehq.com/@d3/zoomable-icicle (something like this maybe)

Best wishes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.