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 all 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 @@ -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 {
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;
}
}
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