Skip to content

Commit 3601ab6

Browse files
committed
exposeProjection (the old exposeProjection is renamed to prepareProjection)
1 parent 77c6577 commit 3601ab6

2 files changed

Lines changed: 8 additions & 16 deletions

File tree

src/projection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function createProjection(
3838
dimensions
3939
) {
4040
if (projection == null) return;
41-
if (typeof projection.stream === "function") return exposeProjection(projection); // projection implementation
41+
if (typeof projection.stream === "function") return prepareProjection(projection); // projection implementation
4242
let options;
4343
let domain;
4444
let clip = "frame";
@@ -114,7 +114,7 @@ export function createProjection(
114114
};
115115
}
116116

117-
function exposeProjection(projection) {
117+
function prepareProjection(projection) {
118118
return typeof projection === "function"
119119
? {
120120
stream: (s) => projection.stream(s),

src/scales.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
coerceDates
1111
} from "./options.js";
1212
import {orderof} from "./order.js";
13-
import {createProjection, projectionAspectRatio} from "./projection.js";
13+
import {createDimensions} from "./dimensions.js";
14+
import {createProjection} from "./projection.js";
1415
import {registry, color, position, radius, opacity, symbol, length} from "./scales/index.js";
1516
import {
1617
createScaleLinear,
@@ -527,24 +528,15 @@ export function scale(options = {}) {
527528
if (!registry.has(key)) continue; // ignore unknown properties
528529
if (!isScaleOptions(options[key])) continue; // e.g., ignore {color: "red"}
529530
if (scale !== undefined) throw new Error("ambiguous scale definition; multiple scales found");
530-
scale = key === "projection" ? scaleProjection(options[key]) : exposeScale(normalizeScale(key, options[key]));
531+
scale = key === "projection" ? exposeProjection(options[key]) : exposeScale(normalizeScale(key, options[key]));
531532
}
532533
if (scale === undefined) throw new Error("invalid scale definition; no scale found");
533534
return scale;
534535
}
535536

536-
function scaleProjection({
537-
width = 640,
538-
height,
539-
margin = 0,
540-
marginTop = margin,
541-
marginRight = margin,
542-
marginBottom = margin,
543-
marginLeft = margin,
544-
...projection
545-
}) {
546-
if (height === undefined) height = width * projectionAspectRatio(projection);
547-
const p = createProjection({projection}, {width, height, marginTop, marginRight, marginBottom, marginLeft});
537+
function exposeProjection({width, height, margin, marginTop, marginRight, marginBottom, marginLeft, ...projection}) {
538+
const dimensions = createDimensions({}, [], {projection, width, height, margin, marginTop, marginRight, marginBottom, marginLeft}); // prettier-ignore
539+
const p = createProjection({projection}, dimensions);
548540
if (p === undefined) throw new Error("invalid scale definition; unknown projection");
549541
return p;
550542
}

0 commit comments

Comments
 (0)