Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix(view): AuthorBarChart에서 Author 10명 넘어가는 경우 나머지는 others로 처리" #554

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생많으셨습니다!!👍👍👍
추후에 변수명을 data보다 더 자세히 지어봐도 좋을 것 같네요!

}

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
Loading