-
-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1980 from gitcoinco/kevin/gas-guzzlers
gas guzzlers in gas station
- Loading branch information
Showing
7 changed files
with
289 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
{% comment %} | ||
Copyright (C) 2018 Gitcoin Core | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
|
||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
{% endcomment %} | ||
|
||
<style> /* set the CSS */ | ||
|
||
.axis { | ||
font-family: Arial, Helvetica, sans-serif; | ||
font-size: .8em; | ||
} | ||
|
||
.line { | ||
fill: none; | ||
stroke: steelblue; | ||
stroke-width: 2px; | ||
} | ||
{% for key, val in lines.items %} | ||
.line.line_{{key}} { | ||
stroke: {{val}}; | ||
} | ||
{% endfor %} | ||
div.tooltip { | ||
position: absolute; | ||
max-width: 300px; | ||
padding: 3px 6px; | ||
color: grey; | ||
font-family: 'Droid Sans Mono', monospace; | ||
font-size: .7em; | ||
background: whitesmoke; | ||
border: 1px solid grey; | ||
border-radius: 3px; | ||
pointer-events: none; | ||
z-index: 9999; | ||
} | ||
@media screen and (min-width: 901px) { | ||
#key { | ||
right: 100px; | ||
float: right; | ||
top: 270px; | ||
position: absolute; | ||
} | ||
} | ||
@media screen and (max-width: 900px) { | ||
#key { | ||
position: initial; | ||
} | ||
} | ||
#key{ | ||
text-align: right; | ||
} | ||
#key p{ | ||
margin: 0px; | ||
font-size: 12px; | ||
} | ||
|
||
</style> | ||
|
||
<script src="https://d3js.org/d3.v4.min.js"></script> | ||
<script> | ||
|
||
var tooltip; | ||
|
||
tooltip = d3.select("body").append("div") | ||
.attr("class", "tooltip") | ||
.style("opacity", 0); | ||
|
||
var margin = {top: 20, right: 20, bottom: 50, left: 70}, | ||
width = window.innerWidth - 100 - margin.left - margin.right, | ||
height = 500 - margin.top - margin.bottom; | ||
var initialWidth = width; | ||
var xScale = d3.scaleLinear().range([width, 0]); | ||
var yScale = d3.scaleLinear().range([height, 0]); | ||
|
||
// define the line | ||
var valueline = d3.line() | ||
.x(function(d) { return xScale(d.confirmation_time); }) | ||
.y(function(d) { return yScale(d.gas_price); }); | ||
|
||
var svg = d3.select("#graph") | ||
.attr("width", width + margin.left + margin.right) | ||
.attr("height", height + margin.top + margin.bottom) | ||
.append("g") | ||
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | ||
|
||
{% for key, gas_history in gas_histories.items %} | ||
var source = {{gas_history | safe}}; | ||
data = [] | ||
source.forEach(function(d) { | ||
d['confirmation_time'] = parseFloat(d[1]) | ||
d['gas_price'] = parseFloat(d[0]); | ||
d.splice(0,2); | ||
data.push(d); | ||
}); | ||
|
||
xScale.domain([0, d3.max(data, function(d) { return d.confirmation_time; })]).nice(); | ||
yScale.domain([0, d3.max(data, function(d) { return {{max}}; })]).nice(); | ||
|
||
svg.append("path") | ||
.data([data]) | ||
.attr("class", "line line_{{key}}") | ||
.attr("d", valueline); | ||
|
||
{% endfor %} | ||
|
||
// x Axis | ||
svg.append("g") | ||
.attr("class", "x axis") | ||
.attr("transform", "translate(0," + height + ")") | ||
.call(d3.axisBottom(xScale)); | ||
|
||
// text label for the x axis | ||
svg.append("text") | ||
.attr("transform", | ||
"translate(" + (width/2) + " ," + | ||
(height + margin.top + 20) + ")") | ||
.style("text-anchor", "middle") | ||
.attr("class", "axis") | ||
.attr("class", "x-title") | ||
.text("{{breakdown_ui}}-ago"); | ||
|
||
// y Axis | ||
svg.append("g") | ||
.call(d3.axisLeft(yScale)); | ||
|
||
// text label for the y axis | ||
svg.append("text") | ||
.attr("transform", "rotate(-90)") | ||
.attr("y", 0 - margin.left) | ||
.attr("x",0 - (height / 2)) | ||
.attr("dy", "2em") | ||
.attr("class", "axis") | ||
.style("text-anchor", "middle") | ||
.text("Gas Price (gwei)"); | ||
|
||
function resize() { | ||
var newWidth = window.innerWidth - 100 - margin.left - margin.right; | ||
var height = 500 - margin.top - margin.bottom; | ||
if(newWidth < initialWidth) { // initialWidth determines max width of parent div in a way | ||
|
||
// Update the range of the scale with new width/height | ||
xScale.range([newWidth, 0]); | ||
yScale.range([height, 0]); | ||
|
||
svg.select(".x.axis") // resizes x axis | ||
.attr("transform", "translate(0," + height + ")") | ||
.call(d3.axisBottom(xScale)); | ||
|
||
svg.select(".x-title") // resizes the positioning of the x axis title | ||
.attr("transform","translate(" + (newWidth/2) + " ," + (height + margin.top + 20) + ")") | ||
.style("text-anchor", "middle"); | ||
|
||
svg.append("path") // updates line data to conform | ||
.data([data]) | ||
.attr("class", "line line_{{key}}") | ||
.attr("d", valueline); | ||
} | ||
} | ||
// Call the resize function whenever a resize event occurs | ||
d3.select(window).on('resize', resize); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{% extends 'onepager/base.html' %} | ||
{% load i18n static %} | ||
{% block 'scripts' %} | ||
<script src="{% static "v2/js/jquery.js"%}"></script> | ||
{% endblock %} | ||
<!-- Main --> | ||
|
||
{% block 'world' %} | ||
<canvas id="world" style="position:absolute; top:0px; left: 0px;"> | ||
</canvas> | ||
{% endblock %} | ||
|
||
{% block 'main' %} | ||
|
||
<section id=main> | ||
{% include 'shared/gas_nav.html' %} | ||
|
||
<h1> {% trans "Gas Guzzlers" %} ({{breakdown}}) <span id="alpha">{% trans "Alpha" %}</span> </h1> | ||
<p>These are the addresses that are using the most gas</p> | ||
<ul class="gas_nav small"> | ||
{% for granularity in granularity_options %} | ||
<li> | ||
<a href="{%url 'gas_guzzler_view'%}?breakdown={{granularity}}">{{granularity}} view</a> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
|
||
<div id="key"> | ||
{% for key, val in lines.items %} | ||
<p style="color:{{val}}">{% trans "Address no. " %} {{key}} {% trans "." %}</p> | ||
{% endfor %} | ||
</div> | ||
|
||
{% if gas_histories == '[]' %} | ||
<p> | ||
{% blocktrans %} We are unable to sync gas data at this time. We recommend you check out <a href="https://ethgasstation.info/predictionTable.php" target="_blank" rel="noopener noreferrer">ETH Gas Station</a> instead.{% endblocktrans %} | ||
</p> | ||
{% else %} | ||
<svg id="graph"></svg> | ||
{% include 'shared/gas_history.html' %} | ||
{% include 'shared/disqus.html' with page_url='https://gitcoin.co/gas/history?' %} | ||
|
||
</div> | ||
|
||
</div> | ||
<script> | ||
</script> | ||
|
||
|
||
{% endif %} | ||
|
||
</section> | ||
|
||
{% endblock %} |
Oops, something went wrong.