UI development
This commit is contained in:
parent
767ef48e62
commit
2f30dec315
|
@ -77,12 +77,13 @@ def books_per_country(request):
|
|||
data = []
|
||||
df = filterData(getBooksData(), request.META.get('HTTP_YEAR'))
|
||||
|
||||
countries = df.groupby('country')['country'].count().reset_index(name="count")
|
||||
countries = df.groupby(['country_code', 'country'])['country'].count().reset_index(name="count")
|
||||
countries = countries.sort_values(by='count', ascending=False)
|
||||
|
||||
for index, row in countries.iterrows():
|
||||
|
||||
data.append({
|
||||
"code": row['country_code'],
|
||||
"country": row['country'],
|
||||
"count": int(row['count'])
|
||||
})
|
||||
|
|
|
@ -1896,6 +1896,40 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"chart.js": {
|
||||
"version": "2.9.4",
|
||||
"resolved": "https://registry.npmjs.org/chart.js/-/chart.js-2.9.4.tgz",
|
||||
"integrity": "sha512-B07aAzxcrikjAPyV+01j7BmOpxtQETxTSlQ26BEYJ+3iUkbNKaOJ/nDbT6JjyqYxseM0ON12COHYdU2cTIjC7A==",
|
||||
"requires": {
|
||||
"chartjs-color": "^2.1.0",
|
||||
"moment": "^2.10.2"
|
||||
}
|
||||
},
|
||||
"chartjs-color": {
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmjs.org/chartjs-color/-/chartjs-color-2.4.1.tgz",
|
||||
"integrity": "sha512-haqOg1+Yebys/Ts/9bLo/BqUcONQOdr/hoEr2LLTRl6C5LXctUdHxsCYfvQVg5JIxITrfCNUDr4ntqmQk9+/0w==",
|
||||
"requires": {
|
||||
"chartjs-color-string": "^0.6.0",
|
||||
"color-convert": "^1.9.3"
|
||||
}
|
||||
},
|
||||
"chartjs-color-string": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/chartjs-color-string/-/chartjs-color-string-0.6.0.tgz",
|
||||
"integrity": "sha512-TIB5OKn1hPJvO7JcteW4WY/63v6KwEdt6udfnDE9iCAZgy+V4SrbSxoIbTw/xkUIapjEI4ExGtD0+6D3KyFd7A==",
|
||||
"requires": {
|
||||
"color-name": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"chartjs-plugin-style": {
|
||||
"version": "0.5.0",
|
||||
"resolved": "https://registry.npmjs.org/chartjs-plugin-style/-/chartjs-plugin-style-0.5.0.tgz",
|
||||
"integrity": "sha512-QWMWRGpkexgMTHZg2l1OVtnSkElGNAM0MchozG/ucU6NW0xXINS/YsIE2tl7nG1nwZA2FH/myVbI4uMguIAXPA==",
|
||||
"requires": {
|
||||
"chart.js": ">= 2.6.0 < 3"
|
||||
}
|
||||
},
|
||||
"chrome-trace-event": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz",
|
||||
|
@ -2010,6 +2044,23 @@
|
|||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.0.tgz",
|
||||
"integrity": "sha512-uX1KG+x9h5hIJsaKR9xHUeUraxf8IODOwq9JLNPq6BwB04a/xgpq3rcx47l5BZu5zBPlgD342tdke3Hom/nJRA=="
|
||||
},
|
||||
"datatables.net": {
|
||||
"version": "1.12.1",
|
||||
"resolved": "https://registry.npmjs.org/datatables.net/-/datatables.net-1.12.1.tgz",
|
||||
"integrity": "sha512-e6XAMUoV41JdQPS/r9YRfRcmTPcCVvyZbWI+xog1Zg+kjVliMQbEkvWK5XFItmi64Cvwg+IqsZbTUJ1KSY3umA==",
|
||||
"requires": {
|
||||
"jquery": ">=1.7"
|
||||
}
|
||||
},
|
||||
"datatables.net-dt": {
|
||||
"version": "1.12.1",
|
||||
"resolved": "https://registry.npmjs.org/datatables.net-dt/-/datatables.net-dt-1.12.1.tgz",
|
||||
"integrity": "sha512-HYsHbSYqOqlgsgjKMH/kkCB5455t51GmmtXRxgnDMRbjPLEIKo5CZmAlUe5mdD/RVPRtAUaj5K3SDlkEZ1bUmw==",
|
||||
"requires": {
|
||||
"datatables.net": ">=1.11.3",
|
||||
"jquery": ">=1.7"
|
||||
}
|
||||
},
|
||||
"debug": {
|
||||
"version": "4.3.4",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||
|
@ -2340,6 +2391,11 @@
|
|||
"supports-color": "^8.0.0"
|
||||
}
|
||||
},
|
||||
"jquery": {
|
||||
"version": "3.6.1",
|
||||
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.1.tgz",
|
||||
"integrity": "sha512-opJeO4nCucVnsjiXOE+/PcCgYw9Gwpvs/a6B1LL/lQhwWwpbVEVYDZ1FokFr8PRc7ghYlrFPuyHuiiDNTQxmcw=="
|
||||
},
|
||||
"js-tokens": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
|
||||
|
@ -2448,6 +2504,11 @@
|
|||
"mime-db": "1.52.0"
|
||||
}
|
||||
},
|
||||
"moment": {
|
||||
"version": "2.29.4",
|
||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
||||
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w=="
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
|
|
|
@ -26,6 +26,10 @@
|
|||
"@emotion/styled": "^11.10.4",
|
||||
"@material-ui/icons": "^4.11.3",
|
||||
"@mui/material": "^5.10.3",
|
||||
"chartjs-plugin-style": "^0.5.0",
|
||||
"datatables.net": "^1.12.1",
|
||||
"datatables.net-dt": "^1.12.1",
|
||||
"jquery": "^3.6.1",
|
||||
"react-router-dom": "^6.3.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,50 @@ export default class App extends Component {
|
|||
totalpages: 0,
|
||||
totalauthors: 0,
|
||||
totalcountries: 0,
|
||||
totalgenres: 0
|
||||
totalgenres: 0,
|
||||
countries: []
|
||||
}
|
||||
|
||||
this.yearsArray = [];
|
||||
}
|
||||
|
||||
getGenres(){
|
||||
fetch('/api/books/genres', {
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"year": this.state.year
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(books => {
|
||||
this.initChart(books, this.state.year);
|
||||
})
|
||||
}
|
||||
|
||||
getCountries(init){
|
||||
fetch('/api/books/countries', {
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"year": this.state.year
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
this.setState({
|
||||
countries: data
|
||||
})
|
||||
|
||||
if(init == true){
|
||||
$('#DataTable').DataTable({
|
||||
paging: false,
|
||||
ordering: false,
|
||||
info: false,
|
||||
searching: false
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
changeYear(event) {
|
||||
|
||||
this.setState({
|
||||
|
@ -38,6 +76,34 @@ export default class App extends Component {
|
|||
totalgenres: data.totalgenres
|
||||
})
|
||||
})
|
||||
|
||||
fetch('/api/books/countries', {
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"year": this.state.year
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
this.setState({
|
||||
countries: data
|
||||
})
|
||||
|
||||
this.getCountries(false);
|
||||
})
|
||||
|
||||
var $this = this;
|
||||
|
||||
fetch('/api/books/genres/count', {
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"year": this.state.year
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
this.initDoughnut(data);
|
||||
})
|
||||
}
|
||||
|
||||
initHorBar(data){
|
||||
|
@ -90,7 +156,7 @@ export default class App extends Component {
|
|||
{
|
||||
label: "Boeken",
|
||||
data: counts,
|
||||
backgroundColor: '#696ffc'
|
||||
backgroundColor: '#696ffc',
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
@ -123,13 +189,25 @@ export default class App extends Component {
|
|||
backgroundColor: [
|
||||
'#696ffc', '#7596fa', '#92adfe', '#abc0ff'
|
||||
],
|
||||
borderWidth: 3,
|
||||
borderWidth: 0,
|
||||
borderColor: '#1f2940'
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
//cutoutPercentage: 40,
|
||||
cutout: '70%',
|
||||
responsive: true,
|
||||
plugins: {
|
||||
legend: {
|
||||
labels: {
|
||||
// This more specific font property overrides the global property
|
||||
color: "white",
|
||||
font: {
|
||||
size: 14,
|
||||
family: 'Source Sans Pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -218,6 +296,7 @@ export default class App extends Component {
|
|||
ticks: {
|
||||
beginAtZero: true,
|
||||
color: "white",
|
||||
fontFamily: "Source Sans Pro",
|
||||
},
|
||||
stacked: true,
|
||||
},
|
||||
|
@ -226,6 +305,7 @@ export default class App extends Component {
|
|||
beginAtZero: true,
|
||||
stepSize: 1,
|
||||
color: "white",
|
||||
fontFamily: "Source Sans Pro",
|
||||
},
|
||||
stacked: true
|
||||
}
|
||||
|
@ -233,52 +313,23 @@ export default class App extends Component {
|
|||
plugins: {
|
||||
legend: {
|
||||
labels: {
|
||||
color: "white"
|
||||
color: "white",
|
||||
font: {
|
||||
size: 14,
|
||||
family: 'Source Sans Pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
tooltips: {
|
||||
bodyFont: 'Source Sans Pro'
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
var $this = this;
|
||||
|
||||
fetch('/api/books/genres', {
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"year": this.state.year
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(books => {
|
||||
this.initChart(books, this.state.year);
|
||||
})
|
||||
|
||||
fetch('/api/books/genres/count', {
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"year": this.state.year
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
this.initDoughnut(data);
|
||||
})
|
||||
|
||||
fetch('/api/books/countries', {
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"year": this.state.year
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
this.initHorBar(data);
|
||||
})
|
||||
|
||||
|
||||
|
||||
this.getGenres();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -309,16 +360,7 @@ export default class App extends Component {
|
|||
this.initDoughnut(data);
|
||||
})
|
||||
|
||||
fetch('/api/books/countries', {
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"year": this.state.year
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
this.initHorBar(data);
|
||||
})
|
||||
this.getCountries(true);
|
||||
|
||||
fetch('/api/books/stats', {
|
||||
"method": "GET",
|
||||
|
@ -346,9 +388,11 @@ export default class App extends Component {
|
|||
readingYears: data
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
console.log(this.state);
|
||||
return (
|
||||
<React.Fragment>
|
||||
<div className="content">
|
||||
|
@ -417,18 +461,46 @@ export default class App extends Component {
|
|||
<div className="container-fluid">
|
||||
<div className="row">
|
||||
<div className="col-md-8">
|
||||
<div className="books-per-month"><canvas id="chart"></canvas></div>
|
||||
<div className="books-per-month"><span className="block_name">Boeken per maand per genre</span><canvas id="chart"></canvas></div>
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<div className="genresPercent"><canvas id="chartGenres"></canvas></div>
|
||||
<div className="genresPercent"><span className="block_name">Genres</span><canvas id="chartGenres"></canvas></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="container-fluid">
|
||||
<div className="row">
|
||||
<div className="col-md-6">
|
||||
<div className="books-per-country"><canvas id="countryChart"></canvas></div>
|
||||
<div className="col-md-2">
|
||||
{/* <div className="books-per-country"><canvas id="countryChart"></canvas></div> */}
|
||||
<div className="books-per-country">
|
||||
<span className="block_name">Landen</span>
|
||||
<table id="DataTable" class="showHead table responsive nowrap" width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Land</th>
|
||||
<th>Boeken</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{this.state.countries.map((country, i) => {
|
||||
|
||||
var code = country.code.toLowerCase();
|
||||
return(
|
||||
<React.Fragment>
|
||||
<tr>
|
||||
<td>{i+1}</td>
|
||||
<td><img src={`https://flagcdn.com/32x24/${code}.png`} /> {country.country}</td>
|
||||
<td>{country.count}</td>
|
||||
</tr>
|
||||
</React.Fragment>
|
||||
)
|
||||
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-md-6">
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -19,6 +19,16 @@
|
|||
|
||||
<script src="https://kit.fontawesome.com/c4a0df9f18.js" crossorigin="anonymous"></script>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.css">
|
||||
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter+Tight:wght@100;200;300;400;500;600;700&display=swap" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700&display=swap" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@200;300;400;600;700&display=swap" rel="stylesheet">
|
||||
|
||||
|
||||
<!-- Make sure you put this AFTER Leaflet's CSS -->
|
||||
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
|
||||
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
|
||||
|
@ -28,6 +38,7 @@
|
|||
background:#141b2d;
|
||||
margin:0;
|
||||
padding:0;
|
||||
font-family: 'Source Sans Pro', sans-serif;
|
||||
}
|
||||
|
||||
.filter{
|
||||
|
@ -112,7 +123,7 @@
|
|||
|
||||
.books-stats .stat-block .stats-label{
|
||||
color: rgba(255,255,255,0.5);
|
||||
font-weight: bold;
|
||||
font-weight: 600;
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
|
@ -129,6 +140,34 @@
|
|||
margin-bottom:20px !important;
|
||||
}
|
||||
|
||||
.table{
|
||||
border-bottom: none !important;
|
||||
}
|
||||
|
||||
.table td{
|
||||
color:#ffffff;
|
||||
border-bottom:none !important;
|
||||
padding: 10px 10px !important;
|
||||
}
|
||||
|
||||
.table td img{
|
||||
margin-right:5px;
|
||||
}
|
||||
|
||||
#DataTable thead{
|
||||
display:none !important;
|
||||
}
|
||||
|
||||
span.block_name{
|
||||
color: #ffffff;
|
||||
font-weight: 600;
|
||||
border-bottom: solid 1px rgba(255,255,255,0.1);
|
||||
width: 100%;
|
||||
display: block;
|
||||
padding-bottom: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
|
@ -138,7 +177,7 @@
|
|||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-u1OknCvxWvY5kfmNBILK2hRnQC3Pr17a+RTT6rIHI7NnikvbZlHgTPOOmMi466C8" crossorigin="anonymous"></script>
|
||||
|
||||
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script src="{% static "js/main.js" %}"></script>
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue