PMSI-AlignAlytics / dimple

An object-oriented API for business analytics
Other
2.73k stars 557 forks source link

Question - Is there a way to access the original data in `getTooltipText`? #152

Closed andrewjmead closed 9 years ago

andrewjmead commented 9 years ago

Goal

I would like to pass some extra data along to dimple for display in the tooltip.

Right now I show the number of products on the shelf and the time at which they were counted. I would also like to show other data in the hover tooltip, specifically the name of the person who counted the product on the shelf.

Issue

The callback for getTooltipText only gets back a event which does not seem to contain the original data. I went into the dimple source to see if the original data could be added to the event, but I was unable to find it in the event stack. I know I could do a lookup in my original array for data with the same x,y values, but there it needs to take into account data with the same count/timestamp.

Any other suggestions on how I could do this?

johnkiernander commented 9 years ago

Because dimple does aggregation on the dataset, it ignores any fields which do not form part of its definition of a data point. In your case you need to include any additional fields you would like to reference in the first parameter of the series. For example if I had a bar chart of SKUs and sales volume:

var c = new dimple.chart(svg, data);
c.addCategoryAxis("x", "SKU");
c.addMeasureAxis("y", "Sales Volume");
c.addSeries(null, dimple.plot.bar);
c.draw();

And I wanted to add brand owner, brand, price tier and pack size in the tool tip I would define it using the first parameter of the addSeries. NB. One caveat here is that the last element of an array passed in here is used to define colours, so in the example below I pass an empty string to ensure all bars continue to be coloured the same. I could choose any of the other values, or SKU depending on the effect I want to achieve.

var c = new dimple.chart(svg, data);
c.addCategoryAxis("x", "SKU");
c.addMeasureAxis("y", "Sales Volume");
c.addSeries(["Brand Owner", "Brand", "Price Tier", "Pack Size", ""], dimple.plot.bar);
c.draw();

This will add those fields into the default tooltip and also make them available should you wish to use them in a custom tooltip.

andrewjmead commented 9 years ago

@johnkiernander Thanks for replying, that was super useful information. I was able to get the data (persons name) to show up in e.aggField[0].

One last question if you could. When I add that name data, if the data different it is not connected by the dimple line. Example

Before adding name data:

After adding name data:

In this case all the other black points have "John" as the name, and that last point has "Jane" as the name. Any idea how I could get the line to still connect them (they're still the same series).