This repository has been archived by the owner on Jun 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support custom tooltip for scatterplot and box plot
- Loading branch information
Showing
6 changed files
with
136 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/superset-ui-preset-chart-xy/src/BoxPlot/DefaultTooltipRenderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import { isDefined } from '@superset-ui/core'; | ||
import { TooltipFrame, TooltipTable } from '@superset-ui/chart-composition'; | ||
import Encoder from './Encoder'; | ||
import { BoxPlotDataRow } from './types'; | ||
|
||
export default function DefaultTooltipRenderer({ | ||
datum, | ||
color, | ||
encoder, | ||
}: { | ||
datum: BoxPlotDataRow; | ||
color: string; | ||
encoder: Encoder; | ||
}) { | ||
const { label, min, max, median, firstQuartile, thirdQuartile, outliers } = datum; | ||
const { channels } = encoder; | ||
|
||
const formatValue = | ||
channels.y.definition.type === 'nominal' ? channels.x.formatValue : channels.y.formatValue; | ||
|
||
const data = []; | ||
if (isDefined(min)) { | ||
data.push({ key: 'Min', valueColumn: formatValue(min) }); | ||
} | ||
if (isDefined(max)) { | ||
data.push({ key: 'Max', valueColumn: formatValue(max) }); | ||
} | ||
if (isDefined(median)) { | ||
data.push({ key: 'Median', valueColumn: formatValue(median) }); | ||
} | ||
if (isDefined(firstQuartile)) { | ||
data.push({ key: '1st Quartile', valueColumn: formatValue(firstQuartile) }); | ||
} | ||
if (isDefined(thirdQuartile)) { | ||
data.push({ key: '3rd Quartile', valueColumn: formatValue(thirdQuartile) }); | ||
} | ||
if (isDefined(outliers) && outliers.length > 0) { | ||
data.push({ key: '# Outliers', valueColumn: outliers.length }); | ||
} | ||
|
||
return ( | ||
<TooltipFrame> | ||
<div> | ||
<strong style={{ color }}>{label}</strong> | ||
</div> | ||
{data.length > 0 && <br />} | ||
<TooltipTable data={data} /> | ||
</TooltipFrame> | ||
); | ||
} |
46 changes: 0 additions & 46 deletions
46
packages/superset-ui-preset-chart-xy/src/BoxPlot/createTooltip.tsx
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
packages/superset-ui-preset-chart-xy/src/ScatterPlot/DefaultTooltipRenderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* eslint-disable no-magic-numbers */ | ||
|
||
import React from 'react'; | ||
import { TooltipFrame, TooltipTable } from '@superset-ui/chart-composition'; | ||
import { isFieldDef } from '../encodeable/types/ChannelDef'; | ||
import { TooltipProps } from './ScatterPlot'; | ||
|
||
export default function DefaultTooltipRenderer({ datum, encoder }: TooltipProps) { | ||
const { channels, commonChannels } = encoder; | ||
const { x, y, size, fill, stroke } = channels; | ||
|
||
const tooltipRows = [ | ||
{ key: 'x', keyColumn: x.getTitle(), valueColumn: x.format(datum.data) }, | ||
{ key: 'y', keyColumn: y.getTitle(), valueColumn: y.format(datum.data) }, | ||
]; | ||
|
||
if (isFieldDef(fill.definition)) { | ||
tooltipRows.push({ | ||
key: 'fill', | ||
keyColumn: fill.getTitle(), | ||
valueColumn: fill.format(datum.data), | ||
}); | ||
} | ||
if (isFieldDef(stroke.definition)) { | ||
tooltipRows.push({ | ||
key: 'stroke', | ||
keyColumn: stroke.getTitle(), | ||
valueColumn: stroke.format(datum.data), | ||
}); | ||
} | ||
if (isFieldDef(size.definition)) { | ||
tooltipRows.push({ | ||
key: 'size', | ||
keyColumn: size.getTitle(), | ||
valueColumn: size.format(datum.data), | ||
}); | ||
} | ||
commonChannels.group.forEach(g => { | ||
tooltipRows.push({ | ||
key: `${g.name}`, | ||
keyColumn: g.getTitle(), | ||
valueColumn: g.format(datum.data), | ||
}); | ||
}); | ||
|
||
return ( | ||
<TooltipFrame> | ||
<TooltipTable data={tooltipRows} /> | ||
</TooltipFrame> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 0 additions & 56 deletions
56
packages/superset-ui-preset-chart-xy/src/ScatterPlot/createTooltip.tsx
This file was deleted.
Oops, something went wrong.