-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tooltip and layout components for charts (#13)
* feat: add components for charts * refactor: remove jsx * refactor: address comments
- Loading branch information
1 parent
270386b
commit 4013721
Showing
5 changed files
with
149 additions
and
90 deletions.
There are no files selected for viewing
50 changes: 0 additions & 50 deletions
50
...ns/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/components/ChartFrame.jsx
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
...ns/superset-ui-plugins/packages/superset-ui-preset-chart-xy/src/components/ChartFrame.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,47 @@ | ||
import React from 'react'; | ||
import { isDefined } from '@superset-ui/core'; | ||
|
||
function checkNumber(input: any): input is number { | ||
return isDefined(input) && typeof input === 'number'; | ||
} | ||
|
||
type Props = { | ||
contentWidth?: number; | ||
contentHeight?: number; | ||
height: number; | ||
renderContent: ({ height, width }: { height: number; width: number }) => React.ReactElement; | ||
width: number; | ||
}; | ||
|
||
export default class ChartFrame extends React.PureComponent<Props, {}> { | ||
static defaultProps = { | ||
renderContent() {}, | ||
}; | ||
|
||
render() { | ||
const { contentWidth, contentHeight, width, height, renderContent } = this.props; | ||
|
||
const overflowX = checkNumber(contentWidth) && contentWidth > width; | ||
const overflowY = checkNumber(contentHeight) && contentHeight > height; | ||
|
||
if (overflowX || overflowY) { | ||
return ( | ||
<div | ||
style={{ | ||
height, | ||
overflowX: overflowX ? 'auto' : 'hidden', | ||
overflowY: overflowY ? 'auto' : 'hidden', | ||
width, | ||
}} | ||
> | ||
{renderContent({ | ||
height: Math.max(contentHeight || 0, height), | ||
width: Math.max(contentWidth || 0, width), | ||
})} | ||
</div> | ||
); | ||
} | ||
|
||
return renderContent({ height, width }); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
...t-ui-plugins/packages/superset-ui-preset-chart-xy/src/components/tooltip/TooltipFrame.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,26 @@ | ||
import React from 'react'; | ||
|
||
type Props = { | ||
className?: string; | ||
children: React.ReactNode; | ||
}; | ||
|
||
const CONTAINER_STYLE = { padding: 8 }; | ||
|
||
class TooltipFrame extends React.PureComponent<Props, {}> { | ||
static defaultProps = { | ||
className: '', | ||
}; | ||
|
||
render() { | ||
const { className, children } = this.props; | ||
|
||
return ( | ||
<div className={className} style={CONTAINER_STYLE}> | ||
{children} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default TooltipFrame; |
39 changes: 39 additions & 0 deletions
39
...t-ui-plugins/packages/superset-ui-preset-chart-xy/src/components/tooltip/TooltipTable.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,39 @@ | ||
import React, { CSSProperties } from 'react'; | ||
|
||
type Props = { | ||
className?: string; | ||
data: { | ||
key: string; | ||
keyStyle?: CSSProperties; | ||
value: string | number; | ||
valueStyle?: CSSProperties; | ||
}[]; | ||
}; | ||
|
||
const VALUE_CELL_STYLE: CSSProperties = { paddingLeft: 8, textAlign: 'right' }; | ||
|
||
export default class TooltipTable extends React.PureComponent<Props, {}> { | ||
static defaultProps = { | ||
className: '', | ||
data: [], | ||
}; | ||
|
||
render() { | ||
const { className, data } = this.props; | ||
|
||
return ( | ||
<table className={className}> | ||
<tbody> | ||
{data.map(({ key, keyStyle, value, valueStyle }) => ( | ||
<tr key={key}> | ||
<td style={keyStyle}>{key}</td> | ||
<td style={valueStyle ? { ...VALUE_CELL_STYLE, ...valueStyle } : VALUE_CELL_STYLE}> | ||
{value} | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
); | ||
} | ||
} |