-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,872 additions
and
87 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
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
2 changes: 1 addition & 1 deletion
2
packages/patternfly-4/react-charts/src/components/ChartLegend/ChartLegend.test.js
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
10 changes: 10 additions & 0 deletions
10
packages/patternfly-4/react-charts/src/components/ChartPoint/ChartPoint.d.ts
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,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; |
58 changes: 58 additions & 0 deletions
58
packages/patternfly-4/react-charts/src/components/ChartPoint/ChartPoint.js
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,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; |
25 changes: 25 additions & 0 deletions
25
packages/patternfly-4/react-charts/src/components/ChartPoint/ChartPoint.test.js
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,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(); | ||
}); |
Oops, something went wrong.