@@ -16,6 +16,9 @@ import ACHIEVEMENTS from "../data/achievements.json";
1616const MARGIN = 10 ;
1717const FONTSIZE = 12 ;
1818
19+ const numberFormatter = ( value , total ) =>
20+ countFormatter ( value ) + " (" + Math . floor ( ( value / total ) * 100 ) + "%)" ;
21+
1922const measureText = ( text , font ) => {
2023 const canvas = document . createElement ( "canvas" ) ;
2124 const context = canvas . getContext ( "2d" ) ;
@@ -35,15 +38,8 @@ export default function AchievementStats(props) {
3538 const [ spoiler , setSpoiler ] = useState ( false ) ;
3639
3740 const { days} = useDays ( ) ;
38-
39- const numberFormatter = ( value ) => {
40- return (
41- countFormatter ( value ) +
42- " (" +
43- Math . floor ( ( value / instanceCount ) * 100 ) +
44- "%)"
45- ) ;
46- } ;
41+ const theme = useTheme ( ) ;
42+ const isSmallScreen = useMediaQuery ( theme . breakpoints . down ( "md" ) ) ;
4743
4844 const getDescriptionOf = ( label ) => {
4945 if ( label === "(Hidden)" ) return "This achievement is hidden." ;
@@ -71,7 +67,7 @@ export default function AchievementStats(props) {
7167 >
7268 < p className = "label" >
7369 < strong >
74- { label } : { numberFormatter ( payload [ 0 ] . value ) }
70+ { label } : { numberFormatter ( payload [ 0 ] . value , instanceCount ) }
7571 </ strong >
7672 </ p >
7773 < p className = "desc" > { getDescriptionOf ( label ) } </ p >
@@ -91,7 +87,9 @@ export default function AchievementStats(props) {
9187 const font = `${ FONTSIZE } px ${ theme . typography . fontFamily } ` ;
9288
9389 setInstanceCount ( stats . instances ) ;
94- setMaxTextWidthRight ( measureText ( numberFormatter ( stats . instances ) , font ) ) ;
90+ setMaxTextWidthRight (
91+ measureText ( numberFormatter ( stats . instances , stats . instances ) , font )
92+ ) ;
9593
9694 const data = [ ] ;
9795 for ( const a in ACHIEVEMENTS ) {
@@ -120,11 +118,7 @@ export default function AchievementStats(props) {
120118
121119 setAchievementData ( data ) ;
122120 console . log ( "Achievement data" , data ) ;
123- } , [ stats , spoiler ] ) ;
124-
125- const theme = useTheme ( ) ;
126-
127- const isSmallScreen = useMediaQuery ( theme . breakpoints . down ( "lg" ) ) ;
121+ } , [ stats , spoiler , theme . typography . fontFamily ] ) ;
128122
129123 return (
130124 < Stats
@@ -172,7 +166,7 @@ export default function AchievementStats(props) {
172166 fill : theme . palette . text . secondary ,
173167 fontSize : FONTSIZE
174168 } }
175- tickFormatter = { numberFormatter }
169+ tickFormatter = { ( v ) => numberFormatter ( v , instanceCount ) }
176170 />
177171 ) }
178172 < Tooltip
0 commit comments