Skip to content

Commit

Permalink
Merge pull request #1322 from evidence-dev/fix-chart-loading
Browse files Browse the repository at this point in the history
Add SSR loading to all ECharts components
  • Loading branch information
archiewood authored Nov 30, 2023
2 parents ffa649e + c7af488 commit 969c8de
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-poems-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@evidence-dev/core-components': patch
---

Add SSR loading to all charts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<script context="module">
export const evidenceInclude = true;
</script>

<script>
import { fade } from 'svelte/transition';
Expand Down
11 changes: 2 additions & 9 deletions packages/core-components/src/lib/unsorted/viz/Chart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
</script>

<script>
import { browser } from '$app/environment';
import { writable } from 'svelte/store';
import { setContext } from 'svelte';
import { propKey, configKey, strictBuild } from './context';
Expand All @@ -14,7 +13,6 @@
$: setContext(configKey, config);
import ECharts from './ECharts.svelte';
import ChartLoading from '../ui/ChartLoading.svelte';
import getColumnSummary from '@evidence-dev/component-utilities/getColumnSummary';
import getDistinctValues from '@evidence-dev/component-utilities/getDistinctValues';
import getDistinctCount from '@evidence-dev/component-utilities/getDistinctCount';
Expand Down Expand Up @@ -1006,13 +1004,8 @@
</script>
{#if !error}
{#if !browser}
<slot />
<ChartLoading {height} />
{:else}
<slot />
<ECharts config={$config} {height} {width} {data} {showAllXAxisLabels} {swapXY} />
{/if}
<slot />
<ECharts config={$config} {height} {width} {data} {showAllXAxisLabels} {swapXY} />
{:else}
<ErrorChart {error} {chartType} />
{/if}
32 changes: 19 additions & 13 deletions packages/core-components/src/lib/unsorted/viz/ECharts.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
</script>

<script>
import { browser } from '$app/environment';
import echarts from '@evidence-dev/component-utilities/echarts';
import echartsCanvasDownload from '@evidence-dev/component-utilities/echartsCanvasDownload';
import EchartsCopyTarget from './EchartsCopyTarget.svelte';
import DownloadData from '../ui/DownloadData.svelte';
import ChartLoading from '../ui/ChartLoading.svelte';
import { flush } from 'svelte/internal';
import { createEventDispatcher } from 'svelte';
Expand Down Expand Up @@ -45,19 +47,23 @@
on:mouseleave={() => (hovering = false)}
>
{#if !printing}
<div
class="chart"
style="
height: {height};
width: {width};
margin-left: 0;
margin-top: 15px;
margin-bottom: 10px;
overflow: visible;
display: {copying ? 'none' : 'inherit'}
"
use:echarts={{ ...config, ...$$restProps, dispatch }}
/>
{#if !browser}
<ChartLoading {height} />
{:else}
<div
class="chart"
style="
height: {height};
width: {width};
margin-left: 0;
margin-top: 15px;
margin-bottom: 10px;
overflow: visible;
display: {copying ? 'none' : 'inherit'}
"
use:echarts={{ ...config, ...$$restProps, dispatch }}
/>
{/if}
{/if}

<EchartsCopyTarget {config} {height} {width} {copying} {printing} />
Expand Down
32 changes: 19 additions & 13 deletions packages/core-components/src/lib/unsorted/viz/EChartsMap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
</script>

<script>
import { browser } from '$app/environment';
import echartsMap from '@evidence-dev/component-utilities/echartsMap';
import echartsCanvasDownload from '@evidence-dev/component-utilities/echartsCanvasDownload';
import EchartsCopyTarget from './EchartsCopyTarget.svelte';
import DownloadData from '../ui/DownloadData.svelte';
import ChartLoading from '../ui/ChartLoading.svelte';
import { flush } from 'svelte/internal';
export let config = undefined;
Expand Down Expand Up @@ -44,19 +46,23 @@
on:mouseleave={() => (hovering = false)}
>
{#if !printing}
<div
class="chart"
style="
height: {height};
width: {width};
margin-left: 0;
margin-top: 15px;
margin-bottom: 10px;
overflow: visible;
display: {copying ? 'none' : 'inherit'}
"
use:echartsMap={{ config, hasLink }}
/>
{#if !browser}
<ChartLoading {height} />
{:else}
<div
class="chart"
style="
height: {height};
width: {width};
margin-left: 0;
margin-top: 15px;
margin-bottom: 10px;
overflow: visible;
display: {copying ? 'none' : 'inherit'}
"
use:echartsMap={{ config, hasLink }}
/>
{/if}
{/if}

<EchartsCopyTarget {config} {height} {width} {copying} {printing} />
Expand Down

0 comments on commit 969c8de

Please sign in to comment.