Show user's best perf in rating graph navigator

pull/9719/head
Albert Ford 2021-09-04 04:28:03 -07:00
parent 26069874ed
commit fc12506c37
No known key found for this signature in database
GPG Key ID: 9C200032321A04A3
5 changed files with 36 additions and 21 deletions

View File

@ -30,7 +30,7 @@ object perfStat {
frag(
jsTag("chart/ratingHistory.js"),
embedJsUnsafeLoadThen(
s"lichess.ratingHistoryChart($rc,'${perfType.trans(lila.i18n.defaultLang)}');"
s"lichess.ratingHistoryChart($rc,{singlePerfName:'${perfType.trans(lila.i18n.defaultLang)}'});"
)
)
}

View File

@ -11,6 +11,7 @@ import lila.app.ui.ScalatagsTemplate._
import lila.common.paginator.Paginator
import lila.game.Game
import lila.user.User
import lila.history.RatingChartApi
object page {
@ -84,7 +85,9 @@ object page {
info.ratingChart.map { ratingChart =>
frag(
jsTag("chart/ratingHistory.js"),
embedJsUnsafeLoadThen(s"lichess.ratingHistoryChart($ratingChart)")
embedJsUnsafeLoadThen(
s"lichess.ratingHistoryChart($ratingChart,{perfIndex:${RatingChartApi.bestPerfIndex(info.user)}})"
)
)
},
withSearch option jsModule("gameSearch"),

View File

@ -43,24 +43,7 @@ final class RatingChartApi(
historyApi get userId map2 { (history: History) =>
lila.common.String.html.safeJsonValue {
Json.toJson {
import lila.rating.PerfType._
List(
Bullet,
Blitz,
Rapid,
Classical,
Correspondence,
Chess960,
KingOfTheHill,
ThreeCheck,
Antichess,
Atomic,
Horde,
RacingKings,
Crazyhouse,
Puzzle,
UltraBullet
) map { pt =>
RatingChartApi.perfTypes map { pt =>
Json.obj(
"name" -> pt.trans(lila.i18n.defaultLang),
"points" -> ratingsMapToJson(userId, createdAt, history(pt))
@ -72,3 +55,27 @@ final class RatingChartApi(
}
}
}
object RatingChartApi {
def bestPerfIndex(user: User): Int = user.bestPerf ?? { perfTypes indexOf _ }
import lila.rating.PerfType._
private val perfTypes = List(
Bullet,
Blitz,
Rapid,
Classical,
Correspondence,
Chess960,
KingOfTheHill,
ThreeCheck,
Antichess,
Atomic,
Horde,
RacingKings,
Crazyhouse,
Puzzle,
UltraBullet
)
}

View File

@ -106,6 +106,8 @@ case class User(
def best3Perfs: List[PerfType] = bestOf(User.firstRow, 3)
def bestPerf: Option[PerfType] = bestOf(User.firstRow ::: User.secondRow, 1) headOption
def hasEstablishedRating(pt: PerfType) = perfs(pt).established
def isPatron = plan.active

View File

@ -1,4 +1,4 @@
lichess.ratingHistoryChart = function (data, singlePerfName) {
lichess.ratingHistoryChart = function (data, { singlePerfName, perfIndex }) {
var oneDay = 86400000;
function smoothDates(data) {
if (!data.length) return [];
@ -96,6 +96,9 @@ lichess.ratingHistoryChart = function (data, singlePerfName) {
lineWidth: 0,
tickWidth: 0,
},
navigator: {
baseSeries: perfIndex,
},
scrollbar: disabled,
series: data
.filter(function (v) {