Skip to content

Commit

Permalink
Treemap chart (#1870)
Browse files Browse the repository at this point in the history
* Init

* Bring old PR work to new PR

* Get React chart showing

* Add grouped data and color exploration

* Fix theme typo to correctly apply config options

* Add drillable functionality

* Add tooltip customization

* Add color override option

* Add color grouping

* Add tooltip example

* Update some documentation wording

* Add rails treemap examples

* Update sample data and documention

* Alphabetize props

* Remove Jest file and add some documentation

* Add rails spec coverage

* Remove unneeded scss and update html dot

Co-authored-by: Stephen Crane <scrane88@gmail.com>
  • Loading branch information
thestephenmarshall and RudeChowder authored May 5, 2022
1 parent 0e2dbff commit 8a4e2c6
Show file tree
Hide file tree
Showing 29 changed files with 839 additions and 1 deletion.
1 change: 1 addition & 0 deletions playbook/app/pb_kits/playbook/data/menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ kits:
- gauge
- legend
- line_graph
- treemap_chart
- dialog
- filter
- fixed_confirmation_toast
Expand Down
3 changes: 2 additions & 1 deletion playbook/app/pb_kits/playbook/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'lazysizes/plugins/attrchange/ls.attrchange'
import 'lazysizes'

// vvv React Component JSX Imports from the React Kits vvv
export { default as Walkthrough } from './pb_walkthrough/_walkthrough'
export { default as Avatar } from './pb_avatar/_avatar'
export { default as AvatarActionButton } from './pb_avatar_action_button/_avatar_action_button'
export { default as Background } from './pb_background/_background'
Expand Down Expand Up @@ -98,9 +97,11 @@ export { default as Title } from './pb_title/_title'
export { default as TitleCount } from './pb_title_count/_title_count'
export { default as TitleDetail } from './pb_title_detail/_title_detail'
export { default as Toggle } from './pb_toggle/_toggle'
export { default as TreemapChart } from './pb_treemap_chart/_treemap_chart'
export { default as Typeahead } from './pb_typeahead/_typeahead'
export { default as User } from './pb_user/_user'
export { default as UserBadge } from './pb_user_badge/_user_badge'
export { default as Walkthrough } from './pb_walkthrough/_walkthrough'
export { default as WeekdayStacked } from './pb_weekday_stacked/_weekday_stacked'
// ^^^ React Component JSX Imports from the React Kits ^^^

Expand Down
37 changes: 37 additions & 0 deletions playbook/app/pb_kits/playbook/pb_dashboard/pbChartsDarkTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,43 @@ const highchartsDarkTheme = {
threshold: null,
},
},

//TREEMAP CHART STYLES
treemap: {
layoutAlgorithm: "squarified",
allowTraversingTree: false,
animationLimit: 1000,
colors: [
colors.data_1,
colors.data_2,
colors.data_3,
colors.data_4,
colors.data_5,
colors.data_6,
colors.data_7,
colors.data_8,
],
colorByPoint: true,
dataLabels: {
enabled: true,
style: {
fontFamily: typography.font_family_base,
fontWeight: typography.bold,
fontSize: typography.heading_4,
},
},
levels: [
{
level: 1,
dataLabels: {
enabled: false,
},
},
],
traverseUpButton: {
position: { y: -40 },
}
},
},
}

Expand Down
37 changes: 37 additions & 0 deletions playbook/app/pb_kits/playbook/pb_dashboard/pbChartsLightTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,43 @@ const highchartsTheme = {
threshold: null,
},
},

//TREEMAP CHART STYLES
treemap: {
layoutAlgorithm: "squarified",
allowTraversingTree: false,
animationLimit: 1000,
colors: [
colors.data_1,
colors.data_2,
colors.data_3,
colors.data_4,
colors.data_5,
colors.data_6,
colors.data_7,
colors.data_8,
],
colorByPoint: true,
dataLabels: {
enabled: true,
style: {
fontFamily: typography.font_family_base,
fontWeight: typography.bold,
fontSize: typography.heading_4,
},
},
levels: [
{
level: 1,
dataLabels: {
enabled: false,
},
},
],
traverseUpButton: {
position: { y: -40 },
}
},
},
}

Expand Down
79 changes: 79 additions & 0 deletions playbook/app/pb_kits/playbook/pb_treemap_chart/_treemap_chart.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* @flow */

import React from 'react'
import classnames from 'classnames'

import { globalProps } from '../utilities/globalProps'
import pbChart from '../plugins/pb_chart'

type TreemapChartProps = {
chartData: array<{
name: string,
parent?: string | number,
value: number,
color?: string,
id?: string | number,
}>,
className?: string,
colors: array,
dark?: boolean,
drillable: boolean,
grouped: boolean,
height?: string,
id: number,
title: string,
tooltipHtml: string,
type?: string,
}

export default class TreemapChart extends React.Component<TreemapChartProps> {
static defaultProps = {
className: 'pb_treemap_chart',
dark: false,
drillable: false,
grouped: false,
type: 'treemap',
}

componentDidMount() {
const {
chartData,
className,
colors = [],
dark,
drillable,
grouped,
height,
id,
title = "",
tooltipHtml = '<span style="font-weight: bold; color:{point.color};">&#9679; </span>{point.name}: <b>{point.value}</b>',
type,
} = this.props

new pbChart(`.${className}`, {
chartData: chartData,
colors: colors,
dark,
drillable,
grouped,
height: height,
id: id,
title: title,
tooltipHtml,
type,
})
}

props: TreemapChartProps

render() {
const { className, id } = this.props

return (
<div
className={classnames(globalProps(this.props), className)}
id={id}
/>
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Treemap charts are used to compare the relative size of groups of data. They can also use a nested data structure, allowing a user to drill down into a group to see its constituent data points.

The default height of treemap is 400px and can be changed. The default height is in pixel units, but can also use percentage string (percentage would be that of the width. For example, `height:"50%"` would mean that the height is 50% of the width). This allows for preserving the aspect ratio across responsive sizes.

For more information, see: <a href="https://api.highcharts.com/highcharts/chart.height" target="_blank"> highcharts/chart.height</a>.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<% data = [
{
name: "Pepperoni",
parent: "Toppings",
value: 600,
}, {
name: "Cheese",
parent: "Toppings",
value: 510,
}, {
name: "Mushroom",
parent: "Toppings",
value: 330,
},{
name: "Onions",
parent: "Toppings",
value: 250,
}, {
name: "Olives",
parent: "Toppings",
value: 204,
}, {
name: "Pineapple",
parent: "Toppings",
value: 90,
}, {
name: "Pizza Toppings",
id: "Toppings",
},
] %>

<%= pb_rails("treemap_chart", props: {
chart_data: data,
colors: ["data-4", "data-7", "#8E6E53", "#124732"],
id: "treemap-colors",
title: "Favored Pizza Toppings",
}) %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react'

import TreemapChart from '../_treemap_chart'

const chartData = [
{
name: "Pepperoni",
parent: "Toppings",
value: 600,
}, {
name: "Cheese",
parent: "Toppings",
value: 510,
}, {
name: "Mushroom",
parent: "Toppings",
value: 330,
},{
name: "Onions",
parent: "Toppings",
value: 250,
}, {
name: "Olives",
parent: "Toppings",
value: 204,
}, {
name: "Pineapple",
parent: "Toppings",
value: 90,
}, {
name: "Pizza Toppings",
id: "Toppings",
},
]

const TreemapChartColors = (props) => (
<div>
<TreemapChart
chartData={chartData}
colors={["data-4", "data-7", "#8E6E53", "#124732"]}
id="treemap-colors"
title="Favored Pizza Toppings"
{...props}
/>
</div>
)

export default TreemapChartColors
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Custom data colors allow for color customization to match the needs of business requirements.
Pass the prop `colors` and use desired values `data-1 | data-2 | data-3 | data-4 | data-5 | data-6 | data-7 | data-8` in an array. Hex colors are also available `eg: #CA0095`
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<% data = [
{
name: "Pepperoni",
parent: "Toppings",
value: 600,
}, {
name: "Cheese",
parent: "Toppings",
value: 510,
}, {
name: "Mushroom",
parent: "Toppings",
value: 330,
},{
name: "Onions",
parent: "Toppings",
value: 250,
}, {
name: "Olives",
parent: "Toppings",
value: 204,
}, {
name: "Pineapple",
parent: "Toppings",
value: 90,
}, {
name: "Pizza Toppings",
id: "Toppings",
},
] %>


<%= pb_rails("treemap_chart", props: {
chart_data: data,
id: "treemap-default",
title: "Favored Pizza Toppings",
}) %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'

import TreemapChart from '../_treemap_chart'

const chartData = [
{
name: "Pepperoni",
parent: "Toppings",
value: 600,
}, {
name: "Cheese",
parent: "Toppings",
value: 510,
}, {
name: "Mushroom",
parent: "Toppings",
value: 330,
},{
name: "Onions",
parent: "Toppings",
value: 250,
}, {
name: "Olives",
parent: "Toppings",
value: 204,
}, {
name: "Pineapple",
parent: "Toppings",
value: 90,
}, {
name: "Pizza Toppings",
id: "Toppings",
},
]

const TreemapChartDefault = (props) => (
<div>
<TreemapChart
chartData={chartData}
id="treemap-default"
title="Favored Pizza Toppings"
{...props}
/>
</div>
)

export default TreemapChartDefault
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Points are automatically arranged by their `value` size.

By default, point colors are assigned sequentially from the global `data` colors. Note that data points without a value (such as parent nodes) will still take on the next available color.
Loading

0 comments on commit 8a4e2c6

Please # to comment.