Skip to content

Commit

Permalink
[APM] Make number of x ticks responsive to the plot width (#44870) (#…
Browse files Browse the repository at this point in the history
…44992)

* [APM] Make number of x ticks responsive to the plot width

* Fix snapshots
  • Loading branch information
sorenlouv authored Sep 6, 2019
1 parent 3afe1c0 commit 47876a8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
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.

0 comments on commit 47876a8

Please sign in to comment.