|
| 1 | +import { yTickCallbackShowMinAndMaxValues } from "./helpers"; |
| 2 | +import { alignedTooltip } from "./tooltip"; |
| 3 | + |
| 4 | +export const costPerProofCustomOptions = (options, data) => { |
| 5 | + // show only 0, min and max values |
| 6 | + options.scales.y.ticks.callback = yTickCallbackShowMinAndMaxValues( |
| 7 | + data, |
| 8 | + (val) => `${val} USD` |
| 9 | + ); |
| 10 | + |
| 11 | + // show age min, mean and max age in x axis |
| 12 | + options.scales.x.ticks.callback = (_value, index, values) => { |
| 13 | + const age = data.datasets[0].age; |
| 14 | + if (index === 0) return age[0]; |
| 15 | + if (index === Math.floor((age.length - 1) / 2)) |
| 16 | + return age[Math.floor((age.length - 1) / 2)]; |
| 17 | + if (index === values.length - 1) return age[age.length - 1]; |
| 18 | + return ""; |
| 19 | + }; |
| 20 | + |
| 21 | + options.plugins.tooltip.external = (context) => |
| 22 | + alignedTooltip(context, { |
| 23 | + name: "cost-per-proof", |
| 24 | + title: "Cost per proof", |
| 25 | + items: [ |
| 26 | + { title: "Fee per proof", id: "cost" }, |
| 27 | + { title: "Age", id: "age" }, |
| 28 | + { title: "Merkle root", id: "merkle_root" }, |
| 29 | + { title: "Block number", id: "block_number" }, |
| 30 | + { title: "Amount of proofs", id: "amount_of_proofs" }, |
| 31 | + ], |
| 32 | + onTooltipClick: (tooltipModel) => { |
| 33 | + const dataset = tooltipModel.dataPoints[0].dataset; |
| 34 | + const idx = tooltipModel.dataPoints[0].dataIndex; |
| 35 | + const merkleRootHash = dataset.merkle_root[idx]; |
| 36 | + window.location.href = `/batches/${merkleRootHash}`; |
| 37 | + }, |
| 38 | + onTooltipUpdate: (tooltipModel) => { |
| 39 | + const dataset = tooltipModel.dataPoints[0].dataset; |
| 40 | + const idx = tooltipModel.dataPoints[0].dataIndex; |
| 41 | + |
| 42 | + const cost = `${dataset.data[idx].y} USD`; |
| 43 | + const age = dataset.age[idx]; |
| 44 | + const merkleRootHash = dataset.merkle_root[idx]; |
| 45 | + const merkle_root = `${merkleRootHash.slice( |
| 46 | + 0, |
| 47 | + 6 |
| 48 | + )}...${merkleRootHash.slice(merkleRootHash.length - 4)}`; |
| 49 | + const block_number = dataset.data[idx].x; |
| 50 | + const amount_of_proofs = dataset.amount_of_proofs[idx]; |
| 51 | + |
| 52 | + return { |
| 53 | + cost, |
| 54 | + age, |
| 55 | + merkle_root, |
| 56 | + block_number, |
| 57 | + amount_of_proofs, |
| 58 | + }; |
| 59 | + }, |
| 60 | + }); |
| 61 | +}; |
0 commit comments