Skip to content

Commit

Permalink
Merge pull request #554 from githru/revert-548-main
Browse files Browse the repository at this point in the history
Revert "fix(view): AuthorBarChart에서 Author 10명 넘어가는 경우 나머지는 others로 처리"
  • Loading branch information
HIITMEMARIO authored Jul 23, 2024
2 parents 9b12452 + e7df049 commit b38016a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<SVGSVGElement>(null);
const tooltipRef = useRef<HTMLDivElement>(null);

const [metric, setMetric] = useState<MetricType>(METRIC_TYPE[0]);
const [prevData, setPrevData] = useState<ClusterNode[][]>([]);
const authorData = getDataByAuthor(rawData as ClusterNode[]);
const [prevData, setPrevData] = useState<ClusterNode[]>([]);

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(() => {
Expand Down Expand Up @@ -114,73 +101,20 @@ const AuthorBarChart = () => {
const handleMouseOut = () => {
tooltip.style("display", "none");
};

// const handleClickBar = (_: MouseEvent<SVGRectElement | SVGTextElement>, 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<SVGRectElement | SVGTextElement>, 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export type AuthorDataType = {
commit: number;
insertion: number;
deletion: number;
names?: string[];
};

export type MetricType = (typeof METRIC_TYPE)[number];
Expand Down

0 comments on commit b38016a

Please sign in to comment.