Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fires within settings btn #3997

Merged
merged 8 commits into from May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -13,7 +13,7 @@ class ChartTooltip extends PureComponent {
{settings &&
settings.length && (
<div className={cx('c-chart-tooltip', { simple })}>
{settings.map(d => {
{settings.map((d, i) => {
const label = d.labelFormat
? d.labelFormat(d.label || values[d.labelKey])
: d.label || values[d.labelKey];
Expand All @@ -23,7 +23,10 @@ class ChartTooltip extends PureComponent {
: values[d.key];

return hideZeros && (!values || !value) ? null : (
<div key={d.key} className={`data-line ${d.position || ''}`}>
<div
key={d.key ? d.key : `setting-${i}`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no use of i in keys please. React gets very upset about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves an issue where the key is undefined and react complains about it. Not sure what to add then 🙃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't have a key we shouldn't be rendering it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no unique data to identify what it is then what is it doing there? Check the data and the render to tidy it up.

className={`data-line ${d.position || ''}`}
>
{label && (
<div className="data-label">
{d.color && (
Expand Down
Expand Up @@ -14,7 +14,7 @@ class WidgetComposedChart extends Component {
data: PropTypes.array,
config: PropTypes.object,
settings: PropTypes.object,
settingsConfig: PropTypes.object,
settingsConfig: PropTypes.array,
edbrett marked this conversation as resolved.
Show resolved Hide resolved
preventRenderKeys: PropTypes.array,
handleChangeSettings: PropTypes.func,
parseInteraction: PropTypes.func,
Expand Down
Expand Up @@ -4,40 +4,57 @@ import { format } from 'd3-format';

import PieChart from 'components/charts/pie-chart';
import PieChartLegend from 'components/charts/components/pie-chart-legend';
import Button from 'components/ui/button';

import './styles';

class WidgetPieChart extends PureComponent {
render() {
const { data, settings, simple } = this.props;
const { data, settings, simple, toggleSettingsMenu } = this.props;
const noIntersectionSelected =
!settings.forestType && !settings.landCategory;

return (
<div className="c-pie-chart-legend-widget">
<PieChartLegend
className="cover-legend"
data={data}
config={{
format: '.3s',
unit: 'ha',
key: 'value',
...settings
}}
simple={simple}
/>
<PieChart
className="cover-pie-chart"
data={data}
maxSize={140}
tooltip={[
{
key: 'percentage',
unit: '%',
labelKey: 'label',
unitFormat: value => format('.1f')(value)
}
]}
simple={simple}
/>
{settings &&
settings.showSettingsBtn &&
noIntersectionSelected &&
toggleSettingsMenu && (
<Button
theme="theme-button-small theme-button-light"
className="pie-contextual-settings-btn"
onClick={() => toggleSettingsMenu()}
>
+ Select an intersection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isnt generic, a widget might not have intersections but want this button to exist. It should be configurable.

</Button>
)}
<div className="pie-and-legend">
<PieChartLegend
className="cover-legend"
data={data}
config={{
format: '.3s',
unit: 'ha',
key: 'value',
...settings
}}
simple={simple}
/>
<PieChart
className="cover-pie-chart"
data={data}
maxSize={140}
tooltip={[
{
key: 'percentage',
unit: '%',
labelKey: 'label',
unitFormat: value => format('.1f')(value)
}
]}
simple={simple}
/>
</div>
</div>
);
}
Expand All @@ -46,7 +63,8 @@ class WidgetPieChart extends PureComponent {
WidgetPieChart.propTypes = {
data: PropTypes.array,
simple: PropTypes.bool,
settings: PropTypes.object.isRequired
settings: PropTypes.object.isRequired,
toggleSettingsMenu: PropTypes.func
};

export default WidgetPieChart;
@@ -1,10 +1,17 @@
.c-pie-chart-legend-widget {
display: flex;
flex-direction: row;
justify-content: space-between;
padding-top: rem(30px);

.cover-legend {
min-width: 50%;
.pie-and-legend {
edbrett marked this conversation as resolved.
Show resolved Hide resolved
display: flex;
flex-direction: row;
justify-content: space-between;

.cover-legend {
min-width: 50%;
}
}

.pie-contextual-settings-btn {
margin: 0 10px 20px auto;
}
}
5 changes: 3 additions & 2 deletions app/javascript/components/widgets/fires/fires-within/index.js
Expand Up @@ -22,13 +22,13 @@ export default {
categories: ['fires'],
types: ['global', 'country', 'geostore'],
admins: ['adm0', 'adm1', 'adm2'],
potato: true,
dfrico marked this conversation as resolved.
Show resolved Hide resolved
settingsConfig: [
{
key: 'forestType',
label: 'Forest Type',
type: 'select',
placeholder: 'All categories',
// TODO: default option -> Primary Forests if available, IFL otherwise.
clearable: true,
border: false
},
Expand Down Expand Up @@ -80,7 +80,8 @@ export default {
dataset: 'viirs',
confidence: 'h',
landCategory: '',
forestType: 'ifl'
forestType: '',
showSettingsBtn: true
dfrico marked this conversation as resolved.
Show resolved Hide resolved
},
refetchKeys: ['weeks', 'confidence', 'landCategory', 'forestType'],
sentences: {
Expand Down