-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔄 refactor: move chart plotting code to a separate directory for clea…
…ner code
- Loading branch information
1 parent
1e287ca
commit 89542b2
Showing
4 changed files
with
242 additions
and
237 deletions.
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
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,113 @@ | ||
import ReactEcharts from "echarts-for-react"; | ||
|
||
const QuestionFinishedChart = ({ questionsRaw }) => { | ||
// console.log("QuestionFinishedChart questionsRaw=", questionsRaw); | ||
const questions = [...questionsRaw].sort((a, b) => | ||
a.credit === b.credit ? a.qi - b.qi : a.credit - b.credit | ||
); | ||
|
||
const real_time_count = [["Minute", "Question", "Count"]]; | ||
for (let i = 1; i <= questions.length; i++) { | ||
for (let j = 1; j <= questions[0].real_time_count?.length; j++) { | ||
real_time_count.push([ | ||
j, | ||
`Q${i}`, | ||
questions[i - 1].real_time_count[j - 1], | ||
]); | ||
} | ||
} | ||
|
||
const questionsId = ["Q1", "Q2", "Q3", "Q4"]; | ||
const datasetWithFilters = []; | ||
const seriesList = []; | ||
|
||
questionsId.forEach((id) => { | ||
const datasetId = "dataset_" + id; | ||
datasetWithFilters.push({ | ||
id: datasetId, | ||
fromDatasetId: "dataset_raw", | ||
transform: { | ||
type: "filter", | ||
config: { | ||
and: [{ dimension: "Question", "=": id }], | ||
}, | ||
}, | ||
}); | ||
seriesList.push({ | ||
type: "line", | ||
datasetId: datasetId, | ||
showSymbol: false, | ||
name: id, | ||
endLabel: { | ||
show: true, | ||
formatter: function (params) { | ||
return params.value[1] + ": " + params.value[2]; | ||
}, | ||
}, | ||
labelLayout: { | ||
moveOverlap: "shiftY", | ||
}, | ||
emphasis: { | ||
focus: "series", | ||
}, | ||
encode: { | ||
x: "Minute", | ||
y: "Count", | ||
label: ["Question", "Count"], | ||
itemName: "Minute", | ||
tooltip: ["Count"], | ||
}, | ||
}); | ||
}); | ||
|
||
const option = { | ||
animation: true, | ||
animationDuration: 10000, | ||
dataset: [ | ||
{ | ||
id: "dataset_raw", | ||
source: real_time_count, | ||
}, | ||
...datasetWithFilters, | ||
], | ||
title: { | ||
text: "Question Finished Count", | ||
x: "center", | ||
}, | ||
tooltip: { | ||
order: "valueDesc", | ||
trigger: "axis", | ||
}, | ||
xAxis: { | ||
type: "category", | ||
name: "Minute", | ||
}, | ||
yAxis: { | ||
name: "Accepted", | ||
// axisLabel: { | ||
// rotate: 45, | ||
// margin: 1 | ||
// } | ||
}, | ||
grid: { | ||
left: "70em", | ||
right: "70em", | ||
}, | ||
series: seriesList, | ||
}; | ||
|
||
// console.log("question option= ", option); | ||
return ( | ||
<ReactEcharts | ||
option={option} | ||
// theme="dark" | ||
// lazyUpdate={true} | ||
// opts={{renderer: "svg"}} | ||
style={{ | ||
height: "25em", | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default QuestionFinishedChart; |
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,105 @@ | ||
import ReactEcharts from "echarts-for-react"; | ||
|
||
const RealTimeRankChart = ({ user, rankList }) => { | ||
if (!rankList) return null; | ||
|
||
const realTimeRank = [["Minute", "Username", "Rank"]]; | ||
for (let j = 1; j <= rankList.length; j++) { | ||
realTimeRank.push([j, user.username, rankList[j - 1]]); | ||
} | ||
|
||
const users = [user.username]; | ||
const datasetWithFilters = []; | ||
const seriesList = []; | ||
|
||
// console.log("users", users); | ||
// console.log("realTimeRank", realTimeRank); | ||
|
||
users.forEach((username) => { | ||
const datasetId = "dataset_" + username; | ||
datasetWithFilters.push({ | ||
id: datasetId, | ||
fromDatasetId: "dataset_raw", | ||
transform: { | ||
type: "filter", | ||
config: { | ||
and: [{ dimension: "Username", "=": username }], | ||
}, | ||
}, | ||
}); | ||
seriesList.push({ | ||
type: "line", | ||
datasetId: datasetId, | ||
showSymbol: false, | ||
name: username, | ||
endLabel: { | ||
show: true, | ||
formatter: function (params) { | ||
return params.value[1] + ": " + params.value[2]; | ||
}, | ||
}, | ||
labelLayout: { | ||
moveOverlap: "shiftY", | ||
}, | ||
emphasis: { | ||
focus: "series", | ||
}, | ||
encode: { | ||
x: "Minute", | ||
y: "Rank", | ||
label: ["Username", "Rank"], | ||
itemName: "Minute", | ||
tooltip: ["Rank"], | ||
}, | ||
}); | ||
}); | ||
|
||
const option = { | ||
animationDuration: 10000, | ||
dataset: [ | ||
{ | ||
id: "dataset_raw", | ||
source: realTimeRank, | ||
}, | ||
...datasetWithFilters, | ||
], | ||
title: { | ||
text: "User Real Time Rank", | ||
x: "center", | ||
}, | ||
tooltip: { | ||
order: "valueDesc", | ||
trigger: "axis", | ||
}, | ||
xAxis: { | ||
type: "category", | ||
name: "Minute", | ||
}, | ||
yAxis: { | ||
name: "Rank", | ||
axisLabel: { | ||
rotate: 45, | ||
margin: 1, | ||
}, | ||
}, | ||
grid: { | ||
// left:"70em", | ||
right: "70em", | ||
}, | ||
series: seriesList, | ||
}; | ||
|
||
// console.log("realTimeRank option=", option); | ||
|
||
return ( | ||
<ReactEcharts | ||
option={option} | ||
// theme="dark" | ||
// lazyUpdate={true} | ||
// opts={{renderer: "svg"}} | ||
style={{ height: "25em" }} | ||
/> | ||
); | ||
}; | ||
|
||
export default RealTimeRankChart; |
Oops, something went wrong.