kurkle / chartjs-chart-treemap

Chart.js module for creating treemap charts
MIT License
139 stars 34 forks source link

Enable sumKeys option to sum more than one key when data are grouped #144

Closed stockiNail closed 1 year ago

stockiNail commented 2 years ago

Fix #47

New sumKeys option could be an array of keys of the objects used in tree and consumed grouping the data. The result of sums of these additional keys will be stored in data object in vs key as object, where the keys are the same that sumKeys option has provided.

{
  "x": 0,
  "y": 32,
  "w": 714,
  "h": 682,
  "a": 486948,
  "v": 50,
  "vs": {
    "pop": 40
  },
  "s": 50,
  "g": "A",
  "l": 0
}

TODO

kurkle commented 2 years ago

How about just allowing an array as key? And internally, just make it always be an array, so the calculation is cleaner. Just a thought, does not have to be that way.

stockiNail commented 2 years ago

I thought to use ah array but in this case we must assume the first element of the array is the key to use for grouping and drawing. Personally I dont like this convention based on the position of an element in an array. I will have a look anyway next week if is not urgent

kurkle commented 2 years ago

The "position 1" convention can be kept internal and should only be used if the code is cleaner that way. Maybe sumKeys would be better name for it? Or additionalSumKeys.

stockiNail commented 1 year ago

Maybe sumKeys would be better name for it? Or additionalSumKeys.

Done, in sumKeys.

stockiNail commented 1 year ago

The "position 1" convention can be kept internal and should only be used if the code is cleaner that way.

Let me review better the code in order to merge key and sumKeys in an array (and then arguments for all other functions which are receiving that).

EDIT: apologize but I need more time to do something "good" enough" ;)

stockiNail commented 1 year ago

@kurkle when you have time, can you have a look if sounds better now? PR is still in draft.