-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4859 from wri/FLAG-1145-support-legend-in-bar-cha…
…rt-widgets [FLAG-1145][FLAG-1110] Support legend in bar chart widgets + add legend primary forest loss widget
- Loading branch information
Showing
10 changed files
with
213 additions
and
2 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
78 changes: 78 additions & 0 deletions
78
components/widget/components/widget-chart-legend/component.jsx
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,78 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import cx from 'classnames'; | ||
|
||
class WidgetChartLegend extends PureComponent { | ||
render() { | ||
const { className, vertical = false, data = {} } = this.props; | ||
const { columns = [] } = data; | ||
|
||
const anyColumnsHaveTitle = !!columns.find((column) => column.title); | ||
|
||
return ( | ||
<div className={cx('c-widget-chart-legend', className, { vertical })}> | ||
{columns.map(({ title, items }, columnIdx) => { | ||
return ( | ||
<div key={columnIdx} className="c-widget-chart-legend__column"> | ||
{title && ( | ||
<span className="c-widget-chart-legend__column-title"> | ||
{title} | ||
</span> | ||
)} | ||
<ul | ||
className={cx('c-widget-chart-legend__column-items', { | ||
padded: anyColumnsHaveTitle && !title, | ||
})} | ||
> | ||
{items.map(({ label, color, dashline }, titleIdx) => { | ||
return ( | ||
<li | ||
key={titleIdx} | ||
className="c-widget-chart-legend__column-item" | ||
> | ||
{dashline ? ( | ||
<span | ||
className="c-widget-chart-legend__column-item--dashline" | ||
style={{ | ||
borderColor: color, | ||
}} | ||
/> | ||
) : ( | ||
<span | ||
className="c-widget-chart-legend__column-item--circle" | ||
style={{ | ||
backgroundColor: color, | ||
}} | ||
/> | ||
)} | ||
<p>{label}</p> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
WidgetChartLegend.propTypes = { | ||
className: PropTypes.string, | ||
vertical: PropTypes.bool, | ||
data: { | ||
columns: { | ||
title: PropTypes.string, | ||
items: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
color: PropTypes.string.isRequired, | ||
label: PropTypes.string.isRequired, | ||
}) | ||
), | ||
}, | ||
}, | ||
}; | ||
|
||
export default WidgetChartLegend; |
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,3 @@ | ||
import Component from './component'; | ||
|
||
export default Component; |
81 changes: 81 additions & 0 deletions
81
components/widget/components/widget-chart-legend/styles.scss
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,81 @@ | ||
@import '~styles/settings.scss'; | ||
|
||
.c-widget-chart-legend { | ||
display: flex; | ||
margin: 20px 0 0; | ||
width: 100%; | ||
gap: 60px; | ||
|
||
&__column { | ||
&-title { | ||
display: block; | ||
font-weight: 500; | ||
font-size: rem(13px); | ||
margin: 0 0 rem(8px) 0; | ||
} | ||
|
||
&-items { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 5px; | ||
|
||
&.padded { | ||
padding-top: rem(2px); | ||
} | ||
} | ||
|
||
&-item { | ||
font-size: rem(12px); | ||
display: flex; | ||
|
||
&--circle, | ||
&--dashline { | ||
display: inline-block; | ||
width: rem(12px); | ||
min-width: rem(12px); | ||
min-height: rem(12px); | ||
height: rem(12px); | ||
margin-right: rem(7px); | ||
} | ||
|
||
&--circle { | ||
border-radius: 100%; | ||
align-self: flex-start; | ||
margin-top: 1px; | ||
} | ||
|
||
&--dashline { | ||
border-radius: 0; | ||
border: none; | ||
border-top: 2px dotted; | ||
align-self: center; | ||
transform: translateY(4px); | ||
} | ||
|
||
p { | ||
color: $slate; | ||
font-size: rem(12px); | ||
line-height: 1.4; | ||
} | ||
} | ||
} | ||
|
||
&.vertical { | ||
flex-direction: column; | ||
gap: 5px; | ||
|
||
.c-widget-chart-legend { | ||
&__column { | ||
&-title { | ||
margin-top: rem(8px); | ||
} | ||
|
||
&-items { | ||
&.padded { | ||
padding-top: 0; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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