Skip to content

Commit

Permalink
feat(layer-legend): add possibility to set legend values manually (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwambach authored Aug 31, 2020
1 parent 8e469dd commit 7f9aa1f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/scripts/components/layers/layer-legend/layer-legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import styles from './layer-legend.styl';

interface Props {
id: string;
values: number[];
values: (number | string)[];
unit: string;
isCompare?: boolean;
}
Expand All @@ -30,7 +30,13 @@ const LayerLegend: FunctionComponent<Props> = ({
<div className={styles.values}>
{values.map((value, index) => (
<div className={styles.value} key={value}>
<FormattedNumber value={value} /> {index === 0 ? unit : ''}
{typeof value === 'string' ? (
value
) : (
<span>
<FormattedNumber value={value} /> {index === 0 ? unit : ''}
</span>
)}
</div>
))}
</div>
Expand Down
14 changes: 12 additions & 2 deletions src/scripts/components/main/globes/globes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface Props {
markers?: Marker[];
}

// eslint-disable-next-line complexity
const Globes: FunctionComponent<Props> = ({backgroundColor, markers = []}) => {
const dispatch = useDispatch();
const selectedLayerIds = useSelector(selectedLayerIdsSelector);
Expand Down Expand Up @@ -87,19 +88,28 @@ const Globes: FunctionComponent<Props> = ({backgroundColor, markers = []}) => {
setCurrentView(globalGlobeView);
}, [globalGlobeView]);

const mainLegendValues = mainLayerDetails?.legendValues || [
mainLayerDetails?.maxValue || 0,
mainLayerDetails?.minValue || 0
];
const compareLegendValues = compareLayerDetails?.legendValues || [
compareLayerDetails?.maxValue || 0,
compareLayerDetails?.minValue || 0
];

return (
<div className={styles.globes}>
{mainLayerDetails && (
<LayerLegend
id={mainLayerDetails.id}
values={[mainLayerDetails.maxValue, mainLayerDetails.minValue]}
values={mainLegendValues}
unit={mainLayerDetails.units}
/>
)}
{compareLayerDetails && (
<LayerLegend
id={compareLayerDetails.id}
values={[compareLayerDetails.maxValue, compareLayerDetails.minValue]}
values={compareLegendValues}
unit={compareLayerDetails.units}
isCompare={true}
/>
Expand Down
1 change: 1 addition & 0 deletions src/scripts/types/layer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export interface Layer {
minValue: number;
maxValue: number;
units: string;
legendValues: string[];
}

0 comments on commit 7f9aa1f

Please sign in to comment.