forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] show custom color ramps in legend (elastic#53780) (elastic#53996)
- Loading branch information
1 parent
3d088cc
commit 647d7cd
Showing
16 changed files
with
541 additions
and
89 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
39 changes: 39 additions & 0 deletions
39
...s/maps/public/layers/styles/vector/components/legend/extract_color_from_style_property.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,39 @@ | ||
/* | ||
* 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 { VectorStyle } from '../../vector_style'; | ||
import { getColorRampCenterColor } from '../../../color_utils'; | ||
|
||
export function extractColorFromStyleProperty(colorStyleProperty, defaultColor) { | ||
if (!colorStyleProperty) { | ||
return defaultColor; | ||
} | ||
|
||
if (colorStyleProperty.type === VectorStyle.STYLE_TYPE.STATIC) { | ||
return colorStyleProperty.options.color; | ||
} | ||
|
||
// Do not use dynamic color unless configuration is complete | ||
if (!colorStyleProperty.options.field || !colorStyleProperty.options.field.name) { | ||
return defaultColor; | ||
} | ||
|
||
// return middle of gradient for dynamic style property | ||
|
||
if (colorStyleProperty.options.useCustomColorRamp) { | ||
if ( | ||
!colorStyleProperty.options.customColorRamp || | ||
!colorStyleProperty.options.customColorRamp.length | ||
) { | ||
return defaultColor; | ||
} | ||
// favor the lowest color in even arrays | ||
const middleIndex = Math.floor((colorStyleProperty.options.customColorRamp.length - 1) / 2); | ||
return colorStyleProperty.options.customColorRamp[middleIndex].color; | ||
} | ||
|
||
return getColorRampCenterColor(colorStyleProperty.options.color); | ||
} |
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
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
105 changes: 105 additions & 0 deletions
105
.../public/layers/styles/vector/properties/__snapshots__/dynamic_color_property.test.js.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
...gacy/plugins/maps/public/layers/styles/vector/properties/components/categorical_legend.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,56 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import _ from 'lodash'; | ||
const EMPTY_VALUE = ''; | ||
|
||
export class CategoricalLegend extends React.Component { | ||
constructor() { | ||
super(); | ||
this._isMounted = false; | ||
this.state = { | ||
label: EMPTY_VALUE, | ||
isPointsOnly: null, | ||
isLinesOnly: null, | ||
}; | ||
} | ||
|
||
async _loadParams() { | ||
const label = await this.props.style.getField().getLabel(); | ||
const isLinesOnly = await this.props.loadIsLinesOnly(); | ||
const isPointsOnly = await this.props.loadIsPointsOnly(); | ||
const newState = { label, isLinesOnly, isPointsOnly }; | ||
if (this._isMounted && !_.isEqual(this.state, newState)) { | ||
this.setState(newState); | ||
} | ||
} | ||
|
||
componentDidUpdate() { | ||
this._loadParams(); | ||
} | ||
|
||
componentWillUnmount() { | ||
this._isMounted = false; | ||
} | ||
|
||
componentDidMount() { | ||
this._isMounted = true; | ||
this._loadParams(); | ||
} | ||
|
||
render() { | ||
if (this.state.label === EMPTY_VALUE) { | ||
return null; | ||
} | ||
return this.props.style.renderBreakedLegend({ | ||
fieldLabel: this.state.label, | ||
isLinesOnly: this.state.isLinesOnly, | ||
isPointsOnly: this.state.isPointsOnly, | ||
symbolId: this.props.symbolId, | ||
}); | ||
} | ||
} |
Oops, something went wrong.