Skip to content

Commit

Permalink
Merge cdca287 into 1f1b451
Browse files Browse the repository at this point in the history
  • Loading branch information
dlabrecq committed Feb 23, 2019
2 parents 1f1b451 + cdca287 commit 1963a89
Show file tree
Hide file tree
Showing 14 changed files with 1,872 additions and 87 deletions.
3 changes: 2 additions & 1 deletion packages/patternfly-4/react-charts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"optionalDependencies": {
"@types/victory": "^0.9.19",
"hoist-non-react-statics": "^3.1.0",
"victory": "^30.1.0"
"victory": "^30.1.0",
"victory-core": "^31.1.0"
},
"devDependencies": {
"@patternfly/patternfly": "1.0.184",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import hoistNonReactStatics from 'hoist-non-react-statics';
import { VictoryLegend } from 'victory';
import { default as ChartTheme } from '../ChartTheme/ChartTheme';
import ChartContainer from '../ChartContainer/ChartContainer';
import ChartPoint from '../ChartPoint/ChartPoint';

export const propTypes = {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import ChartLegend from '../ChartDonut/ChartDonut';
import ChartLegend from './ChartLegend';

Object.values([true, false]).forEach(isRead => {
test(`Chart`, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Chart 1`] = `
<VictoryPie
<VictoryLegend
borderComponent={
<Border
rectComponent={<Rect />}
/>
}
containerComponent={
<VictoryContainer
className="VictoryContainer"
portalComponent={<Portal />}
portalZIndex={99}
responsive={true}
<ChartContainer
responsive={false}
/>
}
data={
Array [
Object {
"x": "A",
"y": 1,
},
Object {
"x": "B",
"y": 2,
},
Object {
"x": "C",
"y": 3,
},
Object {
"x": "D",
"y": 1,
"name": "Series 1",
},
Object {
"x": "E",
"y": 2,
"name": "Series 2",
},
]
}
dataComponent={
<Slice
pathComponent={<Path />}
dataComponent={<ChartPoint />}
groupComponent={<g />}
labelComponent={
<VictoryLabel
capHeight={0.71}
direction="inherit"
lineHeight={1}
textComponent={<Text />}
tspanComponent={<TSpan />}
/>
}
groupComponent={<g />}
innerRadius={88}
labelComponent={<ChartTooltip />}
padAngle={1}
sortOrder="ascending"
standalone={true}
theme={
Object {
Expand Down Expand Up @@ -492,53 +481,51 @@ exports[`Chart 1`] = `
},
}
}
titleComponent={
<VictoryLabel
capHeight={0.71}
direction="inherit"
lineHeight={1}
textComponent={<Text />}
tspanComponent={<TSpan />}
/>
}
/>
`;

exports[`Chart 2`] = `
<VictoryPie
<VictoryLegend
borderComponent={
<Border
rectComponent={<Rect />}
/>
}
containerComponent={
<VictoryContainer
className="VictoryContainer"
portalComponent={<Portal />}
portalZIndex={99}
responsive={true}
<ChartContainer
responsive={false}
/>
}
data={
Array [
Object {
"x": "A",
"y": 1,
},
Object {
"x": "B",
"y": 2,
"name": "Series 1",
},
Object {
"x": "C",
"y": 3,
},
Object {
"x": "D",
"y": 1,
},
Object {
"x": "E",
"y": 2,
"name": "Series 2",
},
]
}
dataComponent={
<Slice
pathComponent={<Path />}
dataComponent={<ChartPoint />}
groupComponent={<g />}
labelComponent={
<VictoryLabel
capHeight={0.71}
direction="inherit"
lineHeight={1}
textComponent={<Text />}
tspanComponent={<TSpan />}
/>
}
groupComponent={<g />}
innerRadius={88}
labelComponent={<ChartTooltip />}
padAngle={1}
sortOrder="ascending"
standalone={true}
theme={
Object {
Expand Down Expand Up @@ -987,17 +974,28 @@ exports[`Chart 2`] = `
},
}
}
titleComponent={
<VictoryLabel
capHeight={0.71}
direction="inherit"
lineHeight={1}
textComponent={<Text />}
tspanComponent={<TSpan />}
/>
}
/>
`;

exports[`renders component data 1`] = `
<VictoryPie
<VictoryLegend
borderComponent={
<Border
rectComponent={<Rect />}
/>
}
containerComponent={
<VictoryContainer
className="VictoryContainer"
portalComponent={<Portal />}
portalZIndex={99}
responsive={true}
<ChartContainer
responsive={false}
/>
}
data={
Expand All @@ -1010,17 +1008,18 @@ exports[`renders component data 1`] = `
},
]
}
dataComponent={
<Slice
pathComponent={<Path />}
/>
}
dataComponent={<ChartPoint />}
groupComponent={<g />}
height={50}
innerRadius={88}
labelComponent={<ChartTooltip />}
padAngle={1}
sortOrder="ascending"
labelComponent={
<VictoryLabel
capHeight={0.71}
direction="inherit"
lineHeight={1}
textComponent={<Text />}
tspanComponent={<TSpan />}
/>
}
standalone={true}
theme={
Object {
Expand Down Expand Up @@ -1470,6 +1469,15 @@ exports[`renders component data 1`] = `
}
}
title="Average number of pets"
titleComponent={
<VictoryLabel
capHeight={0.71}
direction="inherit"
lineHeight={1}
textComponent={<Text />}
tspanComponent={<TSpan />}
/>
}
width={200}
/>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as victory from 'victory';
// import { OneOf } from '../../typeUtils';

export interface ChartPointProps extends victory.VictoryLegendProps {
symbol: string;
}

declare const Chartpoint: React.ComponentClass<ChartPointProps>;

export default Chartpoint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import PropTypes from 'prop-types';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { Point } from 'victory';
import { Helpers } from 'victory-core';
import pathHelpers from './path-helpers';

export const propTypes = {
...Point.propTypes,
symbol: PropTypes.oneOfType([
PropTypes.oneOf([
'circle',
'diamond',
'plus',
'minus',
'square',
'star',
'triangleDown',
'triangleUp',
'dash',
]),
PropTypes.func
])
};

// Todo: Submit dash symbol to victory-core, providing PF4 doesn't need a smaller lineHeight for dash and minus?
class VictoryPoint extends Point {
getPath(props) {
const { datum, active, x, y } = props;
const size = Helpers.evaluateProp(props.size, datum, active);
if (props.getPath) {
return props.getPath(x, y, size);
}
const pathFunctions = {
circle: pathHelpers.circle,
square: pathHelpers.square,
diamond: pathHelpers.diamond,
triangleDown: pathHelpers.triangleDown,
triangleUp: pathHelpers.triangleUp,
plus: pathHelpers.plus,
minus: pathHelpers.minus,
star: pathHelpers.star,
dash: pathHelpers.dash
};
const symbol = Helpers.evaluateProp(props.symbol, datum, active);
const symbolFunction = typeof pathFunctions[symbol] === 'function' ? pathFunctions[symbol] : pathFunctions.circle;
return symbolFunction(x, y, size);
}
}

const ChartPoint = (props) => (
<VictoryPoint {...props}/>
);

hoistNonReactStatics(ChartPoint, Point);
ChartPoint.propTypes = propTypes;

export default ChartPoint;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { shallow } from 'enzyme';
import ChartLegend from '../ChartLegend/ChartLegend';
import ChartPoint from './ChartPoint';

Object.values([true, false]).forEach(isRead => {
test(`Chart`, () => {
const view = shallow(<ChartLegend dataComponent={<ChartPoint />}/>);
expect(view).toMatchSnapshot();
});
});

test('renders component data', () => {
const view = shallow(
<ChartLegend
data={[
{ name: 'Cats' }, { name: 'Dogs', symbol: { type: 'dash'} }
]}
title="Average number of pets"
height={50}
width={200}
/>
);
expect(view).toMatchSnapshot();
});
Loading

0 comments on commit 1963a89

Please sign in to comment.