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

A map transform that makes z interval-aware #1846

Draft
wants to merge 4 commits 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
7 changes: 4 additions & 3 deletions src/transforms/map.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {count, group, rank} from "d3";
import {column, identity, isObject, maybeInput, maybeZ, taker, valueof} from "../options.js";
import {column, identity, isObject, maybeApplyInterval, maybeInput, maybeZ, taker, valueof} from "../options.js";
import {basic} from "./basic.js";

export function mapX(mapper, options = {}) {
Expand All @@ -24,15 +24,16 @@ export function mapY(mapper, options = {}) {

export function map(outputs = {}, options = {}) {
const z = maybeZ(options);
const zscale = options.z == null ? null : options.z === options.x ? "x" : options.z === options.y ? "y" : null;
const channels = Object.entries(outputs).map(([key, map]) => {
const input = maybeInput(key, options);
if (input == null) throw new Error(`missing channel: ${key}`);
const [output, setOutput] = column(input);
return {key, input, output, setOutput, map: maybeMap(map)};
});
return {
...basic(options, (data, facets) => {
const Z = valueof(data, z);
...basic(options, (data, facets, plotOptions) => {
const Z = maybeApplyInterval(valueof(data, z), plotOptions?.[zscale]);
const X = channels.map(({input}) => valueof(data, input));
const MX = channels.map(({setOutput}) => setOutput(new Array(data.length)));
for (const facet of facets) {
Expand Down
Loading