nicolaskruchten / pivottable

Open-source Javascript Pivot Table (aka Pivot Grid, Pivot Chart, Cross-Tab) implementation with drag'n'drop.
https://pivottable.js.org/
MIT License
4.35k stars 1.08k forks source link

Get Full Data-Record by Datum & Trace-Key #1282

Open Gykonik opened 3 years ago

Gykonik commented 3 years ago

Is there a possibility to get (all) full data records gievn a datum and trace key? I want to create custom hover-templates for plotly-charts, which contain all available information about the data entry (and not only those ones dragged in the horizontal & vertical pivot-list). For this, my idea was to somehow modify this code inside of poltly_renderers.js:

for (j = 0, len = datumKeys.length; j < len; j++) {
    datumKey = datumKeys[j];
    val = parseFloat(pivotData.getAggregator(transpose ? datumKey : traceKey, transpose ? traceKey : datumKey).value());

    // Get the complete entry object(s) which belong to 'val, datumKey & traceKey' in here somehow...?
    // Then, a hover template with all keys & values of the object could be generated

    values.push(isFinite(val) ? val : null);
    labels.push(datumKey.join('-') || ' ');
}

I thought about using forEachMatchingRecord but I was unable to find the correct filters to only get the objects which contribute to the exact cell-value (note that the solution of using click-callback recommended in other issues doesn't work here, because I need to extract the relevant data inside of plotly_renderers.js)

Gykonik commented 3 years ago

@nicolaskruchten Are there any news yet / was my question understandable? (If you just had no time until now, no problem - I'm just curious :) )