diff --git a/src/viewer/app/i18n/ru.ts b/src/viewer/app/i18n/ru.ts index 6d78c00..dd8c1d7 100644 --- a/src/viewer/app/i18n/ru.ts +++ b/src/viewer/app/i18n/ru.ts @@ -523,6 +523,8 @@ export const RU: Record = { 'Fundamentals of {symbol}': 'Фундаментальные данные {symbol}', 'F': 'Ф', 'C': 'Г', + 'Only this chart': 'Только этот график', + 'Back to the charts before': 'Назад к прежним графикам', View: 'Открыть', ETF: 'ETF', Stock: 'Акция', diff --git a/src/viewer/app/prefs.ts b/src/viewer/app/prefs.ts index 0ab2997..2bacaf8 100644 --- a/src/viewer/app/prefs.ts +++ b/src/viewer/app/prefs.ts @@ -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; // the corner of the 🔔 popups (app/notice-corner.ts) @@ -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 | undefined = globalThis.localStorage): Prefs { @@ -125,6 +127,7 @@ export function loadPrefs(storage: Pick | 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) : '', diff --git a/src/viewer/app/tv-chart.test.ts b/src/viewer/app/tv-chart.test.ts index 879226b..0cf58f0 100644 --- a/src/viewer/app/tv-chart.test.ts +++ b/src/viewer/app/tv-chart.test.ts @@ -1,7 +1,7 @@ /// /// 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'); @@ -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(); +}); diff --git a/src/viewer/app/tv-chart.ts b/src/viewer/app/tv-chart.ts index 45b84b8..f51ca07 100644 --- a/src/viewer/app/tv-chart.ts +++ b/src/viewer/app/tv-chart.ts @@ -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, '.'); diff --git a/src/viewer/ui/Fundamentals.tsx b/src/viewer/ui/Fundamentals.tsx index b800472..0165653 100644 --- a/src/viewer/ui/Fundamentals.tsx +++ b/src/viewer/ui/Fundamentals.tsx @@ -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'; @@ -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 string> = { D: () => t('Daily'), W: () => t('Weekly'), M: () => t('Monthly') }; @@ -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)} @@ -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 ?
- {shown.map((iv) => )} + {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 +
+ + {shown.length > 1 + ? + : back && } +
+ ))}
: