pat310 / quick-pivot

Quickly format data to create a pivot table
https://www.npmjs.com/package/quick-pivot
MIT License
64 stars 21 forks source link

Should pivot.getUniqueValues return unique values of the current pivot or original? #50

Closed turnerniles closed 7 years ago

turnerniles commented 7 years ago

When adding a filter on a certain dimension and then going back to edit that same filter, I need access to all the original unique values associated with that dimension. I am keeping track of the selected values associated with the dimension in order to filter the data using those values and could add them back into the list of values to select from; however, I would not be able to maintain the original order of values to select from unless I alphabetized strings and sorted numbers from the start. Which perhaps we should do... Other pivots seem to.

Below is an example of the current implementation, where pivot.getUniqueValues returns the unique values based on the current pivot?

const dataArray = [ ['name', 'gender', 'house', 'age'], ['Jon', 'm', 'Stark', 14], ['Arya', 'f', 'Stark', 10], ['Cersei', 'f', 'Baratheon', 38], ['Tywin', 'm', 'Lannister', 67], ['Tyrion', 'm', 'Lannister', 34], ['Joffrey', 'm', 'Baratheon', 18], ['Bran', 'm', 'Stark', 8], ['Jaime', 'm', 'Lannister', 32], ['Sansa', 'f', 'Stark', 12] ];

const pivot = new pivot(dataArray, ['gender'], [], 'age', 'sum');

pivot.getUniqueValues('gender') -> ["m", "f"]

pivot.filter('gender', ['m'], 'exclude') pivot.getUniqueValues('gender') -> ["f"]