Search code examples
javascriptd3.jscal-heatmap

Cal-HeatMap - How to format date and value in subDomainText cell


I'm trying to include both Date and Value in the same cell using Cal-HeatMap

Here is a fiddle example of what I'm trying to do ....

[https://jsfiddle.net/paulrollings/6L36ajhn/12/][2]

Any advice help greatly appreciated. Thanks Paul


Solution

  • You could hack it in after CalHeatMap renders:

    // wrap in timeout to let map render
    setTimeout(function(){
      var t = d3.selectAll('.subdomain-text') // find all the text blocks
        .text(null); // blank them out
      t.append('tspan')
        .text(function(d){
          return new Date(d.t).getDate(); //append tspan with date
        })
        .attr('x', function(d){
          return d3.select(this.parentNode).attr('x'); // steal parent x value so it stays in place
        });
      t.append('tspan')
        .text(function(d){
          return "€" + d.v; //append tspan with value
        })
        .attr('dy','1.2em')
        .attr('x', function(d){
          return d3.select(this.parentNode).attr('x'); // steal parent x value so it stays in place
        });
    }, 100);
    

    Updated fiddle here.

    enter image description here