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

Time axis shadow #15411

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 8 additions & 1 deletion src/coord/Axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import OrdinalScale from '../scale/Ordinal';
import Model from '../model/Model';
import { AxisBaseOption, OptionAxisType } from './axisCommonTypes';
import { AxisBaseModel } from './AxisBaseModel';
import TimeScale from '../scale/Time';

const NORMALIZED_EXTENT = [0, 1] as [number, number];

Expand Down Expand Up @@ -246,7 +247,13 @@ class Axis {
const axisExtent = this._extent;
const dataExtent = this.scale.getExtent();

let len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0);
let len = 0;
if (this.scale.type === 'time') {
len = Math.ceil((dataExtent[1] - dataExtent[0]) / (this.scale as TimeScale)._approxInterval);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the engineering point of view, it may not be a good idea to check the type of scale in Axis. I didn't dive into the code but does this change means the getExtent of time axis returns a result that is not expected? If so, should we change the logic inside time scale? For example, does other functions have bug with time axis when calling getExtent?

Copy link
Contributor Author

@susiwen8 susiwen8 Jul 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this change means the getExtent of time axis returns a result that is not expected?

No, getExtent returns perfectly. Nothing wrong about that. The problem here is dataExtent could be extremely larger that axisExtent since time dataExtent are timestamps. that leads Math.abs(size) / len to almost 0

For example in this case: dataExtent is 505854800.9370117

We should treat time axis as category axis to calcule how many section on axis. @Ovilia

}
else {
len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0);
}
// Fix #2728, avoid NaN when only one data.
len === 0 && (len = 1);

Expand Down
47 changes: 47 additions & 0 deletions test/axis-interval2.html

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

Loading