krispo / angular-nvd3

AngularJS directive for NVD3 reusable charting library (based on D3). Easily customize your charts via JSON API.
http://krispo.github.io/angular-nvd3
MIT License
1.29k stars 377 forks source link

Tooltip headerFormatter is ignored #644

Open thany opened 7 years ago

thany commented 7 years ago

I've got a graph with tooltips, and I want to format a tooltip header differently than what's on the X-axis. This is not possible, because tooltip.headerFormatter is being ingored. It always uses xAxis.tickFormat.

Example config:

const options = {
  chart: {
    type: "lineChart",
    clipEdge: true,
    duration: 500,
    xAxis: {
      tickFormat: d => moment.unix(d).format(timeFormatter),
    },
    yAxis: {
      axisLabelDistance: -20,
      tickValues: [ 0, 1200 ]
    },
    showControls: false,
    showLegend: false,
    tooltip: {
      headerFormatter: time => moment.unix(time).format("D MMM H:mm"),
      keyFormatter: key => PARAMETERS[key].title
    }
  }
};

The headerFormatter function isn't even called. Not once. Incidentally, keyFormatter isn't called either. Not once. valueFormatter has the same problem (not included above). Is there a problem with tooltip config alltogether? What's going on?

It also doesn't work when trying out the same functions in one of the examples.

Versions: AngularJS 1.6.2 Angular-NVD3 1.0.9 NVD3 1.8.5 D3 3.5.17

thany commented 7 years ago

In fact none of the options under tooltip do anything at all, even in the examples. All of them.

I'm no expert on nvd3 or anything, but, maybe this is freaking important? Some folks might not want a tooltip at all, and right now it's impossible to even disable it.

Cameron485 commented 7 years ago

Turns out if you have useInteractiveGuideline set to true then the you must set your headerFormatter inside the interactiveLayer tooltip.

interactiveLayer: {
  tooltip: {
    headerFormatter(d) {
      return d3.time.format('%b %-d, %Y %I:%M%p')(new Date(d));
    }
  }
}
thany commented 7 years ago

It shouldn't be so complicated. Without this weirdness, it's complicated enough as it is.

I say this is a bug.