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.x] [APM] Make number of x ticks responsive to the plot width (#44870) #44991

Merged
merged 1 commit into from
Sep 6, 2019
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 @@ -27,8 +27,6 @@ import { isValidCoordinateValue } from '../../../../utils/isValidCoordinateValue
// see https://github.com/uber/react-vis/issues/1214
const getNull = d => isValidCoordinateValue(d.y) && !isNaN(d.y);

const X_TICK_TOTAL = 7;

class StaticPlot extends PureComponent {
getVisSeries(series, plotValues) {
return series
Expand Down Expand Up @@ -141,12 +139,23 @@ class StaticPlot extends PureComponent {
}

render() {
const { series, tickFormatX, tickFormatY, plotValues, noHits } = this.props;
const {
width,
series,
tickFormatX,
tickFormatY,
plotValues,
noHits
} = this.props;
const { yTickValues } = plotValues;

// approximate number of x-axis ticks based on the width of the plot. There should by approx 1 tick per 100px
// d3 will determine the exact number of ticks based on the selected range
const xTickTotal = Math.floor(width / 100);

return (
<SharedPlot plotValues={plotValues}>
<XAxis tickSize={0} tickTotal={X_TICK_TOTAL} tickFormat={tickFormatX} />
<XAxis tickSize={0} tickTotal={xTickTotal} tickFormat={tickFormatX} />
{noHits ? (
<StatusText
marginLeft={30}
Expand Down Expand Up @@ -181,5 +190,6 @@ StaticPlot.propTypes = {
series: PropTypes.array.isRequired,
plotValues: PropTypes.object.isRequired,
tickFormatX: PropTypes.func,
tickFormatY: PropTypes.func.isRequired
tickFormatY: PropTypes.func.isRequired,
width: PropTypes.number.isRequired
};
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export class InnerCustomPlot extends PureComponent {
<Fragment>
<div style={{ position: 'relative', height: plotValues.XY_HEIGHT }}>
<StaticPlot
width={width}
noHits={noHits}
plotValues={plotValues}
series={enabledSeries}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe('when response has no data', () => {
onHover={onHover}
onMouseLeave={onMouseLeave}
onSelectionEnd={onSelectionEnd}
width={100}
width={800}
tickFormatX={x => x.getTime()} // Avoid timezone issues in snapshots
/>
);
Expand Down

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