Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/legends/ramp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {inferFontVariant} from "../axes.js";
import {createContext, create} from "../context.js";
import {map, maybeNumberChannel} from "../options.js";
import {interpolatePiecewise} from "../scales/quantitative.js";
import {applyInlineStyles, impliedString, maybeClassName} from "../style.js";
import {applyInlineStyles, impliedString, maybeClassName, offset} from "../style.js";

export function legendRamp(color, options) {
let {
Expand Down Expand Up @@ -164,6 +164,7 @@ export function legendRamp(color, options) {
.tickFormat(typeof tickFormat === "function" ? tickFormat : undefined)
.tickSize(tickSize)
.tickValues(Array.isArray(ticks) ? ticks : null)
.offset(offset)
)
.attr("font-size", null)
.attr("font-family", null)
Expand Down
6 changes: 5 additions & 1 deletion src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {isNone, isNoneish, isRound, maybeColorChannel, maybeNumberChannel} from
import {keyof, number, string} from "./options.js";
import {warn} from "./warnings.js";

export const offset = (typeof window !== "undefined" ? window.devicePixelRatio > 1 : typeof it === "undefined") ? 0 : 0.5; // prettier-ignore
export let offset = typeof window === "undefined" || window.devicePixelRatio > 1 ? 0 : 0.5;

export function setOffset(o) {
offset = o;
}

let nextClipId = 0;
let nextPatternId = 0;
Expand Down
3 changes: 3 additions & 0 deletions test/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import {createCanvas, loadImage} from "canvas";
import {max, mean, quantile} from "d3";
import * as path from "path";
import beautify from "js-beautify";
import {setOffset} from "../src/style.js";
import assert from "./assert.js";
import it from "./jsdom.js";
import * as plots from "./plots/index.ts"; // TODO index.js

setOffset(0.5);

for (const [name, plot] of Object.entries(plots)) {
it(`plot ${name}`, async () => {
const root = await (name.startsWith("warn") ? assert.warnsAsync : assert.doesNotWarnAsync)(plot);
Expand Down
Loading