Skip to content

Commit 61a60cf

Browse files
committed
allows several marks to play together even when their time domains are different
1 parent 9a0e97a commit 61a60cf

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/plot.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,18 @@ export function plot(options = {}) {
7777
for (const mark of marks) {
7878
if (mark.time) {
7979
const time = valueof(mark.data, mark.time);
80+
const domain = sort(new Set(time));
8081
const tkey = new Map();
8182
const key = mark.key
8283
? valueof(mark.data, mark.key)
8384
: time.map((t) => (tkey.set(t, tkey.has(t) ? 1 + tkey.get(t) : 0), tkey.get(t)));
84-
markTimes.set(mark, {time, key});
85+
markTimes.set(mark, {time, domain, key});
8586
}
8687
}
8788
const timeChannels = Array.from(markTimes, ([, {time}]) => ({value: time}));
8889
const timeDomain = inferDomain(timeChannels);
8990
const times = aggregateTimes(timeChannels);
90-
const timesIndex = new Map(times.map((d,i) => [d,i]));
91+
const timesIndex = new Map(times.map((d, i) => [d, i]));
9192

9293
// Initialize the marks’ state.
9394
for (const mark of marks) {
@@ -170,7 +171,7 @@ export function plot(options = {}) {
170171
const newFacets = [];
171172
const newTimes = [];
172173
const newKeys = [];
173-
const {key} = markTimes.get(mark);
174+
const {key, domain} = markTimes.get(mark);
174175
for (let k = 0; k < facets.length; ++k) {
175176
const j = Math.floor(k / times.length);
176177
newFacets[j] = newFacets[j] ? newFacets[j].concat(facets[k]) : facets[k];
@@ -182,7 +183,8 @@ export function plot(options = {}) {
182183
state.facets = newFacets;
183184
markTimes.set(mark, {
184185
key: newKeys,
185-
time: newTimes
186+
time: newTimes,
187+
domain
186188
});
187189
}
188190
}
@@ -315,13 +317,13 @@ export function plot(options = {}) {
315317
requestAnimationFrame(function tick() {
316318
const t = Math.max(0, Math.min(1, (performance.now() - startTime) / duration));
317319
const currentTime = interpolateTime(t);
318-
const i0 = bisectLeft(times, currentTime);
319-
const time0 = times[i0 - 1];
320-
const time1 = times[i0];
321-
const timet = (currentTime - time0) / (time1 - time0);
322320
for (const timeMark of animateMarks) {
323321
const {mark, facet, interp, dimensions} = timeMark;
324-
const {time: T, key: K} = markTimes.get(mark);
322+
const {time: T, domain, key: K} = markTimes.get(mark);
323+
const i0 = bisectLeft(domain, currentTime);
324+
const time0 = domain[i0 - 1];
325+
const time1 = domain[i0];
326+
const timet = (currentTime - time0) / (time1 - time0);
325327
interp.time = T.slice();
326328
const {values} = stateByMark.get(mark);
327329
let timeNode;

0 commit comments

Comments
 (0)