-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·41 lines (33 loc) · 1001 Bytes
/
index.php
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
<?php
require_once __DIR__ . '/vendor/autoload.php';
use VoteResultWidget\VoteParser;
use VoteResultWidget\GraphicGenerator;
/**
* Step 1: Parse votes from the congress.gov JSON file
*/
$voteFilePath = __DIR__ . '/data/115th-congress-h3-2017.json';
$voteParser = (new VoteParser())->parseFromFilePath($voteFilePath);
// If you want to play around with vote sorting, you can skip the call below and do your own sort
$voteParser->sortVotes();
/**
* Step 2: Create a graphic from the votes
*
* For demo purposes we are only doing a House vote to keep things simple & easily readable.
*/
$graphicGenerator = (new GraphicGenerator())->createHouseGraphic(
$voteParser->getPassResult(),
$voteParser->votes,
$voteParser->getVotesRequirement()
);
/**
* Step 3: Save to a PNG in the export folder
*/
$outputTo = sprintf(
'%s/%s.png',
__DIR__ . '/export',
data_get($voteParser->data, 'vote_id')
);
imagepng(
$graphicGenerator->getExportableGraphic(),
$outputTo
);