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

no implicit round #302

Merged
merged 1 commit into from
Apr 8, 2021
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
11 changes: 2 additions & 9 deletions src/axis.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {axisTop, axisBottom, axisRight, axisLeft} from "d3";
import {interpolateRound} from "d3";
import {create} from "d3";

export class AxisX {
Expand Down Expand Up @@ -60,7 +59,7 @@ export class AxisX {
const ty = offsetSign * offset + (axis === "top" ? marginTop : height - marginBottom);
return create("svg:g")
.attr("transform", `translate(0,${ty})`)
.call((axis === "top" ? axisTop : axisBottom)(round(x))
.call((axis === "top" ? axisTop : axisBottom)(x)
.ticks(Array.isArray(ticks) ? null : ticks, typeof tickFormat === "function" ? null : tickFormat)
.tickFormat(typeof tickFormat === "function" || !x.tickFormat ? tickFormat : null)
.tickSizeInner(tickSize)
Expand Down Expand Up @@ -145,7 +144,7 @@ export class AxisY {
const tx = offsetSign * offset + (axis === "right" ? width - marginRight : marginLeft);
return create("svg:g")
.attr("transform", `translate(${tx},0)`)
.call((axis === "right" ? axisRight : axisLeft)(round(y))
.call((axis === "right" ? axisRight : axisLeft)(y)
.ticks(Array.isArray(ticks) ? null : ticks, typeof tickFormat === "function" ? null : tickFormat)
.tickFormat(typeof tickFormat === "function" || !y.tickFormat ? tickFormat : null)
.tickSizeInner(tickSize)
Expand Down Expand Up @@ -176,12 +175,6 @@ export class AxisY {
}
}

function round(scale) {
return scale.interpolate // TODO round band and point scales?
? scale.copy().interpolate(interpolateRound)
: scale;
}

function gridX(y2) {
return g => g.selectAll(".tick line")
.clone(true)
Expand Down
8 changes: 4 additions & 4 deletions src/marks/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export class RuleX extends Mark {
.data(index)
.join("line")
.call(applyDirectStyles, this)
.attr("x1", X ? i => Math.round(X[i]) : (marginLeft + width - marginRight) / 2)
.attr("x2", X ? i => Math.round(X[i]) : (marginLeft + width - marginRight) / 2)
.attr("x1", X ? i => X[i] : (marginLeft + width - marginRight) / 2)
.attr("x2", X ? i => X[i] : (marginLeft + width - marginRight) / 2)
.attr("y1", Y1 ? i => Y1[i] : marginTop)
.attr("y2", Y2 ? (y.bandwidth ? i => Y2[i] + y.bandwidth() : i => Y2[i]) : height - marginBottom)
.attr("stroke", S && (i => S[i]))
Expand Down Expand Up @@ -102,8 +102,8 @@ export class RuleY extends Mark {
.call(applyDirectStyles, this)
.attr("x1", X1 ? i => X1[i] : marginLeft)
.attr("x2", X2 ? (x.bandwidth ? i => X2[i] + x.bandwidth() : i => X2[i]) : width - marginRight)
.attr("y1", Y ? i => Math.round(Y[i]) : (marginTop + height - marginBottom) / 2)
.attr("y2", Y ? i => Math.round(Y[i]) : (marginTop + height - marginBottom) / 2)
.attr("y1", Y ? i => Y[i] : (marginTop + height - marginBottom) / 2)
.attr("y2", Y ? i => Y[i] : (marginTop + height - marginBottom) / 2)
.attr("stroke", S && (i => S[i]))
.call(title(L)))
.node();
Expand Down
8 changes: 4 additions & 4 deletions src/marks/tick.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export class TickX extends AbstractTick {
selection.call(applyTransform, x, null, 0.5, 0);
}
_x1(scales, {x: X}) {
return i => Math.round(X[i]);
return i => X[i];
}
_x2(scales, {x: X}) {
return i => Math.round(X[i]);
return i => X[i];
}
_y1(scales, {y: Y}, {marginTop}) {
return Y ? i => Y[i] : marginTop;
Expand Down Expand Up @@ -98,10 +98,10 @@ export class TickY extends AbstractTick {
return X ? i => X[i] + x.bandwidth() : width - marginRight;
}
_y1(scales, {y: Y}) {
return i => Math.round(Y[i]);
return i => Y[i];
}
_y2(scales, {y: Y}) {
return i => Math.round(Y[i]);
return i => Y[i];
}
}

Expand Down
500 changes: 250 additions & 250 deletions test/output/aaplCandlestick.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 23 additions & 23 deletions test/output/aaplChangeVolume.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 14 additions & 14 deletions test/output/aaplClose.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions test/output/aaplVolume.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading