From 24696f8ef9b2dc3656e6caab0be79fbc9791b846 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Thu, 8 Aug 2024 11:15:42 +0200 Subject: [PATCH] improve plot replacing layercake to echarts back again --- src/routes/home/+page.svelte | 113 ++++++++++++++++++++++++++++------- 1 file changed, 91 insertions(+), 22 deletions(-) diff --git a/src/routes/home/+page.svelte b/src/routes/home/+page.svelte index 95d204c8..83a67ea8 100644 --- a/src/routes/home/+page.svelte +++ b/src/routes/home/+page.svelte @@ -13,11 +13,15 @@ import { numberOfUnreadNotification} from '$lib/store'; - import { LayerCake, Svg } from 'layercake'; - import { scaleBand } from 'd3-scale'; - import Bar from '$lib/components/LayerCake/Bar/Bar.svelte'; - import AxisY from '$lib/components/LayerCake/Bar/AxisY.svelte'; - import { goto } from '$app/navigation'; + import { Chart } from 'svelte-echarts' + import { init, use } from 'echarts/core' + import { BarChart } from 'echarts/charts' + import { GridComponent } from 'echarts/components' + import { CanvasRenderer } from 'echarts/renderers' + + // now with tree-shaking + use([BarChart, GridComponent, CanvasRenderer]) + export let data; let isLoaded = false; @@ -28,6 +32,68 @@ function reformatDate(dateString) { return dateString.substring(5, 7) + '/' + dateString.substring(8) + '/' + dateString.substring(2, 4); } + +const tickerGraphName = data?.getDashboard?.retailTracker?.map(item => item?.symbol) || []; +const tradedList = data?.getDashboard?.retailTracker?.map(item => item?.traded) || []; + +const optionsGraph = { + animation: false, + grid: { + left: '2%', + right: '3%', + bottom: '6%', + top: '0%', + containLabel: true + }, + xAxis: { + type: 'value', + splitLine: { + show: false, // Disable x-axis grid lines + }, + axisLabel: { + show: false // Hide x-axis labels + }, + axisTick: { + show: false // Hide x-axis ticks + }, + axisLine: { + show: false // Hide x-axis line + } + }, + yAxis: { + type: 'category', + data: tickerGraphName, + inverse: true, + axisTick: { + show: false // Hide x-axis ticks + }, + axisLabel: { + color: '#fff' // Set the y-axis label color to white + } + }, + series: [ + { + data: tradedList, + label: { + show: true, + position: 'inside', + formatter: function(params) { + return abbreviateNumber(params?.value,true); + }, + fontWeight: 600, + }, + type: 'bar', + showBackground: true, + backgroundStyle: { + color: 'rgba(180, 180, 180, 0.2)' + }, + itemStyle: { + color: 'white' // Bar color is white + } + } + ] +}; + function latestInfoDate(inputDate) { // Convert the input date string to milliseconds since epoch const inputDateMs = Date?.parse(inputDate); @@ -46,8 +112,6 @@ function latestInfoDate(inputDate) { } -const xKey = 'traded'; -const yKey = 'symbol'; let Feedback; @@ -260,21 +324,9 @@ onMount( async() => { {#if data?.getDashboard?.retailTracker?.length !== 0 && isLoaded} -
- - - - - - -
+
+ +
{:else}
@@ -383,6 +435,23 @@ onMount( async() => {