Skip to content

Commit

Permalink
improve time bucket selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
kenkunz committed Sep 13, 2023
1 parent 58225e5 commit 812369e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 66 deletions.
54 changes: 0 additions & 54 deletions src/lib/chart/TimeBucketSelector.svelte

This file was deleted.

1 change: 0 additions & 1 deletion src/lib/chart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ export { default as HudMetric } from './HudMetric.svelte';
export { default as Marker } from './Marker.svelte';
export { default as PairCandleChart } from './PairCandleChart.svelte';
export { default as ReserveInterestChart } from './ReserveInterestChart.svelte';
export { default as TimeBucketSelector } from './TimeBucketSelector.svelte';
2 changes: 1 addition & 1 deletion src/lib/components/SegmentedControl.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ button-like control with a segement for each possible value.
{#each options as option}
<label class:selected={option === selected}>
<span>{option}</span>
<input type="radio" bind:group={selected} value={option} />
<input type="radio" bind:group={selected} value={option} on:change />
</label>
{/each}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ for the same hovered date. Also displays a time-bucket selector.
-->
<script lang="ts">
import { page } from '$app/stores';
import { goto } from '$app/navigation';
import type { TimeBucket } from '$lib/chart';
import { type Candle, quoteFeed, candleToQuote } from '$lib/chart';
import { ChartLinker, HudRow, HudMetric, PairCandleChart, TimeBucketSelector } from '$lib/chart';
import { Alert } from '$lib/components';
import { ChartLinker, HudRow, HudMetric, PairCandleChart } from '$lib/chart';
import { Alert, SegmentedControl } from '$lib/components';
export let pairId: number | string;
export let pairSymbol: string;
Expand All @@ -39,7 +40,11 @@ for the same hovered date. Also displays a time-bucket selector.

<div class="chart-header">
<h2>{pairSymbol} charts</h2>
<TimeBucketSelector active={timeBucket} />
<SegmentedControl
options={['1m', '5m', '15m', '1h', '4h', '1d', '7d', '30d']}
selected={timeBucket}
on:change={({ target }) => goto(`#${target.value}`, { replaceState: true, noScroll: true })}
/>
</div>

<div class="chart-wrapper">
Expand Down Expand Up @@ -127,13 +132,11 @@ for the same hovered date. Also displays a time-bucket selector.
<style lang="postcss">
.chart-header {
display: flex;
gap: var(--space-md);
flex-wrap: wrap;
align-items: center;
gap: var(--space-sm) var(--space-lg);
margin-bottom: 1em;
@media (--viewport-md-down) {
flex-direction: column;
}
h2 {
flex: 1;
font: var(--f-h2-medium);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts">
import { page } from '$app/stores';
import { goto } from '$app/navigation';
import type { LendingReserve } from '$lib/explorer/lending-reserve-client';
import type { RateType } from '$lib/chart/ReserveInterestChart.svelte';
import { type TimeBucket, ReserveInterestChart } from '$lib/chart';
Expand Down Expand Up @@ -29,7 +31,7 @@
$: borrowable = isBorrowable(reserve);
$: showChart = borrowable && !isGhoToken;
let timeBucket: TimeBucket = '1d';
$: timeBucket = ($page.url.hash.slice(1) || '1d') as TimeBucket;
function getSecondaryRates({ additional_details: details }: LendingReserve) {
const rates: RateType[] = ['supply_apr'];
Expand Down Expand Up @@ -80,7 +82,11 @@
<Section padding="md">
<div class="chart-header">
<h3>Interest rates</h3>
<SegmentedControl options={['1h', '4h', '1d', '7d', '30d']} bind:selected={timeBucket} />
<SegmentedControl
options={['1h', '4h', '1d', '7d', '30d']}
selected={timeBucket}
on:change={({ target }) => goto(`#${target.value}`, { replaceState: true, noScroll: true })}
/>
</div>
<ReserveInterestChart
{reserve}
Expand Down

0 comments on commit 812369e

Please sign in to comment.