Skip to content

Commit

Permalink
feat(legacy-plugin-chart-histogram): subject Add legend option to his…
Browse files Browse the repository at this point in the history
…togram chart (apache#905)
  • Loading branch information
maloun96 authored and zhaoyongjie committed Nov 25, 2021
1 parent 71fc9be commit b24d8a5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const config: ControlPanelConfig = {
type: 'CheckboxControl',
label: t('Legend'),
renderTrigger: true,
default: true,
default: false,
description: t('Whether to display the legend (toggles)'),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const propTypes = {
opacity: PropTypes.number,
xAxisLabel: PropTypes.string,
yAxisLabel: PropTypes.string,
showLegend: PropTypes.bool,
};
const defaultProps = {
binCount: 15,
Expand All @@ -66,6 +67,7 @@ class CustomHistogram extends React.PureComponent {
opacity,
xAxisLabel,
yAxisLabel,
showLegend,
} = this.props;

const colorFn = CategoricalColorNamespace.getScale(colorScheme);
Expand All @@ -81,15 +83,17 @@ class CustomHistogram extends React.PureComponent {
width={width}
height={height}
position="top"
renderLegend={({ direction, style }) => (
<LegendOrdinal
style={style}
scale={colorScale}
direction={direction}
shape="rect"
labelMargin="0 15px 0 0"
/>
)}
renderLegend={({ direction, style }) =>
showLegend && (
<LegendOrdinal
style={style}
scale={colorScale}
direction={direction}
shape="rect"
labelMargin="0 15px 0 0"
/>
)
}
renderChart={parent => (
<Histogram
width={parent.width}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ const config: ControlPanelConfig = {
expanded: true,
controlSetRows: [
['color_scheme', 'label_colors'],
[
{
name: 'show_legend',
config: {
type: 'CheckboxControl',
label: t('Legend'),
renderTrigger: true,
default: false,
description: t('Whether to display the legend (toggles)'),
},
},
],
[
{
name: 'link_length',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
*/
export default function transformProps(chartProps) {
const { width, height, formData, queriesData } = chartProps;
const { colorScheme, linkLength, normalized, globalOpacity, xAxisLabel, yAxisLabel } = formData;
const {
colorScheme,
linkLength,
normalized,
globalOpacity,
xAxisLabel,
yAxisLabel,
showLegend,
} = formData;

return {
width,
Expand All @@ -30,5 +38,6 @@ export default function transformProps(chartProps) {
opacity: globalOpacity,
xAxisLabel,
yAxisLabel,
showLegend,
};
}

0 comments on commit b24d8a5

Please sign in to comment.