-
Notifications
You must be signed in to change notification settings - Fork 102
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
[OSS101] Task 5: Display Community OpenRank #843
Open
Fiveneves
wants to merge
32
commits into
hypertrons:master
Choose a base branch
from
Fiveneves:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
14df77c
init colorful-calendar
Fiveneves 873b31c
change calendar's color
Fiveneves a763ef5
add ColorPicker
Fiveneves f9d5ea0
restore colorful-calendar
Fiveneves 99674fb
Merge pull request #1 from hypertrons/master
Fiveneves 0a97d64
Merge branch 'hypertrons:master' into fiveneves
Fiveneves 957347a
Merge pull request #3 from Fiveneves/fiveneves
Fiveneves 4631e33
add community openrank api
Fiveneves 5f28e97
Merge remote-tracking branch 'origin/fiveneves' into fiveneves
Fiveneves 0a7b9d0
add community openrank feature container to perceptor
Fiveneves a69ce7a
Merge pull request #4 from Fiveneves/fiveneves
Fiveneves 17f03b8
add Community OpenRank Detail Network
Fiveneves 3961e60
add DatePicker to Community OpenRank Detail Network
Fiveneves b81fc98
Merge branch 'hypertrons:master' into master
Fiveneves 9678532
Merge branch 'master' into fiveneves
Fiveneves 93cb3d6
Merge pull request #6 from Fiveneves/fiveneves
Fiveneves f1effd5
add Community OpenRank Racing Bar
Fiveneves 28c658f
Merge remote-tracking branch 'origin/fiveneves' into fiveneves
Fiveneves abcb34b
Merge pull request #7 from Fiveneves/fiveneves
Fiveneves cf334c3
Delete src/pages/ContentScripts/features/colorful-calendar directory
Fiveneves 968fd6e
remove colorful calendar from index.ts
Fiveneves a7a58a2
Merge pull request #8 from Fiveneves/master
Fiveneves 124ff58
Fix a Bug in sorting data
Fiveneves 0e01d64
Update index.tsx
reset0514 25f7b19
Merge pull request #10 from Fiveneves/fiveneves
Fiveneves fe54aa1
Merge branch 'hypertrons:master' into master
Fiveneves 99543c4
delete Chinese comments
Fiveneves b8b220f
delete code that has been commented out
Fiveneves 3c5113e
delete imported items are not used
Fiveneves c69e4d2
add rsuite dependency
Fiveneves 1a4e558
add a selectPicker to the CommunityOpenRankRacingBar feature to choos…
Fiveneves f20fd91
Merge pull request #11 from Fiveneves/fiveneves
Fiveneves File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import request from '../helpers/request'; | ||
import { ErrorCode, OSS_XLAB_ENDPOINT } from '../constant'; | ||
|
||
export const getMetricByDate = async (repoName: string, date: string) => { | ||
let response; | ||
try { | ||
response = await request( | ||
`${OSS_XLAB_ENDPOINT}/open_digger/github/${repoName}/project_openrank_detail/${date}.json` | ||
); | ||
} catch (error) { | ||
// the catched error being "404" means the metric file is not available so return a null | ||
if (error === ErrorCode.NOT_FOUND) { | ||
return null; | ||
} else { | ||
// other errors should be throwed | ||
throw error; | ||
} | ||
} | ||
return response; | ||
}; | ||
|
||
export const getOpenRank = async (repo: string, date: string) => { | ||
return getMetricByDate(repo, date); | ||
}; |
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
258 changes: 258 additions & 0 deletions
258
src/pages/ContentScripts/features/community-openrank-network/Network.tsx
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 |
---|---|---|
@@ -0,0 +1,258 @@ | ||
import React, { CSSProperties, forwardRef, useEffect, useRef, ForwardedRef, useImperativeHandle } from 'react'; | ||
import * as echarts from 'echarts'; | ||
|
||
import optionsStorage, { HypercrxOptions, defaults } from '../../../../options-storage'; | ||
|
||
import { debounce } from 'lodash-es'; | ||
import getGithubTheme from '../../../../helpers/get-github-theme'; | ||
import dayjs from 'dayjs'; | ||
import { getOpenRank } from '../../../../api/community'; | ||
|
||
export interface DateControllers { | ||
update: (newDate: string) => void; | ||
} | ||
|
||
interface NetworkProps { | ||
/** | ||
* data | ||
*/ | ||
readonly data: any; | ||
/** | ||
* `style` for graph container | ||
*/ | ||
readonly style?: CSSProperties; | ||
|
||
readonly focusedNodeID: string; | ||
|
||
date?: string; | ||
} | ||
|
||
const typeMap = new Map([ | ||
['r', 'repo'], | ||
['i', 'issue'], | ||
['p', 'pull'], | ||
['u', 'user'], | ||
]); | ||
|
||
const genName = (node: { c: string; n: { toString: () => any } }) => | ||
node.c == 'i' || node.c == 'p' ? `#${node.n.toString()}` : node.n.toString(); | ||
|
||
const categories = Array.from(typeMap.values()); | ||
|
||
const theme = getGithubTheme(); | ||
const DARK_TEXT_COLOR = 'rgba(230, 237, 243, 0.9)'; | ||
|
||
const generateEchartsData = (data: any, focusedNodeID: string | undefined): any => { | ||
const generateNodes = (nodes: any[]): any => { | ||
return nodes.map((n: any) => { | ||
return { | ||
id: n.id, | ||
name: genName(n), | ||
value: n.v, | ||
symbolSize: Math.log(n.v + 1) * 6, | ||
category: typeMap.get(n.c), | ||
}; | ||
}); | ||
}; | ||
const generateEdges = (edges: any[]): any => { | ||
if (edges.length === 0) { | ||
return []; | ||
} | ||
return edges.map((e: any) => { | ||
return { | ||
source: e.s, | ||
target: e.t, | ||
value: e.w, | ||
}; | ||
}); | ||
}; | ||
return { | ||
nodes: generateNodes(data.nodes), | ||
edges: generateEdges(data.links), | ||
}; | ||
}; | ||
|
||
const getOption = (data: any, date: string | undefined) => { | ||
return { | ||
tooltip: { | ||
trigger: 'item', | ||
}, | ||
animation: true, | ||
animationDuration: 2000, | ||
|
||
legend: [ | ||
{ | ||
data: categories, | ||
}, | ||
], | ||
series: [ | ||
{ | ||
name: 'Collaborative graph', | ||
type: 'graph', | ||
layout: 'force', | ||
nodes: data.nodes, | ||
edges: data.edges, | ||
categories: categories.map((c) => { | ||
return { name: c }; | ||
}), | ||
// Enable mouse zooming and translating | ||
roam: true, | ||
label: { | ||
position: 'right', | ||
show: true, | ||
}, | ||
force: { | ||
// initLayout: 'circular', | ||
// gravity: 0.1, | ||
repulsion: 300, | ||
// edgeLength: [50, 100], | ||
// Disable the iteration animation of layout | ||
layoutAnimation: false, | ||
}, | ||
lineStyle: { | ||
curveness: 0.3, | ||
opacity: 0.2, | ||
}, | ||
emphasis: { | ||
focus: 'adjacency', | ||
label: { | ||
position: 'right', | ||
show: true, | ||
}, | ||
}, | ||
}, | ||
], | ||
graphic: { | ||
elements: [ | ||
{ | ||
type: 'text', | ||
right: 60, | ||
bottom: 60, | ||
style: { | ||
text: date, | ||
font: 'bolder 60px monospace', | ||
fill: theme === 'light' ? 'rgba(100, 100, 100, 0.3)' : DARK_TEXT_COLOR, | ||
}, | ||
z: 100, | ||
}, | ||
], | ||
}, | ||
}; | ||
}; | ||
|
||
const Network = forwardRef( | ||
( | ||
{ data, style = {}, focusedNodeID, date }: NetworkProps, | ||
forwardedRef: ForwardedRef<DateControllers> | ||
): JSX.Element => { | ||
const divEL = useRef(null); | ||
let graphData = generateEchartsData(data, focusedNodeID); | ||
let option = getOption(graphData, date); | ||
|
||
const clearDiv = (id: string) => { | ||
var div = document.getElementById(id); | ||
if (div && div.hasChildNodes()) { | ||
var children = div.childNodes; | ||
for (var child of children) { | ||
div.removeChild(child); | ||
} | ||
} | ||
}; | ||
|
||
const addRow = (table: HTMLElement | null, texts: any[]) => { | ||
// @ts-ignore | ||
var tr = table.insertRow(); | ||
for (var t of texts) { | ||
var td = tr.insertCell(); | ||
td.appendChild(document.createTextNode(t)); | ||
} | ||
}; | ||
|
||
const update = (newDate: string) => { | ||
getOpenRank(focusedNodeID, newDate).then((openRank) => { | ||
let chartDOM = divEL.current; | ||
const instance = echarts.getInstanceByDom(chartDOM as any); | ||
if (instance) { | ||
if (openRank == null) { | ||
instance.setOption( | ||
{ | ||
title: { | ||
text: `OpenRank for ${focusedNodeID} in ${newDate} is has not been generated`, | ||
top: 'middle', | ||
left: 'center', | ||
}, | ||
}, | ||
{ notMerge: true } | ||
); | ||
} else { | ||
graphData = generateEchartsData(openRank, focusedNodeID); | ||
option = getOption(graphData, newDate); | ||
instance.setOption(option, { notMerge: true }); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
const setDetails = (graph: { links: any[]; nodes: any[] }, node: { r: number; i: number; id: any }) => { | ||
clearDiv('details_table'); | ||
var table = document.getElementById('details_table'); | ||
addRow(table, ['From', 'Ratio', 'Value', 'OpenRank']); | ||
addRow(table, ['Self', node.r, node.i, (node.r * node.i).toFixed(3)]); | ||
var other = graph.links | ||
.filter((l) => l.t == node.id) | ||
.map((l) => { | ||
var source = graph.nodes.find((n) => n.id == l.s); | ||
return [ | ||
genName(source), | ||
parseFloat(((1 - node.r) * l.w).toFixed(3)), | ||
source.v, | ||
parseFloat(((1 - node.r) * l.w * source.v).toFixed(3)), | ||
]; | ||
}) | ||
.sort((a, b) => b[3] - a[3]); | ||
for (var r of other) { | ||
addRow(table, r); | ||
} | ||
}; | ||
|
||
useImperativeHandle(forwardedRef, () => ({ | ||
update, | ||
})); | ||
|
||
useEffect(() => { | ||
let chartDOM = divEL.current; | ||
const instance = echarts.init(chartDOM as any); | ||
|
||
return () => { | ||
instance.dispose(); | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
let chartDOM = divEL.current; | ||
const instance = echarts.getInstanceByDom(chartDOM as any); | ||
if (instance) { | ||
instance.setOption(option); | ||
instance.on('dblclick', function (params) { | ||
setDetails( | ||
data, | ||
// @ts-ignore | ||
data.nodes.find((i: { id: any }) => i.id === params.data.id) | ||
); | ||
}); | ||
const debouncedResize = debounce(() => { | ||
instance.resize(); | ||
}, 1000); | ||
window.addEventListener('resize', debouncedResize); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<div className="hypertrons-crx-border"> | ||
<div ref={divEL} style={style}></div> | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
export default Network; |
31 changes: 31 additions & 0 deletions
31
src/pages/ContentScripts/features/community-openrank-network/index.scss
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#details_table { | ||
width: 95%; | ||
margin: 10px; | ||
tr:nth-child(even) { | ||
background-color: #d6eeee; | ||
} | ||
th, | ||
td { | ||
border: 1px solid black; | ||
text-align: center; /* 水平居中 */ | ||
vertical-align: middle; /* 垂直居中 */ | ||
} | ||
} | ||
|
||
#details_title { | ||
text-align: center; | ||
font-size: 12px; | ||
} | ||
|
||
.bordered { | ||
border: 2px solid grey; | ||
} | ||
|
||
#details_div { | ||
height: 250px; | ||
} | ||
|
||
.scrollit { | ||
overflow-x: hidden; | ||
overflow-y: auto; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is best to replace the Chinese comments in the code with English.