Skip to content

Commit

Permalink
Fixed tooltip title for radar chart. Ref: chartjs/Chart.js#6890
Browse files Browse the repository at this point in the history
  • Loading branch information
lucka-me committed May 26, 2020
1 parent 3b161f0 commit 53aea0a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ TBA
### Fixed
- Map doesn't update after saving portal details
- Card doesn't follow filter after saving the portal details
- Tooltips of radar chart display value as title
```

```markdown
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

<div class="mdc-top-app-bar--fixed-adjust"></div>

<div class="mdc-linear-progress" id="progressBar" hidden>
<div class="mdc-linear-progress" id="progress-bar" hidden>
<div class="mdc-linear-progress__buffering-dots"></div>
<div class="mdc-linear-progress__buffer"></div>
<div class="mdc-linear-progress__bar mdc-linear"></div>
Expand Down
29 changes: 14 additions & 15 deletions lib/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const dashboard = {
map: {
init: () => mapKit.load(),
update: () => mapKit.updateData(),
updateStyle: (dark) => { },
updateStyle: () => { },
setVisible: (visible) => visible,
},
filter: {
Expand Down Expand Up @@ -214,7 +214,7 @@ const dashboard = {
},
}],
},
tooltips: { mode: 'index', },
tooltips: { mode: 'x', },
maintainAspectRatio: false,
}
});
Expand Down Expand Up @@ -284,16 +284,13 @@ const dashboard = {
datasets: [{
data: [],
borderColor: style.getPropertyValue('--mdc-theme-primary'),
pointHoverBorderColor: style.getPropertyValue('--mdc-theme-primary'),
}],
},
options: {
legend: {
display: false,
},
legend: { display: false, },
scales: {
yAxes: [{
ticks: { beginAtZero: true, },
}],
yAxes: [{ ticks: { beginAtZero: true, }, }],
xAxes: [{
scaleLabel: {
display: true,
Expand Down Expand Up @@ -349,9 +346,7 @@ const dashboard = {
card.textReviews.innerHTML = `${stats.review}`;
card.textSubtitle.innerHTML = `${stats.review < 2 ? 'Review' : 'Reviews'} for ${stats.portal} ${stats.portal < 2 ? 'Portal' : 'Portals'}`;
},
updateStyle: () => {

},
updateStyle: () => { },
setVisible: (visible) => document.querySelector('#card-bs-basic').hidden = !visible,
onUpdate: () => process.updateBsData(),
},
Expand Down Expand Up @@ -380,9 +375,7 @@ const dashboard = {
scale: {
ticks: {
display: false,
min: 1,
max: 5,
stepSize: 1,
min: 1, max: 5, stepSize: 1,
},
angleLines: {
color: style.getPropertyValue('--mdc-theme-text-disabled-on-light'),
Expand All @@ -399,7 +392,7 @@ const dashboard = {
const data = [];
for (const rate of Object.keys(value.string.bs.rate)) {
const avg = stats.rate[rate].reduce((pre, cur) => pre + cur, 0) / stats.rate[rate].length;
data.push(avg);
data.push(parseFloat(avg.toFixed(2)));
}
const card = dashboard.card.bs.card.rates;
card.chart.data.datasets[0].data = data;
Expand Down Expand Up @@ -470,6 +463,12 @@ const dashboard = {
},
init() {
Chart.defaults.global.legend.labels.boxWidth = 10;
// Fix for #6890, should remove when upgrade to 3.0
Chart.defaults.radar.tooltips = {
callbacks: {
title: (items, data) => data.labels[items[0].index],
}
}
for (const card of Object.keys(dashboard.card)) {
dashboard.card[card].init();
}
Expand Down
10 changes: 4 additions & 6 deletions lib/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ const ui = {
enabled : false,
onMediaQueryChanged: (mediaQueryList) => {
ui.dark.enabled = mediaQueryList.matches;
const style = mediaQueryList.matches ? value.string.mapbox.style.dark : value.string.mapbox.style.default;
const style = value.string.mapbox.style[ui.dark.enabled ? 'dark' : 'default'];
if (mapKit.isLoaded()) {
mapKit.ctrl.setStyle(style);
mapKit.ctrl.once('render', () => {
mapKit.updateData();
});
mapKit.ctrl.once('render', () => mapKit.updateData());
}
dashboard.updateStyle(mediaQueryList.matches);
dashboard.updateStyle();
if (dialogKit.details.map.ctrl) dialogKit.details.map.ctrl.setStyle(style);
},
},
Expand Down Expand Up @@ -96,7 +94,7 @@ const ui = {
ui.appBar.button.menu.root_.hidden = false;
},
},
progressBar: new mdc.linearProgress.MDCLinearProgress(document.querySelector('#progressBar')),
progressBar: new mdc.linearProgress.MDCLinearProgress(document.querySelector('#progress-bar')),
cardList: document.getElementById('card-list'),
init: () => {
const darkMediaQueryList = window.matchMedia('(prefers-color-scheme: dark)');
Expand Down

0 comments on commit 53aea0a

Please sign in to comment.