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

[7.6] Fix missing labels on certain axes and label filter configurations (#47563) #55565

Merged
merged 1 commit into from
Jan 22, 2020
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 @@ -30,6 +30,7 @@ interface SelectOptionProps<ParamName extends string, ValidParamValues extends s
paramName: ParamName;
value?: ValidParamValues;
setValue: (paramName: ParamName, value: ValidParamValues) => void;
'data-test-subj'?: string;
}

const emptyValue = { text: '', value: 'EMPTY_VALUE', disabled: true, hidden: true };
Expand All @@ -44,6 +45,7 @@ function SelectOption<ParamName extends string, ValidParamValues extends string
paramName,
value,
setValue,
'data-test-subj': dataTestSubj,
}: SelectOptionProps<ParamName, ValidParamValues>) {
const availableOptions = useMemo(() => [emptyValue, ...options], [options]);

Expand All @@ -63,6 +65,7 @@ function SelectOption<ParamName extends string, ValidParamValues extends string
value={value === undefined ? emptyValue.value : value}
onChange={ev => setValue(paramName, ev.target.value as ValidParamValues)}
fullWidth={true}
data-test-subj={dataTestSubj}
/>
</EuiFormRow>
);
Expand Down

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

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 @@ -76,6 +76,7 @@ function CategoryAxisPanel(props: CategoryAxisPanelProps) {
paramName="position"
value={axis.position}
setValue={setPosition}
data-test-subj="categoryAxisPosition"
/>

<SwitchOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ function ValueAxisOptions(props: ValueAxisOptionsParams) {
label={i18n.translate('kbnVislibVisTypes.controls.pointSeries.valueAxes.showLabel', {
defaultMessage: 'Show axis lines and labels',
})}
data-test-subj={`valueAxisShow-${axis.id}`}
paramName="show"
value={axis.show}
setValue={setValueAxis}
Expand Down
39 changes: 25 additions & 14 deletions src/legacy/ui/public/vislib/lib/axis/axis_labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,43 @@ export class AxisLabels {
filterAxisLabels() {
const self = this;
const config = this.axisConfig;
let startPos = 0;
const padding = 1.1;
let lastTickStartEdge = Number.POSITIVE_INFINITY;
let lastTickEndEdge = Number.NEGATIVE_INFINITY;

return function(selection) {
if (!config.get('labels.filter')) return;

const el = $(config.get('rootEl')).find(config.get('elSelector'));
const maxSize = config.isHorizontal() ? el.width() : el.height();
const upperBound = config.isHorizontal() ? el.width() : el.height();
const lowerBound = 0;
const scaleRange = self.axisScale.scale.range();
const scaleWidth = Math.abs(scaleRange[scaleRange.length - 1] - scaleRange[0]);
const scaleStartPad = 0.5 * (maxSize - scaleWidth);
const scaleStartPad = 0.5 * (upperBound - scaleWidth);

selection.selectAll('.tick text').text(function(d) {
const par = d3.select(this.parentNode).node();
const myPos =
const parentNode = d3.select(this.parentNode).node();
const currentTickCenter =
scaleStartPad +
(config.isHorizontal() ? self.axisScale.scale(d) : maxSize - self.axisScale.scale(d));
const mySize =
(config.isHorizontal() ? par.getBBox().width : par.getBBox().height) * padding;
const halfSize = mySize / 2;

if (startPos + halfSize < myPos && maxSize > myPos + halfSize) {
startPos = myPos + halfSize;
return this.textContent;
} else {
(config.isHorizontal() ? self.axisScale.scale(d) : upperBound - self.axisScale.scale(d));
const currentTickSize =
(config.isHorizontal() ? parentNode.getBBox().width : parentNode.getBBox().height) *
padding;
const currentTickHalfSize = currentTickSize / 2;
const currentTickStartEdge = currentTickCenter - currentTickHalfSize;
const currentTickEndEdge = currentTickCenter + currentTickHalfSize;

const outsideUpperBound = currentTickEndEdge > upperBound;
const outsideLowerBound = currentTickStartEdge < lowerBound;
const overlapsLastTick =
currentTickEndEdge >= lastTickStartEdge && currentTickStartEdge <= lastTickEndEdge;

if (outsideUpperBound || outsideLowerBound || overlapsLastTick) {
d3.select(this.parentNode).remove();
} else {
lastTickStartEdge = currentTickCenter - currentTickHalfSize;
lastTickEndEdge = currentTickCenter + currentTickHalfSize;
return this.textContent;
}
});
};
Expand Down
1 change: 0 additions & 1 deletion test/functional/apps/visualize/_area_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ export default function({ getService, getPageObjects }) {
await PageObjects.visEditor.clickMetricsAndAxes();
await PageObjects.visEditor.clickYAxisOptions(axisId);
await PageObjects.visEditor.selectYAxisScaleType(axisId, 'log');
await PageObjects.visEditor.clickYAxisAdvancedOptions(axisId);
await PageObjects.visEditor.changeYAxisFilterLabelsCheckbox(axisId, false);
await PageObjects.visEditor.clickGo();
const labels = await PageObjects.visChart.getYAxisLabels();
Expand Down
1 change: 0 additions & 1 deletion test/functional/apps/visualize/_line_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ export default function({ getService, getPageObjects }) {
await PageObjects.visEditor.clickMetricsAndAxes();
await PageObjects.visEditor.clickYAxisOptions(axisId);
await PageObjects.visEditor.selectYAxisScaleType(axisId, 'log');
await PageObjects.visEditor.clickYAxisAdvancedOptions(axisId);
await PageObjects.visEditor.changeYAxisFilterLabelsCheckbox(axisId, false);
await PageObjects.visEditor.clickGo();
const labels = await PageObjects.visChart.getYAxisLabels();
Expand Down
Loading