Skip to content

Commit 5b3fc8f

Browse files
committed
move isCollapsed
1 parent 29fdc97 commit 5b3fc8f

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

src/mark.js

-15
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,3 @@ export function isTemporal(values) {
326326
return value instanceof Date;
327327
}
328328
}
329-
330-
// Certain marks have special behavior if a scale is collapsed, i.e. if the
331-
// domain is degenerate and represents only a single value such as [3, 3]; for
332-
// example, a rect will span the full extent of the chart along a collapsed
333-
// dimension (whereas a dot will simply be drawn in the center).
334-
export function isCollapsed(scale) {
335-
const domain = scale.domain();
336-
const value = scale(domain[0]);
337-
for (let i = 1, n = domain.length; i < n; ++i) {
338-
if (scale(domain[i]) - value) {
339-
return false;
340-
}
341-
}
342-
return true;
343-
}

src/marks/bar.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {create} from "d3";
22
import {filter} from "../defined.js";
3-
import {Mark, number, isCollapsed} from "../mark.js";
3+
import {Mark, number} from "../mark.js";
4+
import {isCollapsed} from "../scales.js";
45
import {applyDirectStyles, applyIndirectStyles, applyTransform, impliedString, applyAttr, applyChannelStyles} from "../style.js";
56
import {maybeStackX, maybeStackY} from "../transforms/stack.js";
67

src/marks/rect.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {create} from "d3";
22
import {filter} from "../defined.js";
3-
import {Mark, number, isCollapsed} from "../mark.js";
3+
import {Mark, number} from "../mark.js";
4+
import {isCollapsed} from "../scales.js";
45
import {applyDirectStyles, applyIndirectStyles, applyTransform, impliedString, applyAttr, applyChannelStyles} from "../style.js";
56
import {maybeStackX, maybeStackY} from "../transforms/stack.js";
67

src/marks/rule.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {create} from "d3";
22
import {filter} from "../defined.js";
3-
import {Mark, identity, number, isCollapsed} from "../mark.js";
3+
import {Mark, identity, number} from "../mark.js";
4+
import {isCollapsed} from "../scales.js";
45
import {applyDirectStyles, applyIndirectStyles, applyTransform, applyChannelStyles} from "../style.js";
56

67
const defaults = {

src/scales.js

+15
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,18 @@ export function applyScales(channels = [], scales) {
129129
}
130130
return values;
131131
}
132+
133+
// Certain marks have special behavior if a scale is collapsed, i.e. if the
134+
// domain is degenerate and represents only a single value such as [3, 3]; for
135+
// example, a rect will span the full extent of the chart along a collapsed
136+
// dimension (whereas a dot will simply be drawn in the center).
137+
export function isCollapsed(scale) {
138+
const domain = scale.domain();
139+
const value = scale(domain[0]);
140+
for (let i = 1, n = domain.length; i < n; ++i) {
141+
if (scale(domain[i]) - value) {
142+
return false;
143+
}
144+
}
145+
return true;
146+
}

0 commit comments

Comments
 (0)