vasturiano / timelines-chart

Timelines Chart
http://vasturiano.github.io/timelines-chart/example/categorical/
MIT License
558 stars 121 forks source link

Allow a tooltip callback to be registered #25

Closed jeffvarga closed 4 years ago

jeffvarga commented 5 years ago

Would it be possible to register a custom callback for tooltips? Often a data payload can have more data ('val' has a direct correlation to the colorScale, so I can't overload it with more specific event data) and it would be useful to be able to put arbitrary information into the tooltip like so:

TimelinesChart()
  .width(1582)
  .data(data)
  .segmentTooltip(function() {
    return d3Tip()
        .attr('class', 'chart-tooltip segment-tooltip')
        .direction('s')
        .offset([5, 0])
        .html(d => {
            /* my stuff here */
            return "<...>" + d.arbitraryVariable + "...";
          });
  })
  (document.getElementById('myPlot'));
Steve-Pegg commented 5 years ago

Add arbitrary data to labelVal and it will appear in the tooltip instead of val.