Skip to content

Commit

Permalink
fix: update
Browse files Browse the repository at this point in the history
  • Loading branch information
huxiaoyun committed Nov 5, 2019
1 parent 3418020 commit bc18894
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 303 deletions.
4 changes: 2 additions & 2 deletions src/cartesian/CartesianAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import Label from '../component/Label';
import { isSsr, filterEventsOfChild } from '../util/ReactUtils';
// @ts-ignore
import { isNumber, mathSign } from '../util/DataUtils';
import { ViewBox, PresentationAttributes, filterProps, TickItem } from '../util/types';
import { ViewBox, PresentationAttributes, filterProps, TickItem, BaseAxisProps } from '../util/types';

interface CartesianTickItem extends TickItem {
tickCoord?: number;
tickSize?: number;
isShow?: boolean;
}

interface CartesianAxisProps {
export interface CartesianAxisProps {
className?: string;
x?: number;
y?: number;
Expand Down
4 changes: 2 additions & 2 deletions src/chart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Area from '../cartesian/Area';
import XAxis from '../cartesian/XAxis';
import YAxis from '../cartesian/YAxis';
import { formatAxisMap } from '../util/CartesianUtils';
import { ICategoricalChart } from './index.d';
import { CategoricalChart } from './types';

export default generateCategoricalChart({
chartName: 'AreaChart',
Expand All @@ -16,4 +16,4 @@ export default generateCategoricalChart({
{ axisType: 'yAxis', AxisComp: YAxis },
],
formatAxisMap,
} as ICategoricalChart);
} as CategoricalChart);
4 changes: 2 additions & 2 deletions src/chart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Bar from '../cartesian/Bar';
import XAxis from '../cartesian/XAxis';
import YAxis from '../cartesian/YAxis';
import { formatAxisMap } from '../util/CartesianUtils';
import { ICategoricalChart } from './index.d';
import { CategoricalChart } from './types';

export default generateCategoricalChart({
chartName: 'BarChart',
Expand All @@ -16,4 +16,4 @@ export default generateCategoricalChart({
{ axisType: 'yAxis', AxisComp: YAxis },
],
formatAxisMap,
} as ICategoricalChart);
} as CategoricalChart);
4 changes: 2 additions & 2 deletions src/chart/ComposedChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import XAxis from '../cartesian/XAxis';
import YAxis from '../cartesian/YAxis';
import ZAxis from '../cartesian/ZAxis';
import { formatAxisMap } from '../util/CartesianUtils';
import { ICategoricalChart } from './index.d';
import { CategoricalChart } from './types';

export default generateCategoricalChart({
chartName: 'ComposedChart',
Expand All @@ -21,4 +21,4 @@ export default generateCategoricalChart({
{ axisType: 'zAxis', AxisComp: ZAxis },
],
formatAxisMap,
} as ICategoricalChart);
} as CategoricalChart);
4 changes: 2 additions & 2 deletions src/chart/FunnelChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import generateCategoricalChart from './generateCategoricalChart';
import Funnel from '../numberAxis/Funnel';
import { ICategoricalChart } from './index.d';
import { CategoricalChart } from './types';

export default generateCategoricalChart({
chartName: 'FunnelChart',
Expand All @@ -13,4 +13,4 @@ export default generateCategoricalChart({
defaultProps: {
layout: 'centric',
},
} as ICategoricalChart);
} as CategoricalChart);
4 changes: 2 additions & 2 deletions src/chart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Line from '../cartesian/Line';
import XAxis from '../cartesian/XAxis';
import YAxis from '../cartesian/YAxis';
import { formatAxisMap } from '../util/CartesianUtils';
import { ICategoricalChart } from './index.d';
import { CategoricalChart } from './types';

export default generateCategoricalChart({
chartName: 'LineChart',
Expand All @@ -16,4 +16,4 @@ export default generateCategoricalChart({
{ axisType: 'yAxis', AxisComp: YAxis },
],
formatAxisMap,
} as ICategoricalChart);
} as CategoricalChart);
4 changes: 2 additions & 2 deletions src/chart/PieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PolarAngleAxis from '../polar/PolarAngleAxis';
import PolarRadiusAxis from '../polar/PolarRadiusAxis';
import { formatAxisMap } from '../util/PolarUtils';
import Pie from '../polar/Pie';
import { ICategoricalChart } from './index.d';
import { CategoricalChart } from './types';

export default generateCategoricalChart({
chartName: 'PieChart',
Expand All @@ -28,4 +28,4 @@ export default generateCategoricalChart({
innerRadius: 0,
outerRadius: '80%',
},
} as ICategoricalChart);
} as CategoricalChart);
4 changes: 2 additions & 2 deletions src/chart/RadarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Radar from '../polar/Radar';
import PolarAngleAxis from '../polar/PolarAngleAxis';
import PolarRadiusAxis from '../polar/PolarRadiusAxis';
import { formatAxisMap } from '../util/PolarUtils';
import { ICategoricalChart } from './index.d';
import { CategoricalChart } from './types';

export default generateCategoricalChart({
chartName: 'RadarChart',
Expand All @@ -25,4 +25,4 @@ export default generateCategoricalChart({
innerRadius: 0,
outerRadius: '80%',
},
} as ICategoricalChart);
} as CategoricalChart);
4 changes: 2 additions & 2 deletions src/chart/RadialBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PolarAngleAxis from '../polar/PolarAngleAxis';
import PolarRadiusAxis from '../polar/PolarRadiusAxis';
import { formatAxisMap } from '../util/PolarUtils';
import RadialBar from '../polar/RadialBar';
import { ICategoricalChart } from './index.d';
import { CategoricalChart } from './types';

export default generateCategoricalChart({
chartName: 'RadialBarChart',
Expand All @@ -26,4 +26,4 @@ export default generateCategoricalChart({
innerRadius: 0,
outerRadius: '80%',
},
} as ICategoricalChart);
} as CategoricalChart);
44 changes: 22 additions & 22 deletions src/chart/Sankey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import Rectangle from '../shape/Rectangle';
import { shallowEqual } from '../util/ShallowEqual';
import { getPresentationAttributes, filterSvgElements, validateWidthHeight, findChildByType } from '../util/ReactUtils';
import { getValueByDataKey } from '../util/ChartUtils';
import { IMargin, IPresentationAttributes, IEvent, ISankeyLink, ISankeyNode } from './index.d';
import { SankeyLink, SankeyNode } from './types';
import { Margin, DataKey } from '../util/types';

const defaultCoordinateOfTooltip = { x: 0, y: 0 };

Expand All @@ -20,20 +21,20 @@ const interpolationGenerator = (a: number, b: number) => {
const kb = b - ka;
return (t: any) => ka + kb * t;
};
const centerY = (node: ISankeyNode) => (node.y + node.dy / 2);
const getValue = (entry: ISankeyLink) => ((entry && entry.value) || 0);
const getSumOfIds = (links: ISankeyLink[], ids: number[]) => (
const centerY = (node: SankeyNode) => (node.y + node.dy / 2);
const getValue = (entry: SankeyLink) => ((entry && entry.value) || 0);
const getSumOfIds = (links: SankeyLink[], ids: number[]) => (
ids.reduce((result: any, id: any) => (result + getValue(links[id])), 0)
);
const getSumWithWeightedSource = (tree: any, links: ISankeyLink[], ids: number[]) => (
const getSumWithWeightedSource = (tree: any, links: SankeyLink[], ids: number[]) => (
ids.reduce((result: any, id: any) => {
const link = links[id];
const sourceNode = tree[link.source];

return result + centerY(sourceNode) * getValue(links[id]);
}, 0)
);
const getSumWithWeightedTarget = (tree: any, links: ISankeyLink[], ids: number[]) => (
const getSumWithWeightedTarget = (tree: any, links: SankeyLink[], ids: number[]) => (
ids.reduce((result: number, id: number) => {
const link = links[id];
const targetNode = tree[link.target];
Expand All @@ -43,7 +44,7 @@ const getSumWithWeightedTarget = (tree: any, links: ISankeyLink[], ids: number[]
);
const ascendingY = (a: any, b: any) => (a.y - b.y);

const searchTargetsAndSources = (links: ISankeyLink[], id: number) => {
const searchTargetsAndSources = (links: SankeyLink[], id: number) => {
const sourceNodes: number[] = [];
const sourceLinks: number[] = [];
const targetNodes: number[] = [];
Expand Down Expand Up @@ -102,7 +103,7 @@ const getNodesTree = ({ nodes, links }: any, width: number, nodeWidth: number):
updateDepthOfTargets(tree, node);
}
}
const maxDepth = _.maxBy(tree, (entry: ISankeyNode) => entry.depth).depth;
const maxDepth = _.maxBy(tree, (entry: SankeyNode) => entry.depth).depth;

if (maxDepth >= 1) {
const childWidth = (width - nodeWidth) / maxDepth;
Expand Down Expand Up @@ -259,8 +260,8 @@ const computeData = ({ data, width, height, iterations, nodeWidth, nodePadding }
nodeWidth: number,
nodePadding: number,
}): {
nodes: ISankeyNode[],
links: ISankeyLink[]
nodes: SankeyNode[],
links: SankeyLink[]
} => {
const { links } = data;
const { tree } = getNodesTree(data, width, nodeWidth);
Expand Down Expand Up @@ -296,7 +297,7 @@ const getCoordinateOfTooltip = (el: any, type: string) => {
};
};

const getPayloadOfTooltip = (el: any, type: string, nameKey: string | number) => {
const getPayloadOfTooltip = (el: any, type: string, nameKey: DataKey<any>) => {
const { payload } = el;
if (type === 'node') {
return [{
Expand All @@ -320,14 +321,13 @@ const getPayloadOfTooltip = (el: any, type: string, nameKey: string | number) =>
};

class Props implements IPresentationAttributes, IEvent {
// TODO nameKey dataKey 需要支持 func
nameKey: string | number = 'name';
dataKey: string | number = 'value';
nameKey: DataKey<any> = 'name';
dataKey: DataKey<any> = 'value';
width: number;
height: number;
data: {
node: ISankeyNode[];
links: ISankeyLink[];
node: SankeyNode[];
links: SankeyLink[];
};
nodePadding: number = 10;
nodeWidth: number = 10;
Expand All @@ -341,7 +341,7 @@ class Props implements IPresentationAttributes, IEvent {

className: string;
children: any;
margin: IMargin = { top: 5, right: 5, bottom: 5, left: 5 };
margin: Margin = { top: 5, right: 5, bottom: 5, left: 5 };

onClick: any;

Expand All @@ -360,8 +360,8 @@ class State {
activeElement: any = null;
activeElementType: any = null;
isTooltipActive: boolean = false;
nodes: ISankeyNode[] = [];
links: ISankeyLink[] = [];
nodes: SankeyNode[] = [];
links: SankeyLink[] = [];
}

class Sankey extends PureComponent<Props, State> {
Expand Down Expand Up @@ -477,15 +477,15 @@ class Sankey extends PureComponent<Props, State> {
);
}

renderLinks(links: ISankeyLink[], nodes: ISankeyNode[]) {
renderLinks(links: SankeyLink[], nodes: SankeyNode[]) {
const { linkCurvature, link: linkContent, margin } = this.props;
const top = margin.top || 0;
const left = margin.left || 0;

return (
<Layer className="recharts-sankey-links" key="recharts-sankey-links">
{
links.map((link: ISankeyLink, i: number) => {
links.map((link: SankeyLink, i: number) => {
const { sy: sourceRelativeY, ty: targetRelativeY, dy: linkWidth } = link;
const source = nodes[link.source];
const target = nodes[link.target];
Expand Down Expand Up @@ -542,7 +542,7 @@ class Sankey extends PureComponent<Props, State> {
);
}

renderNodes(nodes: ISankeyNode[]) {
renderNodes(nodes: SankeyNode[]) {
const { node: nodeContent, margin } = this.props;
const top = margin.top || 0;
const left = margin.left || 0;
Expand Down
4 changes: 2 additions & 2 deletions src/chart/ScatterChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import XAxis from '../cartesian/XAxis';
import YAxis from '../cartesian/YAxis';
import ZAxis from '../cartesian/ZAxis';
import { formatAxisMap } from '../util/CartesianUtils';
import { ICategoricalChart } from './index.d';
import { CategoricalChart } from './types';

export default generateCategoricalChart({
chartName: 'ScatterChart',
Expand All @@ -19,4 +19,4 @@ export default generateCategoricalChart({
{ axisType: 'zAxis', AxisComp: ZAxis },
],
formatAxisMap,
} as ICategoricalChart);
} as CategoricalChart);
Loading

0 comments on commit bc18894

Please sign in to comment.