Skip to content

interval scale override #1855

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

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
40 changes: 23 additions & 17 deletions src/transforms/interval.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function maybeIntervalValue(value, {interval}) {

function maybeIntervalK(k, maybeInsetK, options, trivial) {
const {[k]: v, [`${k}1`]: v1, [`${k}2`]: v2} = options;
const {value, interval} = maybeIntervalValue(v, options);
const {value, interval, scale} = maybeIntervalValue(v, options);
if (value == null || (interval == null && !trivial)) return options;
const label = labelof(v);
if (interval == null) {
Expand All @@ -33,31 +33,37 @@ function maybeIntervalK(k, maybeInsetK, options, trivial) {
return maybeInsetK({
...options,
[k]: undefined,
[`${k}1`]: v1 === undefined ? {transform, label} : v1,
[`${k}2`]: v2 === undefined ? {transform: (data) => transform(data).map((v) => interval.offset(v)), label} : v2
[`${k}1`]: v1 === undefined ? {value: {transform, label}, scale} : v1,
[`${k}2`]:
v2 === undefined
? {value: {transform: (data) => transform(data).map((v) => interval.offset(v)), label}, scale}
: v2
});
}

function maybeIntervalMidK(k, maybeInsetK, options) {
const {[k]: v} = options;
const {value, interval} = maybeIntervalValue(v, options);
const {value, interval, scale} = maybeIntervalValue(v, options);
if (value == null || interval == null) return options;
return maybeInsetK({
...options,
[k]: {
label: labelof(v),
transform: (data) => {
const V1 = map(valueof(data, value), (v) => interval.floor(v));
const V2 = V1.map((v) => interval.offset(v));
return V1.map(
isTemporal(V1)
? (v1, v2) =>
v1 == null || isNaN((v1 = +v1)) || ((v2 = V2[v2]), v2 == null) || isNaN((v2 = +v2))
? undefined
: new Date((v1 + v2) / 2)
: (v1, v2) => (v1 == null || ((v2 = V2[v2]), v2 == null) ? NaN : (+v1 + +v2) / 2)
);
}
value: {
label: labelof(v),
transform: (data) => {
const V1 = map(valueof(data, value), (v) => interval.floor(v));
const V2 = V1.map((v) => interval.offset(v));
return V1.map(
isTemporal(V1)
? (v1, v2) =>
v1 == null || isNaN((v1 = +v1)) || ((v2 = V2[v2]), v2 == null) || isNaN((v2 = +v2))
? undefined
: new Date((v1 + v2) / 2)
: (v1, v2) => (v1 == null || ((v2 = V2[v2]), v2 == null) ? NaN : (+v1 + +v2) / 2)
);
}
},
scale
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/transforms/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {InternMap, cumsum, greatest, group, groupSort, max, min, rollup, sum} fr
import {ascendingDefined, descendingDefined} from "../defined.js";
import {withTip} from "../mark.js";
import {maybeApplyInterval, maybeColumn, maybeZ, maybeZero} from "../options.js";
import {column, field, mid, one, range, valueof} from "../options.js";
import {column, field, maybeValue, mid, one, range, valueof} from "../options.js";
import {basic} from "./basic.js";
import {exclusiveFacets} from "./exclusiveFacets.js";

Expand Down Expand Up @@ -87,7 +87,7 @@ function stack(x, y = one, kx, ky, {offset, order, reverse}, options) {
return [
basic(options, (data, facets, plotOptions) => {
({data, facets} = exclusiveFacets(data, facets));
const X = x == null ? undefined : setX(maybeApplyInterval(valueof(data, x), plotOptions?.[kx]));
const X = x == null ? undefined : setX(maybeApplyInterval(valueof(data, maybeValue(x).value), plotOptions?.[kx]));
const Y = valueof(data, y, Float64Array);
const Z = valueof(data, z);
const compare = order && order(data, X, Y, Z);
Expand Down
Loading