diff --git a/packages/view/src/components/Statistics/AuthorBarChart/AuthorBarChart.tsx b/packages/view/src/components/Statistics/AuthorBarChart/AuthorBarChart.tsx index 2fc10526..b1aae6d9 100644 --- a/packages/view/src/components/Statistics/AuthorBarChart/AuthorBarChart.tsx +++ b/packages/view/src/components/Statistics/AuthorBarChart/AuthorBarChart.tsx @@ -16,36 +16,23 @@ import "./AuthorBarChart.scss"; const AuthorBarChart = () => { const { data: totalData, filteredData, setSelectedData, setFilteredData } = useGlobalData(); - console.log("filteredData", filteredData); - const rawData = useGetSelectedData(); + const svgRef = useRef(null); const tooltipRef = useRef(null); const [metric, setMetric] = useState(METRIC_TYPE[0]); - const [prevData, setPrevData] = useState([]); - const authorData = getDataByAuthor(rawData as ClusterNode[]); + const [prevData, setPrevData] = useState([]); + const authorData = getDataByAuthor(rawData as ClusterNode[]); let data = authorData.sort((a, b) => { if (a[metric] === b[metric]) { return sortDataByName(a.name, b.name); } return b[metric] - a[metric]; }); - console.log("data", data.slice(9)); if (data.length > 10) { - const topAuthors = data.slice(0, 9); - const otherAuthors = data.slice(9); - const reducedOtherAuthors = otherAuthors.reduce( - (acc, cur) => { - acc[metric] += cur[metric]; - acc.names?.push(cur.name); - return acc; - }, - { name: "others", commit: 0, insertion: 0, deletion: 0, names: [] } as AuthorDataType - ); - console.log("reducedOtherAuthors", reducedOtherAuthors); - data = [...topAuthors, reducedOtherAuthors]; + data = data.slice(0, 10); } useEffect(() => { @@ -114,73 +101,20 @@ const AuthorBarChart = () => { const handleMouseOut = () => { tooltip.style("display", "none"); }; - - // const handleClickBar = (_: MouseEvent, d: AuthorDataType) => { - // const isAuthorSelected = !!prevData.length; - - // if (isAuthorSelected) { - // setFilteredData(prevData); - // setPrevData([]); - // } else { - // setFilteredData(sortDataByAuthor(filteredData, d.name)); - // setPrevData(filteredData); - // } - - // setSelectedData([]); - // tooltip.style("display", "none"); - // }; - const handleClickBar = (_: MouseEvent, d: AuthorDataType) => { const isAuthorSelected = !!prevData.length; - // 원래대로 돌리는 로직 - // prevData.pop(); - // if (d.name !== d.name) { - // setTest((prev) => !prev); - // } if (isAuthorSelected) { - const newFilteredData = () => - d.names - ? d.names.flatMap((name) => sortDataByAuthor(filteredData, name)) - : sortDataByAuthor(filteredData, d.name); - setFilteredData(newFilteredData); - // setShowPrevData([...showPrevData, filteredData]); + setFilteredData(prevData); setPrevData([]); - } - if (!isAuthorSelected) { - // 없다면 이전데이터에 현재 필터된 데이터를 집어넣음 - - // names 배열이 있다면 함수에 하나씩 집어 넣음 없다면 기존 필터된 데이터를 집어넣음 - // 그리고 새로 필터링된 데이터를 필터된 데이터 스테이트에 집어넣음 - const newFilteredData = d.names - ? d.names.flatMap((name) => sortDataByAuthor(filteredData, name)) - : sortDataByAuthor(filteredData, d.name); - setFilteredData(newFilteredData); - setPrevData([filteredData]); + } else { + setFilteredData(sortDataByAuthor(filteredData, d.name)); + setPrevData(filteredData); } setSelectedData([]); tooltip.style("display", "none"); }; - // // 선택된 사용자가 있을경우 - // if (isAuthorSelected) { - // setFilteredData(prevData); - // setPrevData([]); - // return; - // } - // // 선택된 사용자가 있고 others(d.names을 포함)의 데이터일때 - // if (isAuthorSelected && !d.names) { - // } - - // if (d.names) { - // const newFilteredData = d.names - // ? d.names.flatMap((name) => sortDataByAuthor(filteredData, name)) - // : sortDataByAuthor(filteredData, d.name); - // setFilteredData(newFilteredData); - // } - // setPrevData(filteredData); - // setSelectedData([]); - // tooltip.style("display", "none"); // Draw bars barGroup diff --git a/packages/view/src/components/Statistics/AuthorBarChart/AuthorBarChart.type.ts b/packages/view/src/components/Statistics/AuthorBarChart/AuthorBarChart.type.ts index 2dfd54b8..ec0ba232 100644 --- a/packages/view/src/components/Statistics/AuthorBarChart/AuthorBarChart.type.ts +++ b/packages/view/src/components/Statistics/AuthorBarChart/AuthorBarChart.type.ts @@ -5,7 +5,6 @@ export type AuthorDataType = { commit: number; insertion: number; deletion: number; - names?: string[]; }; export type MetricType = (typeof METRIC_TYPE)[number];