Giter Club home page Giter Club logo

d3plus-hierarchy's Introduction

d3plus-hierarchy

Nested, hierarchical, and cluster charts built on D3

Installing

If using npm, npm install d3plus-hierarchy. Otherwise, you can download the latest release from GitHub or load from a CDN.

import modules from "d3plus-hierarchy";

d3plus-hierarchy can be loaded as a standalone library or bundled as part of D3plus. ES modules, AMD, CommonJS, and vanilla environments are supported. In vanilla, a d3plus global is exported:

<script src="https://cdn.jsdelivr.net/npm/d3plus-hierarchy@1"></script>
<script>
  console.log(d3plus);
</script>

Examples

Live examples can be found on d3plus.org, which includes a collection of example visualizations using d3plus-react. These examples are powered by the d3plus-storybook repo, and PRs are always welcome. 🍻

API Reference


Donut <>

This is a global class, and extends all of the methods and functionality of Pie.

# new Donut()

Extends the Pie visualization to create a donut chart.


Pack <>

This is a global class, and extends all of the methods and functionality of Viz.

# new Pack()

Uses the d3 pack layout to creates Circle Packing chart based on an array of data.

# Pack.hover([value]) <>

If value is specified, sets the hover method to the specified function and returns the current class instance.

This is a static method of Pack, and is chainable with other methods of this Class.

# Pack.layoutPadding([value]) <>

If value is specified, sets the opacity accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current pack opacity accessor.

This is a static method of Pack.

# Pack.packOpacity([value]) <>

If value is specified, sets the padding accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current pack opacity accessor.

This is a static method of Pack.

# Pack.sort([comparator]) <>

If comparator is specified, sets the sort order for the pack using the specified comparator function. If comparator is not specified, returns the current group sort order, which defaults to descending order by the associated input data's numeric value attribute.

This is a static method of Pack.

function comparator(a, b) {
  return b.value - a.value;
}

# Pack.sum([value]) <>

If value is specified, sets the sum accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current sum accessor.

This is a static method of Pack.

function sum(d) {
  return d.sum;
}

Pie <>

This is a global class, and extends all of the methods and functionality of Viz.

# new Pie()

Uses the d3 pie layout to creates SVG arcs based on an array of data.

# Pie.innerRadius([value]) <>

If value is specified, sets the inner radius accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current inner radius accessor.

This is a static method of Pie.

# Pie.padAngle([value]) <>

If value is specified, sets the arc padding to the specified radian value and returns the current class instance. If value is not specified, returns the current radian padding.

This is a static method of Pie.

# Pie.padPixel([value]) <>

If value is specified, sets the arc padding to the specified pixel value and returns the current class instance. If value is not specified, returns the current pixel padding.

This is a static method of Pie.

# Pie.sort([comparator]) <>

If comparator is specified, sets the sort order for the pie slices using the specified comparator function. If comparator is not specified, returns the current sort order, which defaults to descending order by the associated input data's numeric value attribute.

This is a static method of Pie.

function comparator(a, b) {
  return b.value - a.value;
}

# Pie.value(value) <>

If value is specified, sets the value accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current value accessor.

This is a static method of Pie.

function value(d) {
  return d.value;
}

Tree <>

This is a global class, and extends all of the methods and functionality of Viz.

# new Tree()

Uses d3's tree layout to create a tidy tree chart based on an array of data.

# Tree.orient([value]) <>

If value is specified, sets the orientation to the specified value. If value is not specified, returns the current orientation.

This is a static method of Tree.

# Tree.separation([value]) <>

If value is specified, sets the separation accessor to the specified function. If value is not specified, returns the current separation accessor.

From the d3-hierarchy documentation:

The separation accessor is used to separate neighboring nodes. The separation function is passed two nodes a and b, and must return the desired separation. The nodes are typically siblings, though the nodes may be more distantly related if the layout decides to place such nodes adjacent.

This is a static method of Tree.

function separation(a, b) {
  return a.parent === b.parent ? 1 : 2;
}

Treemap <>

This is a global class, and extends all of the methods and functionality of Viz.

# new Treemap()

Uses the d3 treemap layout to creates SVG rectangles based on an array of data. See this example for help getting started using the treemap generator.

# Treemap.layoutPadding([value]) <>

If value is specified, sets the inner and outer padding accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current padding accessor.

This is a static method of Treemap.

# Treemap.sort([comparator]) <>

If comparator is specified, sets the sort order for the treemap using the specified comparator function. If comparator is not specified, returns the current group sort order, which defaults to descending order by the associated input data's numeric value attribute.

This is a static method of Treemap.

function comparator(a, b) {
  return b.value - a.value;
}

# Treemap.sum([value]) <>

If value is specified, sets the sum accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current sum accessor.

This is a static method of Treemap.

function sum(d) {
  return d.sum;
}

# Treemap.tile([value]) <>

Sets the tiling method used when calcuating the size and position of the rectangles.

Can either be a string referring to a d3-hierarchy tiling method, or a custom function in the same format.

This is a static method of Treemap.


Documentation generated on Wed, 25 Jan 2023 18:05:43 GMT

d3plus-hierarchy's People

Contributors

cnavarreteliz avatar davelandry avatar frabarz avatar greenkeeper[bot] avatar nbond211 avatar rbaheti avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

cherradii

d3plus-hierarchy's Issues

share thresholding and "other" grouping

Not sure if it exists yet in 2.0, but could be nice to have the ability to set a share threshold, like 0.5%, below which any boxes less than the threshold would automatically get grouped into an another box (perhaps that could could default to being called "Other" but would also be nice if user could set the name of the new group too)

Treemap Combining Groups

Expected Behaviour:

  • Treemap combines id's into it's parents. Each parent is separate from one another.
  • Hex color assignment are easily applied as per tutorials.

Current Map

  • Executing treemap results in combining of several parents
  • Hex color's are not assigned

Steps to Reproduce (for bugs)

Example Data

var data = [
        { parent: "Animal Products",
            id: "Horses",
            value: 27237745.0,
            color: "#F2AA86",
            image: "/images/icons/hs/hs_1.svg",
        },
        { parent: "Animal Products",
            id: "Horses",
            value: 27237745.0,
            color: "#F2AA86",
            image: "/images/icons/hs/hs_1.svg",
        },
.....]

Code as it exists:

function currency(x){
        if (x >= 1e9){
          return "$" + (x/1e9).toFixed(2).toString() + " Billion (USD)";
        } else if ( x < 1e9 && x >= 1e6 ){
          return "$" + (x/1e6).toFixed(2).toString() + " Million USD";
        } else {
          return "$" + (x).toFixed(2).toString() + " (USD)";
        }
      }
      new d3plus.Treemap()
        .data(data)
        .config({
          threshold: 0.0,
        })
        .tooltipConfig({
          body: function(d){
            var table = "<table class='tooltip-table'>";
            table+="<tr><td class='title'>Section:</td><td class='data'>" + d.parent + "</td></tr>";
            table+="<tr><td class='title'>HS4:</td><td class='data'>" + d.id + "</td></tr>";
            table+="<tr><td class='title'>AB Exports:</td><td class='data'>" + currency(d.value) + "</td></tr>";
            table+="</table>";
            return table;
          }
        })
        .groupBy(["parent","id"])
        .legend(true)
        .legendConfig({
          shapeConfig: {
            opacity: 0,
            fill: function(d) { console.log(d.color); return d.color; },
            width: 30,
            height: 30,
            backgroundImage: function(d) {
              if (d.image.length == 2) {
                return d.image.slice(-1)[0]
              } else {
                return d.image;
              }
            },
          },
          label: false
        })
        .sum("value")
        .select("#treemap")
        .render();

Your Environment

  • Browser Name: Chrome
  • Operating System and Version: Win 10

pack visualization

This will be a recreation of the d3plus 1.0 bubbles visualization, renaming to "Pack" to be more inline with the d3 algorithm: https://github.com/d3/d3-hierarchy#pack

When there are multiple parent groups, as in that old example, each parent group should be placed in the optimal number of rows and columns (with the pack algorithm running for the circles inside each group separately). This will allow large numbers of parent groups to be displayed as a grid, as used in DataViva. Here is the old logic (sorry for the coffeescript 😬): https://github.com/alexandersimoes/d3plus/blob/master/src/viz/types/bubbles.coffee#L13-L23

An in-range update of d3plus-common is breaking the build 🚨

Version 0.6.15 of d3plus-common just got published.

Branch Build failing 🚨
Dependency d3plus-common
Current Version 0.6.14
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As d3plus-common is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Release Notes v0.6.15
  • updates d3-array to v1.1.1 (6f44c40)
  • fix(package): update i18next to version 7.1.2 (#72) (ef501ca)
  • chore(package): update d3plus-dev to version 0.3.1 (#71) (4ee5c5d)
Commits

The new version differs by 4 commits .

  • 6f44c40 updates d3-array to v1.1.1
  • ef501ca fix(package): update i18next to version 7.1.2 (#72)
  • 4ee5c5d chore(package): update d3plus-dev to version 0.3.1 (#71)
  • e93f795 compiles v0.6.14

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of d3-array is breaking the build 🚨

Version 1.0.3 of d3-array just got published.

Branch Build failing 🚨
Dependency d3-array
Current Version 1.0.2
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As d3-array is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details
Release Notes v1.0.3
  • Update dependencies.
Commits

The new version differs by 6 commits .

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

show pie chart labels by default

Expected Behavior

Show pie chart labels by default

Current Behavior

It doesn't show label by default and it changes legend labels when label is set to a value.

Steps to Reproduce (for bugs)

http://jsfiddle.net/xbneck43

Your Environment

  • Browser Name: Chrome
  • Operating System and Version: macOS High Sierra

"l" variable collision with user data

If the user uses l as a key in their data objects, d3plus will collide with this variable and use it to determine the offset height of a text box in a tree map.

before (with l variable collision):
Screen-Shot-2019-05-14-at-3 44 40-PM

after (removing l variable from user supplied data):
Screen-Shot-2019-05-14-at-3 44 40-PM

dynamic depth in TreeMap

Hello,
I used d3plus v1 to create a treeMap where I can change the depth dynamically through a drop down list below the treemap (.ui) like the following example:

<script src="//d3plus.org/js/d3.js"></script> <script src="//d3plus.org/js/d3plus.js"></script>
var sample_data = [ {"value": 100, "name": "alpha","category":"A", "weight": 80}, {"value": 70, "name": "beta","category":"A", "weight": 43}, {"value": 40, "name": "gamma","category":"A", "weight": 64}, {"value": 15, "name": "delta","category":"B", "weight": 20}, {"value": 5, "name": "epsilon","category":"A", "weight": 92}, {"value": 1, "name": "zeta","category":"B", "weight": 35} ];

var visualization = d3plus.viz()
.container("#viz")
.data(sample_data)
.type("tree_map")
.id(["category","name"])
.color("category")
.size("value")
.ui([
{
"method" : "depth",
"type": "drop",
"value":[{"category":0},{"name":1}]
}
])
.draw();

https://jsfiddle.net/f670s3co/

I even use the same logic to change dynamically the color, size and even type (treemap, pie bubble)
I'm passing now to d3plus v2 but I can't reproduce the same behaviour , Can we do the same in version 2? what is equivalant to ".ui" and how do we use it?
Thank you

An in-range update of d3-scale is breaking the build 🚨

Version 1.0.5 of d3-scale just got published.

Branch Build failing 🚨
Dependency d3-scale
Current Version 1.0.4
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As d3-scale is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Release Notes v1.0.5
  • Update dependencies.
Commits

The new version differs by 2 commits .

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

threshold does not apply for top-level groupBy

Take this config as an example:

const url = "https://api.oec.world/tesseract/data.jsonrecords?Inventor+Country=nausa&Year=2019&cube=patents_i_uspto_w_cpc&drilldowns=Organization&measures=Patent+Share&parents=false&sparse=false";

new d3plus.Treemap()
  .data(url, resp => resp.data)
  .config({
    "type": "Treemap",
    "groupBy": "Organization ID",
    "shapeConfig": {fill: "#3D8E9C"},
    "sum": "Patent Share",
    "thresholdKey": "Patent Share"
  })
  .render();

But if I add an artificial parent level, it groups the rectangles correctly:

"groupBy": [() => "Parent", "Organization ID"],

thresholdByDepth function linting errors

@frabarz the new thresholdByDepth function has multiple linting errors, one of them having to do with moving the function to root. This will need a little but of refactoring, which I'd rather have you do (rather than me).

An in-range update of d3plus-dev is breaking the build 🚨

The devDependency d3plus-dev was updated from 0.6.8 to 0.6.9.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

d3plus-dev is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v0.6.9
Commits

The new version differs by 9 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of d3plus-viz is breaking the build 🚨

Version 0.6.3 of d3plus-viz just got published.

Branch Build failing 🚨
Dependency d3plus-viz
Current Version 0.6.2
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As d3plus-viz is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details
Release Notes v0.6.3
  • updates d3plus dependencies (610eb84)
Commits

The new version differs by 2 commits .

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

multiple labels visible in nested Pack chart

Expected Behavior

All visualizations should support click-through nesting.

Current Behavior

It looks as though the labels for all depths are being displayed on top of eachother.

Steps to Reproduce (for bugs)

http://jsfiddle.net/ge5cjs6u/

Your Environment

  • Browser Name: Chrome
  • Operating System and Version: macOS Mojave

legend tooltips show N/A share percentage

@cnavarreteliz

Create a treemap with this dummy data:

parent,id,value,icon,color
Group 1,alpha,29,https://datausa.io/static/images/attrs/thing_apple.png,cornflowerblue
Group 1,beta,10,https://datausa.io/static/images/attrs/thing_apple.png,cornflowerblue
Group 1,gamma,2,https://datausa.io/static/images/attrs/thing_apple.png,cornflowerblue
Group 2,delta,29,https://datausa.io/static/images/attrs/thing_fish.png,firebrick
Group 2,eta,25,https://datausa.io/static/images/attrs/thing_fish.png,firebrick

then the share will be ok except for the legend that shows NA:

Screenshot from 2019-07-15 19-44-32

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.