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

[Lens] Threshold: add padding to avoid axis label collision with threshold markers #112952

Merged
merged 19 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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 @@ -30,6 +30,7 @@ interface AxisConfig {
export type YAxisMode = 'auto' | 'left' | 'right' | 'bottom';
export type LineStyle = 'solid' | 'dashed' | 'dotted';
export type FillStyle = 'none' | 'above' | 'below';
export type IconPosition = 'auto' | 'left' | 'right' | 'above' | 'below';

export interface YConfig {
forAccessor: string;
Expand All @@ -39,6 +40,7 @@ export interface YConfig {
lineWidth?: number;
lineStyle?: LineStyle;
fill?: FillStyle;
iconPosition?: IconPosition;
}

export type AxisTitlesVisibilityConfigResult = AxesSettingsConfig & {
Expand Down Expand Up @@ -180,6 +182,11 @@ export const yAxisConfig: ExpressionFunctionDefinition<
types: ['string'],
help: 'An optional icon used for threshold lines',
},
iconPosition: {
types: ['string'],
options: ['auto', 'above', 'below', 'left', 'right'],
help: 'The placement of the icon for the threshold line',
},
fill: {
types: ['string'],
options: ['none', 'above', 'below'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { EuiToolTip, EuiToolTipProps } from '@elastic/eui';

export type TooltipWrapperProps = Partial<Omit<EuiToolTipProps, 'content'>> & {
tooltipContent: string;
/** When the condition is truthy, the tooltip will be shown */
condition: boolean;
};

Expand Down

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

65 changes: 56 additions & 9 deletions x-pack/plugins/lens/public/xy_visualization/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ import { getAxesConfiguration, GroupsConfiguration, validateExtent } from './axe
import { getColorAssignments } from './color_assignment';
import { getXDomain, XyEndzones } from './x_domain';
import { getLegendAction } from './get_legend_action';
import { ThresholdAnnotations } from './expression_thresholds';
import {
computeChartMargins,
getThresholdRequiredPaddings,
ThresholdAnnotations,
} from './expression_thresholds';

declare global {
interface Window {
Expand Down Expand Up @@ -314,6 +318,12 @@ export function XYChart({
Boolean(isHistogramViz)
);

const yAxesMap = {
left: yAxesConfiguration.find(({ groupId }) => groupId === 'left'),
right: yAxesConfiguration.find(({ groupId }) => groupId === 'right'),
};
const thresholdPaddings = getThresholdRequiredPaddings(thresholdLayers, yAxesMap);

const getYAxesTitles = (
axisSeries: Array<{ layer: string; accessor: string }>,
groupId: string
Expand All @@ -330,23 +340,38 @@ export function XYChart({
);
};

const getYAxesStyle = (groupId: string) => {
const getYAxesStyle = (groupId: 'left' | 'right') => {
const tickVisible =
groupId === 'right'
? tickLabelsVisibilitySettings?.yRight
: tickLabelsVisibilitySettings?.yLeft;

const style = {
tickLabel: {
visible:
groupId === 'right'
? tickLabelsVisibilitySettings?.yRight
: tickLabelsVisibilitySettings?.yLeft,
visible: tickVisible,
rotation:
groupId === 'right'
? args.labelsOrientation?.yRight || 0
: args.labelsOrientation?.yLeft || 0,
padding:
thresholdPaddings[groupId] != null
? {
inner: thresholdPaddings[groupId],
}
: undefined,
},
axisTitle: {
visible:
groupId === 'right'
? axisTitlesVisibilitySettings?.yRight
: axisTitlesVisibilitySettings?.yLeft,
// if labels are not visible add the padding to the title
padding:
!tickVisible && thresholdPaddings[groupId] != null
? {
inner: thresholdPaddings[groupId],
}
: undefined,
},
};
return style;
Expand Down Expand Up @@ -510,6 +535,17 @@ export function XYChart({
legend: {
labelOptions: { maxLines: legend.shouldTruncate ? legend?.maxLines ?? 1 : 0 },
},
// if not title or labels are shown for axes, add some padding if required by threshold markers
chartMargins: {
...chartTheme.chartPaddings,
...computeChartMargins(
thresholdPaddings,
tickLabelsVisibilitySettings,
axisTitlesVisibilitySettings,
yAxesMap,
shouldRotate
),
},
}}
baseTheme={chartBaseTheme}
tooltip={{
Expand Down Expand Up @@ -545,9 +581,15 @@ export function XYChart({
tickLabel: {
visible: tickLabelsVisibilitySettings?.x,
rotation: labelsOrientation?.x,
padding:
thresholdPaddings.bottom != null ? { inner: thresholdPaddings.bottom } : undefined,
},
axisTitle: {
visible: axisTitlesVisibilitySettings.x,
padding:
!tickLabelsVisibilitySettings?.x && thresholdPaddings.bottom != null
? { inner: thresholdPaddings.bottom }
: undefined,
},
}}
/>
Expand All @@ -568,7 +610,7 @@ export function XYChart({
}}
hide={filteredLayers[0].hide}
tickFormat={(d) => axis.formatter?.convert(d) || ''}
style={getYAxesStyle(axis.groupId)}
style={getYAxesStyle(axis.groupId as 'left' | 'right')}
domain={getYAxisDomain(axis)}
/>
);
Expand Down Expand Up @@ -839,10 +881,15 @@ export function XYChart({
syncColors={syncColors}
paletteService={paletteService}
formatters={{
left: yAxesConfiguration.find(({ groupId }) => groupId === 'left')?.formatter,
right: yAxesConfiguration.find(({ groupId }) => groupId === 'right')?.formatter,
left: yAxesMap.left?.formatter,
right: yAxesMap.right?.formatter,
bottom: xAxisFormatter,
}}
axesMap={{
left: Boolean(yAxesMap.left),
right: Boolean(yAxesMap.right),
}}
isHorizontal={shouldRotate}
/>
) : null}
</Chart>
Expand Down
Loading