From e7df049d0021a63b9a7f647d0063e3a42599193e Mon Sep 17 00:00:00 2001 From: MARIO <135943045+HIITMEMARIO@users.noreply.github.com> Date: Tue, 23 Jul 2024 18:45:12 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"fix(view):=20AuthorBarChart=EC=97=90?= =?UTF-8?q?=EC=84=9C=20Author=2010=EB=AA=85=20=EB=84=98=EC=96=B4=EA=B0=80?= =?UTF-8?q?=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20=EB=82=98=EB=A8=B8=EC=A7=80?= =?UTF-8?q?=EB=8A=94=20others=EB=A1=9C=20=EC=B2=98=EB=A6=AC"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthorBarChart/AuthorBarChart.tsx | 82 ++----------------- .../AuthorBarChart/AuthorBarChart.type.ts | 1 - 2 files changed, 8 insertions(+), 75 deletions(-) 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];