-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrey
authored and
Andrey
committed
Apr 21, 2017
1 parent
5f4dcec
commit 5b34d4c
Showing
20 changed files
with
1,527 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Empty file.
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,6 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.contrib import admin | ||
|
||
# Register your models here. |
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,8 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.apps import AppConfig | ||
|
||
|
||
class GrabConfig(AppConfig): | ||
name = 'grab' |
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,80 @@ | ||
x.domain(d3.extent(data, function(d) { return d.month; })); | ||
y.domain(d3.extent(data, function(d) { return d.count_items; })); | ||
|
||
svg.append("g") | ||
.attr("class", "x axis") | ||
.attr("transform", "translate(0," + height + ")") | ||
.call(xAxis); | ||
|
||
svg.append("g") | ||
.attr("class", "y axis") | ||
.call(yAxis) | ||
.append("text") | ||
.attr("transform", "rotate(-90)") | ||
.attr("y", 6) | ||
.attr("dy", ".71em") | ||
.style("text-anchor", "end") | ||
.text("Play count"); | ||
|
||
svg.append("path") | ||
.datum(data) | ||
.attr("class", "line") | ||
.attr("d", line); | ||
|
||
|
||
|
||
|
||
|
||
console.log(url); | ||
|
||
// render the table | ||
tabulate(d.data, Object.keys( d )); | ||
|
||
// render the chart with nvd3 | ||
nv.addGraph(function() { | ||
var chart = nv.models.lineChart() | ||
.margin({ | ||
left: 100 | ||
}) | ||
.useInteractiveGuideline(false) | ||
.transitionDuration(350) | ||
.showLegend(true) | ||
.showYAxis(true) | ||
.showXAxis(true); | ||
|
||
chart.xAxis | ||
.axisLabel("Year") | ||
.tickFormat(d3.format(',r')); | ||
|
||
chart.yAxis | ||
.axisLabel(d.name + " x 1M") | ||
.tickFormat(d3.format('.02f')); | ||
|
||
|
||
var chartData = [{ | ||
values: [], //values - represents the array of {x,y} data points | ||
key: d.code, //key - the name of the series. | ||
color: '#ff7f0e' //color - optional: choose your own line color. | ||
}]; | ||
|
||
var roots = d.data.map(function(e) { | ||
return { | ||
x: e[0].slice(0, 4), | ||
y: e[1] / 1000000 | ||
}; | ||
}); | ||
|
||
//push it to chartData; | ||
//change index or wrap in loop if more datasets graphed on the same chart, e.g. emissions from fossil, gas, etc. | ||
chartData[0].values = roots; | ||
|
||
d3.select('#chart svg') //select the <svg> element you want to render the chart in. | ||
.datum(chartData) //populate the <svg> element with chart data... | ||
.call(chart); //render the chart | ||
|
||
//Update the chart when window resizes. | ||
nv.utils.windowResize(function() { | ||
chart.update(); | ||
}); | ||
return chart; | ||
}); |
Empty file.
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,8 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
from django.db import models | ||
|
||
|
||
class Play: | ||
name = models.CharField(max_length=100) | ||
date = models.DateTimeField() |
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,108 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<style> | ||
|
||
body { | ||
font: 10px sans-serif; | ||
} | ||
|
||
.axis path, | ||
.axis line { | ||
fill: none; | ||
stroke: #000; | ||
shape-rendering: crispEdges; | ||
} | ||
|
||
.x.axis path { | ||
display: none; | ||
} | ||
|
||
.line { | ||
fill: none; | ||
stroke: steelblue; | ||
stroke-width: 1.5px; | ||
} | ||
|
||
</style> | ||
<body> | ||
<h1>D3_Data</h1> | ||
<p>первый пример</p> | ||
<div class="chartHTML"></div> | ||
<script src="http://d3js.org/d3.v3.js"></script> | ||
<script> | ||
d3.select("h1").style("color","green"); | ||
|
||
var data_1 = [2,3,45,5,6,7,8,8] | ||
d3.select("body").append("svg") | ||
.selectAll("rect").data(data_1) | ||
.enter() | ||
.append("rect") | ||
|
||
d3.json( | ||
"{% url "PyData" %}", function( data) { | ||
console.log(data) | ||
|
||
var svg = d3.select("svg") | ||
|
||
svg.append("g") | ||
.attr("class", "x axis") | ||
.attr("transform", "translate(0," + d3.max(d.X) + ")") | ||
.call(xAxis); | ||
|
||
svg.append("g") | ||
.attr("class", "y axis") | ||
.call(yAxis) | ||
.append("text") | ||
.attr("transform", "rotate(-90)") | ||
|
||
} | ||
); | ||
|
||
|
||
function tabulate(data, columns) { | ||
|
||
//remove existing table (if), create new one | ||
d3.select("#datatable").selectAll("table").remove(); | ||
var table = d3.select("#datatable").append("table"), | ||
thead = table.append("thead"), | ||
tbody = table.append("tbody"); | ||
|
||
//append the header row | ||
thead.append("tr") | ||
.selectAll("th") | ||
.data(columns) | ||
.enter() | ||
.append("th") | ||
.text(function(column) { | ||
return column; | ||
}); | ||
|
||
// create a row for each object in the data | ||
var rows = tbody.selectAll("tr") | ||
.data(data) | ||
.enter() | ||
.append("tr"); | ||
|
||
// create a cell in each row for each column | ||
var cells = rows.selectAll("td") | ||
.data(function(row) { | ||
return columns.map(function(column) { | ||
return { | ||
column: column, | ||
value: row | ||
}; | ||
}); | ||
}) | ||
.enter() | ||
.append("td") | ||
.text(function(d, i) { | ||
return d.value[i]; | ||
}); | ||
|
||
firstgo=false; | ||
return table; | ||
} | ||
|
||
</script> | ||
</body> | ||
</html> |
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,6 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.test import TestCase | ||
|
||
# Create your tests here. |
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,10 @@ | ||
from django.conf.urls import url | ||
|
||
from .views import graph , PyData | ||
|
||
urlpatterns = [ | ||
#url(r'^$', views.index, name='index'), | ||
url(r'^$', graph), | ||
#url(r'^api/play_count_by_month', play_count_by_month, name='play_count_by_month') | ||
url(r'^PyData', PyData, name='PyData') | ||
] |
Oops, something went wrong.