nivo icon indicating copy to clipboard operation
nivo copied to clipboard

feat(choropleth): add defs and fill capabilities

Open francescocretti opened this issue 2 years ago • 1 comments

Background

Event if it's in the documentation, the usage of defs and fill was missing its implementation in the Choropleth Map component.

This PR adds this features, addressing issues #2068 (and the old #864) and, with a little workaround, also the first question of #2064 (it's enough to define a gradient with the same starting and ending color to achieve what was asked).

Changelog

As was done in other components, now the Choropleth component read the defs and fill, uses the bindDefs method to bind them to the data, and pass them to the SvgWrapper component. Then, each map features check is there's a fill property defined. If so it uses as fill color, otherwise it uses the calculated color.

Example

This PR also adds three example patterns to the Nivo Website:

defs: [
  patternDotsDef('dots', {
      background: 'inherit',
      color: '#38bcb2',
      size: 4,
      padding: 1,
      stagger: true,
  }),
  patternLinesDef('lines', {
      background: 'inherit',
      color: '#eed312',
      rotation: -45,
      lineWidth: 6,
      spacing: 10,
  }),
  linearGradientDef('gradient', [
      { offset: 0, color: '#000' },
      { offset: 100, color: 'inherit' },
  ]),
],

fill: [
  { match: { id: 'CAN' }, id: 'dots' },
  { match: { id: 'CHN' }, id: 'lines' },
  { match: { id: 'ATA' }, id: 'gradient' },
]

Schermata del 2022-07-11 15-48-15

francescocretti avatar Jul 11 '22 13:07 francescocretti

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ed38ef05ea4336f03cc08f739ae805872df99893:

Sandbox Source
nivo Configuration

codesandbox-ci[bot] avatar Jul 11 '22 14:07 codesandbox-ci[bot]

Thank you for your contribution @francescocretti !

plouc avatar Sep 08 '22 22:09 plouc

Hi Guys, I am getting this Typescript compile error: Property 'defs' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<ResponsiveChoropleth> & Readonly<ChoroplethProps> & Readonly<...>'. TS2769

Seems the defs property was not defined in the ChoroplethCommonProps

syengo254 avatar Sep 26 '22 10:09 syengo254

Hi @plouc, I was able to create a workaround for this, but my builds fail. Can you explain how to execute this the intended way since the website only shows the outdated way? Thank you.

officiallyakshay avatar Feb 25 '23 01:02 officiallyakshay