spiermar / d3-flame-graph

A D3.js plugin that produces flame graphs from hierarchical data.
Apache License 2.0
880 stars 119 forks source link

Allow passing comparators to flamegraph.sort #188

Closed nickgirardo closed 2 years ago

nickgirardo commented 3 years ago

I've added a third overload for sort to the type definitions. This definition allows passing in a comparator function.

You can see an example of this in the existing examples. While this works fine, the TypeScript definitions only allowed for passing no args or a boolean in.

You will notice this is a simple comparator function, similar to those used by d3 array in its type definitions. Notice that I've bound the generic variable T here to StackFrame. I'm not 100% sure that's correct. If other things besides StackFrames could be passed as arguments to sort, we can modify it or keep it generic.

spiermar commented 2 years ago

Thank you @nickgirardo! Good catch! A generic variable would be preferable here I believe. I have a few cases where a modified string is passed.