Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New types and TypeScript test for Pie component #216

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/nivo-pie/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"index.d.ts",
"cjs/"
],
"types": "./types/index.d.ts",
"dependencies": {
"@nivo/core": "0.36.0",
"@nivo/legends": "0.35.2",
Expand All @@ -18,6 +19,7 @@
"recompose": "^0.26.0"
},
"peerDependencies": {
"@types/react": ">=16.3.16 < 17.0.0",
"prop-types": "^15.5.10",
"react": ">= 16.2.0 < 17.0.0"
},
Expand Down
73 changes: 57 additions & 16 deletions packages/nivo-pie/index.d.ts → packages/nivo-pie/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
declare module '@nivo/pie' {
import * as React from 'react';
import * as CSS from 'csstype';

export class Pie extends React.Component<Data & PieProps & Dimensions>{ }
export class ResponsivePie extends React.Component<Data & PieProps>{ }

Expand All @@ -23,13 +26,13 @@ declare module '@nivo/pie' {

export type Legend = {

data: Array<{ label: string | number; fill: string; }>;
data?: Array<{ id: string | number; value: number; }>; //injected

// position & layout
anchor: Anchor;

translateX: number; // default 0
translateY: number; // default 0
translateX?: number; // default 0
translateY?: number; // default 0
direction: LegendDirection;

// items
Expand All @@ -45,9 +48,9 @@ declare module '@nivo/pie' {

export interface PieDataItem {
id: string;
value: string;
value: number;
}

export type SettingsGetterFunc = (dataSlize: PieDataItem) => string;

export type Data = { data: Array<PieDataItem> };
Expand Down Expand Up @@ -95,6 +98,11 @@ declare module '@nivo/pie' {
theme: Theme;

legends: Array<Legend>;

// motion
animate: boolean;
motionDamping: number;
motionStiffness: number;
}>;

export interface Dimensions {
Expand All @@ -103,18 +111,51 @@ declare module '@nivo/pie' {
}

export type Theme = Partial<{
axis: React.CSSProperties;
grid: React.CSSProperties;
markers: React.CSSProperties;
dots: React.CSSProperties;
axis: Partial<{
textColor: CSS.ColorProperty;
fontSize: CSS.FontSizeProperty<string | 0>;
tickColor: CSS.ColorProperty;
legendColor: CSS.ColorProperty;
legendFontSize: CSS.FontSizeProperty<string | 0>;
}>,
grid: Partial<{
stroke: CSS.ColorProperty;
strokeWidth: number
strokeDasharray: string;
}>,
markers: Partial<{
lineColor: CSS.ColorProperty;
lineStrokeWidth: number;
textColor: CSS.ColorProperty;
fontSize: CSS.FontSizeProperty<string | 0>;
}>,
dots: Partial<{
textColor: CSS.ColorProperty;
fontSize: CSS.FontSizeProperty<string | 0>;
}>,
tooltip: Partial<{
basic: React.CSSProperties;
container: React.CSSProperties;
table: React.CSSProperties;
tableCell: React.CSSProperties;
}>;
labels: React.CSSProperties;
sankey: Partial<{ label: React.CSSProperties }>;
container: Partial<{
background: CSS.ColorProperty;
color: CSS.ColorProperty;
fontSize: CSS.FontSizeProperty<string | 0>;
borderRadius: CSS.BorderRadiusProperty<string | 0>;
boxShadow: CSS.BoxShadowProperty;
padding: CSS.PaddingProperty<string | 0>;
}>,
basic: Partial<{
whiteSpace: CSS.WhiteSpaceProperty;
display: CSS.DisplayProperty;
alignItems: CSS.AlignItemsProperty;
}>,
table: any;
tableCell: {
padding: CSS.PaddingProperty<string | 0>;
}
}>,
labels: { textColor: CSS.ColorProperty; };
sankey: {
label: any
}
}>

export type Box = Partial<{
Expand Down
128 changes: 128 additions & 0 deletions packages/nivo-pie/types/typescript-tests.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { Pie, ResponsivePie } from "@nivo/pie";

const data = [
{
id: "stylus",
label: "stylus",
value: 38,
color: "hsl(26, 70%, 50%)"
},
{
id: "javascript",
label: "javascript",
value: 159,
color: "hsl(94, 70%, 50%)"
},
{
id: "go",
label: "go",
value: 120,
color: "hsl(36, 70%, 50%)"
}
];
const PieComponent = (
<Pie
height={150}
width={150}
data={[]}
margin={{
"top": 40,
"right": 80,
"bottom": 80,
"left": 80
}}
innerRadius={0.5}
padAngle={0.7}
cornerRadius={3}
colors="d320c"
colorBy="id"
borderColor="inherit:darker(0.6)"
radialLabelsSkipAngle={10}
radialLabelsTextXOffset={6}
radialLabelsTextColor="#333333"
radialLabelsLinkOffset={0}
radialLabelsLinkDiagonalLength={16}
radialLabelsLinkHorizontalLength={24}
radialLabelsLinkStrokeWidth={1}
radialLabelsLinkColor="inherit"
slicesLabelsSkipAngle={10}
slicesLabelsTextColor="#333333"
animate={true}
motionStiffness={90}
motionDamping={15}
tooltip={null}
theme={{
"tooltip": {
"container": {
"fontSize": "13px"
}
},
"labels": {
"textColor": "#555"
}
}}
legends={
[
{
"anchor": "bottom",
"direction": "row",
"translateY": 56,
"itemWidth": 100,
"itemHeight": 14,
"symbolSize": 14,
"symbolShape": "circle"
}
]}
/>
);

const ResponsivePieComponent = <ResponsivePie
data={data}
margin={{
"top": 40,
"right": 80,
"bottom": 80,
"left": 80
}}
innerRadius={0.5}
padAngle={0.7}
cornerRadius={3}
colors="d320c"
colorBy="id"
borderColor="inherit:darker(0.6)"
radialLabelsSkipAngle={10}
radialLabelsTextXOffset={6}
radialLabelsTextColor="#333333"
radialLabelsLinkOffset={0}
radialLabelsLinkDiagonalLength={16}
radialLabelsLinkHorizontalLength={24}
radialLabelsLinkStrokeWidth={1}
radialLabelsLinkColor="inherit"
slicesLabelsSkipAngle={10}
slicesLabelsTextColor="#333333"
animate={true}
motionStiffness={90}
motionDamping={15}
tooltip={null}
theme={{
"tooltip": {
"container": {
"fontSize": "13px"
}
},
"labels": {
"textColor": "#555"
}
}}
legends={[
{
"anchor": "bottom",
"direction": "row",
"translateY": 56,
"itemWidth": 100,
"itemHeight": 14,
"symbolSize": 14,
"symbolShape": "circle"
}
]}
/>
Loading