Skip to content

Commit

Permalink
Ajustamos el gráfico de idiomas
Browse files Browse the repository at this point in the history
  • Loading branch information
Verdoso committed Oct 30, 2022
1 parent 264bdc8 commit 9834672
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
Binary file added docs/grafico_idiomas.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/frontend/src/less/librarian.less
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,8 @@ Typeahead
.empty-message {
padding: .5em 1em;
font-weight: bold;
}

canvas#idiomas-chart {
margin: auto;
}
47 changes: 42 additions & 5 deletions src/main/frontend/src/vue/idiomas-chart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export default {
},
width: {
type: Number,
default: 400
default: 800
},
height: {
type: Number,
default: 150
default: 500
},
cssClasses: {
default: '',
default: 'idiomas_doughnut',
type: String
},
styles: {
Expand All @@ -70,10 +70,47 @@ export default {
]
}
, chartOptions: {
responsive: true
responsive: false
, aspectRatio: 5
, maintainAspectRatio: false
, plugins: {
tooltip: {
legend: {
position: 'right'
, labels: {
generateLabels: ((chart) => {
const data = chart.data;
if (data.labels.length && data.datasets.length) {
const {labels: {pointStyle}} = chart.legend.options;
return data.labels.map((label, i) => {
const meta = chart.getDatasetMeta(0);
const style = meta.controller.getStyle(i);
var total = chart.config.data.datasets[0].data.reduce(function(previousValue, currentValue, currentIndex, array) {
return previousValue + currentValue;
});
var value = chart.config.data.datasets[0].data[i];
var percentage = parseFloat((value/total*100).toFixed(2));
return {
text: label + ': ' + Intl.NumberFormat('ca').format(value) + ' (' + percentage + '%)',
fillStyle: style.backgroundColor,
strokeStyle: style.borderColor,
lineWidth: style.borderWidth,
pointStyle: pointStyle,
hidden: !chart.getDataVisibility(i),
// Extra data used for toggling the correct item
index: i
};
});
}
return [];
})
}
}
, tooltip: {
enabled: true,
callbacks: {
label: ((context) => {
Expand Down

0 comments on commit 9834672

Please sign in to comment.