-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Maps] custom color ramp * round value down to find center color * do not update redux state with invalide color stops * rename EuiColorStop to ColorStop * remove untracked file * fix jest tests * review feedback * use steps instead of interpolate * add percy functional test to verify rendering of interpolate and step color expressions * add padding to color stop row so add/remove icons do not overlap color select
- Loading branch information
Showing
16 changed files
with
497 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@import './components/color_gradient'; | ||
@import './components/static_dynamic_style_row'; | ||
@import './components/vector/color/color_stops'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
...s/public/layers/styles/components/heatmap/__snapshots__/heatmap_style_editor.test.js.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/_color_stops.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.mapColorStop { | ||
position: relative; | ||
padding-right: $euiSizeXL + $euiSizeXS; | ||
|
||
&:hover, | ||
&:focus { | ||
.mapColorStop__icons { | ||
visibility: visible; | ||
opacity: 1; | ||
display: block; | ||
animation: mapColorStopBecomeVisible $euiAnimSpeedFast $euiAnimSlightResistance; | ||
} | ||
} | ||
} | ||
|
||
.mapColorStop__icons { | ||
flex-shrink: 0; | ||
display: none; | ||
position: absolute; | ||
right: 0; | ||
top: 50%; | ||
margin-right: -$euiSizeS; | ||
margin-top: -$euiSizeM; | ||
} | ||
|
||
@keyframes mapColorStopBecomeVisible { | ||
0% { opacity: 0; } | ||
100% { opacity: 1; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
x-pack/legacy/plugins/maps/public/layers/styles/components/vector/color/color_stops.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import _ from 'lodash'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
EuiColorPicker, | ||
EuiFormRow, | ||
EuiFieldNumber, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiButtonIcon | ||
} from '@elastic/eui'; | ||
import { | ||
addRow, | ||
removeRow, | ||
isColorInvalid, | ||
isStopInvalid, | ||
isInvalid, | ||
} from './color_stops_utils'; | ||
|
||
const DEFAULT_COLOR = '#FF0000'; | ||
|
||
export const ColorStops = ({ | ||
colorStops = [{ stop: 0, color: DEFAULT_COLOR }], | ||
onChange, | ||
}) => { | ||
function getStopInput(stop, index) { | ||
const onStopChange = e => { | ||
const newColorStops = _.cloneDeep(colorStops); | ||
const sanitizedValue = parseFloat(e.target.value); | ||
newColorStops[index].stop = isNaN(sanitizedValue) ? '' : sanitizedValue; | ||
onChange({ | ||
colorStops: newColorStops, | ||
isInvalid: isInvalid(newColorStops), | ||
}); | ||
}; | ||
|
||
let error; | ||
if (isStopInvalid(stop)) { | ||
error = 'Stop must be a number'; | ||
} else if (index !== 0 && colorStops[index - 1].stop >= stop) { | ||
error = 'Stop must be greater than previous stop value'; | ||
} | ||
|
||
return { | ||
stopError: error, | ||
stopInput: ( | ||
<EuiFieldNumber | ||
aria-label="Stop" | ||
value={stop} | ||
onChange={onStopChange} | ||
/> | ||
), | ||
}; | ||
} | ||
|
||
function getColorInput(color, index) { | ||
const onColorChange = color => { | ||
const newColorStops = _.cloneDeep(colorStops); | ||
newColorStops[index].color = color; | ||
onChange({ | ||
colorStops: newColorStops, | ||
isInvalid: isInvalid(newColorStops), | ||
}); | ||
}; | ||
|
||
return { | ||
colorError: isColorInvalid(color) | ||
? 'Color must provide a valid hex value' | ||
: undefined, | ||
colorInput: <EuiColorPicker onChange={onColorChange} color={color} />, | ||
}; | ||
} | ||
|
||
const rows = colorStops.map((colorStop, index) => { | ||
const { stopError, stopInput } = getStopInput(colorStop.stop, index); | ||
const { colorError, colorInput } = getColorInput(colorStop.color, index); | ||
const errors = []; | ||
if (stopError) { | ||
errors.push(stopError); | ||
} | ||
if (colorError) { | ||
errors.push(colorError); | ||
} | ||
|
||
const onRemove = () => { | ||
const newColorStops = removeRow(colorStops, index); | ||
onChange({ | ||
colorStops: newColorStops, | ||
isInvalid: isInvalid(newColorStops), | ||
}); | ||
}; | ||
|
||
const onAdd = () => { | ||
const newColorStops = addRow(colorStops, index); | ||
|
||
onChange({ | ||
colorStops: newColorStops, | ||
isInvalid: isInvalid(newColorStops), | ||
}); | ||
}; | ||
|
||
let deleteButton; | ||
if (colorStops.length > 1) { | ||
deleteButton = ( | ||
<EuiButtonIcon | ||
iconType="trash" | ||
color="danger" | ||
aria-label="Delete" | ||
title="Delete" | ||
onClick={onRemove} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<EuiFormRow | ||
key={index} | ||
className="mapColorStop" | ||
isInvalid={errors.length !== 0} | ||
error={errors} | ||
> | ||
<div> | ||
<EuiFlexGroup responsive={false} alignItems="center" gutterSize="s"> | ||
<EuiFlexItem>{stopInput}</EuiFlexItem> | ||
<EuiFlexItem>{colorInput}</EuiFlexItem> | ||
</EuiFlexGroup> | ||
<div className="mapColorStop__icons"> | ||
{deleteButton} | ||
<EuiButtonIcon | ||
iconType="plusInCircle" | ||
color="primary" | ||
aria-label="Add" | ||
title="Add" | ||
onClick={onAdd} | ||
/> | ||
</div> | ||
</div> | ||
</EuiFormRow> | ||
); | ||
}); | ||
|
||
return <div>{rows}</div>; | ||
}; | ||
|
||
ColorStops.propTypes = { | ||
/** | ||
* Array of { stop, color }. | ||
* Stops are numbers in strictly ascending order. | ||
* The range is from the given stop number (inclusive) to the next stop number (exclusive). | ||
* Colors are color hex strings (3 or 6 character). | ||
*/ | ||
colorStops: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
stopKey: PropTypes.number, | ||
color: PropTypes.string, | ||
}) | ||
), | ||
/** | ||
* Callback for when the color stops changes. Called with { colorStops, isInvalid } | ||
*/ | ||
onChange: PropTypes.func.isRequired, | ||
}; |
Oops, something went wrong.