Skip to content

feat: allow custom tooltip titles #1047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,8 @@ export class CartesianChartComponent<TData> implements OnChanges, OnDestroy {
return undefined;
}

const firstXValue = defaultXDataAccessor<unknown>(data[0].dataPoint);
const xAsDate = this.dateCoercer.coerce(firstXValue);
const title = xAsDate ? this.dateFormatter.format(xAsDate) : String(firstXValue);

return {
title: title,
title: this.resolveTooltipTitle(data[0]),
labeledValues: data.map(singleValue => ({
label: singleValue.context.name,
value: defaultYDataAccessor<number | string>(singleValue.dataPoint),
Expand All @@ -179,4 +175,15 @@ export class CartesianChartComponent<TData> implements OnChanges, OnDestroy {
}))
};
}

private resolveTooltipTitle(location: MouseLocationData<TData, Series<TData>>): string {
const series = location.context;
if (series.getTooltipTitle) {
return series.getTooltipTitle(location.dataPoint);
}
const xValue = defaultXDataAccessor<unknown>(location.dataPoint);
const xAsDate = this.dateCoercer.coerce(xValue);

return xAsDate ? this.dateFormatter.format(xAsDate) : String(xValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Series<TInterval> {
type: CartesianSeriesVisualizationType;
stacking?: boolean;
hide?: boolean;
getTooltipTitle?(datum: TInterval): string;
}

export interface Band<TInterval> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import { ExploreCartesianDataSourceModel, ExplorerData } from './explore-cartesi

describe('Explore cartesian data source model', () => {
const testInterval = new TimeDuration(5, TimeUnit.Minute);
const endTime = new Date('2021-05-11T00:35:00.000Z');
const startTime = new Date(endTime.getTime() - 2 * testInterval.toMillis());
const startTime = new Date('2021-05-11T00:20:00.000Z');
const firstIntervalTime = new Date(startTime.getTime() + testInterval.toMillis());
const secondIntervalTime = new Date(startTime.getTime() + 2 * testInterval.toMillis());
const endTime = new Date(startTime.getTime() + 3 * testInterval.toMillis());

const modelFactory = createModelFactory({
providers: [
Expand Down Expand Up @@ -108,7 +110,7 @@ describe('Explore cartesian data source model', () => {
value: 15,
type: AttributeMetadataType.Number
},
[GQL_EXPLORE_RESULT_INTERVAL_KEY]: endTime
[GQL_EXPLORE_RESULT_INTERVAL_KEY]: secondIntervalTime
}
]
},
Expand All @@ -127,11 +129,11 @@ describe('Explore cartesian data source model', () => {
value: 10
},
{
timestamp: new Date('2021-05-11T00:30:00.000Z'),
timestamp: firstIntervalTime,
value: 0
},
{
timestamp: endTime,
timestamp: secondIntervalTime,
value: 15
}
]
Expand Down Expand Up @@ -247,7 +249,7 @@ describe('Explore cartesian data source model', () => {
value: 'first',
type: AttributeMetadataType.String
},
[GQL_EXPLORE_RESULT_INTERVAL_KEY]: endTime
[GQL_EXPLORE_RESULT_INTERVAL_KEY]: secondIntervalTime
},
{
'sum(foo)': {
Expand All @@ -269,7 +271,7 @@ describe('Explore cartesian data source model', () => {
value: 'second',
type: AttributeMetadataType.String
},
[GQL_EXPLORE_RESULT_INTERVAL_KEY]: endTime
[GQL_EXPLORE_RESULT_INTERVAL_KEY]: secondIntervalTime
}
]
},
Expand All @@ -288,11 +290,11 @@ describe('Explore cartesian data source model', () => {
value: 10
},
{
timestamp: new Date('2021-05-11T00:30:00.000Z'),
timestamp: firstIntervalTime,
value: 0
},
{
timestamp: endTime,
timestamp: secondIntervalTime,
value: 15
}
]
Expand All @@ -307,11 +309,11 @@ describe('Explore cartesian data source model', () => {
value: 20
},
{
timestamp: new Date('2021-05-11T00:30:00.000Z'),
timestamp: firstIntervalTime,
value: 0
},
{
timestamp: endTime,
timestamp: secondIntervalTime,
value: 25
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class ExploreResult {
const startTime = Math.floor(this.timeRange.from.valueOf() / intervalDuration) * intervalDuration;
const endTime = Math.ceil(this.timeRange.to.valueOf() / intervalDuration) * intervalDuration;

for (let timestamp = startTime; timestamp <= endTime; timestamp = timestamp + intervalDuration) {
for (let timestamp = startTime; timestamp < endTime; timestamp = timestamp + intervalDuration) {
buckets.push(timestamp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import { ExplorerVisualizationCartesianDataSourceModel } from './explorer-visual

describe('Explorer Visualization cartesian data source model', () => {
const testInterval = new TimeDuration(5, TimeUnit.Minute);
const endTime = new Date('2021-05-11T00:35:00.000Z');
const startTime = new Date(endTime.getTime() - 2 * testInterval.toMillis());
const startTime = new Date('2021-05-11T00:20:00.000Z');
const firstIntervalTime = new Date(startTime.getTime() + testInterval.toMillis());
const secondIntervalTime = new Date(startTime.getTime() + 2 * testInterval.toMillis());
const endTime = new Date(startTime.getTime() + 3 * testInterval.toMillis());

const modelFactory = createModelFactory({
providers: [
Expand Down Expand Up @@ -127,7 +129,7 @@ describe('Explorer Visualization cartesian data source model', () => {
value: 15,
type: AttributeMetadataType.Number
},
[GQL_EXPLORE_RESULT_INTERVAL_KEY]: endTime
[GQL_EXPLORE_RESULT_INTERVAL_KEY]: secondIntervalTime
}
]
},
Expand All @@ -146,11 +148,11 @@ describe('Explorer Visualization cartesian data source model', () => {
value: 10
},
{
timestamp: new Date('2021-05-11T00:30:00.000Z'),
timestamp: firstIntervalTime,
value: 0
},
{
timestamp: endTime,
timestamp: secondIntervalTime,
value: 15
}
]
Expand Down Expand Up @@ -269,7 +271,7 @@ describe('Explorer Visualization cartesian data source model', () => {
value: 'first',
type: AttributeMetadataType.String
},
[GQL_EXPLORE_RESULT_INTERVAL_KEY]: endTime
[GQL_EXPLORE_RESULT_INTERVAL_KEY]: secondIntervalTime
},
{
'sum(foo)': {
Expand All @@ -291,7 +293,7 @@ describe('Explorer Visualization cartesian data source model', () => {
value: 'second',
type: AttributeMetadataType.String
},
[GQL_EXPLORE_RESULT_INTERVAL_KEY]: endTime
[GQL_EXPLORE_RESULT_INTERVAL_KEY]: secondIntervalTime
}
]
},
Expand All @@ -310,11 +312,11 @@ describe('Explorer Visualization cartesian data source model', () => {
value: 10
},
{
timestamp: new Date('2021-05-11T00:30:00.000Z'),
timestamp: firstIntervalTime,
value: 0
},
{
timestamp: endTime,
timestamp: secondIntervalTime,
value: 15
}
]
Expand All @@ -329,11 +331,11 @@ describe('Explorer Visualization cartesian data source model', () => {
value: 20
},
{
timestamp: new Date('2021-05-11T00:30:00.000Z'),
timestamp: firstIntervalTime,
value: 0
},
{
timestamp: endTime,
timestamp: secondIntervalTime,
value: 25
}
]
Expand Down