Skip to content

Commit

Permalink
[PLAY-1617] Change Bar Graph Override Example (#3982)
Browse files Browse the repository at this point in the history
**What does this PR do?** A clear and concise description with your
runway ticket url.
Runway https://runway.powerhrg.com/backlog_items/PLAY-1617

Make visual updates to the bar graph doc example for custom overrides

**How to test?** Steps to confirm the desired behavior:
1. Go to
https://pr3982.playbook.beta.gm.powerapp.cloud/kits/bar_graph/react#custom-overrides
2. Look at how great the chart is 
3. Rails too
https://pr3982.playbook.beta.gm.powerapp.cloud/kits/bar_graph/rails#custom-overrides

![Screenshot 2024-12-13 at 8 27
41 AM](https://github.com/user-attachments/assets/8f782dee-4398-4874-af00-1b0de5c3d48d)

---------

Co-authored-by: Gary Kang <[email protected]>
  • Loading branch information
markdoeswork and kangaree authored Dec 13, 2024
1 parent b0bf1da commit f07a662
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 85 deletions.
102 changes: 53 additions & 49 deletions playbook/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_custom.jsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,70 @@
import React from 'react'

import ReactDOMServer from 'react-dom/server'
import BarGraph from '../_bar_graph'
import Icon from '../../pb_icon/_icon'

const chartData = [
{
name: 'Role',
data: [0, 200, 300, 654, 656],
},
{
name: 'Company',
data: [150, 524, 320, 440, 500],
},
]

const chartData = [{
name: 'Installation',
data: [1475, 200, 3000, 654, 656],
}, {
name: 'Manufacturing',
data: [4434, 524, 2320, 440, 500],
}, {
name: 'Sales & Distribution',
data: [3387, 743, 1344, 434, 440],
}, {
name: 'Project Development',
data: [3227, 878, 999, 780, 1000],
}, {
name: 'Other',
data: [1111, 677, 3245, 500, 200],
}]
const renderIcon = (iconName, color) => {
return ReactDOMServer.renderToStaticMarkup(
<Icon
color={color}
icon={iconName}
/>)
};

const barGraphOptions = {
subtitle: {
text: "Overwritten subtitle",
style: {
color: "red"
}
yAxis: {
tickInterval: 5,
},
xAxis: {
labels: {
useHTML: true,
formatter: function() {
switch (this.value) {
case 'Jan':
return `<i class="far fa-apple-whole"></i> ${this.value}`
case 'Feb':
return `<i class="far fa-strawberry"></i> ${this.value}`
case 'Mar':
return `<i class="far fa-lemon"></i> ${this.value}`
case 'Apr':
return `<i class="far fa-pear"></i> ${this.value}`
case 'May':
return `<i class="far fa-peach"></i> ${this.value}`
default:
return ''
}
}
}
}
categories: ['1', '2', '3', '4', '5'],
labels: {
useHTML: true,
formatter: function () {
switch (this.value) {
case '1':
return `${renderIcon('frown', 'error')}`;
case '2':
return `${renderIcon('frown', 'warning')}`;
case '3':
return `${renderIcon('frown-open', 'neutral')}`;
case '4':
return `${renderIcon('smile', 'category_7')}`;
case '5':
return `${renderIcon('smile-beam', 'success')}`;
default:
return ''
}
},
style: {
fontSize: '1.4em',
},
y: 42,
},
},
legend: {
itemMarginTop: 62,
},
}

const BarGraphCustom = (props) => (
const BarGraphCustom = () => (
<div>
<BarGraph
axisTitle="Number of Employees"
chartData={chartData}
customOptions={barGraphOptions}
id="bar-custom"
subTitle="Subtitle to replace"
id="happiness-dashboard"
legend
title="Bar Graph with Custom Overrides"
xAxisCategories={['Jan', 'Feb', 'Mar', 'Apr', 'May']}
yAxisMin={0}
{...props}
/>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,42 @@
<% data = [{
name: 'Installation',
data: [1475,200,3000,654,656]
name: 'Role',
data: [0, 200, 300, 654, 656],
}, {
name: 'Manufacturing',
data: [4434,524,2320,440,500]
}, {
name: 'Sales & Distribution',
data: [3387,743,1344,434,440,]
}, {
name: 'Project Development',
data: [3227,878,999,780,1000]
}, {
name: 'Other',
data: [1111,677,3245,500,200]
name: 'Company',
data: [150, 524, 320, 440, 500],
}] %>

<% bar_graph_options = {
customOptions: {
subtitle: {
text: "Overwritten subtitle",
style: {
color: "red"
}
customOptions: {
yAxis: {
tickInterval: 5,
},
xAxis: {
categories: [
raw(pb_rails("icon", props: { icon: "frown", color: "error", size: "2x" })),
raw(pb_rails("icon", props: { icon: "frown", color: "warning", size: "2x" })),
raw(pb_rails("icon", props: { icon: "frown-open", color: "neutral", size: "2x" })),
raw(pb_rails("icon", props: { icon: "smile", color: "category_7", size: "2x" })),
raw(pb_rails("icon", props: { icon: "smile-beam", color: "success", size: "2x" }))
],
labels: {
useHTML: true,
sytle: {
fontSize: '1.4em',
},
xAxis: {
categories: [
'<i class="far fa-apple-whole"></i> Jan',
'<i class="far fa-strawberry"></i> Feb',
'<i class="far fa-lemon"></i> Mar',
'<i class="far fa-pear"></i> Apr',
'<i class="far fa-peach"></i> May'
],
labels: {
useHTML: true,
}
}
}
y: 42,
},
},
legend: {
itemMarginTop: 62,
},
}
} %>

<%= pb_rails("bar_graph", props: {
axis_title: 'Number of Employees',
chart_data: data,
id: "bar-default",
y_axis_min: 0,
subtitle: 'Subtitle to replace',
legend: true,
title: 'Bar Graph with Custom Overrides',
custom_options: bar_graph_options
}) %>
}) %>

0 comments on commit f07a662

Please sign in to comment.