Skip to content

Commit a25ca0b

Browse files
authored
Merge pull request #19 from weaponsforge/dev
v1.0.4
2 parents ade7f64 + 454bdcd commit a25ca0b

File tree

8 files changed

+110
-13
lines changed

8 files changed

+110
-13
lines changed

components/common/ui/charts/bar/index.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import PropTypes from 'prop-types'
12
import {
23
Chart as ChartJS,
34
CategoryScale,
@@ -21,18 +22,33 @@ ChartJS.register(
2122

2223
function BarChart ({
2324
options,
24-
data
25+
data,
26+
width,
27+
height
2528
}) {
29+
const container = (!width || !height)
30+
? { width: '100vw', height: '100vh' }
31+
: {}
32+
2633
return (
27-
<FullBox >
34+
<FullBox sx={container}>
2835
<Bar
29-
width={300}
30-
height={300}
36+
width={width ?? 300}
37+
height={height ?? 300}
3138
options={options}
3239
data={data}
3340
/>
3441
</FullBox>
3542
)
3643
}
3744

45+
BarChart.propTypes = {
46+
data: PropTypes.object,
47+
options: PropTypes.object,
48+
/** Graph width in pixels. Will occupy full screen width if ommitted */
49+
width: PropTypes.number,
50+
/** Graph height in pixels. Will occupy full screen height if ommitted */
51+
height: PropTypes.number
52+
}
53+
3854
export default BarChart
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
1+
import PropTypes from 'prop-types'
12
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js'
23
import { Doughnut } from 'react-chartjs-2'
34
import FullBox from '@/components/common/layout/fullbox'
45
ChartJS.register(ArcElement, Tooltip, Legend)
56

67
function DonutChart (props) {
8+
const container = (!props.width || !props.height)
9+
? { width: '100vw', height: '100vh' }
10+
: {}
11+
712
return (
8-
<FullBox >
13+
<FullBox sx={container}>
914
<Doughnut
1015
data={props}
11-
width={300}
12-
height={300}
16+
width={props?.width || 300}
17+
height={props?.height || 300}
1318
options={{maintainAspectRatio: false}}
1419
/>
1520
</FullBox>
1621
)
1722
}
1823

24+
DonutChart.propTypes = {
25+
data: PropTypes.array,
26+
/** Graph width in pixels. Will occupy full screen width if ommitted */
27+
width: PropTypes.number,
28+
/** Graph height in pixels. Will occupy full screen height if ommitted */
29+
height: PropTypes.number
30+
}
31+
1932
export default DonutChart

components/common/ui/charts/line/index.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import PropTypes from 'prop-types'
12
import {
23
Chart as ChartJS,
34
CategoryScale,
@@ -23,18 +24,33 @@ import FullBox from '@/components/common/layout/fullbox'
2324

2425
function LineGraph ({
2526
options,
26-
data
27+
data,
28+
width,
29+
height
2730
}) {
31+
const container = (!width || !height)
32+
? { width: '100vw', height: '100vh' }
33+
: {}
34+
2835
return (
29-
<FullBox >
36+
<FullBox sx={container}>
3037
<Line
31-
width={300}
32-
height={300}
3338
options={options}
3439
data={data}
40+
width={width ?? 300}
41+
height={height ?? 300}
3542
/>
3643
</FullBox>
3744
)
3845
}
3946

47+
LineGraph.propTypes = {
48+
data: PropTypes.object,
49+
options: PropTypes.object,
50+
/** Graph width in pixels. Will occupy full screen width if ommitted */
51+
width: PropTypes.number,
52+
/** Graph height in pixels. Will occupy full screen height if ommitted */
53+
height: PropTypes.number
54+
}
55+
4056
export default LineGraph

components/profile-centered/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ function ProfileCenteredComponent ({
3434

3535
{/** Greehouse Gas (GHG) Emmissions Section */}
3636
<Grid item xs={12} sm={5}>
37-
<DonutChart {...donutData} />
37+
<DonutChart
38+
{...donutData}
39+
width={300}
40+
height={300}
41+
/>
3842
</Grid>
3943

4044
<Grid item xs={12} sm={7}>
@@ -58,6 +62,8 @@ function ProfileCenteredComponent ({
5862
<Grid item xs={12} sm={5}>
5963
<BarChart
6064
{...barData}
65+
width={300}
66+
height={300}
6167
/>
6268
</Grid>
6369

@@ -72,6 +78,8 @@ function ProfileCenteredComponent ({
7278
<Grid item xs={12} sm={5}>
7379
<LineGraph
7480
{...barData}
81+
width={300}
82+
height={300}
7583
/>
7684
</Grid>
7785

components/profile/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ function ProfileComponent ({
3333

3434
{/** Greehouse Gas (GHG) Emmissions Section */}
3535
<Grid item xs={12} sm={5}>
36-
<DonutChart {...donutData} />
36+
<DonutChart
37+
{...donutData}
38+
width={300}
39+
height={300}
40+
/>
3741
</Grid>
3842

3943
<Grid item xs={12} sm={7}>
@@ -57,6 +61,8 @@ function ProfileComponent ({
5761
<Grid item xs={12} sm={5}>
5862
<BarChart
5963
{...barData}
64+
width={300}
65+
height={300}
6066
/>
6167
</Grid>
6268

@@ -71,6 +77,8 @@ function ProfileComponent ({
7177
<Grid item xs={12} sm={5}>
7278
<LineGraph
7379
{...barData}
80+
width={300}
81+
height={300}
7482
/>
7583
</Grid>
7684

pages/barchartviz/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import BarChart from '@/components/common/ui/charts/bar'
2+
import { options, data } from '@/data/bar_data'
3+
4+
function BarChartViz () {
5+
return (
6+
<BarChart
7+
options={options}
8+
data={data}
9+
/>
10+
)
11+
}
12+
13+
export default BarChartViz

pages/donutchartviz/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import DonutChart from '@/components/common/ui/charts/donut'
2+
import donutChartData from '@/data/donut_data'
3+
4+
function DonutChartViz () {
5+
return (
6+
<DonutChart {...donutChartData} />
7+
)
8+
}
9+
10+
export default DonutChartViz

pages/linechartviz/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import LineGraph from '@/components/common/ui/charts/line'
2+
import { options, data } from '@/data/bar_data'
3+
4+
function LineChartViz () {
5+
return (
6+
<LineGraph
7+
options={options}
8+
data={data}
9+
/>
10+
)
11+
}
12+
13+
export default LineChartViz

0 commit comments

Comments
 (0)