Skip to content

Commit

Permalink
use elastic-charts axis calculation (elastic#130429)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Apr 19, 2022
1 parent 1d1903e commit 0045559
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 146 deletions.

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 @@ -530,6 +530,7 @@ describe('XYChart component', () => {
fit: false,
min: 123,
max: 456,
includeDataFromIds: [],
});
});

Expand All @@ -553,6 +554,7 @@ describe('XYChart component', () => {
fit: true,
min: NaN,
max: NaN,
includeDataFromIds: [],
});
});

Expand Down Expand Up @@ -582,6 +584,7 @@ describe('XYChart component', () => {
fit: false,
min: NaN,
max: NaN,
includeDataFromIds: [],
});
});

Expand Down Expand Up @@ -613,6 +616,7 @@ describe('XYChart component', () => {
fit: false,
min: NaN,
max: NaN,
includeDataFromIds: [],
});
});

Expand All @@ -622,44 +626,9 @@ describe('XYChart component', () => {
const component = shallow(<XYChart {...defaultProps} data={data} args={args} />);
expect(component.find(Axis).find('[id="left"]').prop('domain')).toEqual({
fit: false,
min: 0,
max: 150,
});
});

test('it should ignore referenceLine values when set to custom extents', () => {
const { data, args } = sampleArgsWithReferenceLine();

const component = shallow(
<XYChart
{...defaultProps}
data={data}
args={{
...args,
yLeftExtent: {
type: 'axisExtentConfig',
mode: 'custom',
lowerBound: 123,
upperBound: 456,
},
}}
/>
);
expect(component.find(Axis).find('[id="left"]').prop('domain')).toEqual({
fit: false,
min: 123,
max: 456,
});
});

test('it should work for negative values in referenceLines', () => {
const { data, args } = sampleArgsWithReferenceLine(-150);

const component = shallow(<XYChart {...defaultProps} data={data} args={args} />);
expect(component.find(Axis).find('[id="left"]').prop('domain')).toEqual({
fit: false,
min: -150,
max: 5,
min: NaN,
max: NaN,
includeDataFromIds: ['referenceLine-referenceLine-a-rect'],
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import {
getAxesConfiguration,
GroupsConfiguration,
validateExtent,
computeOverallDataDomain,
getColorAssignments,
getLinesCausedPaddings,
} from '../helpers';
Expand Down Expand Up @@ -338,42 +337,21 @@ export function XYChart({
min = extent.lowerBound ?? NaN;
max = extent.upperBound ?? NaN;
}
} else {
const axisHasReferenceLine = referenceLineLayers.some(({ yConfig }) =>
yConfig?.some(({ axisMode }) => axisMode === axis.groupId)
);
if (!fit && axisHasReferenceLine) {
// Remove this once the chart will support automatic annotation fit for other type of charts
const { min: computedMin, max: computedMax } = computeOverallDataDomain(
filteredLayers,
axis.series.map(({ accessor }) => accessor),
data.tables
);

if (computedMin != null && computedMax != null) {
max = Math.max(computedMax, max || 0);
min = Math.min(computedMin, min || 0);
}
for (const { layerId, yConfig } of referenceLineLayers) {
const table = data.tables[layerId];
for (const { axisMode, forAccessor } of yConfig || []) {
if (axis.groupId === axisMode) {
for (const row of table.rows) {
const value = row[forAccessor];
// keep the 0 in view
max = Math.max(value, max || 0, 0);
min = Math.min(value, min || 0, 0);
}
}
}
}
}
}

return {
fit,
min,
max,
includeDataFromIds: referenceLineLayers
.flatMap((l) =>
l.yConfig ? l.yConfig.map((yConfig) => ({ layerId: l.layerId, yConfig })) : []
)
.filter(({ yConfig }) => yConfig.axisMode === axis.groupId)
.map(
({ layerId, yConfig }) =>
`${layerId}-${yConfig.forAccessor}-${yConfig.fill !== 'none' ? 'rect' : 'line'}`
),
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export * from './state';
export * from './visualization';
export * from './fitting_functions';
export * from './axes_configuration';
export * from './reference_lines';
export * from './icon';
export * from './color_assignment';
export * from './annotations_icon_set';
Expand Down

This file was deleted.

0 comments on commit 0045559

Please sign in to comment.