Giter Site home page Giter Site logo

Comments (4)

curran avatar curran commented on July 16, 2024

Hello,

I recently came across a similar issue in chiasm-charts. I wanted to have a "bar chart" module that would work both as a typical bar chart (using ordinal rangeBands) and also as a histogram (using bars with zero padding in conjunction with a linear scale). I ended up adding the specification of the interval between histogram bins into the dataset specification, so the bar chart module can read that data to know how wide to make the bars of a histogram.

Here's the solution I ended up with in code, found in mixins.rangeBands:

  if(metadata.interval){

    // Histogram bins.
    my[rangeBand] = Math.abs( scale(metadata.interval) - scale(0) );
  } else {

    // Typical ordinal bars.
    my[rangeBand] = scale.rangeBand();
  }

Here's an example that shows the bar chart mode and histogram mode working next to one another: Chiasm-Charts v0.1.0.

thumbnail

I'm excited to come across your project! It looks we are exploring similar territory.

from d3.compose.

timhall avatar timhall commented on July 16, 2024

@curran Thanks for the reference, lots of interesting things happening in the chiasm-project. I had been figuring an explicit width was the best approach (especially in your histogram example where there are plenty of empty bands that would throw off most calculations). I'll have to think about how to best integrate it, but it looks like a good direction to me.

from d3.compose.

curran avatar curran commented on July 16, 2024

Indeed, the empty bands throw off any approach where you could try to guess the widths. This is something I only really understood after studying this example, which really boils it down with straight D3 - Heatmap (2D Histogram, CSV).

from d3.compose.

timhall avatar timhall commented on July 16, 2024

(From #45) Some possible solutions:

  1. Specify an interval for the chart and calculate the width from that
  2. Specify the data length and calculate the width from this (automatically determining is difficult since the data could be sparse)
  3. Use the linear/time scale to specify the domain for an ordinal scale

I think an interval solution will work and I've been investigating how best to add it, but I think the best solution is to create an ordinal scale from the given linear/time scale:

// Use linear/time scale to define ticks for ordinal
var xScale = d3.scale.linear().domain([0, 50]);
var xScaleOrdinal = d3.scale.ordinal().domain(xScale.ticks(10));
// => pass ordinal to bars

from d3.compose.

Related Issues (8)

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.