-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding simulator to playground (#1131)
* Adding simulator to playground * adding graphs and remaining fields * fixing charts bug * undoing changes * Remove unrelated files from pr * Remove unrelated files from pr #2 * using vue-chartjs instead of chartjs * Converting FarmingProfile class into a vue component * fixing line chart * Removing props from charts' divs --------- Co-authored-by: MohamedElmdary <[email protected]>
- Loading branch information
1 parent
74f83eb
commit 34fcc78
Showing
8 changed files
with
640 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<template> | ||
<ChLine :data="data" :options="options" /> | ||
</template> | ||
<script setup lang="ts"> | ||
import { Line } from "vue-chartjs"; | ||
ChartJS.register(...registerables); | ||
const props = defineProps<{ | ||
getTotalReward: (currentPrice: number) => number; | ||
getRoi: (price: number) => number; | ||
xs: number[]; | ||
isProfit: boolean; | ||
}>(); | ||
const X = (20 - 0.15) / 19; | ||
const xs = [...Array.from({ length: 20 }).map((_, i) => 0.15 + X * i)]; | ||
const data = computed(() => { | ||
if (props.isProfit) { | ||
return { | ||
labels: props.xs.map(i => i.toFixed(2)) || xs.map(i => i.toFixed(2)), | ||
datasets: [ | ||
{ | ||
label: "ROI", | ||
data: props.xs.map(x => props.getRoi(x) / 100), | ||
backgroundColor: "rgb(26, 161, 143)", | ||
borderColor: "rgba(26, 161, 143, 0.5)", | ||
pointRadius: 3, | ||
}, | ||
], | ||
}; | ||
} | ||
return { | ||
labels: props.xs.map(i => i.toFixed(2)) || xs.map(i => i.toFixed(2)), | ||
datasets: [ | ||
{ | ||
label: "Margin", | ||
data: props.xs.map(x => props.getTotalReward(x)) || xs.map(x => props.getTotalReward(x)), | ||
backgroundColor: "rgb(26, 161, 143)", | ||
borderColor: "rgba(26, 161, 143, 0.5)", | ||
pointRadius: 3, | ||
}, | ||
], | ||
}; | ||
}); | ||
const options = computed(() => { | ||
if (props.isProfit) { | ||
return { | ||
responsive: true, | ||
maintainAspectRatio: true, | ||
plugins: { | ||
title: { | ||
display: true, | ||
text: "Return (USD) / TFT price (USD)", | ||
}, | ||
}, | ||
}; | ||
} | ||
return { | ||
responsive: true, | ||
maintainAspectRatio: true, | ||
plugins: { | ||
title: { | ||
display: true, | ||
text: "Return (USD) / TFT price (USD)", | ||
}, | ||
}, | ||
}; | ||
}); | ||
</script> | ||
|
||
<script lang="ts"> | ||
import { Chart as ChartJS, registerables } from "chart.js"; | ||
import { computed } from "vue"; | ||
export default { | ||
name: "LineChart", | ||
components: { ChLine: Line }, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<template> | ||
<ChDoughnut :data="data" :options="options" /> | ||
</template> | ||
<script setup lang="ts"> | ||
ChartJS.register(...registerables); | ||
const props = defineProps<{ | ||
chartdata: any[]; | ||
}>(); | ||
const options = ref({ | ||
responsive: true, | ||
plugins: { | ||
legend: { | ||
position: "top", | ||
}, | ||
title: { | ||
position: "top", | ||
display: true, | ||
padding: 10, | ||
text: "Reward for CU, SU & NU", | ||
}, | ||
}, | ||
}); | ||
const data = computed(() => { | ||
console.log("props.chartdata", props.chartdata); | ||
return { | ||
labels: ["NU", "CU", "SU"], | ||
datasets: [ | ||
{ | ||
data: props.chartdata || [50, 100, 30], | ||
backgroundColor: ["rgb(255, 99, 132)", "rgb(54, 162, 235)", "rgb(255, 205, 86)"], | ||
hoverOffset: 4, | ||
}, | ||
], | ||
}; | ||
}); | ||
</script> | ||
|
||
<script lang="ts"> | ||
import { Chart as ChartJS, registerables } from "chart.js"; | ||
import { computed, ref } from "vue"; | ||
import { Doughnut } from "vue-chartjs"; | ||
export default { | ||
name: "PieChart", | ||
components: { ChDoughnut: Doughnut }, | ||
}; | ||
</script> |
Oops, something went wrong.