Skip to content

Commit c086ee4

Browse files
committed
checkpoint
1 parent 5a9abae commit c086ee4

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/plot.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,22 @@ export function plot(options = {}) {
7272
}
7373
}
7474

75+
// Aggregate and sort time channels.
76+
const timeMarks = new Map();
77+
for (const mark of marks) {
78+
if (mark.timeChannel) {
79+
timeMarks.set(mark, valueof(mark.data, mark.timeChannel.time.value));
80+
}
81+
}
82+
const timeChannels = Array.from(timeMarks, ([,times]) => ({value: times}));
83+
const timeDomain = inferDomain(timeChannels);
84+
const times = aggregateTimes(timeChannels);
85+
7586
// Initialize the marks’ state.
7687
for (const mark of marks) {
7788
if (stateByMark.has(mark)) throw new Error("duplicate mark; each mark must be unique");
89+
90+
// TODO: augment the facets with time, for time-aware marks
7891
const markFacets = facetsIndex === undefined ? undefined
7992
: mark.facet === "auto" ? mark.data === facet.data ? facetsIndex : undefined
8093
: mark.facet === "include" ? facetsIndex
@@ -126,12 +139,6 @@ export function plot(options = {}) {
126139

127140
autoScaleLabels(channelsByScale, scaleDescriptors, axes, dimensions, options);
128141

129-
// Aggregate and sort time channels.
130-
const timeChannels = findTimeChannels(stateByMark);
131-
const timeDomain = inferDomain(timeChannels);
132-
const times = aggregateTimes(timeChannels);
133-
const timeMarks = [];
134-
135142
// Compute value objects, applying scales as needed.
136143
for (const state of stateByMark.values()) {
137144
state.values = valueObject(state.channels, scales);
@@ -217,25 +224,19 @@ export function plot(options = {}) {
217224
for (const [mark, {channels, values, facets}] of stateByMark) {
218225
const facet = facets ? mark.filter(facets[j] ?? facets[0], channels, values) : null;
219226
const node = mark.render(facet, scales, values, subdimensions, context);
220-
if (node != null) {
221-
this.appendChild(node);
222-
if (channels.time) timeMarks.push({mark, node, facet, interp: Object.fromEntries(Object.entries(values).map(([key, value]) => [key, Array.from(value)]))});
223-
}
227+
if (node != null) this.appendChild(node);
224228
}
225229
});
226230
} else {
227231
for (const [mark, {channels, values, facets}] of stateByMark) {
228232
const facet = facets ? mark.filter(facets[0], channels, values) : null;
229233
const index = channels.time ? [] : facet;
230234
const node = mark.render(index, scales, values, dimensions, context);
231-
if (node != null) {
232-
svg.appendChild(node);
233-
if (channels.time) timeMarks.push({mark, node, facet, interp: Object.fromEntries(Object.entries(values).map(([key, value]) => [key, Array.from(value)]))});
234-
}
235+
if (node != null) svg.appendChild(node);
235236
}
236237
}
237238

238-
if (timeMarks.length) {
239+
if (timeMarks.size > 0) {
239240
// TODO There needs to be an option to avoid interpolation and just play
240241
// the distinct times, as given, in ascending order, as keyframes. And
241242
// there needs to be an option to control the delay, duration, iterations,
@@ -244,7 +245,9 @@ export function plot(options = {}) {
244245
const delay = 0; // TODO configurable; delay initial rendering
245246
const duration = 5000; // TODO configurable
246247
const startTime = performance.now() + delay;
247-
requestAnimationFrame(function tick() {
248+
console.warn(timeMarks);
249+
250+
if (false) requestAnimationFrame(function tick() {
248251
const t = Math.max(0, Math.min(1, (performance.now() - startTime) / duration));
249252
const currentTime = interpolateTime(t);
250253
const i0 = bisectLeft(times, currentTime);
@@ -353,7 +356,7 @@ export class Mark {
353356
channels = maybeNamed(channels);
354357
if (extraChannels !== undefined) channels = {...maybeNamed(extraChannels), ...channels};
355358
if (defaults !== undefined) channels = {...styles(this, options, defaults), ...channels};
356-
if (time != null) channels = {time: {value: time}, ...channels};
359+
this.timeChannel = (time != null) ? {time: {value: time}} : null;
357360
this.channels = Object.fromEntries(Object.entries(channels).filter(([name, {value, optional}]) => {
358361
if (value != null) return true;
359362
if (optional) return false;

0 commit comments

Comments
 (0)