Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/viewer/app/i18n/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ export const RU: Record<string, string> = {
'Fundamentals of {symbol}': 'Фундаментальные данные {symbol}',
'F': 'Ф',
'C': 'Г',
'Only this chart': 'Только этот график',
'Back to the charts before': 'Назад к прежним графикам',
View: 'Открыть',
ETF: 'ETF',
Stock: 'Акция',
Expand Down
5 changes: 4 additions & 1 deletion src/viewer/app/prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export interface Prefs {
// (app/tv-chart.ts); fundamentalsInterval (one) was kept before 2026-12-03 and is read once into the list
fundamentalsView: FundView;
fundamentalsIntervals: TvInterval[];
// the charts shown before ⤢ left one of them alone, for ⤡ (app/tv-chart.ts focusChart); [] none
fundamentalsBefore: TvInterval[];
// the share of each chart's width (on a phone height) per set of intervals shown, `D,M` (app/split.ts); none saved: equal
fundamentalsSplit: Record<string, number[]>;
// the corner of the 🔔 popups (app/notice-corner.ts)
Expand All @@ -75,7 +77,7 @@ export interface Prefs {
fundamentalsOpen: string;
}

export const DEFAULT_PREFS: Prefs = { scope: 'all', tab: 'summary', sort: { key: 'marketCap', dir: -1 }, search: '', filters: {}, types: {}, hidden: DEFAULT_HIDDEN.slice(), columnsV: 9, columns: [], period: '1Y', views: {}, moversBy: 'pct', moversOf: 'all', incomeOf: 'all', incomeSpans: INCOME_SPANS.slice(), dividendsOf: 'all', activityPeriod: 'All', dividendsSort: DEFAULT_DIV_SORTS.slice(), dividendsSize: 'payout', dividendsWindow: 'DTM', dividendsWhen: 'upcoming', dividendsPastWindow: 'MTD', accountSort: 'mine', accountOrder: [], groupOrder: [], collapsed: [], merge: false, reportOf: { watchlist: 'all', investments: 'all', dividends: 'all', drips: 'all' }, reportTax: { watchlist: 'all', investments: 'all', dividends: 'all', drips: 'all' }, report: 'watchlist', adpHidden: [], adpContribSpans: SPANS.slice(), adpIncomeSpans: SPANS.slice(), adpPeriod: '1Y', adpActivityPeriod: asActivityPeriod(undefined), fundamentalsView: 'page', fundamentalsIntervals: ['D'], fundamentalsSplit: {}, noticesAt: 'top-right', fundamentalsOpen: '' };
export const DEFAULT_PREFS: Prefs = { scope: 'all', tab: 'summary', sort: { key: 'marketCap', dir: -1 }, search: '', filters: {}, types: {}, hidden: DEFAULT_HIDDEN.slice(), columnsV: 9, columns: [], period: '1Y', views: {}, moversBy: 'pct', moversOf: 'all', incomeOf: 'all', incomeSpans: INCOME_SPANS.slice(), dividendsOf: 'all', activityPeriod: 'All', dividendsSort: DEFAULT_DIV_SORTS.slice(), dividendsSize: 'payout', dividendsWindow: 'DTM', dividendsWhen: 'upcoming', dividendsPastWindow: 'MTD', accountSort: 'mine', accountOrder: [], groupOrder: [], collapsed: [], merge: false, reportOf: { watchlist: 'all', investments: 'all', dividends: 'all', drips: 'all' }, reportTax: { watchlist: 'all', investments: 'all', dividends: 'all', drips: 'all' }, report: 'watchlist', adpHidden: [], adpContribSpans: SPANS.slice(), adpIncomeSpans: SPANS.slice(), adpPeriod: '1Y', adpActivityPeriod: asActivityPeriod(undefined), fundamentalsView: 'page', fundamentalsIntervals: ['D'], fundamentalsBefore: [], fundamentalsSplit: {}, noticesAt: 'top-right', fundamentalsOpen: '' };
const KEY = 'accounts.prefs';

export function loadPrefs(storage: Pick<Storage, 'getItem'> | undefined = globalThis.localStorage): Prefs {
Expand Down Expand Up @@ -125,6 +127,7 @@ export function loadPrefs(storage: Pick<Storage, 'getItem'> | undefined = global
sort: savedSort(p.sort, p.columnsV),
fundamentalsView: asFundView(p.fundamentalsView),
fundamentalsIntervals: asTvIntervals(p.fundamentalsIntervals, (p as { fundamentalsInterval?: unknown }).fundamentalsInterval),
fundamentalsBefore: Array.isArray(p.fundamentalsBefore) ? asTvIntervals(p.fundamentalsBefore) : [],
fundamentalsSplit: asSplits(p.fundamentalsSplit),
noticesAt: asNoticeCorner(p.noticesAt),
fundamentalsOpen: typeof p.fundamentalsOpen === 'string' ? p.fundamentalsOpen.slice(0, 24) : '',
Expand Down
15 changes: 14 additions & 1 deletion src/viewer/app/tv-chart.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="bun" />
/// <reference lib="esnext" />
import { expect, test } from 'bun:test';
import { asFundView, asTvIntervals, brandColor, candleColors, candleOverrides, tvChartUrl, tvConfig, tvSymbol } from './tv-chart';
import { asFundView, asTvIntervals, brandColor, focusChart, unfocusChart, candleColors, candleOverrides, tvChartUrl, tvConfig, tvSymbol } from './tv-chart';

test('a class share is written with a dot for TradingView', () => {
expect(tvSymbol('BRK-B')).toBe('BRK.B');
Expand Down Expand Up @@ -68,3 +68,16 @@ test('the accent is read from the page, Fidelity green when there is none', () =
const doc = { documentElement: {}, defaultView: { getComputedStyle: () => ({ getPropertyValue: () => ' #4f46e5 ' }) } } as unknown as Document;
expect(brandColor(doc)).toBe('#4f46e5');
});

test('⤢ shows one chart and remembers the others, ⤡ brings them back while it still fits', () => {
// three shown, Daily focused: Daily alone, the three kept in their order
const f = focusChart(['M', 'W', 'D'], 'D');
expect(f).toEqual({ intervals: ['D'], before: ['M', 'W', 'D'] });
expect(unfocusChart(f.intervals, f.before)).toEqual(['M', 'W', 'D']);
// a single chart focused: nothing to go back to
expect(focusChart(['W'], 'W')).toEqual({ intervals: ['W'], before: [] });
expect(unfocusChart(['W'], [])).toBeNull();
// the pills changed meanwhile: two shown now, or another single one that was not among them
expect(unfocusChart(['D', 'M'], ['M', 'W', 'D'])).toBeNull();
expect(unfocusChart(['W'], ['M', 'D'])).toBeNull();
});
13 changes: 13 additions & 0 deletions src/viewer/app/tv-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ export const asFundView = (v: unknown): FundView => (v === 'chart' ? 'chart' : '
export const asTvIntervals = (v: unknown, old?: unknown): TvInterval[] =>
Array.isArray(v) ? asPicked(v, TV_INTERVALS) : (TV_INTERVALS as readonly unknown[]).indexOf(old) >= 0 ? [old as TvInterval] : ['D'];

/**
* ⤢ on one chart of the window shows only that chart (owner 2026-12-03: "a zoom button for each chart ... if I clicked for
* right daily one" only Daily, its pill alone on): the intervals become that one, the charts shown before are kept to go
* back. ⤡ on the single chart brings them back while they still hold it; a choice made on the pills meanwhile wins
*/
export function focusChart(shown: readonly TvInterval[], iv: TvInterval): { intervals: TvInterval[]; before: TvInterval[] } {
return { intervals: [iv], before: shown.length > 1 ? shown.slice() : [] };
}
/** the charts ⤡ brings back, or null when there is nothing to go back to (one chart shown that was not focused from them) */
export function unfocusChart(shown: readonly TvInterval[], before: readonly TvInterval[]): TvInterval[] | null {
return shown.length === 1 && before.length > 1 && before.indexOf(shown[0]!) >= 0 ? before.slice() : null;
}

/** TradingView writes a class share with a dot (BRK.B); Fidelity has a slash, Stocks a dash */
export const tvSymbol = (ticker: string): string => ticker.trim().toUpperCase().replace(/[/-]/g, '.');

Expand Down
21 changes: 18 additions & 3 deletions src/viewer/ui/Fundamentals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { createStore } from '../../shared/store';
import { shownPicked } from '../app/multi';
import { asSplit, paneDir } from '../app/split';
import { CHART_HEAD_STEPS, chartHeadLook, fitStep } from '../app/head-fit';
import { FUND_VIEWS, TV_INTERVALS, tvChartUrl, type TvInterval } from '../app/tv-chart';
import { FUND_VIEWS, TV_INTERVALS, focusChart, tvChartUrl, unfocusChart, type TvInterval } from '../app/tv-chart';
import { MultiPills } from './MultiPills';
import { TipLink } from './TipLink';
import { useWidth } from './useWidth';
import { useWidths } from './useWidths';
import { Pills } from './Pills';
import { CORNER_BUTTON, ResetIcon } from './icons';
import { CORNER_BUTTON, ExpandIcon, ResetIcon, ShrinkIcon } from './icons';
import { SplitPanes } from './SplitPanes';
import { TvChart } from './TvChart';
import { useStore } from './useStore';
Expand All @@ -35,6 +35,9 @@ export function FundamentalsCell({ p, empty }: { p: Position; empty: React.React
/** a security with a Stocks ticker page (a stock), so a link can open its Fundamentals window */
export const hasFundamentals = (p: Position): boolean => !!fundamentalsFrame(p, false) && !!fundamentalsUrl(p);

// a chart's own ⤢ or ⤡: a small square over the top right corner of its price scale, on the chart's dark or light card
const PANE_BUTTON = 'absolute right-1 top-1 z-10 grid h-7 w-7 place-items-center rounded-md bg-white/80 text-slate-600 outline-none transition-colors hover:text-slate-900 keys-focus:text-[var(--brand)] dark:bg-slate-900/80 dark:text-slate-300 dark:hover:text-white';

// the words of the intervals, said in the app's language when drawn
const WORDS: Record<TvInterval, () => string> = { D: () => t('Daily'), W: () => t('Weekly'), M: () => t('Monthly') };

Expand Down Expand Up @@ -118,6 +121,9 @@ export function FundamentalsLink({ p, className, children }: { p: Position; clas
);
};
const step = fitStep(chartsWidth, headingWidth, looks);
// the charts ⤡ brings back on a single chart, if it came from several (app/tv-chart.ts unfocusChart)
const back = unfocusChart(shown, pr.fundamentalsBefore);
const focus = (iv: TvInterval): void => { const f = focusChart(shown, iv); setPrefs({ fundamentalsIntervals: f.intervals, fundamentalsBefore: f.before }); };
const tools = (
<>
{controls(step, true)}
Expand All @@ -135,7 +141,16 @@ export function FundamentalsLink({ p, className, children }: { p: Position; clas
// one chart per interval: side by side, or one under another when the window is too narrow for that
? <div ref={charts} className="h-[78vh] w-full" data-tv-charts={shown.join(' ')}>
<SplitPanes dir={paneDir(chartsWidth || 9999, shown.length)} sizes={sizes} onChange={saveSizes} label={t('Chart sizes')}>
{shown.map((iv) => <TvChart key={`${iv}-${drawn}`} ticker={ticker} interval={iv} dark={dark} language={language} className="h-full w-full overflow-hidden rounded-lg" />)}
{shown.map((iv) => (
// ⤢ in each chart's top right corner, over its price scale: only this chart (focusChart); on a single
// chart that came from several, ⤡ brings them back. The chart keeps its key, so its zoom stays
<div key={`${iv}-${drawn}`} className="relative h-full w-full" data-tv-pane={iv}>
<TvChart ticker={ticker} interval={iv} dark={dark} language={language} className="h-full w-full overflow-hidden rounded-lg" />
{shown.length > 1
? <button type="button" className={PANE_BUTTON} title={t('Only this chart')} aria-label={t('Only this chart')} onClick={() => focus(iv)} data-tv-focus={iv}><ExpandIcon /></button>
: back && <button type="button" className={PANE_BUTTON} title={t('Back to the charts before')} aria-label={t('Back to the charts before')} onClick={() => setPrefs({ fundamentalsIntervals: back, fundamentalsBefore: [] })} data-tv-unfocus><ShrinkIcon /></button>}
</div>
))}
</SplitPanes>
</div>
: <iframe ref={charts} src={frame} title={title} className="h-[78vh] w-full rounded-lg border-0 bg-white dark:bg-slate-950" data-fundamentals-frame />}
Expand Down
2 changes: 2 additions & 0 deletions src/viewer/ui/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const svg = (children: React.ReactNode) => (
);
export const ExpandIcon = () => svg(<><path d="M15 3h6v6" /><path d="M9 21H3v-6" /><path d="M21 3l-7 7" /><path d="M3 21l7-7" /></>);
/** back to the standard view: an arrow going round (the price charts drawn again as they open) */
// ⤡: the arrows of ExpandIcon turned inwards, back from one chart to the ones before
export const ShrinkIcon = () => svg(<><path d="M4 14h6v6" /><path d="M20 10h-6V4" /><path d="M14 10l7-7" /><path d="M3 21l7-7" /></>);
export const ResetIcon = () => svg(<><path d="M3 12a9 9 0 1 0 2.6-6.4L3 8" /><path d="M3 3v5h5" /></>);
export const CloseIcon = () => svg(<path d="M18 6 6 18M6 6l12 12" />);
/** settings sliders: a control that configures what a view shows (the positions columns) */
Expand Down