Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done release 4 #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
</head>
<body>
<div id="container">

<h1>AFC Wimbledon Results</h1>
<div id="results"></div>
<hr />
<h2>AFC Wimbledon Top Scorer</h2>
<div id="top-score"></div>
</div>
<script src="https://d3js.org/d3.v4.js"></script>
<script src="https://d3js.org/d3-axis.v1.min.js"></script>
<script src="script.js"></script>
<script src="d3.layout.cloud.js"></script>
<script src="topscore.js"></script>
Expand Down
68 changes: 61 additions & 7 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,79 @@
/* global d3 */

// Our canvas
const width = 750,
height = 300,
margin = 20
marginLeft = 40
const width = 1000,
height = 300,
margin = 20,
marginLeft = 40,
multiplier = 50

// Drawing area
let svg = d3.select('#results')
.append('svg')
.attr('width', width)
.attr('height', height)
.style('background',"rgb(196, 196, 196)")
.style('padding','30px')

// Data reloading
let reload = () => {
// Your data parsing here...
d3.tsv("afcw-results.tsv", function(error, data) {
if (error) throw error;
goals = []
data.forEach(function(d) {
goals.push(d.GoalsScored)
})
// console.log(goals);
redraw(goals)
})
}

// redraw function
let redraw = (data) => {
// Your data to graph here
let redraw = (goals) => {

// Y Scaling
var yScale = d3.scaleLinear()
.domain([d3.max(goals),0])
.range([0, height])
// X Scaling
var xScale = d3.scaleLinear()
.domain([0, goals.length])
.range([0, width])

var yAxis = d3.axisLeft(yScale)
var xAxis = d3.axisBottom(xScale).ticks(goals.length,'s')

svg.selectAll('rect')
.data(goals)
.enter()
.append('rect')
.attr('class', 'bar')
.attr('x', (d, i) => {
return xScale(i)
})
.attr('y', (d) => {
return height
})
.attr('width', (width - 200)/goals.length)
.transition()
.duration(750)
.attr("height", 0)
.transition()
.duration(200)
.attr('y', (d) => {
return yScale(d)
})
.attr('height', (d) => {
return height - yScale(d)
})

svg.append('g')
.attr('transform','rotate(0)')
.call(yAxis)

svg.append('g')
.attr('transform',`translate(0,${height})`)
.call(xAxis)

}

Expand Down