Skip to content

Commit 977748d

Browse files
author
Cédric Farcy
committed
Add manual discretization method for styles
1 parent 729388a commit 977748d

File tree

4 files changed

+59
-11
lines changed

4 files changed

+59
-11
lines changed

public/locales/en/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,8 @@
617617
"styles": {
618618
"tab": "Style",
619619
"no-source": "Please select a source before configuring style",
620-
"secondarylabels": "Secondary styles"
620+
"secondarylabels": "Secondary styles",
621+
"boundary": "boundary"
621622
}
622623
}
623624
},

public/locales/fr/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@
619619
"styles": {
620620
"tab": "Style",
621621
"no-source": "Veuillez choisir une source de données avant de configurer les styles",
622-
"secondarylabels": "Styles secondaires"
622+
"secondarylabels": "Styles secondaires",
623+
"boundary": "limite"
623624
}
624625
}
625626
},

src/modules/RA/DataLayer/components/tabs/StyleTab/Style/ColorListField.js

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ import randomColor from 'randomcolor';
33

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

6+
import { number, useTranslate } from 'react-admin';
7+
import { Field } from 'react-final-form';
8+
import { TextField } from '@material-ui/core';
69
import ColorPicker from '../../../../../../../components/react-admin/ColorPicker';
10+
import Condition from '../../../../../../../components/react-admin/Condition';
711

812
import styles from './styles';
913

1014
const useStyles = makeStyles(styles);
1115

1216
const DEFAULT_MAX_CLASSES = 15;
1317

14-
const ColorListField = ({ value, onChange = () => {}, maxClasses = DEFAULT_MAX_CLASSES }) => {
18+
const ColorListField = ({ path, value, onChange = () => {}, maxClasses = DEFAULT_MAX_CLASSES }) => {
1519
const classes = useStyles();
20+
const translate = useTranslate();
1621

1722
const handleColorChange = index => newValue => {
1823
const newColorList = [...value];
@@ -35,13 +40,54 @@ const ColorListField = ({ value, onChange = () => {}, maxClasses = DEFAULT_MAX_C
3540
return (
3641
<div className={classes.colorList}>
3742
{(value || []).map((color, index) => (
38-
<ColorPicker
39-
// eslint-disable-next-line react/no-array-index-key
40-
key={index}
41-
value={color}
42-
onChange={handleColorChange(index)}
43-
/>
43+
// eslint-disable-next-line react/no-array-index-key
44+
<React.Fragment key={index}>
45+
<Condition when={`${path}.method`} is="manual">
46+
<Field
47+
name={`${path}.boundaries[${index}]`}
48+
validate={number()}
49+
parse={v => Number(v)}
50+
initialValue=""
51+
>
52+
{({ meta, input: { value: boundValue, onChange: onBoundChange } }) => (
53+
<TextField
54+
label={translate('datalayer.form.styles.boundary')}
55+
value={boundValue}
56+
onChange={onBoundChange}
57+
error={meta.error && meta.touched}
58+
helperText={(meta.error && meta.touched ? meta.error : '')}
59+
/>
60+
)}
61+
</Field>
62+
</Condition>
63+
<ColorPicker
64+
value={color}
65+
onChange={handleColorChange(index)}
66+
/>
67+
<Condition
68+
when={`${path}.method`}
69+
is={v => (v === 'manual' && index === (value.length - 1))}
70+
>
71+
<Field
72+
name={`${path}.boundaries[${value.length}]`}
73+
validate={number()}
74+
initialValue=""
75+
parse={v => Number(v)}
76+
>
77+
{({ meta, input: { value: boundValue, onChange: onBoundChange } }) => (
78+
<TextField
79+
label={translate('datalayer.form.styles.boundary')}
80+
value={boundValue}
81+
onChange={onBoundChange}
82+
error={meta.error && meta.touched}
83+
helperText={meta.error && meta.touched ? meta.error : ''}
84+
/>
85+
)}
86+
</Field>
87+
</Condition>
88+
</React.Fragment>
4489
))}
90+
4591
<button type="button" className="action" onClick={removeColor(value.length - 1)}>
4692
-
4793
</button>

src/modules/RA/DataLayer/components/tabs/StyleTab/Style/GraduateValue.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ const GraduateValue = ({ path, Component = ValueListField, defaultValue = defVal
3030
{ id: 'jenks', name: translate('style-editor.graduate.method.jenks') },
3131
{ id: 'quantile', name: translate('style-editor.graduate.method.quantiles') },
3232
{ id: 'equal_interval', name: translate('style-editor.graduate.method.equal-interval') },
33-
/* { id: 'manual', name: translate('style-editor.graduate.method.manual') }, */
33+
{ id: 'manual', name: translate('style-editor.graduate.method.manual') },
3434
]}
3535
/>
3636
</div>
3737

3838
<FormLabel>{translate('style-editor.graduate.steps')}</FormLabel>
3939
<Field name={`${path}.values`} defaultValue={defaultValue}>
4040
{({ input: { value, onChange } }) => (
41-
<Component value={value} onChange={onChange} />
41+
<Component value={value} onChange={onChange} path={path} />
4242
)}
4343
</Field>
4444
</>

0 commit comments

Comments
 (0)