diff --git a/__tests__/integration/snapshots/tooltip/aapl-line-area-basic-sample/step0.html b/__tests__/integration/snapshots/tooltip/aapl-line-area-basic-sample/step0.html new file mode 100644 index 0000000000..7cc3adc376 --- /dev/null +++ b/__tests__/integration/snapshots/tooltip/aapl-line-area-basic-sample/step0.html @@ -0,0 +1,46 @@ +
+
+ Fri, 06 May 2011 00:00:00 GMT +
+ +
; diff --git a/__tests__/plots/tooltip/aapl-line-area-basic-sample.ts b/__tests__/plots/tooltip/aapl-line-area-basic-sample.ts new file mode 100644 index 0000000000..a42ad0c549 --- /dev/null +++ b/__tests__/plots/tooltip/aapl-line-area-basic-sample.ts @@ -0,0 +1,38 @@ +import { G2Spec } from '../../../src'; +import { seriesTooltipSteps } from './utils'; + +export function aaplLineAreaBasicSample(): G2Spec { + return { + type: 'view', + data: { + type: 'fetch', + value: 'data/aapl.csv', + }, + children: [ + { + type: 'area', + encode: { + x: 'date', + y: 'close', + }, + transform: [ + { + type: 'sample', + thresholds: 100, + strategy: 'lttb', + }, + ], + style: { + fillOpacity: 0.5, + }, + tooltip: { + title: (d) => new Date(d.date).toUTCString(), + }, + }, + ], + }; +} + +aaplLineAreaBasicSample.maxError = 100; + +aaplLineAreaBasicSample.steps = seriesTooltipSteps([500, 200]); diff --git a/__tests__/plots/tooltip/index.ts b/__tests__/plots/tooltip/index.ts index 54ad86e1df..d4d382fc25 100644 --- a/__tests__/plots/tooltip/index.ts +++ b/__tests__/plots/tooltip/index.ts @@ -55,3 +55,4 @@ export { forecastRangeAreaLineTranspose } from './forecast-range-area-line-trans export { scoreByItemAreaRadar } from './score-by-item-area-radar'; export { profitIntervalLegendFilterOrdinal } from './profit-interval-legend-filter-ordinal'; export { aaplLineSliderFilter } from './appl-line-slider-filter'; +export { aaplLineAreaBasicSample } from './aapl-line-area-basic-sample'; diff --git a/src/transform/maybeTitle.ts b/src/transform/maybeTitle.ts index 564d828f6d..f1fbc4038e 100644 --- a/src/transform/maybeTitle.ts +++ b/src/transform/maybeTitle.ts @@ -25,11 +25,15 @@ export const MaybeTitle: TC = (options = {}) => { .filter(([T]) => T) .map((d) => d[0]); if (titles.length === 0) return [I, mark]; + const T = []; + for (const i of I) { + T[i] = { value: titles.map((t) => t[i]).join(', ') }; + } return [ I, deepMix({}, mark, { tooltip: { - title: I.map((i) => ({ value: titles.map((t) => t[i]).join(', ') })), + title: T, }, }), ];