Skip to content

Commit

Permalink
Fix missing labels on certain axes and label filter configurations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Jan 23, 2020
1 parent c847492 commit 4bdb59a
Show file tree
Hide file tree
Showing 11 changed files with 559 additions and 489 deletions.
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 @@ -77,6 +77,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('visTypeVislib.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
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

0 comments on commit 4bdb59a

Please sign in to comment.