Skip to content

Commit 14e90c1

Browse files
committed
Add fill
1 parent da0fb2a commit 14e90c1

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

pages/tools/gachacalc.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
BarElement, CategoryScale, Chart as ChartJS, Legend, LinearScale, LineElement, PointElement, Tooltip
2+
BarElement, CategoryScale, Chart as ChartJS, Filler, Legend, LinearScale, LineElement, PointElement, Tooltip
33
} from "chart.js"
44
import Head from "next/head"
55
import { EffectCallback, useEffect, useState } from "react"
@@ -14,6 +14,7 @@ ChartJS.register(
1414
BarElement,
1515
PointElement,
1616
LineElement,
17+
Filler,
1718
Legend,
1819
Tooltip
1920
)
@@ -220,11 +221,15 @@ export default function GachaCalc({ location }: { location: string }) {
220221
<div className="w-full bg-slate-800 rounded-xl p-1 my-2 md:my-0 text-white col-start-2">
221222
<Line data={({
222223
labels: calculated.map((_, i) => i + pity),
223-
datasets: consts.filter(i => i >= 0).map(i => ({
224+
datasets: consts.filter(i => i >= 0).map((i, x) => ({
224225
label: getName(i, banner),
225-
backgroundColor: ["#c9c9c9", "#ff6363", "#ffd863", "#b1ff63", "#63ff8a", "#63ffff", "#638aff", "#b163ff", "#ff63d8"][i+1],
226-
borderColor: ["#c9c9c9", "#ff6363", "#ffd863", "#b1ff63", "#63ff8a", "#63ffff", "#638aff", "#b163ff", "#ff63d8"][i+1],
227-
fill: true,
226+
backgroundColor: getColor(i, 1),
227+
borderColor: getColor(i, 1),
228+
fill: {
229+
above: getColor(i, 0.15),
230+
below: getColor(i, 0.1),
231+
target: (i == banner.maxConst ? "start" : x + 1)
232+
},
228233
data: calculated.map((c) => (c?.filter(x => x.const >= i)?.reduce((p, c) => p + c.rate, 0) * 100)),
229234
borderWidth: 2,
230235
xAxisID: "xAxes"
@@ -273,6 +278,19 @@ export default function GachaCalc({ location }: { location: string }) {
273278
</Main>
274279
)
275280
}
281+
function getColor(i: number, alpha: number) {
282+
return [
283+
`rgba(201,201,201,${alpha})`,
284+
`rgba(255,99,99,${alpha})`,
285+
`rgba(255,216,99,${alpha})`,
286+
`rgba(177,255,99,${alpha})`,
287+
`rgba(99,255,138,${alpha})`,
288+
`rgba(99,255,255,${alpha})`,
289+
`rgba(99,138,255,${alpha})`,
290+
`rgba(177,99,255,${alpha})`,
291+
`rgba(255,99,216,${alpha})`
292+
][i + 1]
293+
}
276294

277295
function getName(c: number, banner: Banner) {
278296
return c == banner.minConst ? "Not owned" : `${banner.constFormat}${c}`

0 commit comments

Comments
 (0)