mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-11 06:31:51 +08:00
fix:#4124 graph buttons are now toggles (#4203) D3press3dd Miodec
* fix:#4124 graph buttons are now toggles * fix: delete deletes unnecessary code and removes a typo * renamed function * only updating if on account page * updating account buttons on account page load --------- Co-authored-by: Miodec <jack@monkeytype.com>
This commit is contained in:
parent
b766c626b3
commit
f5d713256a
2 changed files with 27 additions and 1 deletions
|
|
@ -28,6 +28,8 @@ import chartAnnotation, {
|
|||
} from "chartjs-plugin-annotation";
|
||||
import chartTrendline from "chartjs-plugin-trendline";
|
||||
|
||||
import * as ActivePage from "../states/active-page";
|
||||
|
||||
Chart.register(
|
||||
BarController,
|
||||
BarElement,
|
||||
|
|
@ -943,8 +945,29 @@ export const miniResult: ChartWithUpdateColors<
|
|||
},
|
||||
});
|
||||
|
||||
type ButtonBelowChart =
|
||||
| ".toggleAccuracyOnChart"
|
||||
| ".toggleAverage10OnChart"
|
||||
| ".toggleAverage100OnChart";
|
||||
|
||||
export function updateAccountChartButtons(): void {
|
||||
updateAccuracy();
|
||||
updateAverage10();
|
||||
updateAverage100();
|
||||
}
|
||||
|
||||
function updateAccountChartButton(
|
||||
isActive: boolean,
|
||||
className: ButtonBelowChart
|
||||
): void {
|
||||
isActive
|
||||
? $(`.pageAccount ${className}`).addClass("active")
|
||||
: $(`.pageAccount ${className}`).removeClass("active");
|
||||
}
|
||||
|
||||
function updateAccuracy(): void {
|
||||
const accOn = Config.accountChart[0] === "on";
|
||||
updateAccountChartButton(accOn, ".toggleAccuracyOnChart");
|
||||
|
||||
accountHistory.data.datasets[2].hidden = !accOn;
|
||||
accountHistory.data.datasets[4].hidden = !accOn;
|
||||
|
|
@ -958,6 +981,7 @@ function updateAccuracy(): void {
|
|||
function updateAverage10(): void {
|
||||
const accOn = Config.accountChart[0] === "on";
|
||||
const avg10On = Config.accountChart[1] === "on";
|
||||
updateAccountChartButton(avg10On, ".toggleAverage10OnChart");
|
||||
|
||||
if (accOn) {
|
||||
accountHistory.data.datasets[3].hidden = !avg10On;
|
||||
|
|
@ -972,6 +996,7 @@ function updateAverage10(): void {
|
|||
function updateAverage100(): void {
|
||||
const accOn = Config.accountChart[0] === "on";
|
||||
const avg100On = Config.accountChart[2] === "on";
|
||||
updateAccountChartButton(avg100On, ".toggleAverage100OnChart");
|
||||
|
||||
if (accOn) {
|
||||
accountHistory.data.datasets[5].hidden = !avg100On;
|
||||
|
|
@ -1147,7 +1172,7 @@ export function updateAllChartColors(): void {
|
|||
}
|
||||
|
||||
ConfigEvent.subscribe((eventKey, eventValue) => {
|
||||
if (eventKey === "accountChart") {
|
||||
if (eventKey === "accountChart" && ActivePage.get() === "account") {
|
||||
updateAccuracy();
|
||||
updateAverage10();
|
||||
updateAverage100();
|
||||
|
|
|
|||
|
|
@ -1027,6 +1027,7 @@ function fillContent(): void {
|
|||
delete ChartController.accountHistory.options.animation;
|
||||
}
|
||||
|
||||
ChartController.updateAccountChartButtons();
|
||||
ChartController.accountActivity.update();
|
||||
ChartController.accountHistogram.update();
|
||||
LoadingPage.updateBar(100, true);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue