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

tip for dense raster #1647

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
16 changes: 12 additions & 4 deletions src/interactions/pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,18 @@ export function pointerY(options) {
return pointerK(0.01, 1, options);
}

export function anchorX({x1: X1, x2: X2, x: X = X1}, cx) {
return X1 && X2 ? (i) => (X1[i] + X2[i]) / 2 : X ? (i) => X[i] : () => cx;
function anchorK(k, values, c) {
let {[`${k}1`]: V1, [`${k}2`]: V2, [k]: V, channels} = values;
if (V1 && channels[`${k}1`].hint?.singleton) V1 = null;
if (V2 && channels[`${k}2`].hint?.singleton) V2 = null;
if (V === undefined) V = V1;
return V1 && V2 ? (i) => (V1[i] + V2[i]) / 2 : V ? (i) => V[i] : () => c;
}

export function anchorY({y1: Y1, y2: Y2, y: Y = Y1}, cy) {
return Y1 && Y2 ? (i) => (Y1[i] + Y2[i]) / 2 : Y ? (i) => Y[i] : () => cy;
export function anchorX(values, cx) {
return anchorK("x", values, cx);
}

export function anchorY(values, cy) {
return anchorK("y", values, cy);
}
11 changes: 7 additions & 4 deletions src/marks/raster.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {Mark} from "../mark.js";
import {applyAttr, applyDirectStyles, applyIndirectStyles, applyTransform, impliedString} from "../style.js";
import {initializer} from "../transforms/basic.js";

// A hint for the pointer interaction…
const singleton = {singleton: true};

const defaults = {
ariaLabel: "raster",
stroke: null,
Expand Down Expand Up @@ -65,10 +68,10 @@ export class AbstractRaster extends Mark {
{
x: {value: x, scale: "x", optional: true},
y: {value: y, scale: "y", optional: true},
x1: {value: x1 == null ? null : [x1], scale: "x", optional: true, filter: null},
y1: {value: y1 == null ? null : [y1], scale: "y", optional: true, filter: null},
x2: {value: x2 == null ? null : [x2], scale: "x", optional: true, filter: null},
y2: {value: y2 == null ? null : [y2], scale: "y", optional: true, filter: null},
x1: {value: x1 == null ? null : [x1], scale: "x", optional: true, filter: null, hint: singleton},
y1: {value: y1 == null ? null : [y1], scale: "y", optional: true, filter: null, hint: singleton},
x2: {value: x2 == null ? null : [x2], scale: "x", optional: true, filter: null, hint: singleton},
y2: {value: y2 == null ? null : [y2], scale: "y", optional: true, filter: null, hint: singleton},
...channels
},
options,
Expand Down
73 changes: 73 additions & 0 deletions test/output/tipRasterDense.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions test/plots/tip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ export async function tipRaster() {
});
}

export async function tipRasterDense() {
const volcano = await d3.json<any>("data/volcano.json");
return Plot.plot({
marks: [Plot.raster(volcano.values, {width: volcano.width, height: volcano.height, tip: true}), Plot.frame()]
});
}

export async function tipRule() {
const penguins = await d3.csv<any>("data/penguins.csv", d3.autoType);
return Plot.ruleX(penguins, {x: "body_mass_g", tip: true}).plot();
Expand Down