Skip to content

Commit

Permalink
Merge pull request #3997 from Vizzuality/feature/fires-within-setting…
Browse files Browse the repository at this point in the history
…s-btn

Feature/fires within settings btn
  • Loading branch information
edbrett committed May 26, 2020
2 parents ffb25fc + 77669e6 commit 371fc23
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 37 deletions.
Expand Up @@ -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.labelKey}
className={`data-line ${d.position || ''}`}
>
{label && (
<div className="data-label">
{d.color && (
Expand Down
7 changes: 5 additions & 2 deletions app/javascript/components/widget/component.jsx
Expand Up @@ -49,7 +49,8 @@ class Widget extends PureComponent {
location: PropTypes.object,
adminLevel: PropTypes.string,
preventRenderKeys: PropTypes.array,
geostore: PropTypes.object
geostore: PropTypes.object,
settingsBtnConfig: PropTypes.object
};

state = {
Expand Down Expand Up @@ -97,7 +98,8 @@ class Widget extends PureComponent {
locationData,
location,
preventRenderKeys,
geostore
geostore,
settingsBtnConfig
} = this.props;
const { main } = colors || {};

Expand Down Expand Up @@ -167,6 +169,7 @@ class Widget extends PureComponent {
handleChangeSettings={handleChangeSettings}
parseInteraction={parseInteraction}
toggleSettingsMenu={toggleSettingsMenu}
settingsBtnConfig={settingsBtnConfig}
/>
{sentence &&
data && (
Expand Down
Expand Up @@ -36,7 +36,7 @@ WidgetNumberedList.propTypes = {
className: PropTypes.string,
data: PropTypes.array,
settings: PropTypes.object.isRequired,
settingsConfig: PropTypes.object,
settingsConfig: PropTypes.array,
handleChangeSettings: PropTypes.func.isRequired,
embed: PropTypes.bool
};
Expand Down
Expand Up @@ -4,40 +4,64 @@ 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,
settingsBtnConfig
} = this.props;
const showSettingsBtn =
settingsBtnConfig &&
settingsBtnConfig.shouldShowButton &&
settingsBtnConfig.shouldShowButton(this.props);

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 &&
showSettingsBtn &&
toggleSettingsMenu && (
<Button
theme="theme-button-small theme-button-light"
className="pie-contextual-settings-btn"
onClick={() => toggleSettingsMenu()}
>
{settingsBtnConfig.text}
</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 +70,9 @@ class WidgetPieChart extends PureComponent {
WidgetPieChart.propTypes = {
data: PropTypes.array,
simple: PropTypes.bool,
settings: PropTypes.object.isRequired
settings: PropTypes.object.isRequired,
toggleSettingsMenu: PropTypes.func,
settingsBtnConfig: PropTypes.object
};

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 {
display: flex;
flex-direction: row;
justify-content: space-between;

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

.pie-contextual-settings-btn {
margin: 0 10px 20px auto;
}
}
Expand Up @@ -28,7 +28,6 @@ export default {
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,6 +79,11 @@ export default {
dataset: 'viirs',
confidence: 'h'
},
settingsBtnConfig: {
text: '+ Select an intersection',
shouldShowButton: props =>
!props.settings.forestType && !props.settings.landCategory
},
refetchKeys: ['weeks', 'confidence', 'landCategory', 'forestType'],
sentences: {
noIndicator:
Expand Down

0 comments on commit 371fc23

Please sign in to comment.