Skip to content

Commit

Permalink
feat(chord): improve @nivo/chord package
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed Apr 23, 2019
1 parent 99c7f6b commit 51a58c1
Show file tree
Hide file tree
Showing 26 changed files with 1,713 additions and 764 deletions.
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,23 @@ package-tslint-%: ##@1 packages run tslint on package
packages-tslint: ##@1 packages run tslint on all packages
@echo "${YELLOW}Running tslint on all packages${RESET}"
@./node_modules/.bin/tslint \
./packages/annotations/index.d.ts \
./packages/annotations/index.d.ts \
./packages/axes/index.d.ts \
./packages/bar/index.d.ts \
./packages/calendar/index.d.ts \
./packages/colors/index.d.ts \
./packages/chord/index.d.ts \
./packages/colors/index.d.ts \
./packages/core/index.d.ts \
./packages/geo/index.d.ts \
./packages/geo/index.d.ts \
./packages/heatmap/index.d.ts \
./packages/legends/index.d.ts \
./packages/line/index.d.ts \
./packages/pie/index.d.ts \
./packages/radar/index.d.ts \
./packages/radar/index.d.ts \
./packages/sankey/index.d.ts \
./packages/scales/index.d.ts \
./packages/scatterplot/index.d.ts \
./packages/swarmplot/index.d.ts \
./packages/waffle/index.d.ts

package-test-cover-%: ##@1 packages run tests for a package with code coverage
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"devDependencies": {
"@babel/core": "^7.4.0",
"@ekino/config": "^0.3.0",
"@nivo/babel-preset": "0.55.0",
"@nivo/generators": "0.55.0",
"@nivo/babel-preset": "latest",
"@nivo/generators": "latest",
"@storybook/addon-actions": "^5.0.3",
"@storybook/addon-info": "^5.0.3",
"@storybook/addon-knobs": "^5.0.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/chord/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

[documentation](http://nivo.rocks/chord)

![Chord](./doc/chord.png)
![Chord](https://raw.githubusercontent.com/plouc/nivo/master/packages/chord/doc/chord.png)

## ChordCanvas

[documentation](http://nivo.rocks/chord/canvas)

![ChordCanvas](./doc/chord-canvas.png)
![ChordCanvas](https://raw.githubusercontent.com/plouc/nivo/master/packages/chord/doc/chord-canvas.png)
104 changes: 104 additions & 0 deletions packages/chord/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* This file is part of the nivo project.
*
* Copyright 2016-present, Raphaël Benitte.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Component } from 'react'
import { Box, MotionProps, Dimensions, Theme } from '@nivo/core'
import { OrdinalColorsInstruction, InheritedColorProp } from '@nivo/colors'

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>

declare module '@nivo/chord' {
export interface ArcData {
id: string
index: number
label: string
value: number
formattedValue: number | string
startAngle: number
endAngle: number
color: string
}

export interface RibbonSubject extends ArcData {
subindex: number
}

export interface RibbonData {
id: string
source: RibbonSubject
target: RibbonSubject
}

export type ChordArcMouseHandler = (arc: ArcData, event: React.MouseEvent<any>) => void

export type ChordRibbonMouseHandler = (ribbon: RibbonData, event: React.MouseEvent<any>) => void

type LabelAccessor = (datum: Omit<ArcData, 'label'>) => string
type ValueFormatter = (datum: Omit<ArcData, 'formattedValue' | 'label'>) => string | number

interface CommonChordProps {
keys: string[]
matrix: number[][]
label?: string | LabelAccessor
valueFormat?: string | ValueFormatter

margin?: Box

padAngle?: number
innerRadiusRatio?: number
innerRadiusOffset?: number

layers: any[]

colors?: OrdinalColorsInstruction
theme?: Theme

arcOpacity?: number
arcHoverOpacity?: number
arcHoverOthersOpacity?: number
arcBorderWidth?: number
arcBorderColor?: InheritedColorProp
onArcMouseEnter?: ChordArcMouseHandler
onArcMouseMove?: ChordArcMouseHandler
onArcMouseLeave?: ChordArcMouseHandler
onArcClick?: ChordArcMouseHandler
arcTooltip?: any

ribbonOpacity?: number
ribbonHoverOpacity?: number
ribbonHoverOthersOpacity?: number
ribbonBorderWidth?: number
BorderColor?: InheritedColorProp

enableLabel?: boolean
labelOffset?: number
labelRotation?: number
labelTextColor?: InheritedColorProp

isInteractive?: boolean
}

export type ChordProps = CommonChordProps &
MotionProps & {
onRibbonMouseEnter?: ChordRibbonMouseHandler
onRibbonMouseMove?: ChordRibbonMouseHandler
onRibbonMouseLeave?: ChordRibbonMouseHandler
onRibbonClick?: ChordRibbonMouseHandler
ribbonTooltip?: any
}

export class Chord extends Component<ChordProps & Dimensions> {}
export class ResponsiveChord extends Component<ChordProps> {}

export type ChordCanvasProps = CommonChordProps & {
pixelRatio?: number
}

export class ChordCanvas extends Component<ChordCanvasProps & Dimensions> {}
export class ResponsiveChordCanvas extends Component<ChordCanvasProps> {}
}
5 changes: 2 additions & 3 deletions packages/chord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
"files": [
"README.md",
"LICENSE.md",
"index.d.ts",
"dist/"
],
"dependencies": {
"@nivo/colors": "0.56.0",
"@nivo/core": "0.56.0",
"@nivo/legends": "0.56.0",
"d3-chord": "^1.0.6",
"d3-format": "^1.3.2",
"d3-shape": "^1.3.5",
"lodash": "^4.17.11",
"react-motion": "^0.5.2",
"recompose": "^0.30.0"
"react-motion": "^0.5.2"
},
"peerDependencies": {
"prop-types": ">= 15.5.10 < 16.0.0",
Expand Down
Loading

0 comments on commit 51a58c1

Please sign in to comment.