-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(arcs): introduce @nivo/arcs package
- Loading branch information
Showing
17 changed files
with
232 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) Raphaël Benitte | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `@nivo/arcs` | ||
|
||
[![version](https://img.shields.io/npm/v/@nivo/arcs.svg?style=flat-square)](https://www.npmjs.com/package/@nivo/arcs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "@nivo/arcs", | ||
"version": "0.66.0", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Raphaël Benitte", | ||
"url": "https://github.com/plouc" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/plouc/nivo.git", | ||
"directory": "packages/arcs" | ||
}, | ||
"keywords": [ | ||
"nivo", | ||
"dataviz", | ||
"react", | ||
"d3", | ||
"arcs" | ||
], | ||
"main": "./dist/nivo-arcs.cjs.js", | ||
"module": "./dist/nivo-arcs.es.js", | ||
"typings": "./dist/types/index.d.ts", | ||
"files": [ | ||
"README.md", | ||
"LICENSE.md", | ||
"dist/", | ||
"!dist/tsconfig.tsbuildinfo" | ||
], | ||
"dependencies": { | ||
"d3-shape": "^1.3.5", | ||
"react-spring": "9.0.0-rc.3" | ||
}, | ||
"devDependencies": { | ||
"@nivo/core": "0.66.0", | ||
"@types/d3-shape": "^2.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@nivo/core": "0.66.0", | ||
"react": ">= 16.8.4 < 18.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './types' | ||
export * from './useAnimatedArc' | ||
export * from './useArcGenerator' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Arc as D3Arc } from 'd3-shape' | ||
|
||
export interface Arc { | ||
// start angle in radians | ||
startAngle: number | ||
// end angle in radians | ||
endAngle: number | ||
// inner radius in pixels | ||
innerRadius: number | ||
// outer radius in pixels | ||
outerRadius: number | ||
} | ||
|
||
export interface DatumWithArc { | ||
arc: Arc | ||
} | ||
|
||
export type ArcGenerator = D3Arc<any, Arc> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { to, useSpring } from 'react-spring' | ||
import { useMotionConfig } from '@nivo/core' | ||
import { Arc, ArcGenerator } from './types' | ||
|
||
export const useAnimatedArc = (datumWithArc: { arc: Arc }, arcGenerator: ArcGenerator) => { | ||
const { animate, config: springConfig } = useMotionConfig() | ||
|
||
const animatedValues = useSpring({ | ||
startAngle: datumWithArc.arc.startAngle, | ||
endAngle: datumWithArc.arc.endAngle, | ||
innerRadius: datumWithArc.arc.innerRadius, | ||
outerRadius: datumWithArc.arc.outerRadius, | ||
config: springConfig, | ||
immediate: !animate, | ||
}) | ||
|
||
return { | ||
...animatedValues, | ||
path: to( | ||
[ | ||
animatedValues.startAngle, | ||
animatedValues.endAngle, | ||
animatedValues.innerRadius, | ||
animatedValues.outerRadius, | ||
], | ||
(startAngle, endAngle, innerRadius, outerRadius) => | ||
arcGenerator({ | ||
startAngle, | ||
endAngle, | ||
innerRadius, | ||
outerRadius, | ||
}) | ||
), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useMemo } from 'react' | ||
import { arc as d3Arc } from 'd3-shape' | ||
import { ArcGenerator, Arc } from './types' | ||
|
||
export const useArcGenerator = ({ cornerRadius = 0 }: { cornerRadius: number }): ArcGenerator => | ||
useMemo( | ||
() => | ||
d3Arc<Arc>() | ||
.innerRadius(arc => arc.innerRadius) | ||
.outerRadius(arc => arc.outerRadius) | ||
.cornerRadius(cornerRadius), | ||
[cornerRadius] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfig.types.json", | ||
"compilerOptions": { | ||
"outDir": "./dist/types", | ||
"rootDir": "./src" | ||
}, | ||
"include": ["src/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.