delay point updates and fix randomizer
This commit is contained in:
parent
21d02b7d31
commit
1df852500d
2 changed files with 22 additions and 16 deletions
|
@ -18,7 +18,20 @@ interface RankChartProps {
|
||||||
Chart.register(CategoryScale, LinearScale, PointElement, LineElement, Tooltip);
|
Chart.register(CategoryScale, LinearScale, PointElement, LineElement, Tooltip);
|
||||||
|
|
||||||
function RankChart(props: RankChartProps) {
|
function RankChart(props: RankChartProps) {
|
||||||
|
let delayed: boolean;
|
||||||
const options: ChartOptions<"line"> = {
|
const options: ChartOptions<"line"> = {
|
||||||
|
animation: {
|
||||||
|
onComplete: () => {
|
||||||
|
delayed = true;
|
||||||
|
},
|
||||||
|
delay: (context) => {
|
||||||
|
let delay = 0;
|
||||||
|
if (context.type === "data" && context.mode === "default" && !delayed) {
|
||||||
|
delay = context.dataIndex * 9;
|
||||||
|
}
|
||||||
|
return delay;
|
||||||
|
},
|
||||||
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
tooltip: {
|
tooltip: {
|
||||||
mode: "index",
|
mode: "index",
|
||||||
|
|
|
@ -520,22 +520,15 @@ const TwitchLogo = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const randomRankHistory = (currentRank: number): RankHistoryJSON => {
|
const randomRankHistory = (currentRank: number): RankHistoryJSON => {
|
||||||
// make a random rank array ranging 1 - 18, with a 75% chance to remain the same rank, end with current rank
|
// make a random rank array of size 31 ranging 1 - 18, with a 50% chance to remain the previous index's rank, end with current rank
|
||||||
const history: number[] = Array.from(
|
let prevRank = Math.floor(Math.random() * 18) + 1;
|
||||||
{ length: 31 },
|
const history: number[] = Array.from({ length: 31 }, (_, i) => {
|
||||||
() => Math.floor(Math.random() * 18) + 1
|
if (i === 30) return currentRank;
|
||||||
)
|
let chance = i === 0 ? 0 : Math.random();
|
||||||
.map((rank, i, arr) => {
|
prevRank = chance <= 0.5 ? prevRank : Math.floor(Math.random() * 18) + 1;
|
||||||
if (i === 29) return currentRank;
|
return prevRank;
|
||||||
if (Math.random() < 0.75) return arr[i - 1];
|
});
|
||||||
return rank;
|
|
||||||
// if rank same as previous, remove
|
|
||||||
})
|
|
||||||
.filter((rank, i, arr) => {
|
|
||||||
if (i === 0) return true;
|
|
||||||
return rank !== arr[i - 1];
|
|
||||||
});
|
|
||||||
history.push(currentRank);
|
|
||||||
return {
|
return {
|
||||||
rank: history,
|
rank: history,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue