Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add back minBarHeight on discover histogram #168644

Merged
merged 12 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const createArgsWithLayers = (
layers: DataLayerConfig | DataLayerConfig[] = sampleLayer
): XYProps => ({
showTooltip: true,
minBarHeight: 1,
legend: {
type: 'legendConfig',
isVisible: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,8 @@ export const commonXYArgs: CommonXYFn['args'] = {
types: ['string'],
help: strings.getMinTimeBarIntervalHelp(),
},
minBarHeight: {
types: ['number'],
help: strings.getMinBarHeightHelp(),
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const layeredXyVisFn: LayeredXyVisFn['fn'] = async (data, args, handlers)
args: {
...args,
layers,
minBarHeight: args.minBarHeight ?? 1,
markSizeRatio: hasMarkSizeAccessors && !args.markSizeRatio ? 10 : args.markSizeRatio,
ariaLabel:
args.ariaLabel ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ export const errors = {
defaultMessage: '`minTimeBarInterval` argument is applicable only for time bar charts.',
}
),
invalidMinBarHeightError: () =>
i18n.translate('expressionXY.reusable.function.xyVis.errors.invalidMinBarHeightError', {
defaultMessage:
'The min bar height should be a positive integer, representing pixel height of the bar.',
}),
axisIsNotAssignedError: (axisId: string) =>
i18n.translate('expressionXY.reusable.function.xyVis.errors.axisIsNotAssignedError', {
defaultMessage:
Expand Down Expand Up @@ -297,3 +302,9 @@ export const validateMinTimeBarInterval = (
}
}
};

export const validateMinBarHeight = (minBarHeight?: number) => {
if (minBarHeight !== undefined && minBarHeight < 0) {
throw new Error(errors.invalidMinBarHeightError());
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
validatePointsRadiusForChartType,
validateLinesVisibilityForChartType,
validateAxes,
validateMinBarHeight,
} from './validate';
import { logDatatable } from '../utils';

Expand Down Expand Up @@ -111,6 +112,7 @@ export const xyVisFn: XyVisFn['fn'] = async (data, args, handlers) => {
validateFillOpacity(args.fillOpacity, hasArea);
validateAddTimeMarker(dataLayers, args.addTimeMarker);
validateMinTimeBarInterval(dataLayers, hasBar, args.minTimeBarInterval);
validateMinBarHeight(args.minBarHeight);

validateValueLabels(args.valueLabels, hasBar);
validateMarkSizeRatioWithAccessor(args.markSizeRatio, dataLayers[0].markSizeAccessor);
Expand All @@ -127,6 +129,7 @@ export const xyVisFn: XyVisFn['fn'] = async (data, args, handlers) => {
args: {
...restArgs,
layers,
minBarHeight: args.minBarHeight ?? 1,
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
markSizeRatio:
dataLayers[0].markSizeAccessor && !args.markSizeRatio ? 10 : args.markSizeRatio,
ariaLabel:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export const strings = {
i18n.translate('expressionXY.xyVis.xAxisInterval.help', {
defaultMessage: 'Specifies the min interval for time bar chart',
}),
getMinBarHeightHelp: () =>
i18n.translate('expressionXY.xyVis.minBarHeight.help', {
defaultMessage: 'Specifies the min bar height in pixels for bar chart',
}),
getSplitColumnAccessorHelp: () =>
i18n.translate('expressionXY.xyVis.splitColumnAccessor.help', {
defaultMessage: 'Specifies split column of the xy chart',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export interface XYArgs extends DataLayerArgs {
addTimeMarker?: boolean;
markSizeRatio?: number;
minTimeBarInterval?: string;
minBarHeight?: number;
splitRowAccessor?: ExpressionValueVisDimension | string;
splitColumnAccessor?: ExpressionValueVisDimension | string;
detailedTooltip?: boolean;
Expand Down Expand Up @@ -284,6 +285,7 @@ export interface LayeredXYArgs {
addTimeMarker?: boolean;
markSizeRatio?: number;
minTimeBarInterval?: string;
minBarHeight?: number;
orderBucketsBySum?: boolean;
showTooltip: boolean;
splitRowAccessor?: ExpressionValueVisDimension | string;
Expand All @@ -307,6 +309,7 @@ export interface XYProps {
addTimeMarker?: boolean;
markSizeRatio?: number;
minTimeBarInterval?: string;
minBarHeight: number;
splitRowAccessor?: ExpressionValueVisDimension | string;
splitColumnAccessor?: ExpressionValueVisDimension | string;
detailedTooltip?: boolean;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import {
AreaSeries,
BarSeries,
BarSeriesProps,
CurveType,
LabelOverflowConstraint,
LineSeries,
Expand Down Expand Up @@ -51,6 +52,7 @@ interface Props {
timeZone?: string;
emphasizeFitting?: boolean;
fillOpacity?: number;
minBarHeight: number;
shouldShowValueLabels?: boolean;
valueLabels: ValueLabelMode;
defaultXScaleType: XScaleType;
Expand All @@ -68,6 +70,7 @@ export const DataLayers: FC<Props> = ({
syncColors,
valueLabels,
fillOpacity,
minBarHeight,
formatFactory,
paletteService,
fittingFunction,
Expand Down Expand Up @@ -189,22 +192,28 @@ export const DataLayers: FC<Props> = ({
/>
);
case SeriesTypes.BAR:
const valueLabelsSettings = {
const valueLabelsSettings: Pick<BarSeriesProps, 'displayValueSettings'> = {
displayValueSettings: {
// This format double fixes two issues in elastic-chart
// * when rotating the chart, the formatter is not correctly picked
// * in some scenarios value labels are not strings, and this breaks the elastic-chart lib
valueFormatter: (d: unknown) => yAxis?.formatter?.convert(d) || '',
showValueLabel: shouldShowValueLabels && valueLabels !== ValueLabelModes.HIDE,
isValueContainedInElement: false,
isAlternatingValueLabel: false,
overflowConstraints: [
LabelOverflowConstraint.ChartEdges,
LabelOverflowConstraint.BarGeometry,
],
},
};
return <BarSeries key={index} {...seriesProps} {...valueLabelsSettings} />;
return (
<BarSeries
key={index}
{...seriesProps}
{...valueLabelsSettings}
minBarHeight={minBarHeight}
/>
);
case SeriesTypes.AREA:
return (
<AreaSeries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,7 @@ describe('XYChart component', () => {

const args: XYProps = {
showTooltip: true,
minBarHeight: 1,
legend: { type: 'legendConfig', isVisible: false, position: Position.Top },
valueLabels: 'hide',
yAxisConfigs: [
Expand Down Expand Up @@ -2618,6 +2619,7 @@ describe('XYChart component', () => {
const args: XYProps = {
legend: { type: 'legendConfig', isVisible: false, position: Position.Top },
valueLabels: 'hide',
minBarHeight: 1,
yAxisConfigs: [
{
type: 'yAxisConfig',
Expand Down Expand Up @@ -2706,6 +2708,7 @@ describe('XYChart component', () => {

const args: XYProps = {
showTooltip: true,
minBarHeight: 1,
legend: { type: 'legendConfig', isVisible: true, position: Position.Top },
valueLabels: 'hide',
yAxisConfigs: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ export function XYChart({
syncColors={syncColors}
valueLabels={valueLabels}
fillOpacity={args.fillOpacity}
minBarHeight={args.minBarHeight}
formatFactory={formatFactory}
paletteService={paletteService}
fittingFunction={fittingFunction}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ describe('getLensAttributes', () => {
"position": "right",
"shouldTruncate": false,
},
"minBarHeight": 2,
"preferredSeriesType": "bar_stacked",
"showCurrentTimeMarker": true,
"tickLabelsVisibilitySettings": Object {
Expand Down Expand Up @@ -352,6 +353,7 @@ describe('getLensAttributes', () => {
"position": "right",
"shouldTruncate": false,
},
"minBarHeight": 2,
"preferredSeriesType": "bar_stacked",
"showCurrentTimeMarker": true,
"tickLabelsVisibilitySettings": Object {
Expand Down Expand Up @@ -510,6 +512,7 @@ describe('getLensAttributes', () => {
"position": "right",
"shouldTruncate": false,
},
"minBarHeight": 2,
"preferredSeriesType": "bar_stacked",
"showCurrentTimeMarker": true,
"tickLabelsVisibilitySettings": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
Suggestion,
} from '@kbn/lens-plugin/public';
import { LegendSize } from '@kbn/visualizations-plugin/public';
import { XYConfiguration } from '@kbn/visualizations-plugin/common';
import { fieldSupportsBreakdown } from './field_supports_breakdown';

export interface LensRequestData {
Expand Down Expand Up @@ -139,7 +140,7 @@ export const getLensAttributes = ({
? {
...suggestionVisualizationState,
}
: {
: ({
layers: [
{
accessors: ['count_column'],
Expand Down Expand Up @@ -167,6 +168,7 @@ export const getLensAttributes = ({
preferredSeriesType: 'bar_stacked',
valueLabels: 'hide',
fittingFunction: 'None',
minBarHeight: 2,
showCurrentTimeMarker: true,
axisTitlesVisibilitySettings: {
x: false,
Expand All @@ -183,7 +185,7 @@ export const getLensAttributes = ({
yLeft: true,
yRight: false,
},
};
} as XYConfiguration);
const attributes = {
title:
title ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export interface XYConfiguration {
labelsOrientation?: LabelsOrientationConfig;
curveType?: XYCurveType;
fillOpacity?: number;
minBarHeight?: number;
hideEndzones?: boolean;
valuesInLegend?: boolean;
showCurrentTimeMarker?: boolean;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions x-pack/plugins/lens/public/visualizations/xy/to_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,15 @@ export const buildXYExpression = (

const layeredXyVisFn = buildExpressionFunction<LayeredXyVisFn>('layeredXyVis', {
legend: buildExpression([legendConfigFn]).toAst(),
fittingFunction: state.fittingFunction || 'None',
endValue: state.endValue || 'None',
emphasizeFitting: state.emphasizeFitting || false,
fillOpacity: state.fillOpacity || 0.3,
valueLabels: state?.valueLabels || 'hide',
hideEndzones: state?.hideEndzones || false,
addTimeMarker: state?.showCurrentTimeMarker || false,
valuesInLegend: state?.valuesInLegend || false,
fittingFunction: state.fittingFunction ?? 'None',
endValue: state.endValue ?? 'None',
emphasizeFitting: state.emphasizeFitting ?? false,
minBarHeight: state.minBarHeight ?? 1,
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
fillOpacity: state.fillOpacity ?? 0.3,
valueLabels: state.valueLabels ?? 'hide',
hideEndzones: state.hideEndzones ?? false,
addTimeMarker: state.showCurrentTimeMarker ?? false,
valuesInLegend: state.valuesInLegend ?? false,
yAxisConfigs: [...yAxisConfigsToExpression(yAxisConfigs)],
xAxisConfig: buildExpression([xAxisConfigFn]).toAst(),
showTooltip: [],
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/lens/public/visualizations/xy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export interface XYState {
labelsOrientation?: LabelsOrientationConfig;
curveType?: XYCurveType;
fillOpacity?: number;
minBarHeight?: number;
hideEndzones?: boolean;
showCurrentTimeMarker?: boolean;
valuesInLegend?: boolean;
Expand Down
Loading