Skip to content

Commit 4c1125a

Browse files
committed
tweaks
1 parent 6e794be commit 4c1125a

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

src/marks/tip.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ export interface TipOptions extends MarkOptions, TextStyles {
6363
anchor?: FrameAnchor;
6464

6565
/**
66-
* The format option controls what the tip shows. It may be specified as a
67-
* function which is passed the datum d and zero-based index i and returns a
68-
* string or an iterable of already-formatted tip items, or an iterable of
69-
* channels or values and how to format them.
66+
* The format option controls what the tip shows; either a function which is
67+
* passed the datum d and zero-based index i and returns a string or an
68+
* iterable of formatted tip items, or an iterable of channel names or values
69+
* and optionally how to label and format them.
7070
*/
7171
format?: ((d: any, i: number) => string | Iterable<TipItem>) | Iterable<ChannelName | ChannelValue | TipFormatItem>;
7272
}

src/marks/tip.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export class Tip extends Mark {
4343
lineWidth = 20,
4444
frameAnchor,
4545
format,
46-
source, // TODO a better way to detect channels that will be derived?
4746
textAnchor = "start",
4847
textOverflow,
4948
textPadding = 8,
@@ -84,7 +83,7 @@ export class Tip extends Mark {
8483
for (const key in defaults) if (key in this.channels) this[key] = defaults[key]; // apply default even if channel
8584
this.splitLines = splitter(this);
8685
this.clipLine = clipper(this);
87-
this.format = maybeTipFormat(this.channels, source?.channels, format);
86+
this.format = maybeTipFormat(this.channels, format);
8887
}
8988
render(index, scales, values, dimensions, context) {
9089
const mark = this;
@@ -320,14 +319,14 @@ function getSources({channels}) {
320319
}
321320

322321
// Note: mutates channels!
323-
function maybeTipFormat(channels, sourceChannels, format) {
322+
function maybeTipFormat(channels, format) {
324323
if (format === undefined) return;
325324
if (typeof format === "function") {
326325
return function (i, index, channels, scales, {data}) {
327326
return format.call(this, data[i], i);
328327
};
329328
}
330-
format = Array.from(format, (f) => maybeTipFormatItem(f, channels, sourceChannels));
329+
format = Array.from(format, (f) => maybeTipFormatItem(f, channels));
331330
return function* (i, index, channels, scales, values) {
332331
for (let {label, channel: key, format: formatValue} of format) {
333332
if (label === undefined) label = formatLabel(scales, channels, key);
@@ -339,22 +338,22 @@ function maybeTipFormat(channels, sourceChannels, format) {
339338
};
340339
} else {
341340
if (formatValue === undefined) formatValue = formatDefault;
342-
const value = values[key][i];
343-
const scale = channels[key].scale;
341+
const channel = channels[key];
342+
const scale = channel.scale;
344343
yield {
345344
label,
346-
value: formatValue(value),
347-
color: scale === "color" ? value : null,
348-
opacity: scale === "opacity" ? value : null
345+
value: formatValue(channel.value[i]),
346+
color: scale === "color" ? values[key][i] : null,
347+
opacity: scale === "opacity" ? values[key][i] : null
349348
};
350349
}
351350
}
352351
};
353352
}
354353

355354
// Note: mutates channels!
356-
function maybeTipFormatItem(f, channels, sourceChannels) {
357-
if (typeof f === "string") f = channels[f] || sourceChannels?.[f] ? {channel: f} : {value: f}; // shorthand string
355+
function maybeTipFormatItem(f, channels) {
356+
if (typeof f === "string") f = {channel: f}; // shorthand channel name
358357
f = maybeValue(f); // shorthand function, array, etc.
359358
if (typeof f.format === "string") f = {...f, format: numberFormat(f.format)}; // shorthand format; TODO dates
360359
if (f.value !== undefined) f = {...f, channel: deriveChannel(channels, f)}; // shorthand channel

src/plot.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,6 @@ function inferTips(marks) {
532532
p = /^x$/i.test(p) ? pointerX : /^y$/i.test(p) ? pointerY : pointer; // TODO validate
533533
tipOptions = p(derive(mark, tipOptions));
534534
tipOptions.title = null; // prevent implicit title for primitive data
535-
tipOptions.source = mark; // TODO cleaner
536535
tips.push(tip(mark.data, tipOptions));
537536
}
538537
}

0 commit comments

Comments
 (0)