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

Add manual discretization method for styles #352

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@
"styles": {
"tab": "Style",
"no-source": "Please select a source before configuring style",
"secondarylabels": "Secondary styles"
"secondarylabels": "Secondary styles",
"boundary": "boundary"
CFarcy marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,8 @@
"styles": {
"tab": "Style",
"no-source": "Veuillez choisir une source de données avant de configurer les styles",
"secondarylabels": "Styles secondaires"
"secondarylabels": "Styles secondaires",
"boundary": "limite"
CFarcy marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ import randomColor from 'randomcolor';

import { makeStyles } from '@material-ui/core/styles';

import { number, useTranslate } from 'react-admin';
import { Field } from 'react-final-form';
import { TextField } from '@material-ui/core';
import ColorPicker from '../../../../../../../components/react-admin/ColorPicker';
import Condition from '../../../../../../../components/react-admin/Condition';

import styles from './styles';

const useStyles = makeStyles(styles);

const DEFAULT_MAX_CLASSES = 15;

const ColorListField = ({ value, onChange = () => {}, maxClasses = DEFAULT_MAX_CLASSES }) => {
const ColorListField = ({ path, value, onChange = () => {}, maxClasses = DEFAULT_MAX_CLASSES }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not a colorListField anymore...

const classes = useStyles();
const translate = useTranslate();

const handleColorChange = index => newValue => {
const newColorList = [...value];
Expand All @@ -35,13 +40,54 @@ const ColorListField = ({ value, onChange = () => {}, maxClasses = DEFAULT_MAX_C
return (
<div className={classes.colorList}>
{(value || []).map((color, index) => (
<ColorPicker
// eslint-disable-next-line react/no-array-index-key
key={index}
value={color}
onChange={handleColorChange(index)}
/>
// eslint-disable-next-line react/no-array-index-key
<React.Fragment key={index}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a validation for step order ?

<Condition when={`${path}.method`} is="manual">
<Field
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't you use react-admin NumberInput here ?

name={`${path}.boundaries[${index}]`}
validate={number()}
parse={v => Number(v)}
initialValue=""
>
{({ meta, input: { value: boundValue, onChange: onBoundChange } }) => (
<TextField
label={translate('datalayer.form.styles.boundary')}
CFarcy marked this conversation as resolved.
Show resolved Hide resolved
value={boundValue}
onChange={onBoundChange}
error={meta.error && meta.touched}
helperText={(meta.error && meta.touched ? meta.error : '')}
/>
)}
</Field>
</Condition>
<ColorPicker
value={color}
onChange={handleColorChange(index)}
/>
<Condition
when={`${path}.method`}
is={v => (v === 'manual' && index === (value.length - 1))}
>
<Field
name={`${path}.boundaries[${value.length}]`}
validate={number()}
initialValue=""
parse={v => Number(v)}
>
{({ meta, input: { value: boundValue, onChange: onBoundChange } }) => (
<TextField
label={translate('datalayer.form.styles.boundary')}
value={boundValue}
onChange={onBoundChange}
error={meta.error && meta.touched}
helperText={meta.error && meta.touched ? meta.error : ''}
/>
)}
</Field>
</Condition>
</React.Fragment>
))}

<button type="button" className="action" onClick={removeColor(value.length - 1)}>
-
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ const GraduateValue = ({ path, Component = ValueListField, defaultValue = defVal
{ id: 'jenks', name: translate('style-editor.graduate.method.jenks') },
{ id: 'quantile', name: translate('style-editor.graduate.method.quantiles') },
{ id: 'equal_interval', name: translate('style-editor.graduate.method.equal-interval') },
/* { id: 'manual', name: translate('style-editor.graduate.method.manual') }, */
{ id: 'manual', name: translate('style-editor.graduate.method.manual') },
]}
/>
</div>

<FormLabel>{translate('style-editor.graduate.steps')}</FormLabel>
<Field name={`${path}.values`} defaultValue={defaultValue}>
{({ input: { value, onChange } }) => (
<Component value={value} onChange={onChange} />
<Component value={value} onChange={onChange} path={path} />
)}
</Field>
</>
Expand Down