@v587d/capital-generation 2.26.0 → 2.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -139,13 +139,39 @@ const zh = {
139
139
  'desk.noMatchHint': '换个关键词,或切回「全部」分组。',
140
140
  'desk.selectHint': '选择一只标的查看详情',
141
141
  'desk.selectHintBody': '左侧列表按分组筛选;选中后这里显示报价、分时与成交量。',
142
- 'desk.intraday': '当日分时',
143
- 'desk.intradayEmpty': '当前行情接口只返回最新快照',
144
- 'desk.intradayEmptyHint': '接入分时序列后,这里直接绘制当日走势。',
145
- 'desk.volume': '成交量',
146
- 'desk.volumeEmpty': '暂无成交量数据',
147
- 'desk.capturedAt': '快照时间',
148
- 'desk.sourceTime': '交易所时间',
142
+ 'desk.intraday': '分时',
143
+ 'desk.trendLoading': '正在读取分时…',
144
+ 'desk.trendUnavailable': '该市场暂时没有分时数据',
145
+ 'desk.trendUnavailableHint': '场外美股与部分海外指数没有分时源,这里不画假走势。',
146
+ 'desk.trendError': '分时加载失败',
147
+ 'desk.trendRetry': '重试',
148
+ 'desk.daily': '日K',
149
+ 'desk.fold': '收起',
150
+ 'desk.unfold': '展开',
151
+ 'desk.adjustQfq': '前复权',
152
+ 'desk.klineLoading': '正在读取日K…',
153
+ 'desk.klineError': '日K暂时取不到',
154
+ 'desk.klineUnavailable': '该市场暂时没有日K数据',
155
+ 'desk.klineUnavailableHint': '港美股指数只有分时,没有可用的日线序列',
156
+ 'desk.kOpen': '开',
157
+ 'desk.kHigh': '高',
158
+ 'desk.kLow': '低',
159
+ 'desk.kClose': '收',
160
+ 'desk.trendLive': '盘中',
161
+ 'desk.trendClosed': '收盘',
162
+ 'desk.trendPrevious': '上一交易日',
163
+ 'desk.trendStale': '数据滞后',
164
+ 'desk.trendOpen': '今开',
165
+ 'desk.trendHigh': '最高',
166
+ 'desk.trendLow': '最低',
167
+ 'desk.trendAvg': '均价',
168
+ 'desk.trendVolume': '成交量',
169
+ 'desk.trendAmount': '成交额',
170
+ 'desk.lot': '手',
171
+ 'desk.share': '股',
172
+ 'desk.trendZoneUs': '美东',
173
+ 'desk.trendZoneHk': '香港',
174
+ 'desk.capturedAt': '行情时间',
149
175
  'desk.groupsOf': '所属分组',
150
176
  'desk.kind': '标的类型',
151
177
  'desk.colName': '名称',
@@ -261,12 +287,38 @@ const en = {
261
287
  'desk.selectHint': 'Select a symbol',
262
288
  'desk.selectHintBody': 'The left list filters by group; the quote, intraday and volume panels follow the selection.',
263
289
  'desk.intraday': 'Intraday',
264
- 'desk.intradayEmpty': 'The quote endpoint returns a snapshot only',
265
- 'desk.intradayEmptyHint': 'Once an intraday series is available, the same-session trend draws here.',
266
- 'desk.volume': 'Volume',
267
- 'desk.volumeEmpty': 'No volume data',
268
- 'desk.capturedAt': 'Captured',
269
- 'desk.sourceTime': 'Exchange time',
290
+ 'desk.trendLoading': 'Loading intraday…',
291
+ 'desk.trendUnavailable': 'No intraday series for this market',
292
+ 'desk.trendUnavailableHint': 'OTC US lines and some overseas indices have no intraday source; nothing is drawn to fill the gap.',
293
+ 'desk.trendError': 'Intraday failed to load',
294
+ 'desk.trendRetry': 'Retry',
295
+ 'desk.daily': 'Daily',
296
+ 'desk.fold': 'Collapse',
297
+ 'desk.unfold': 'Expand',
298
+ 'desk.adjustQfq': 'Forward-adjusted',
299
+ 'desk.klineLoading': 'Loading daily bars…',
300
+ 'desk.klineError': 'Daily bars are unavailable',
301
+ 'desk.klineUnavailable': 'No daily bars for this market',
302
+ 'desk.klineUnavailableHint': 'HK/US indices carry an intraday series only',
303
+ 'desk.kOpen': 'Open',
304
+ 'desk.kHigh': 'High',
305
+ 'desk.kLow': 'Low',
306
+ 'desk.kClose': 'Close',
307
+ 'desk.trendLive': 'Live',
308
+ 'desk.trendClosed': 'Closed',
309
+ 'desk.trendPrevious': 'Previous session',
310
+ 'desk.trendStale': 'Stale',
311
+ 'desk.trendOpen': 'Open',
312
+ 'desk.trendHigh': 'High',
313
+ 'desk.trendLow': 'Low',
314
+ 'desk.trendAvg': 'VWAP',
315
+ 'desk.trendVolume': 'Volume',
316
+ 'desk.trendAmount': 'Turnover',
317
+ 'desk.lot': 'lots',
318
+ 'desk.share': 'shares',
319
+ 'desk.trendZoneUs': 'ET',
320
+ 'desk.trendZoneHk': 'HK',
321
+ 'desk.capturedAt': 'As of',
270
322
  'desk.groupsOf': 'Groups',
271
323
  'desk.kind': 'Instrument',
272
324
  'desk.colName': 'Symbol',
@@ -471,8 +523,8 @@ const CSS = `
471
523
  /* Theme has no global border-box reset; the official item padding would overflow the list. */
472
524
  .capital-watchlist-rows button { box-sizing: border-box; }
473
525
  /* --- 行情工作台:左侧栏入口 + main 面板。卡片走发丝线,浮层交给官方 Menu。 --- */
474
- .cwd-page { height: 100%; min-height: 0; overflow-y: auto; --cwd-body-h: clamp(520px, 78vh, 860px); background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); --cwd-card: var(--dsw-alias-bg-layer-2, var(--dsw-alias-bg-layer-1)); --capital-watchlist-up: #d1493f; --capital-watchlist-down: #17a063; }
475
- .cwd-inner { max-width: 1180px; margin: 0 auto; padding: 28px 32px 44px; }
526
+ .cwd-page { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow-y: auto; background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); --cwd-card: var(--dsw-alias-bg-layer-2, var(--dsw-alias-bg-layer-1)); --capital-watchlist-up: #d1493f; --capital-watchlist-down: #17a063; }
527
+ .cwd-inner { display: flex; flex: 1; flex-direction: column; width: 100%; min-height: 0; max-width: 1180px; margin: 0 auto; padding: 24px 32px 32px; }
476
528
  .cwd-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
477
529
  .cwd-title { margin: 0; font-size: 26px; line-height: 32px; font-weight: 650; letter-spacing: -.2px; }
478
530
  .cwd-headactions { display: flex; align-items: center; gap: 14px; flex: none; }
@@ -480,7 +532,8 @@ const CSS = `
480
532
  .cwd-refresh { display: inline-flex; align-items: center; gap: 6px; flex: none; height: 34px; padding: 0 14px; border: .5px solid color-mix(in srgb, var(--dsw-alias-state-business-primary) 25%, transparent); border-radius: 10px; background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 12%, transparent); color: var(--dsw-alias-state-business-primary); font-family: inherit; font-size: 13px; line-height: 20px; font-weight: 500; cursor: pointer; }
481
533
  .cwd-refresh:hover:not(:disabled) { background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 20%, transparent); }
482
534
  .cwd-refresh:disabled { opacity: .45; cursor: not-allowed; }
483
- .cwd-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(430px, 1.35fr); gap: 22px; align-items: stretch; height: var(--cwd-body-h); }
535
+ .cwd-body { display: grid; flex: 1 1 auto; grid-template-columns: minmax(0, 1fr) minmax(430px, 1.35fr); grid-template-rows: minmax(0, 1fr); gap: 22px; align-items: stretch; min-height: 420px; max-height: 880px; }
536
+ /* ⛔ 行高必须钉死:隐式行按内容自适应时,右栏一旦长高就把行撑开,左列跟着 height:100% 一起变高(实测症状)。 */
484
537
  .cwd-card { display: flex; flex-direction: column; height: 100%; min-width: 0; min-height: 0; border: .5px solid var(--dsw-alias-border-l1); border-radius: 14px; background: var(--cwd-card); overflow: hidden; }
485
538
  .cwd-toolbar { display: flex; flex: none; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 14px; border-bottom: .5px solid var(--dsw-alias-border-l2); }
486
539
  .cwd-field { display: flex; align-items: center; gap: 6px; flex: 1 1 170px; min-width: 0; height: 34px; padding: 0 10px; border-radius: 10px; background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-tertiary); }
@@ -515,7 +568,7 @@ const CSS = `
515
568
  .cwd-iconbtn { flex: none; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: var(--dsw-radius-sm); background: transparent; color: var(--dsw-alias-label-secondary); cursor: pointer; }
516
569
  .cwd-iconbtn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover-accent); color: var(--dsw-alias-label-primary); }
517
570
  .cwd-iconbtn:disabled { opacity: .45; cursor: not-allowed; }
518
- .cwd-detail { display: flex; flex: 1; flex-direction: column; gap: 14px; min-height: 0; padding: 16px; overflow-y: auto; }
571
+ .cwd-detail { display: flex; flex: 1; flex-direction: column; gap: 12px; min-height: 0; padding: 16px; overflow-y: auto; }
519
572
  .cwd-detailhead { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; min-width: 0; }
520
573
  .cwd-detailname { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 16px; line-height: 22px; font-weight: 600; }
521
574
  .cwd-detailtext { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
@@ -523,19 +576,59 @@ const CSS = `
523
576
  .cwd-bigquote { display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px; }
524
577
  .cwd-bigprice { font-size: 34px; line-height: 40px; font-weight: 650; font-variant-numeric: tabular-nums; }
525
578
  .cwd-bigpct { font-size: 14px; line-height: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
526
- .cwd-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
527
- .cwd-metaitem { min-width: 0; }
528
- .cwd-metalabel { font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
529
- .cwd-metavalue { font-size: 12.5px; line-height: 18px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
579
+ .cwd-quoterow { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; }
580
+ .cwd-meta { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 20px; padding-bottom: 4px; }
581
+ .cwd-metaitem { display: flex; align-items: baseline; gap: 6px; }
582
+ .cwd-metalabel { flex: none; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
583
+ .cwd-metavalue { font-size: 12px; line-height: 16px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
530
584
  .cwd-block { flex: none; padding-top: 12px; border-top: .5px solid var(--dsw-alias-border-l2); }
531
- .cwd-block-chart { flex: 1; display: flex; flex-direction: column; min-height: 0; }
532
- .cwd-blockhead { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
533
- .cwd-blocktitle { font-size: 12.5px; line-height: 18px; font-weight: 600; }
534
- .cwd-blocknote { font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
585
+ .cwd-block-chart { flex: 1 1 0; display: flex; flex-direction: column; min-height: 200px; }
586
+ /* Folded block keeps only its title row, so it stops competing for height. */
587
+ .cwd-block-chart.cwd-folded { flex: none; min-height: 0; }
588
+ .cwd-blockhead { display: flex; flex: none; align-items: baseline; gap: 12px; margin-bottom: 8px; }
589
+ .cwd-blocktitle { flex: none; font-size: 12.5px; line-height: 18px; font-weight: 600; }
590
+ .cwd-blocknote { margin-left: auto; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
591
+ .cwd-blockfold { flex: none; padding: 0 2px; border: 0; background: none; font-family: inherit; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); cursor: pointer; }
592
+ .cwd-blockfold:hover { color: var(--dsw-alias-label-primary); }
535
593
  .cwd-chart { flex: 1; min-height: 150px; display: grid; place-items: center; padding: 12px; border: 1px dashed var(--dsw-alias-border-l2); border-radius: 10px; background: repeating-linear-gradient(180deg, color-mix(in srgb, var(--dsw-alias-border-l2) 60%, transparent) 0 1px, transparent 1px 36px), var(--dsw-alias-bg-module-platform); text-align: center; }
536
594
  .cwd-charttext { font-size: 12.5px; line-height: 18px; font-weight: 500; color: var(--dsw-alias-label-secondary); }
537
595
  .cwd-charthint { margin-top: 4px; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
538
- .cwd-volume { height: 92px; display: grid; place-items: center; border: 1px dashed var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-module-platform); border-radius: 10px; font-size: 12px; color: var(--dsw-alias-label-tertiary); }
596
+ .cwd-trendstats { display: flex; flex: 1 1 auto; flex-wrap: wrap; gap: 2px 14px; min-width: 0; }
597
+ .cwd-trendstat { display: flex; align-items: baseline; gap: 5px; font-size: 11px; line-height: 17px; }
598
+ .cwd-trendstat span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
599
+ .cwd-trendstat span:first-child { flex: none; color: var(--dsw-alias-label-tertiary); }
600
+ .cwd-trendstat span:last-child { font-variant-numeric: tabular-nums; }
601
+ .cwd-chartbox { position: relative; flex: 1; min-height: 120px; min-width: 0; overflow: hidden; border-radius: 10px; background: var(--dsw-alias-bg-module-platform); }
602
+ /* The daily pane shares the SVG contract above (absolute child, determinate height): a flexed chart
603
+ next to a scrolled column is exactly how the container used to grow. */
604
+ .cwd-block-kline { flex: 1 1 0; display: flex; flex-direction: column; min-height: 220px; }
605
+ .cwd-klinebox { position: relative; flex: 1; min-height: 140px; min-width: 0; overflow: hidden; border-radius: 10px; background: var(--dsw-alias-bg-module-platform); }
606
+ .cwd-malegend { display: flex; flex: 1 1 auto; flex-wrap: wrap; gap: 2px 12px; min-width: 0; font-size: 11px; line-height: 16px; font-variant-numeric: tabular-nums; }
607
+ .cwd-candle-up { fill: var(--capital-watchlist-up); stroke: var(--capital-watchlist-up); stroke-width: 1; }
608
+ .cwd-candle-down { fill: var(--capital-watchlist-down); stroke: var(--capital-watchlist-down); stroke-width: 1; }
609
+ .cwd-maline { fill: none; stroke-width: 1.1; stroke-linejoin: round; }
610
+ .cwd-ma5 { color: var(--dsw-alias-label-primary); stroke: var(--dsw-alias-label-primary); }
611
+ .cwd-ma10 { color: var(--dsw-alias-state-warn-primary); stroke: var(--dsw-alias-state-warn-primary); }
612
+ .cwd-ma20 { color: var(--dsw-alias-brand-primary); stroke: var(--dsw-alias-brand-primary); }
613
+ .cwd-ma60 { color: var(--dsw-alias-label-tertiary); stroke: var(--dsw-alias-label-tertiary); }
614
+ /* ⛔ 绝对定位不是为了叠层:SVG 一旦参与流式布局,viewBox 的宽高比会反推父盒高度,
615
+ 量测回写就把容器越撑越大(实测逐帧增长)。它必须永远影响不了自己的容器。 */
616
+ .cwd-chartsvg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: pan-y; }
617
+ .cwd-chartaxis { fill: var(--dsw-alias-label-tertiary); font-size: 10.5px; font-variant-numeric: tabular-nums; }
618
+ .cwd-chartbaselabel { fill: var(--dsw-alias-label-secondary); }
619
+ .cwd-chartgrid { stroke: color-mix(in srgb, var(--dsw-alias-border-l2) 55%, transparent); stroke-width: 1; shape-rendering: crispEdges; }
620
+ .cwd-chartsep { stroke: var(--dsw-alias-border-l2); stroke-width: 1; stroke-dasharray: 2 3; }
621
+ .cwd-chartline { fill: none; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
622
+ .cwd-chartavg { fill: none; stroke: var(--dsw-alias-state-business-primary); stroke-width: 1; stroke-dasharray: 3 3; opacity: .85; }
623
+ .cwd-chartbase { stroke: var(--dsw-alias-label-tertiary); stroke-width: 1; opacity: .7; }
624
+ .cwd-chartcross { stroke: var(--dsw-alias-label-tertiary); stroke-width: 1; stroke-dasharray: 3 3; opacity: .8; }
625
+ .cwd-chartdot { fill: currentColor; }
626
+ .cwd-vol-up { fill: var(--capital-watchlist-up); opacity: .55; }
627
+ .cwd-vol-down { fill: var(--capital-watchlist-down); opacity: .55; }
628
+ .cwd-charttip { position: absolute; top: 8px; min-width: 150px; padding: 7px 9px; border-radius: 8px; border: .5px solid var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-2, var(--dsw-alias-bg-layer-1)); pointer-events: none; }
629
+ .cwd-charttiptime { font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
630
+ .cwd-charttipprice { font-size: 13px; line-height: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
631
+ .cwd-charttiprow { display: flex; justify-content: space-between; gap: 10px; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }
539
632
  .cwd-empty { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 34px 18px; text-align: center; }
540
633
  .cwd-emptytitle { font-size: 14px; line-height: 20px; font-weight: 600; }
541
634
  .cwd-emptyhint { margin: 6px 0 0; font-size: 12.5px; line-height: 19px; color: var(--dsw-alias-label-tertiary); }
@@ -548,7 +641,7 @@ const CSS = `
548
641
  .cwd-field:focus-within { outline: var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); outline-offset: 1px; }
549
642
  .cwd-page button:focus-visible, .cwd-groupcreate input:focus-visible { outline: var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); outline-offset: 1px; }
550
643
  .cwd-skeleton { display: block; height: 12px; border-radius: 6px; background: var(--dsw-alias-bg-skeleton); }
551
- @media (max-width: 1040px) { .cwd-body { grid-template-columns: minmax(0, 1fr); gap: 16px; height: auto; } .cwd-card { height: auto; } .cwd-tablebody { flex: none; max-height: 60vh; } .cwd-chart { flex: none; height: 200px; } }
644
+ @media (max-width: 1040px) { .cwd-body { flex: none; grid-template-columns: minmax(0, 1fr); gap: 16px; height: auto; max-height: none; } .cwd-card { height: auto; } .cwd-tablebody { flex: none; max-height: 60vh; } .cwd-chart { flex: none; height: 200px; } .cwd-chartbox { flex: none; height: 260px; } .cwd-klinebox { flex: none; height: 260px; } .cwd-block-chart, .cwd-block-kline { flex: none; } }
552
645
  @media (max-width: 720px) { .cwd-inner { padding: 20px 16px 32px; } .cwd-thead, .cwd-row { grid-template-columns: minmax(0, 1.5fr) 78px 72px 36px; gap: 8px; } .cwd-thead { padding: 8px 10px; } .cwd-row { padding: 9px 10px; } }
553
646
  `
554
647
 
@@ -1403,6 +1496,9 @@ function WatchlistDialog({ useDialog, surface, t, inputActions }) {
1403
1496
  const DESK_PANEL_ID = `${ENTRY_NAME}:desk`
1404
1497
  const DESK_GROUPS_KEY = 'capital.watchlist.desk.groups.v1'
1405
1498
  const DESK_ALL = '__all__'
1499
+ /** Monotonic request id for the desk's series: a late answer must not overwrite a newer selection. */
1500
+ let deskTrendSequence = 0
1501
+ let deskKlineSequence = 0
1406
1502
 
1407
1503
  function readDeskGroups() {
1408
1504
  const empty = { names: [], assignments: {} }
@@ -1440,6 +1536,424 @@ const deskPctText = (value) => (value === null ? '—' : `${value > 0 ? '+' : ''
1440
1536
  /** Comma grouping is the market convention here, so it does not follow the UI locale. */
1441
1537
  const deskPriceFormat = new Intl.NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
1442
1538
  const deskPriceText = (quote) => (quote !== null && quote !== undefined && typeof quote.price === 'number' && Number.isFinite(quote.price) ? deskPriceFormat.format(quote.price) : '—')
1539
+ /** Any number → grouped text; every price on the desk keeps two decimals, indices included. */
1540
+ const deskNumberText = (value) => (typeof value === 'number' && Number.isFinite(value) ? deskPriceFormat.format(value) : '—')
1541
+
1542
+ /** 万 / 亿 scaling for totals; the suffix stays Chinese in both locales, like the market comma. */
1543
+ function deskScaledText(value, digits = 2) {
1544
+ if (typeof value !== 'number' || !Number.isFinite(value)) return '—'
1545
+ const size = Math.abs(value)
1546
+ if (size >= 1e8) return `${(value / 1e8).toFixed(digits)}亿`
1547
+ if (size >= 1e4) return `${(value / 1e4).toFixed(digits)}万`
1548
+ return new Intl.NumberFormat('en-US', { maximumFractionDigits: digits }).format(value)
1549
+ }
1550
+
1551
+ const deskMinutesOf = (time) => (typeof time === 'string' && time.length >= 5 ? Number(time.slice(0, 2)) * 60 + Number(time.slice(3, 5)) : 0)
1552
+
1553
+ function deskVolumeText(value, unit, t) {
1554
+ const text = deskScaledText(value)
1555
+ if (text === '—') return text
1556
+ if (unit === 'lot') return `${text}${t('desk.lot')}`
1557
+ if (unit === 'share') return `${text}${t('desk.share')}`
1558
+ return text
1559
+ }
1560
+
1561
+ function deskAmountText(value, currency) {
1562
+ const text = deskScaledText(value)
1563
+ if (text === '—') return text
1564
+ return currency === null || currency === undefined || currency === 'CNY' ? text : `${text} ${currency}`
1565
+ }
1566
+
1567
+ /**
1568
+ * The x axis is the trading clock, not the point count: a 09:32 print must stay near the left edge
1569
+ * instead of stretching over the whole pane (that is what turns four points into four fat bars).
1570
+ * The lunch break takes no width, so a slot is one trading minute and `total` is the day's length.
1571
+ */
1572
+ const TREND_SESSIONS = {
1573
+ 'a-share': [[570, 690], [780, 900]],
1574
+ hk: [[570, 720], [780, 960]],
1575
+ us: [[570, 960]],
1576
+ }
1577
+
1578
+ const deskClockText = (minutes) => `${String(Math.floor(minutes / 60)).padStart(2, '0')}:${String(minutes % 60).padStart(2, '0')}`
1579
+
1580
+ function deskSessionOf(market) {
1581
+ const spans = []
1582
+ let total = 0
1583
+ for (const [open, close] of TREND_SESSIONS[market] ?? TREND_SESSIONS.us) {
1584
+ spans.push([open, close, total])
1585
+ total += close - open
1586
+ }
1587
+ return { spans, total }
1588
+ }
1589
+
1590
+ /** Minute of day → compressed slot; a print outside the session (the HK closing auction) lands on the edge. */
1591
+ function deskSlotOf(session, minutes) {
1592
+ for (const [open, close, base] of session.spans) {
1593
+ if (minutes <= open) return base
1594
+ if (minutes < close) return base + minutes - open
1595
+ }
1596
+ return session.total
1597
+ }
1598
+
1599
+ /** Half-hour grid; a tick landing on the previous tick's slot (11:30 and 13:00 share one) is dropped. */
1600
+ function deskTicksOf(session) {
1601
+ const ticks = []
1602
+ for (const [open, close, base] of session.spans) {
1603
+ for (let minutes = open; minutes <= close; minutes += 30) {
1604
+ const slot = base + minutes - open
1605
+ if (ticks.length === 0 || ticks[ticks.length - 1].slot !== slot) ticks.push({ time: deskClockText(minutes), slot })
1606
+ }
1607
+ }
1608
+ return ticks
1609
+ }
1610
+
1611
+ /**
1612
+ * Same-session trend drawn in plain SVG: price line + area, previous-close baseline, VWAP line,
1613
+ * volume histogram and a pointer crosshair. Geometry is computed in pixels (the box is measured),
1614
+ * so labels and dashes stay crisp at any width; nothing here fetches or invents a point.
1615
+ */
1616
+ function IntradayChart({ data, t }) {
1617
+ const [box, setBox] = useState({ width: 720, height: 300 })
1618
+ const [cursor, setCursor] = useState(null)
1619
+ const host = useRef(null)
1620
+
1621
+ useEffect(() => {
1622
+ const element = host.current
1623
+ if (element === null || element === undefined) return undefined
1624
+ // Integer `clientWidth` rounding plus a content-sized box is exactly how a chart grows by a
1625
+ // pixel per frame; measure the fractional rect and ignore sub-2px jitter. Returning the same
1626
+ // object makes React bail out, so a wobbling layout can never re-enter this loop.
1627
+ const measure = () => {
1628
+ const rect = element.getBoundingClientRect()
1629
+ if (!(rect.width > 0) || !(rect.height > 0)) return
1630
+ const width = Math.max(280, Math.round(rect.width))
1631
+ const height = Math.max(180, Math.round(rect.height))
1632
+ setBox((current) => (Math.abs(current.width - width) < 2 && Math.abs(current.height - height) < 2 ? current : { width, height }))
1633
+ }
1634
+ measure()
1635
+ if (typeof ResizeObserver === 'undefined') return undefined
1636
+ const observer = new ResizeObserver(measure)
1637
+ observer.observe(element)
1638
+ return () => observer.disconnect()
1639
+ }, [])
1640
+
1641
+ const points = data.points
1642
+ const prevClose = data.prev_close
1643
+ const width = box.width
1644
+ const height = box.height
1645
+ // Gutters fit `24,547.66` on the left and `+10.00%` on the right at 10.5px without clipping.
1646
+ const left = 66
1647
+ const right = 54
1648
+ const top = 12
1649
+ const axisHeight = 18
1650
+ const volumeHeight = Math.round(Math.min(70, Math.max(30, height * 0.22)))
1651
+ // Reserve the bottom axis band: the volume pane must stop above the tick labels, not under them.
1652
+ const priceHeight = Math.max(60, height - top - axisHeight - volumeHeight - 10)
1653
+ const plotWidth = Math.max(60, width - left - right)
1654
+ const session = deskSessionOf(data.market)
1655
+ const slotWidth = plotWidth / session.total
1656
+
1657
+ const values = points.map((point) => point[1])
1658
+ const floorValue = Math.min(prevClose, ...values)
1659
+ const peakValue = Math.max(prevClose, ...values)
1660
+ const margin = (peakValue - floorValue) * 0.06 || Math.max(peakValue * 0.002, 0.01)
1661
+ const low = floorValue - margin
1662
+ const high = peakValue + margin
1663
+ const scaleY = (value) => top + ((high - value) / (high - low)) * priceHeight
1664
+ const slots = points.map((point) => deskSlotOf(session, deskMinutesOf(point[0])))
1665
+ const scaleX = (slot) => left + slot * slotWidth
1666
+ const firstX = scaleX(slots[0]).toFixed(1)
1667
+ const lastX = scaleX(slots[points.length - 1]).toFixed(1)
1668
+
1669
+ const tone = data.last === null || data.last >= prevClose ? 'up' : 'down'
1670
+ const stroke = tone === 'up' ? 'var(--capital-watchlist-up)' : 'var(--capital-watchlist-down)'
1671
+ const pricePath = points.map((point, index) => `${index === 0 ? 'M' : 'L'}${scaleX(slots[index]).toFixed(1)} ${scaleY(point[1]).toFixed(1)}`).join('')
1672
+ const bottom = (top + priceHeight).toFixed(1)
1673
+ const areaPath = `${pricePath}L${lastX} ${bottom}L${firstX} ${bottom}Z`
1674
+ const averagePath = points.reduce((path, point, index) => (point[2] === null ? path : `${path}${path === '' ? 'M' : 'L'}${scaleX(slots[index]).toFixed(1)} ${scaleY(point[2]).toFixed(1)}`), '')
1675
+
1676
+ const volumeTop = top + priceHeight + 10
1677
+ const maxVolume = Math.max(1, ...points.map((point) => point[3] ?? 0))
1678
+ // One bar per trading minute: thin by construction, never sized by how many points happened to arrive.
1679
+ const barWidth = Math.max(1, Math.min(10, slotWidth * 0.72))
1680
+ const baseY = scaleY(prevClose)
1681
+ const gridLines = [0, 1, 2, 3, 4].map((step) => {
1682
+ const value = low + ((high - low) * step) / 4
1683
+ return { value, y: scaleY(value), pct: ((value - prevClose) / prevClose) * 100 }
1684
+ }).filter((line) => Math.abs(line.y - baseY) > 9)
1685
+
1686
+ const sessionBreak = session.spans.length > 1 ? session.spans[1][2] : null
1687
+ const allTicks = deskTicksOf(session)
1688
+ const tickStep = width >= 620 ? 1 : 2
1689
+ const ticks = allTicks.filter((tick, order) => order % tickStep === 0 || order === allTicks.length - 1)
1690
+
1691
+ const focus = cursor === null || cursor < 0 || cursor >= points.length ? null : points[cursor]
1692
+ const focusX = focus === null ? 0 : scaleX(slots[cursor])
1693
+ const focusY = focus === null ? 0 : scaleY(focus[1])
1694
+ const tipLeft = Math.min(width - 172, Math.max(8, focusX + 12))
1695
+ const summary = `${data.thscode} ${data.session_date ?? ''} ${t('desk.intraday')} · ${t('desk.trendOpen')} ${deskNumberText(data.open)} · ${t('desk.trendHigh')} ${deskNumberText(data.high)} · ${t('desk.trendLow')} ${deskNumberText(data.low)} · ${t('desk.trendAvg')} ${deskNumberText(data.avg)}`
1696
+
1697
+ const onMove = (event) => {
1698
+ const rect = event.currentTarget.getBoundingClientRect()
1699
+ if (!(rect.width > 0)) return
1700
+ const slot = Math.max(0, Math.min(session.total, ((event.clientX - rect.left - left) / plotWidth) * session.total))
1701
+ let nearest = 0
1702
+ for (let index = 1; index < slots.length; index += 1) {
1703
+ if (Math.abs(slots[index] - slot) < Math.abs(slots[nearest] - slot)) nearest = index
1704
+ }
1705
+ setCursor(nearest)
1706
+ }
1707
+
1708
+ return h('div', { className: 'cwd-chartbox', ref: host },
1709
+ h('svg', {
1710
+ className: 'cwd-chartsvg',
1711
+ viewBox: `0 0 ${width} ${height}`,
1712
+ role: 'img',
1713
+ 'aria-label': summary,
1714
+ onPointerMove: onMove,
1715
+ onPointerLeave: () => setCursor(null),
1716
+ },
1717
+ h('defs', null,
1718
+ h('linearGradient', { id: 'cwd-trend-fill', x1: '0', y1: '0', x2: '0', y2: '1' },
1719
+ h('stop', { offset: '0%', style: { stopColor: stroke, stopOpacity: 0.2 } }),
1720
+ h('stop', { offset: '100%', style: { stopColor: stroke, stopOpacity: 0 } }))),
1721
+ gridLines.map((line) => h('g', { key: `grid-${line.value.toFixed(4)}` },
1722
+ h('line', { className: 'cwd-chartgrid', x1: left, x2: left + plotWidth, y1: line.y, y2: line.y }),
1723
+ h('text', { className: 'cwd-chartaxis', x: left - 8, y: line.y + 3.5, textAnchor: 'end' }, deskNumberText(line.value)),
1724
+ h('text', { className: 'cwd-chartaxis', x: left + plotWidth + 8, y: line.y + 3.5 }, `${line.pct > 0 ? '+' : ''}${line.pct.toFixed(2)}%`))),
1725
+ ticks.map((tick) => h('line', {
1726
+ key: `grid-${tick.time}`,
1727
+ className: 'cwd-chartgrid',
1728
+ x1: scaleX(tick.slot),
1729
+ x2: scaleX(tick.slot),
1730
+ y1: top,
1731
+ y2: volumeTop + volumeHeight,
1732
+ })),
1733
+ sessionBreak === null ? null : h('line', {
1734
+ className: 'cwd-chartsep',
1735
+ x1: scaleX(sessionBreak),
1736
+ x2: scaleX(sessionBreak),
1737
+ y1: top,
1738
+ y2: volumeTop + volumeHeight,
1739
+ }),
1740
+ h('path', { className: 'cwd-chartarea', d: areaPath, fill: 'url(#cwd-trend-fill)' }),
1741
+ points.map((point, index) => {
1742
+ const value = point[3] ?? 0
1743
+ const barHeight = Math.max(0, (value / maxVolume) * volumeHeight)
1744
+ const previous = index === 0 ? prevClose : points[index - 1][1]
1745
+ const center = scaleX(slots[index] + 0.5)
1746
+ return h('rect', {
1747
+ key: `vol-${index}`,
1748
+ className: point[1] >= previous ? 'cwd-vol-up' : 'cwd-vol-down',
1749
+ x: (Math.min(left + plotWidth - barWidth, Math.max(left, center - barWidth / 2))).toFixed(1),
1750
+ y: (volumeTop + volumeHeight - barHeight).toFixed(1),
1751
+ width: barWidth.toFixed(1),
1752
+ height: Math.max(0.5, barHeight).toFixed(1),
1753
+ })
1754
+ }),
1755
+ h('path', { className: 'cwd-chartline', d: pricePath, style: { stroke } }),
1756
+ averagePath === '' ? null : h('path', { className: 'cwd-chartavg', d: averagePath }),
1757
+ h('line', { className: 'cwd-chartbase', x1: left, x2: left + plotWidth, y1: baseY, y2: baseY, strokeDasharray: '4 3' }),
1758
+ h('text', { className: 'cwd-chartaxis cwd-chartbaselabel', x: left - 8, y: baseY + 3.5, textAnchor: 'end' }, deskNumberText(prevClose)),
1759
+ ticks.map((tick) => h('text', {
1760
+ key: `tick-${tick.time}`,
1761
+ className: 'cwd-chartaxis',
1762
+ x: scaleX(tick.slot),
1763
+ y: height - 5,
1764
+ textAnchor: tick.slot === 0 ? 'start' : tick.slot >= session.total ? 'end' : 'middle',
1765
+ }, tick.time)),
1766
+ focus === null ? null : h('g', null,
1767
+ h('line', { className: 'cwd-chartcross', x1: focusX, x2: focusX, y1: top, y2: volumeTop + volumeHeight }),
1768
+ h('line', { className: 'cwd-chartcross', x1: left, x2: left + plotWidth, y1: focusY, y2: focusY }),
1769
+ h('circle', { className: `cwd-chartdot ${tone === 'up' ? 'cwd-up' : 'cwd-down'}`, cx: focusX, cy: focusY, r: 3 })),
1770
+ ),
1771
+ focus === null ? null : h('div', { className: 'cwd-charttip', style: { left: `${tipLeft}px` } },
1772
+ h('div', { className: 'cwd-charttiptime' }, focus[0]),
1773
+ h('div', { className: `cwd-charttipprice ${tone === 'up' ? 'cwd-up' : 'cwd-down'}` },
1774
+ `${deskNumberText(focus[1])} ${deskPctText(((focus[1] - prevClose) / prevClose) * 100)}`),
1775
+ focus[2] === null ? null : h('div', { className: 'cwd-charttiprow' }, h('span', null, t('desk.trendAvg')), h('span', null, deskNumberText(focus[2]))),
1776
+ focus[3] === null ? null : h('div', { className: 'cwd-charttiprow' }, h('span', null, t('desk.trendVolume')), h('span', null, deskVolumeText(focus[3], data.volume_unit, t)))))
1777
+ }
1778
+
1779
+ /** Moving averages over a close series; the leading `window-1` slots stay null so a line never starts at the first bar. */
1780
+ function movingAverage(bars, window) {
1781
+ const values = new Array(bars.length).fill(null)
1782
+ let sum = 0
1783
+ for (let index = 0; index < bars.length; index += 1) {
1784
+ sum += bars[index].close
1785
+ if (index >= window) sum -= bars[index - window].close
1786
+ if (index >= window - 1) values[index] = sum / window
1787
+ }
1788
+ return values
1789
+ }
1790
+
1791
+ /** Four lines is what a 700px pane can keep apart; MA30 would sit on top of MA20 most of the time. */
1792
+ const MA_WINDOWS = [5, 10, 20, 60]
1793
+
1794
+ /**
1795
+ * Daily candles for the desk. Same pixel geometry and the same measured box as the intraday pane
1796
+ * (absolute SVG, 2px deadband, no intrinsic sizing), so the two charts stay aligned and neither can
1797
+ * push its container. Candles are red on up and green on down, the A-share convention used above.
1798
+ */
1799
+ function DailyChart({ data, t }) {
1800
+ const [box, setBox] = useState({ width: 720, height: 300 })
1801
+ const [cursor, setCursor] = useState(null)
1802
+ const host = useRef(null)
1803
+
1804
+ useEffect(() => {
1805
+ const element = host.current
1806
+ if (element === null || element === undefined) return undefined
1807
+ const measure = () => {
1808
+ const rect = element.getBoundingClientRect()
1809
+ if (!(rect.width > 0) || !(rect.height > 0)) return
1810
+ const width = Math.max(280, Math.round(rect.width))
1811
+ const height = Math.max(180, Math.round(rect.height))
1812
+ setBox((current) => (Math.abs(current.width - width) < 2 && Math.abs(current.height - height) < 2 ? current : { width, height }))
1813
+ }
1814
+ measure()
1815
+ if (typeof ResizeObserver === 'undefined') return undefined
1816
+ const observer = new ResizeObserver(measure)
1817
+ observer.observe(element)
1818
+ return () => observer.disconnect()
1819
+ }, [])
1820
+
1821
+ const bars = data.bars
1822
+ const width = box.width
1823
+ const height = box.height
1824
+ const left = 66
1825
+ const right = 54
1826
+ const top = 10
1827
+ const axisHeight = 18
1828
+ const volumeHeight = Math.round(Math.min(64, Math.max(28, height * 0.2)))
1829
+ const priceHeight = Math.max(60, height - top - axisHeight - volumeHeight - 12)
1830
+ const plotWidth = Math.max(60, width - left - right)
1831
+ const slot = plotWidth / Math.max(1, bars.length)
1832
+ // Candles keep a gap so a dense series still reads as separate days instead of a solid block.
1833
+ const barWidth = Math.max(1, Math.min(14, slot * 0.62))
1834
+
1835
+ const highest = Math.max(...bars.map((bar) => bar.high))
1836
+ const lowest = Math.min(...bars.map((bar) => bar.low))
1837
+ const margin = (highest - lowest) * 0.06 || Math.max(highest * 0.01, 0.01)
1838
+ const high = highest + margin
1839
+ const low = lowest - margin
1840
+ const scaleY = (value) => top + ((high - value) / (high - low)) * priceHeight
1841
+ const scaleX = (index) => left + (index + 0.5) * slot
1842
+
1843
+ const volumeTop = top + priceHeight + 12
1844
+ const maxVolume = Math.max(1, ...bars.map((bar) => bar.volume))
1845
+ const scaleVolume = (value) => (value / maxVolume) * volumeHeight
1846
+
1847
+ const maSeries = MA_WINDOWS.map((window) => ({ window, values: movingAverage(bars, window) }))
1848
+ const lineOf = (values) => values.reduce((path, value, index) => (value === null ? path : `${path}${path === '' ? 'M' : 'L'}${scaleX(index).toFixed(1)} ${scaleY(value).toFixed(1)}`), '')
1849
+
1850
+ // Month boundaries only: twelve labels over 120 bars would collide, and every broker labels months.
1851
+ const monthTicks = []
1852
+ for (let index = 0; index < bars.length; index += 1) {
1853
+ const month = bars[index].date.slice(5, 7)
1854
+ if (index === 0 || month !== bars[index - 1].date.slice(5, 7)) monthTicks.push({ index, month })
1855
+ }
1856
+ // The year-prefixed first label is twice as wide as the others, so it only earns its place when the
1857
+ // next month boundary is far enough away — a partial first month (five bars of May) collides with it.
1858
+ const firstGapPx = monthTicks.length > 1 ? (monthTicks[1].index - monthTicks[0].index) * slot : Number.POSITIVE_INFINITY
1859
+ const ticks = monthTicks.map((tick, order) => ({
1860
+ index: tick.index,
1861
+ label: order === 0 && firstGapPx >= 56 ? `${bars[tick.index].date.slice(0, 4)}/${tick.month}` : tick.month,
1862
+ }))
1863
+
1864
+ const gridLines = [0, 1, 2, 3, 4].map((step) => {
1865
+ const value = high - ((high - low) * step) / 4
1866
+ return { value, y: scaleY(value) }
1867
+ })
1868
+
1869
+ const focus = cursor === null || cursor < 0 || cursor >= bars.length ? null : bars[cursor]
1870
+ const focusX = focus === null ? 0 : scaleX(cursor)
1871
+ const focusY = focus === null ? 0 : scaleY(focus.close)
1872
+ const focusPrev = cursor === null || cursor <= 0 ? null : bars[cursor - 1].close
1873
+ const focusPct = focus === null || focusPrev === null || focusPrev <= 0 ? null : ((focus.close - focusPrev) / focusPrev) * 100
1874
+ const tipLeft = Math.min(width - 186, Math.max(8, focusX + 12))
1875
+ const summary = `${data.thscode} ${t('desk.daily')} · ${bars.length} · ${deskNumberText(bars[bars.length - 1].close)}`
1876
+
1877
+ const onMove = (event) => {
1878
+ const rect = event.currentTarget.getBoundingClientRect()
1879
+ if (!(rect.width > 0)) return
1880
+ const index = Math.round((event.clientX - rect.left - left) / slot - 0.5)
1881
+ setCursor(Math.max(0, Math.min(bars.length - 1, index)))
1882
+ }
1883
+
1884
+ return h('div', { className: 'cwd-klinebox', ref: host },
1885
+ h('svg', {
1886
+ className: 'cwd-chartsvg',
1887
+ viewBox: `0 0 ${width} ${height}`,
1888
+ role: 'img',
1889
+ 'aria-label': summary,
1890
+ onPointerMove: onMove,
1891
+ onPointerLeave: () => setCursor(null),
1892
+ },
1893
+ gridLines.map((line) => h('g', { key: `grid-${line.value.toFixed(4)}` },
1894
+ h('line', { className: 'cwd-chartgrid', x1: left, x2: left + plotWidth, y1: line.y, y2: line.y }),
1895
+ h('text', { className: 'cwd-chartaxis', x: left - 8, y: line.y + 3.5, textAnchor: 'end' }, deskNumberText(line.value)))),
1896
+ ticks.map((tick) => h('g', { key: `tick-${tick.index}` },
1897
+ h('line', { className: 'cwd-chartgrid', x1: scaleX(tick.index), x2: scaleX(tick.index), y1: top, y2: volumeTop + volumeHeight }),
1898
+ h('text', {
1899
+ className: 'cwd-chartaxis',
1900
+ x: scaleX(tick.index),
1901
+ y: height - 5,
1902
+ textAnchor: tick.index === 0 ? 'start' : 'middle',
1903
+ }, tick.label))),
1904
+ // Volume first: candles read on top of the histogram, never the other way round.
1905
+ bars.map((bar, index) => {
1906
+ const barHeight = Math.max(0.5, scaleVolume(bar.volume))
1907
+ return h('rect', {
1908
+ key: `vol-${bar.date}`,
1909
+ className: bar.close >= bar.open ? 'cwd-vol-up' : 'cwd-vol-down',
1910
+ x: (scaleX(index) - barWidth / 2).toFixed(1),
1911
+ y: (volumeTop + volumeHeight - barHeight).toFixed(1),
1912
+ width: barWidth.toFixed(1),
1913
+ height: barHeight.toFixed(1),
1914
+ })
1915
+ }),
1916
+ h('text', { className: 'cwd-chartaxis', x: left - 8, y: volumeTop + 8, textAnchor: 'end' }, deskScaledText(maxVolume)),
1917
+ bars.map((bar, index) => {
1918
+ const open = scaleY(bar.open)
1919
+ const close = scaleY(bar.close)
1920
+ const bodyTop = Math.min(open, close)
1921
+ const bodyHeight = Math.max(0.8, Math.abs(close - open))
1922
+ return h('g', { key: `bar-${bar.date}`, className: bar.close >= bar.open ? 'cwd-candle-up' : 'cwd-candle-down' },
1923
+ h('line', {
1924
+ x1: scaleX(index).toFixed(1),
1925
+ x2: scaleX(index).toFixed(1),
1926
+ y1: scaleY(bar.high).toFixed(1),
1927
+ y2: scaleY(bar.low).toFixed(1),
1928
+ }),
1929
+ h('rect', {
1930
+ x: (scaleX(index) - barWidth / 2).toFixed(1),
1931
+ y: bodyTop.toFixed(1),
1932
+ width: barWidth.toFixed(1),
1933
+ height: bodyHeight.toFixed(1),
1934
+ }))
1935
+ }),
1936
+ maSeries.map((series) => {
1937
+ const path = lineOf(series.values)
1938
+ return path === '' ? null : h('path', { key: `ma-${series.window}`, className: `cwd-maline cwd-ma${series.window}`, d: path })
1939
+ }),
1940
+ focus === null ? null : h('g', null,
1941
+ h('line', { className: 'cwd-chartcross', x1: focusX, x2: focusX, y1: top, y2: volumeTop + volumeHeight }),
1942
+ h('line', { className: 'cwd-chartcross', x1: left, x2: left + plotWidth, y1: focusY, y2: focusY })),
1943
+ ),
1944
+ focus === null ? null : h('div', { className: 'cwd-charttip', style: { left: `${tipLeft}px` } },
1945
+ h('div', { className: 'cwd-charttiptime' }, focus.date),
1946
+ h('div', { className: `cwd-charttipprice ${deskToneOf(focusPct)}` },
1947
+ `${deskNumberText(focus.close)} ${deskPctText(focusPct)}`),
1948
+ h('div', { className: 'cwd-charttiprow' },
1949
+ h('span', null, t('desk.kOpen')), h('span', null, deskNumberText(focus.open)),
1950
+ h('span', null, t('desk.kHigh')), h('span', null, deskNumberText(focus.high))),
1951
+ h('div', { className: 'cwd-charttiprow' },
1952
+ h('span', null, t('desk.kLow')), h('span', null, deskNumberText(focus.low)),
1953
+ h('span', null, t('desk.kClose')), h('span', null, deskNumberText(focus.close))),
1954
+ h('div', { className: 'cwd-charttiprow' },
1955
+ h('span', null, t('desk.trendVolume')), h('span', null, deskVolumeText(focus.volume, data.volume_unit, t)))))
1956
+ }
1443
1957
 
1444
1958
  /** Sidebar glyph: an axis plus a rising line reads as quotes without inventing a wallet/pie shape. */
1445
1959
  function WatchlistDeskIcon({ size = 18 }) {
@@ -1475,6 +1989,10 @@ function WatchlistDeskPage({ t }) {
1475
1989
  const [selected, setSelected] = useState(null)
1476
1990
  const [pendingRemove, setPendingRemove] = useState(null)
1477
1991
  const [rowMenu, setRowMenu] = useState(null)
1992
+ const [trend, setTrend] = useState({ status: 'idle', data: null, code: null })
1993
+ const [kline, setKline] = useState({ status: 'idle', data: null, code: null })
1994
+ // Folded = the intraday pane keeps only its title row, so the daily pane gets the whole column.
1995
+ const [trendFolded, setTrendFolded] = useState(false)
1478
1996
  const alive = useRef(true)
1479
1997
 
1480
1998
  useEffect(() => {
@@ -1496,6 +2014,56 @@ function WatchlistDeskPage({ t }) {
1496
2014
  setError(payload.error !== undefined && payload.error !== null && typeof payload.error.code === 'string' ? payload.error.code : null)
1497
2015
  }
1498
2016
 
2017
+ /**
2018
+ * The series follows the selection: one request per click (the host caches it for a minute),
2019
+ * no polling and no prefetch. A stale answer is dropped by sequence, not merged.
2020
+ */
2021
+ const loadTrend = async (thscode, options = {}) => {
2022
+ if (typeof thscode !== 'string' || thscode.length === 0) {
2023
+ setTrend({ status: 'idle', data: null, code: null })
2024
+ setKline({ status: 'idle', data: null, code: null })
2025
+ return
2026
+ }
2027
+ const request = (deskTrendSequence += 1)
2028
+ setTrend((previous) => ({ status: 'loading', data: previous.data !== null && previous.data.thscode === thscode ? previous.data : null, code: null }))
2029
+ try {
2030
+ const query = `thscode=${encodeURIComponent(thscode)}${options.bust === true ? '&refresh=1' : ''}`
2031
+ const payload = await call('/trend', { query })
2032
+ if (!alive.current || request !== deskTrendSequence) return
2033
+ setTrend({ status: 'ready', data: payload, code: null })
2034
+ } catch (failure) {
2035
+ if (!alive.current || request !== deskTrendSequence) return
2036
+ const code = typeof failure?.code === 'string' ? failure.code : 'trend_unavailable'
2037
+ setTrend({ status: code === 'trend_unavailable' ? 'unavailable' : 'error', data: null, code })
2038
+ }
2039
+ }
2040
+
2041
+ /** Same shape as `loadTrend`: the daily pane has its own request, so one slow history never blocks a tick. */
2042
+ const loadKline = async (thscode, options = {}) => {
2043
+ if (typeof thscode !== 'string' || thscode.length === 0) {
2044
+ setKline({ status: 'idle', data: null, code: null })
2045
+ return
2046
+ }
2047
+ const request = (deskKlineSequence += 1)
2048
+ setKline((previous) => ({ status: 'loading', data: previous.data !== null && previous.data.thscode === thscode ? previous.data : null, code: null }))
2049
+ try {
2050
+ const query = `thscode=${encodeURIComponent(thscode)}${options.bust === true ? '&refresh=1' : ''}`
2051
+ const payload = await call('/kline', { query })
2052
+ if (!alive.current || request !== deskKlineSequence) return
2053
+ setKline({ status: 'ready', data: payload, code: null })
2054
+ } catch (failure) {
2055
+ if (!alive.current || request !== deskKlineSequence) return
2056
+ const code = typeof failure?.code === 'string' ? failure.code : 'kline_unavailable'
2057
+ setKline({ status: code === 'kline_unavailable' ? 'unavailable' : 'error', data: null, code })
2058
+ }
2059
+ }
2060
+
2061
+ const selectRow = (thscode) => {
2062
+ setSelected(thscode)
2063
+ void loadTrend(thscode)
2064
+ void loadKline(thscode)
2065
+ }
2066
+
1499
2067
  // Opening the panel is the user request: read the list, then quote it once. No polling.
1500
2068
  useEffect(() => {
1501
2069
  let cancelled = false
@@ -1506,7 +2074,12 @@ function WatchlistDeskPage({ t }) {
1506
2074
  const landed = cleanRows(listed.items) ?? []
1507
2075
  setItems(landed)
1508
2076
  // The detail panel is the main area: start on the first symbol instead of an empty aside.
1509
- setSelected((value) => (value !== null ? value : (typeof landed[0]?.thscode === 'string' ? landed[0].thscode : null)))
2077
+ const first = typeof landed[0]?.thscode === 'string' ? landed[0].thscode : null
2078
+ setSelected((value) => (value !== null ? value : first))
2079
+ if (first !== null) {
2080
+ void loadTrend(first)
2081
+ void loadKline(first)
2082
+ }
1510
2083
  } catch (failure) {
1511
2084
  if (!cancelled) setError(failure.code ?? 'load_failed')
1512
2085
  return
@@ -1530,6 +2103,10 @@ function WatchlistDeskPage({ t }) {
1530
2103
  try {
1531
2104
  const payload = await call('/refresh', { body: {} })
1532
2105
  if (alive.current) applyRefresh(payload)
2106
+ if (alive.current && selected !== null) {
2107
+ void loadTrend(selected, { bust: true })
2108
+ void loadKline(selected, { bust: true })
2109
+ }
1533
2110
  } catch (failure) {
1534
2111
  if (alive.current) setError(failure.code ?? 'fuyao_unavailable')
1535
2112
  } finally {
@@ -1541,7 +2118,10 @@ function WatchlistDeskPage({ t }) {
1541
2118
  const before = items
1542
2119
  setPendingRemove(null)
1543
2120
  setItems(before.filter((row) => row.thscode !== thscode))
1544
- if (selected === thscode) setSelected(null)
2121
+ if (selected === thscode) {
2122
+ setSelected(null)
2123
+ setTrend({ status: 'idle', data: null, code: null })
2124
+ }
1545
2125
  try {
1546
2126
  await call('/remove', { body: { thscode } })
1547
2127
  } catch {
@@ -1603,8 +2183,17 @@ function WatchlistDeskPage({ t }) {
1603
2183
  const groupMenuItems = [{ id: DESK_ALL, label: t('desk.allGroups'), icon: activeGroup === DESK_ALL ? h(IconChecklistOutlineRegular, { size: 14 }) : undefined }]
1604
2184
  .concat(groups.names.map((name) => ({ id: name, label: name, icon: activeGroup === name ? h(IconChecklistOutlineRegular, { size: 14 }) : undefined })))
1605
2185
 
2186
+ // The row you are looking at is the freshest thing in the panel: once its intraday payload lands,
2187
+ // the list shows that price too, so one instrument never carries two numbers on the same screen.
2188
+ const liveQuote = (item) => {
2189
+ if (trend.status !== 'ready' || trend.data === null || trend.data.thscode !== item.thscode || typeof trend.data.last !== 'number') return item.quote
2190
+ const prevClose = trend.data.prev_close
2191
+ return { price: trend.data.last, change_pct: prevClose > 0 ? ((trend.data.last - prevClose) / prevClose) * 100 : null }
2192
+ }
2193
+
1606
2194
  const rows = visible.map((item, index) => {
1607
- const pct = deskPctOf(item.quote)
2195
+ const quote = liveQuote(item)
2196
+ const pct = deskPctOf(quote)
1608
2197
  const failure = failures[item.thscode]
1609
2198
  const names = deskGroupsOf(groups, item.thscode)
1610
2199
  const isSelected = selected === item.thscode
@@ -1615,19 +2204,19 @@ function WatchlistDeskPage({ t }) {
1615
2204
  className: 'cwd-row',
1616
2205
  role: 'listitem',
1617
2206
  'aria-current': isSelected ? 'true' : undefined,
1618
- onClick: (event) => { if (event.target.closest('.cwd-rowactions') === null) setSelected(item.thscode) },
2207
+ onClick: (event) => { if (event.target.closest('.cwd-rowactions') === null) selectRow(item.thscode) },
1619
2208
  },
1620
2209
  h('button', {
1621
2210
  type: 'button',
1622
2211
  className: 'cwd-cellname',
1623
2212
  'aria-pressed': isSelected,
1624
- onClick: () => setSelected(item.thscode),
2213
+ onClick: () => selectRow(item.thscode),
1625
2214
  },
1626
2215
  h('span', { className: 'cwd-nameline' },
1627
2216
  h('span', { className: 'cwd-nametext', title: item.name }, scrubInvisible(item.name)),
1628
2217
  h(TypeTag, { assetType: item.asset_type, t })),
1629
2218
  h('span', { className: 'cwd-codeline' }, h('span', { className: 'cwd-code' }, item.thscode))),
1630
- h('div', { className: failure === undefined ? 'cwd-price' : 'cwd-price cwd-stale', title: quoteTitle }, deskPriceText(item.quote)),
2219
+ h('div', { className: failure === undefined ? 'cwd-price' : 'cwd-price cwd-stale', title: quoteTitle }, deskPriceText(quote)),
1631
2220
  h('div', { className: `cwd-pct ${deskToneOf(pct)}`, title: quoteTitle }, deskPctText(pct)),
1632
2221
  // One trigger per row: pin, group checkboxes and remove live in the official Menu.
1633
2222
  h('div', { className: 'cwd-rowactions' },
@@ -1680,8 +2269,78 @@ function WatchlistDeskPage({ t }) {
1680
2269
  ? h('div', { className: 'cwd-empty' }, h('div', { className: 'cwd-emptytitle' }, t('desk.noMatch')), h('p', { className: 'cwd-emptyhint' }, t('desk.noMatchHint')))
1681
2270
  : h('div', { className: 'cwd-tablebody', role: 'list', 'aria-label': t('desk.title') }, rows)
1682
2271
 
1683
- const detailNames = current === null ? [] : deskGroupsOf(groups, current.thscode)
1684
- const detailPct = current === null ? null : deskPctOf(current.quote)
2272
+
2273
+ // The block note states the session fact (live / closed / previous) and the clock the axis uses.
2274
+ const trendData = trend.status === 'ready' ? trend.data : null
2275
+ // The chart is fetched later than the list, so for the selected row it is the fresher vintage:
2276
+ // the headline price, its percentage and the as-of stamp all come from the same series as the
2277
+ // pane below, instead of ageing by every minute the panel sits idle.
2278
+ const trendOwns = trendData !== null && current !== null && trendData.thscode === current.thscode && typeof trendData.last === 'number'
2279
+ const detailQuote = current === null ? null : liveQuote(current)
2280
+ const detailPct = deskPctOf(detailQuote)
2281
+ const detailPrint = trendOwns ? trendData.points[trendData.points.length - 1][0] : null
2282
+ // One clock on the panel: when the number above was printed. The zone suffix only appears when
2283
+ // that clock is not the reader's own (the US session runs on ET); A-share and HK print on it.
2284
+ const printZone = trendOwns && trendData.market === 'us' ? ` ${t('desk.trendZoneUs')}` : ''
2285
+ const detailAt = trendOwns
2286
+ ? `${String(trendData.session_date ?? '').slice(5)} ${detailPrint}${printZone}`.trim()
2287
+ : current === null || current.quote === null || current.quote === undefined ? t('desk.notRefreshed') : (formatTime(current.quote.captured_at) || t('desk.notRefreshed'))
2288
+ const trendZone = trendData === null || trendData.market === 'a-share' ? '' : ` ${t(trendData.market === 'us' ? 'desk.trendZoneUs' : 'desk.trendZoneHk')}`
2289
+ const trendNote = trendData === null
2290
+ ? (trend.status === 'loading' ? t('desk.trendLoading') : trend.status === 'error' ? t('desk.trendError') : '')
2291
+ : trendData.session_status === 'live'
2292
+ ? `${trendData.stale ? t('desk.trendStale') : t('desk.trendLive')}${trendZone} · ${trendData.points[trendData.points.length - 1][0]}`
2293
+ : trendData.session_status === 'closed'
2294
+ ? `${trendData.session_date ?? ''} ${t('desk.trendClosed')}${trendZone}`
2295
+ : `${t('desk.trendPrevious')} ${trendData.session_date ?? ''}${trendZone}`
2296
+
2297
+ const trendStats = trendData === null ? null : h('div', { className: 'cwd-trendstats' },
2298
+ ...[
2299
+ [t('desk.trendOpen'), deskNumberText(trendData.open)],
2300
+ [t('desk.trendHigh'), deskNumberText(trendData.high)],
2301
+ [t('desk.trendLow'), deskNumberText(trendData.low)],
2302
+ [t('desk.trendAvg'), deskNumberText(trendData.avg)],
2303
+ [t('desk.trendVolume'), deskVolumeText(trendData.volume, trendData.volume_unit, t)],
2304
+ [t('desk.trendAmount'), deskAmountText(trendData.amount, trendData.currency)],
2305
+ ].map(([label, value]) => h('div', { key: label, className: 'cwd-trendstat' },
2306
+ h('span', null, label), h('span', { title: value }, value))))
2307
+
2308
+ const trendBody = trendData !== null
2309
+ ? h(IntradayChart, { key: trendData.thscode, data: trendData, t })
2310
+ : h('div', { className: 'cwd-chart' }, h('div', null,
2311
+ h('div', { className: 'cwd-charttext' }, trend.status === 'error' ? t('desk.trendError') : trend.status === 'loading' ? t('desk.trendLoading') : t('desk.trendUnavailable')),
2312
+ trend.status === 'unavailable'
2313
+ ? h('div', { className: 'cwd-charthint' }, t('desk.trendUnavailableHint'))
2314
+ : null,
2315
+ trend.status === 'error'
2316
+ ? h('button', { type: 'button', className: 'cwd-pill', onClick: () => { void loadTrend(selected, { bust: true }) } }, t('desk.trendRetry'))
2317
+ : null))
2318
+ const klineData = kline.status === 'ready' && Array.isArray(kline.data?.bars) && kline.data.bars.length > 0 ? kline.data : null
2319
+ const klineNote = klineData === null
2320
+ ? (kline.status === 'loading' ? t('desk.klineLoading') : kline.status === 'error' ? t('desk.klineError') : '')
2321
+ : t('desk.adjustQfq')
2322
+ // The legend reads the same series the paths draw, so the numbers and the lines cannot disagree.
2323
+ const klineLegend = klineData === null ? null : h('div', { className: 'cwd-malegend' },
2324
+ ...MA_WINDOWS.map((window) => {
2325
+ const values = movingAverage(klineData.bars, window)
2326
+ const last = values[values.length - 1]
2327
+ return h('span', { key: window, className: `cwd-malegenditem cwd-ma${window}` }, `MA${window} ${last === null || last === undefined ? '—' : deskNumberText(last)}`)
2328
+ }))
2329
+ const klineBody = klineData !== null
2330
+ ? h(DailyChart, { key: klineData.thscode, data: klineData, t })
2331
+ : h('div', { className: 'cwd-chart' }, h('div', null,
2332
+ h('div', { className: 'cwd-charttext' }, kline.status === 'error' ? t('desk.klineError') : kline.status === 'loading' ? t('desk.klineLoading') : t('desk.klineUnavailable')),
2333
+ kline.status === 'unavailable' ? h('div', { className: 'cwd-charthint' }, t('desk.klineUnavailableHint')) : null,
2334
+ kline.status === 'error'
2335
+ ? h('button', { type: 'button', className: 'cwd-pill', onClick: () => { void loadKline(selected, { bust: true }) } }, t('desk.trendRetry'))
2336
+ : null))
2337
+ const klineBlock = h('div', { className: 'cwd-block cwd-block-kline' },
2338
+ h('div', { className: 'cwd-blockhead' },
2339
+ h('span', { className: 'cwd-blocktitle' }, t('desk.daily')),
2340
+ klineLegend,
2341
+ h('span', { className: 'cwd-blocknote' }, klineNote)),
2342
+ klineBody)
2343
+
1685
2344
  const detail = current === null
1686
2345
  ? h('div', { className: 'cwd-card' }, h('div', { className: 'cwd-empty' },
1687
2346
  h('div', { className: 'cwd-emptytitle' }, t('desk.selectHint')),
@@ -1693,25 +2352,30 @@ function WatchlistDeskPage({ t }) {
1693
2352
  h('span', { className: 'cwd-detailtext', title: current.name }, scrubInvisible(current.name)),
1694
2353
  h(TypeTag, { assetType: current.asset_type, t })),
1695
2354
  h('div', { className: 'cwd-detailcode' }, current.thscode))),
1696
- h('div', { className: 'cwd-bigquote' },
1697
- h('span', { className: 'cwd-bigprice' }, deskPriceText(current.quote)),
1698
- h('span', { className: `cwd-bigpct ${deskToneOf(detailPct)}` }, deskPctText(detailPct))),
1699
- h('div', { className: 'cwd-meta' },
1700
- h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.capturedAt')), h('div', { className: 'cwd-metavalue' }, current.quote === null || current.quote === undefined ? t('desk.notRefreshed') : (formatTime(current.quote.captured_at) || t('desk.notRefreshed')))),
1701
- h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.sourceTime')), h('div', { className: 'cwd-metavalue' }, typeof current.quote?.source_time === 'string' && current.quote.source_time.length > 0 ? current.quote.source_time : '—')),
1702
- h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.groupsOf')), h('div', { className: 'cwd-metavalue' }, detailNames.length === 0 ? t('desk.noGroup') : detailNames.join(' / '))),
1703
- h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.kind')), h('div', { className: 'cwd-metavalue' }, typeLabel(current.asset_type, t)))),
1704
- h('div', { className: 'cwd-block cwd-block-chart' },
2355
+ // The price row owns the right half of the header: two facts sit beside it instead of under it,
2356
+ // which is what buys both panes their height back.
2357
+ h('div', { className: 'cwd-quoterow' },
2358
+ h('div', { className: 'cwd-bigquote' },
2359
+ h('span', { className: 'cwd-bigprice' }, deskPriceText(detailQuote)),
2360
+ h('span', { className: `cwd-bigpct ${deskToneOf(detailPct)}` }, deskPctText(detailPct))),
2361
+ h('div', { className: 'cwd-meta' },
2362
+ h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.capturedAt')), h('div', { className: 'cwd-metavalue' }, detailAt)),
2363
+ h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.kind')), h('div', { className: 'cwd-metavalue' }, typeLabel(current.asset_type, t))))),
2364
+ h('div', { className: trendFolded ? 'cwd-block cwd-block-chart cwd-folded' : 'cwd-block cwd-block-chart' },
1705
2365
  h('div', { className: 'cwd-blockhead' },
1706
2366
  h('span', { className: 'cwd-blocktitle' }, t('desk.intraday')),
1707
- h('span', { className: 'cwd-blocknote' }, refreshedAt === null ? t('desk.notRefreshed') : formatTime(refreshedAt))),
1708
- h('div', { className: 'cwd-chart' },
1709
- h('div', null,
1710
- h('div', { className: 'cwd-charttext' }, t('desk.intradayEmpty')),
1711
- h('div', { className: 'cwd-charthint' }, t('desk.intradayEmptyHint'))))),
1712
- h('div', { className: 'cwd-block' },
1713
- h('div', { className: 'cwd-blockhead' }, h('span', { className: 'cwd-blocktitle' }, t('desk.volume'))),
1714
- h('div', { className: 'cwd-volume' }, t('desk.volumeEmpty')))))
2367
+ trendFolded ? null : trendStats,
2368
+ h('span', { className: 'cwd-blocknote' }, trendNote),
2369
+ // Two panes in one column: folding the upper one hands the height to the daily pane instead
2370
+ // of pushing the card into a scrollbar.
2371
+ h('button', {
2372
+ type: 'button',
2373
+ className: 'cwd-blockfold',
2374
+ 'aria-expanded': trendFolded ? 'false' : 'true',
2375
+ onClick: () => setTrendFolded(!trendFolded),
2376
+ }, trendFolded ? t('desk.unfold') : t('desk.fold'))),
2377
+ trendFolded ? null : trendBody),
2378
+ klineBlock))
1715
2379
 
1716
2380
  return h('div', { className: 'cwd-page' },
1717
2381
  h('div', { className: 'cwd-inner' },