This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
/
PopulationGraph.js
52 lines (49 loc) · 1.55 KB
/
PopulationGraph.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React from "react";
import { LineChart } from "react-chartkick";
import "chart.js";
const FMARKET = 5;
function PopulationGraph(props) {
if (props.loadingData) {
var data = [];
console.log("props.id = " + props.id);
// if not Financial Market
if (props.id !== FMARKET) {
let env = props.env_file["pop_hist"]["pops"];
Object.keys(env).map((group, i_group) => {
console.log(props.env_file["members"][group]["attrs"]["color"]);
// populate 'data' array with members of 'pops' with their respective values
return (
data.push({
name: group,
color: props.env_file["members"][group]["attrs"]["color"],
data: {}
}),
// modify 'data' dictionary of each pops member copying 'pops' data
Object.keys(env[group]).map((member, i_member) => {
console.log(member);
return (data[i_group]["data"][member] = env[group][i_member]);
})
);
});
// if Financial Market
} else {
let period = props.env_file["pop_hist"]["periods"];
let data_hist =
props.env_file["members"]["market_maker"]["attrs"]["price_hist"];
var i;
data.push({ name: "price history", data: {} });
for (i = 0; i < period; i++) {
data[0]["data"][i] = data_hist[i];
}
}
console.log("data passed to line graph", data);
return (
<div>
<LineChart data={data} width="600px" height="600px" />
</div>
);
} else {
return null;
}
}
export default PopulationGraph;