-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(legend): add custom legend component (#1889)
The settings now have a new prop `customLegend` which lets users provide there own legend React component that is rendered with the chart state into the legend container. Analogously to the `customTooltip` in the `Tooltip`, the `customLegend` takes a React component which will receive the state of the standard legend as props. This allows users to provide their own legend implementation. The legend is still rendered inside of the `div.echLegendListContainer`. Co-authored-by: Marco Vettorello <[email protected]>
- Loading branch information
1 parent
2ba2911
commit 2e1648d
Showing
13 changed files
with
263 additions
and
30 deletions.
There are no files selected for viewing
Binary file added
BIN
+38.7 KB
...reenshots/all.test.ts-snapshots/baselines/legend/custom-legend-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
|
||
import { CustomLegendProps, CustomLegend as CustomLegendComponent } from '../../specs'; | ||
import { GlobalChartState } from '../../state/chart_state'; | ||
import { getPointerValueSelector } from '../../state/selectors/get_pointer_value'; | ||
|
||
interface Props extends CustomLegendProps { | ||
component: CustomLegendComponent; | ||
} | ||
|
||
const CustomLegendComponent: React.FC<Props> = ({ component: Component, ...props }) => <Component {...props} />; | ||
|
||
const mapStateToProps = (state: GlobalChartState) => ({ | ||
pointerValue: getPointerValueSelector(state), | ||
}); | ||
|
||
/** @internal */ | ||
export const CustomLegend = connect(mapStateToProps)(CustomLegendComponent); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { GlobalChartState } from '../chart_state'; | ||
import { PointerValue } from '../types'; | ||
|
||
/** @internal */ | ||
export const getPointerValueSelector = (state: GlobalChartState): PointerValue | undefined => { | ||
// TODO: this is taken from the tooltip header currently. Should in the future | ||
// be implemented separately (and probably used *as* the tooltip header). | ||
const header = state.internalChartState?.getTooltipInfo(state)?.header; | ||
if (header) { | ||
const { value, formattedValue, valueAccessor } = header; | ||
return { value, formattedValue, valueAccessor }; | ||
} | ||
}; |
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
Oops, something went wrong.