applyBandTransform · Salebarn/plot@a2c470d · GitHub
Skip to content

Commit a2c470d

Browse files
committed
applyBandTransform
1 parent b95bf89 commit a2c470d

12 files changed

Lines changed: 41 additions & 17 deletions

File tree

src/marks/area.js

Lines changed: 2 additions & 2 deletions

src/marks/axis.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class AxisY {
139139
}
140140

141141
function round(scale) {
142-
return scale.round // TODO round band and point scales?
143-
? scale
144-
: scale.copy().interpolate(interpolateRound);
142+
return scale.interpolate // TODO round band and point scales?
143+
? scale.copy().interpolate(interpolateRound)
144+
: scale;
145145
}

src/marks/bar.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {ascending} from "d3-array";
22
import {create} from "d3-selection";
33
import {filter} from "../defined.js";
44
import {Mark, number, identity, indexOf, first, second, maybeColor} from "../mark.js";
5-
import {Style, applyDirectStyles, applyIndirectStyles} from "../style.js";
5+
import {Style, applyDirectStyles, applyIndirectStyles, applyBandTransform} from "../style.js";
66

77
class AbstractBar extends Mark {
88
constructor(
@@ -45,6 +45,7 @@ class AbstractBar extends Mark {
4545
if (Z) index.sort((i, j) => ascending(Z[i], Z[j]));
4646
return create("svg:g")
4747
.call(applyIndirectStyles, this)
48+
.call(this._transform, scales)
4849
.call(g => g.selectAll()
4950
.data(index)
5051
.join("rect")
@@ -70,6 +71,9 @@ export class Bar extends AbstractBar {
7071
options
7172
);
7273
}
74+
_transform() {
75+
// noop
76+
}
7377
_x({x}, {x: X}) {
7478
const {insetLeft} = this;
7579
return i => x(X[i]) + insetLeft;
@@ -100,6 +104,9 @@ export class BarX extends AbstractBar {
100104
options
101105
);
102106
}
107+
_transform(selection, {x}) {
108+
selection.call(applyBandTransform, x, false);
109+
}
103110
_x({x}, {x: X}) {
104111
const {insetLeft} = this;
105112
return i => Math.min(x(0), x(X[i])) + insetLeft;
@@ -130,6 +137,9 @@ export class BarY extends AbstractBar {
130137
options
131138
);
132139
}
140+
_transform(selection, {y}) {
141+
selection.call(applyBandTransform, false, y);
142+
}
133143
_x({x}, {x: X}) {
134144
const {insetLeft} = this;
135145
return i => x(X[i]) + insetLeft;

src/marks/dot.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {ascending} from "d3-array";
22
import {create} from "d3-selection";
33
import {filter, nonempty} from "../defined.js";
44
import {Mark, indexOf, identity, first, second, maybeColor, maybeNumber} from "../mark.js";
5-
import {Style, applyDirectStyles, applyIndirectStyles} from "../style.js";
5+
import {Style, applyDirectStyles, applyIndirectStyles, applyBandTransform} from "../style.js";
66

77
export class Dot extends Mark {
88
constructor(
@@ -52,6 +52,7 @@ export class Dot extends Mark {
5252
if (Z) index.sort((i, j) => ascending(Z[i], Z[j]));
5353
return create("svg:g")
5454
.call(applyIndirectStyles, this)
55+
.call(applyBandTransform, x, y)
5556
.call(g => g.selectAll()
5657
.data(index)
5758
.join("circle")

src/marks/line.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {line as shapeLine} from "d3-shape";
44
import {Curve} from "../curve.js";
55
import {defined} from "../defined.js";
66
import {Mark, indexOf, identity, first, second, maybeColor} from "../mark.js";
7-
import {Style, applyDirectStyles, applyIndirectStyles, applyTransform} from "../style.js";
7+
import {Style, applyDirectStyles, applyIndirectStyles, applyBandTransform} from "../style.js";
88

99
export class Line extends Mark {
1010
constructor(
@@ -42,7 +42,7 @@ export class Line extends Mark {
4242
render(I, {x, y, color}, {x: X, y: Y, z: Z, stroke: S}) {
4343
return create("svg:g")
4444
.call(applyIndirectStyles, this)
45-
.call(applyTransform, x, y)
45+
.call(applyBandTransform, x, y)
4646
.call(g => g.selectAll()
4747
.data(Z ? group(I, i => Z[i]).values() : [I])
4848
.join("path")

src/marks/link.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {ascending} from "d3-array";
22
import {create} from "d3-selection";
33
import {filter} from "../defined.js";
44
import {Mark, maybeColor} from "../mark.js";
5-
import {Style, applyDirectStyles, applyIndirectStyles} from "../style.js";
5+
import {Style, applyDirectStyles, applyIndirectStyles, applyBandTransform} from "../style.js";
66

77
export class Link extends Mark {
88
constructor(
@@ -42,6 +42,7 @@ export class Link extends Mark {
4242
if (Z) index.sort((i, j) => ascending(Z[i], Z[j]));
4343
return create("svg:g")
4444
.call(applyIndirectStyles, this)
45+
.call(applyBandTransform, x, y)
4546
.call(g => g.selectAll()
4647
.data(index)
4748
.join("line")

src/marks/rect.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {create} from "d3-selection";
33
import {zero} from "../mark.js";
44
import {filter} from "../defined.js";
55
import {Mark, number, maybeColor} from "../mark.js";
6-
import {Style, applyDirectStyles, applyIndirectStyles} from "../style.js";
6+
import {Style, applyDirectStyles, applyIndirectStyles, applyBandTransform} from "../style.js";
77

88
export class Rect extends Mark {
99
constructor(
@@ -54,6 +54,7 @@ export class Rect extends Mark {
5454
if (Z) index.sort((i, j) => ascending(Z[i], Z[j]));
5555
return create("svg:g")
5656
.call(applyIndirectStyles, this)
57+
.call(applyBandTransform, x, y)
5758
.call(g => g.selectAll()
5859
.data(index)
5960
.join("rect")

src/marks/rule.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {ascending} from "d3-array";
22
import {create} from "d3-selection";
33
import {filter} from "../defined.js";
44
import {Mark, identity, maybeColor} from "../mark.js";
5-
import {Style, applyDirectStyles, applyIndirectStyles} from "../style.js";
5+
import {Style, applyDirectStyles, applyIndirectStyles, applyBandTransform} from "../style.js";
66

77
export class RuleX extends Mark {
88
constructor(
@@ -41,6 +41,7 @@ export class RuleX extends Mark {
4141
if (Z) index.sort((i, j) => ascending(Z[i], Z[j]));
4242
return create("svg:g")
4343
.call(applyIndirectStyles, this)
44+
.call(applyBandTransform, x, y)
4445
.call(g => g.selectAll("line")
4546
.data(index)
4647
.join("line")
@@ -91,6 +92,7 @@ export class RuleY extends Mark {
9192
if (Z) index.sort((i, j) => ascending(Z[i], Z[j]));
9293
return create("svg:g")
9394
.call(applyIndirectStyles, this)
95+
.call(applyBandTransform, x, y)
9496
.call(g => g.selectAll("line")
9597
.data(index)
9698
.join("line")

src/marks/text.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {ascending} from "d3-array";
22
import {create} from "d3-selection";
33
import {filter, nonempty} from "../defined.js";
44
import {Mark, indexOf, identity, string, maybeColor} from "../mark.js";
5-
import {Style, applyDirectStyles, applyIndirectStyles, applyAttr, applyTransform} from "../style.js";
5+
import {Style, applyDirectStyles, applyIndirectStyles, applyAttr, applyBandTransform} from "../style.js";
66

77
const first = d => d[0];
88
const second = d => d[1];
@@ -51,7 +51,7 @@ export class Text extends Mark {
5151
if (Z) index.sort((i, j) => ascending(Z[i], Z[j]));
5252
return create("svg:g")
5353
.call(applyIndirectStyles, this)
54-
.call(applyTransform, x, y)
54+
.call(applyBandTransform, x, y)
5555
.call(g => g.selectAll()
5656
.data(index)
5757
.join("text")

src/marks/tick.js

Lines changed: 8 additions & 1 deletion

0 commit comments

Comments
 (0)