-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da1427b
commit 542e3fb
Showing
4 changed files
with
136 additions
and
179 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,57 @@ | ||
import React from "react"; | ||
import React, { useCallback } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { useHistory } from "react-router-dom"; | ||
import { PieChart } from "bento-charts"; | ||
|
||
import { Empty } from "antd"; | ||
|
||
const titleStyle = { | ||
fontStyle: "italic", | ||
padding: "0", | ||
marginBottom: "-15px", | ||
}; | ||
|
||
const CustomPieChart = ({ | ||
title, | ||
data, | ||
chartHeight, | ||
setAutoQueryPageTransition, | ||
autoQueryDataType, | ||
fieldLabel, | ||
sort = true, | ||
data = [], | ||
chartHeight = 300, | ||
onAutoQueryTransition, | ||
dataType, | ||
labelKey, | ||
sortData = true, | ||
}) => { | ||
const history = useHistory(); | ||
|
||
const onClick = (data) => { | ||
if (!setAutoQueryPageTransition || data.skipAutoquery) { | ||
return; | ||
} | ||
console.log("data", data); | ||
setAutoQueryPageTransition(window.location.href, autoQueryDataType, fieldLabel, data.name); | ||
const handleChartClick = useCallback( | ||
(pointData) => { | ||
if (!onAutoQueryTransition || pointData.skipAutoquery) return; | ||
|
||
// Navigate to Explorer | ||
history.push("/data/explorer/search"); | ||
}; | ||
onAutoQueryTransition(window.location.href, dataType, labelKey, pointData.name); | ||
history.push("/data/explorer/search"); | ||
}, | ||
[onAutoQueryTransition, dataType, labelKey, history] | ||
); | ||
|
||
if (!data || data.length === 0) { | ||
return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="No Data" />; | ||
if (!data.length) { | ||
return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="No available data" />; | ||
} | ||
|
||
const pieChartData = data.map(({ name, value }) => ({ x: name, y: value })); | ||
|
||
return ( | ||
<> | ||
<div | ||
style={{ | ||
marginBottom: "20px", | ||
}} | ||
> | ||
<h2 style={titleStyle}>{title}</h2> | ||
<PieChart | ||
data={data.map(({ name, value }) => ({ x: name, y: value }))} | ||
height={chartHeight} | ||
onClick={onClick} | ||
sort={sort} | ||
/> | ||
</div> | ||
</> | ||
<div style={{ marginBottom: "20px" }}> | ||
<h2 style={{ fontStyle: "italic", padding: "0", marginBottom: "-15px" }}>{title}</h2> | ||
<PieChart data={pieChartData} height={chartHeight} onClick={handleChartClick} sort={sortData} /> | ||
</div> | ||
); | ||
}; | ||
|
||
CustomPieChart.propTypes = { | ||
title: PropTypes.string, | ||
data: PropTypes.array, | ||
title: PropTypes.string.isRequired, | ||
data: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
name: PropTypes.string, | ||
value: PropTypes.number, | ||
}) | ||
), | ||
chartHeight: PropTypes.number, | ||
setAutoQueryPageTransition: PropTypes.func, | ||
autoQueryDataType: PropTypes.string, | ||
sort: PropTypes.bool, | ||
fieldLabel: PropTypes.string, | ||
onAutoQueryTransition: PropTypes.func, | ||
dataType: PropTypes.string, | ||
labelKey: PropTypes.string, | ||
sortData: PropTypes.bool, | ||
}; | ||
|
||
export default CustomPieChart; |
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
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
Oops, something went wrong.