Skip to content

Commit

Permalink
makes {value, scale} channel specification work with the interval tra…
Browse files Browse the repository at this point in the history
…nsform

closes #1329
  • Loading branch information
Fil committed Sep 12, 2023
1 parent e22c41e commit bd80e5f
Show file tree
Hide file tree
Showing 4 changed files with 1,129 additions and 17 deletions.
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
Loading

0 comments on commit bd80e5f

Please sign in to comment.