-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph.cpp
91 lines (78 loc) · 2.93 KB
/
Graph.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "Graph.h"
#include "Shell.h"
const sf::Time Graph::TimePerFrame = seconds(1.f / 60.f);
Graph::Graph()
{
resolution = Vector2f(1181, 1168);
window.create(VideoMode(resolution.x, resolution.y), "Food Access Graph", Style::Default);
window.setFramerateLimit(FPS);
}
void Graph::run(vector<County*>& counties, string demographicSelection, string foodAccessSelection)
{
while (window.isOpen())
{
draw(counties, demographicSelection, foodAccessSelection);
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
}
}
void Graph::draw(vector<County*>& counties, string demographicSelection, string foodAccessSelection)
{
//Make a sprite for the graph
sf::Texture blankGraphTexture;
blankGraphTexture.loadFromFile("blankGraph.png");
sf::Sprite blankGraphSprite;
blankGraphSprite.setTexture(blankGraphTexture);
//Make a sprite for the points
sf::Texture pointTexture;
pointTexture.loadFromFile("plotPoint.png");
sf::Sprite pointSprite;
pointSprite.setTexture(pointTexture);
//scale
pointSprite.setScale(sf::Vector2f(0.03f, 0.03f));
//Make a sprite for the extreme points
sf::Texture extremePointTexture;
extremePointTexture.loadFromFile("bluePlotPoint.png");
sf::Sprite extremePointSprite;
extremePointSprite.setTexture(extremePointTexture);
//scale
extremePointSprite.setScale(sf::Vector2f(0.01f, 0.01f));
window.clear(Color::Black);
window.draw(blankGraphSprite);
//Print dots for counties
for (int i = 10; i < counties.size() - 1; i++)
{
//cout << "demographic value: " << Shell::GetStatistic(counties[i], demographicSelection) << endl;
//cout << "food access value: " << Shell::GetStatistic(counties[i], foodAccessSelection) << endl;
float x = 150 + 900 * Shell::GetStatistic(counties[i], demographicSelection) / 100;
float y = 1020 - (900 * Shell::GetStatistic(counties[i], foodAccessSelection)) / 100;
//cout << "x coordinate: " << x << endl;
// cout << "y coordinate: " << y << endl;
if (i >= (counties.size() - 10))
{
extremePointSprite.setPosition(sf::Vector2f(x, y));
window.draw(extremePointSprite);
}
else
{
pointSprite.setPosition(sf::Vector2f(x, y));
window.draw(pointSprite);
}
}
for(int i = 0; i <= 9; i ++)
{
float x = 150 + 900 * Shell::GetStatistic(counties[i], demographicSelection) / 100;
float y = 1020 - (900 * Shell::GetStatistic(counties[i], foodAccessSelection)) / 100;
extremePointSprite.setPosition(sf::Vector2f(x, y));
window.draw(extremePointSprite);
}
window.display();
}
void Graph::close()
{
window.close();
}