antvis / G2Plot

:dango: An interactive and responsive charting library based on G2.
https://g2plot.antv.antgroup.com
MIT License
2.56k stars 607 forks source link

Treemap sort does not works as expected #2338

Closed calebeaires closed 3 years ago

calebeaires commented 3 years ago

Trying to sort treemap in a way that the name A goes to the first position from top to bottom. Sort function of hierarchyConfig does not work as it should work.

image


import { Treemap } from '@antv/g2plot';

const data = {
  name: 'root',
  children: [

    { name: 'a', value: 9 },
    { name: 'b', value: 8 },
    { name: 'c', value: 7 },
    { name: 'd', value: 6 },
    { name: 'e', value: 5 },
    { name: 'f', value: 4 },
    { name: 'g', value: 10 },

  ],
};

const treemapPlot = new Treemap('container', {
  data,
  colorField: 'name',

  hierarchyConfig: {
    field: 'value',
    tile: 'treemapSquarify',
        sort: () => 1,
      }
});

treemapPlot.render();
hustcc commented 3 years ago

sort config is supported in #2337, new version will be released recently.

You can try it by clone code and run npm start.