vote_chart: sort parsed votes
The SQL query retrieving the votes is deterministicly sorted, but goes through a HashMap, for ease of processing and transfer, which does not maintaing order. Sort the resulting object in the Javascript to keep a consistent order in the graph.
This commit is contained in:
parent
8547312a78
commit
982a7ffd65
2 changed files with 6 additions and 0 deletions
|
@ -115,6 +115,8 @@ pub async fn fetch_vote_data(week: u8, mut db: Connection<database::Db>) -> Opti
|
|||
}
|
||||
|
||||
|
||||
// The hash map makes storing and retrieving the data really easy, *but*
|
||||
// it does lose the order of the original array (which is sorted via the SQL).
|
||||
let mut vote_data = HashMap::<String, Vec<u8>>::new();
|
||||
let mut next_truth_number = 1;
|
||||
for raw_vote in raw_votes {
|
||||
|
|
|
@ -32,11 +32,15 @@ async function main() {
|
|||
return;
|
||||
}
|
||||
|
||||
// Sort by label to maintain the same graph order, as it goes through a hash map in the backend.
|
||||
datasets.sort((a, b) => a.label > b.label)
|
||||
|
||||
const chart_canvas = document.getElementById("vote_chart")
|
||||
let chart
|
||||
function create_chart(keys, data) {
|
||||
let main_axis;
|
||||
let aspect_ratio;
|
||||
// TODO: Move to the event, to check and not re-create for no reason.
|
||||
if (window.innerWidth > window.innerHeight) {
|
||||
main_axis = 'x'
|
||||
aspect_ratio = 2
|
||||
|
|
Loading…
Add table
Reference in a new issue