Skip to content

Commit

Permalink
RT-1384 (charts-on-fhir) Customize tooltip title (#254)
Browse files Browse the repository at this point in the history
* Added customize-tooltip-title

* Updated code

* Updated release version

* Updated version
  • Loading branch information
vdeshkar authored Jun 24, 2024
1 parent d030c81 commit f92d202
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions libs/ngx-charts-on-fhir/src/lib/data-layer/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type TimelineDataPoint = {
y: number | string;
tooltip?: string | string[];
resource?: any;
tooltipTitle?: string;
};

export type TimelineScaleType = 'linear' | 'category';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,19 @@ describe('FhirChartConfigurationService', () => {
const callback = config.options!.plugins!.tooltip!.callbacks!.title!.bind({} as any);
expect(callback(tooltipItems)).toEqual(['1 Jan 2023 12:00 AM']);
});

it('should use tooltipTitle as tooltip title if tooltipTitle present', () => {
const dataset: Dataset = {
label: 'Test',
yAxisID: 'scale',
data: [{ x: new Date('2023-01-01T00:00').getTime(), y: 1, tooltipTitle: 'title' }],
};
const scale = { id: 'scale', type: 'category' } as const;
const layerManager: any = { selectedLayers$: EMPTY };
const configService = new FhirChartConfigurationService(layerManager, timeScaleOptions, timeframeAnnotationOptions, ngZone);
const config = configService.buildConfiguration([dataset], { scale }, []);
const tooltipItems = [{ raw: dataset.data[0] }] as TooltipItem<TimelineChartType>[];
const callback = config.options!.plugins!.tooltip!.callbacks!.title!.bind({} as any);
expect(callback(tooltipItems)).toEqual(['title']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ const datasetMergeCustomizer = (_objValue: any, srcValue: any, key: any) => {

const getTooltipTitle = (item: TooltipItem<TimelineChartType>) => {
const dataPoint = item.raw as TimelineDataPoint;
if (typeof dataPoint.y === 'string') {
if (dataPoint.tooltipTitle) {
return dataPoint.tooltipTitle;
} else if (typeof dataPoint.y === 'string') {
return dataPoint.y;
}
const x = Array.isArray(dataPoint.x) ? dataPoint.x : [dataPoint.x];
Expand Down

0 comments on commit f92d202

Please sign in to comment.