Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #24011 - Add Patternfly bar chart support
- Loading branch information
1 parent
eb0b1c7
commit 277152f
Showing
16 changed files
with
336 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,4 @@ public/webpack | |
package-lock.json | ||
npm-debug.log | ||
.vscode | ||
yarn.lock |
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
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
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
56 changes: 56 additions & 0 deletions
56
webpack/assets/javascripts/react_app/components/common/charts/BarChart/BarChart.fixtures.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,56 @@ | ||
export const multiBars = { | ||
barChartData: [ | ||
['Fedora 21', 3], | ||
['Ubuntu 14.04', 4], | ||
['Centos 7', 2], | ||
['Debian 8', 1], | ||
], | ||
label: 'OS', | ||
}; | ||
|
||
export const singleBar = { | ||
barChartData: [ | ||
['Fedora 21', 3], | ||
['Ubuntu 14.04', 0], | ||
['Centos 7', 0], | ||
['Debian 8', 0], | ||
], | ||
label: 'OS', | ||
}; | ||
|
||
export const barChartConfig = { | ||
data: { | ||
columns: [['Number of Events', 3, 4, 2, 1]], | ||
type: 'bar', | ||
}, | ||
color: { | ||
pattern: ['#0088ce', '#ec7a08', '#3f9c35', '#005c66', 'f9d67a', '#703fec'], | ||
}, | ||
tooltip: { | ||
format: {}, | ||
}, | ||
legend: { | ||
show: true, | ||
}, | ||
padding: null, | ||
size: { | ||
width: 240, | ||
height: 240, | ||
}, | ||
id: 'operatingsystem', | ||
axis: { | ||
x: { | ||
categories: ['Fedora 21', 'Ubuntu 14.04', 'Centos 7', 'Debian 8'], | ||
type: 'category', | ||
}, | ||
}, | ||
categories: ['Fedora 21', 'Ubuntu 14.04', 'Centos 7', 'Debian 8'], | ||
}; | ||
|
||
export const emptyData = { | ||
data: { | ||
columns: [], | ||
type: 'bar', | ||
}, | ||
noDataMsg: 'No data available', | ||
}; |
8 changes: 8 additions & 0 deletions
8
webpack/assets/javascripts/react_app/components/common/charts/BarChart/BarChart.stories.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,8 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import BarChart from './'; | ||
import { multiBars, singleBar } from './BarChart.fixtures'; | ||
|
||
storiesOf('Charts', module) | ||
.add('Bar Chart - multiple bars', () => <BarChart data={multiBars} />) | ||
.add('Bar Chart - single bar', () => <BarChart data={singleBar} />); |
23 changes: 23 additions & 0 deletions
23
webpack/assets/javascripts/react_app/components/common/charts/BarChart/BarChart.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,23 @@ | ||
import { shallow } from 'enzyme'; | ||
import toJson from 'enzyme-to-json'; | ||
import React from 'react'; | ||
import BarChart from './'; | ||
import * as chartService from '../../../../../services/ChartService'; | ||
import { barChartConfig, emptyData } from './BarChart.fixtures'; | ||
|
||
jest.unmock('./'); | ||
describe('renders BarChart', () => { | ||
it('render bar chart chart', () => { | ||
chartService.getBarChartConfig = jest.fn(() => barChartConfig); | ||
const wrapper = shallow(<BarChart data={barChartConfig} />); | ||
|
||
expect(toJson(wrapper)).toMatchSnapshot(); | ||
}); | ||
|
||
it('render empty state', () => { | ||
chartService.getBarChartConfig = jest.fn(() => emptyData); | ||
const wrapper = shallow(<BarChart data={emptyData} />); | ||
|
||
expect(toJson(wrapper)).toMatchSnapshot(); | ||
}); | ||
}); |
93 changes: 93 additions & 0 deletions
93
...vascripts/react_app/components/common/charts/BarChart/__snapshots__/BarChart.test.js.snap
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,93 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders BarChart render bar chart chart 1`] = ` | ||
<BarChart | ||
axis={ | ||
Object { | ||
"x": Object { | ||
"categories": Array [ | ||
"Fedora 21", | ||
"Ubuntu 14.04", | ||
"Centos 7", | ||
"Debian 8", | ||
], | ||
"type": "category", | ||
}, | ||
} | ||
} | ||
categories={ | ||
Array [ | ||
"Fedora 21", | ||
"Ubuntu 14.04", | ||
"Centos 7", | ||
"Debian 8", | ||
] | ||
} | ||
className="bar-chart-pf" | ||
color={ | ||
Object { | ||
"pattern": Array [ | ||
"#0088ce", | ||
"#ec7a08", | ||
"#3f9c35", | ||
"#005c66", | ||
"f9d67a", | ||
"#703fec", | ||
], | ||
} | ||
} | ||
data={ | ||
Object { | ||
"columns": Array [ | ||
Array [ | ||
"Number of Events", | ||
3, | ||
4, | ||
2, | ||
1, | ||
], | ||
], | ||
"type": "bar", | ||
} | ||
} | ||
grid={ | ||
Object { | ||
"y": Object { | ||
"show": true, | ||
}, | ||
} | ||
} | ||
id="operatingsystem" | ||
legend={ | ||
Object { | ||
"show": true, | ||
} | ||
} | ||
padding={null} | ||
size={ | ||
Object { | ||
"height": 240, | ||
"width": 240, | ||
} | ||
} | ||
title={ | ||
Object { | ||
"type": "percent", | ||
} | ||
} | ||
tooltip={ | ||
Object { | ||
"format": Object {}, | ||
} | ||
} | ||
type="bar" | ||
unloadBeforeLoad={false} | ||
/> | ||
`; | ||
|
||
exports[`renders BarChart render empty state 1`] = ` | ||
<MessageBox | ||
icontype="info" | ||
msg="No data available" | ||
/> | ||
`; |
52 changes: 52 additions & 0 deletions
52
webpack/assets/javascripts/react_app/components/common/charts/BarChart/index.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,52 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { BarChart as PfBarChart } from 'patternfly-react'; | ||
import { getBarChartConfig } from '../../../../../services/ChartService'; | ||
import MessageBox from '../../MessageBox'; | ||
|
||
const BarChart = ({ | ||
data, | ||
onclick, | ||
noDataMsg = __('No data available'), | ||
config, | ||
title, | ||
unloadData, | ||
}) => { | ||
const { barChartData, xAxisLabel, yAxisLabel } = data; | ||
|
||
const chartConfig = getBarChartConfig({ | ||
data: barChartData, | ||
config, | ||
onclick, | ||
xAxisLabel, | ||
yAxisLabel, | ||
}); | ||
|
||
if (chartConfig.data.columns.length > 0) { | ||
return ( | ||
<PfBarChart | ||
{...chartConfig} | ||
title={title} | ||
unloadBeforeLoad={unloadData} | ||
/> | ||
); | ||
} | ||
return <MessageBox msg={noDataMsg} icontype="info" />; | ||
}; | ||
|
||
BarChart.defaultProps = { | ||
config: 'regular', | ||
title: { type: 'percent' }, | ||
unloadData: false, | ||
}; | ||
|
||
BarChart.propTypes = { | ||
config: PropTypes.string, | ||
noDataMsg: PropTypes.string, | ||
title: PropTypes.shape({ | ||
type: PropTypes.string, | ||
}), | ||
unloadData: PropTypes.bool, | ||
}; | ||
|
||
export default BarChart; |
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
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
Oops, something went wrong.