@v587d/capital-generation 2.26.0 → 2.27.1

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.retry': '重试',
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.retry': '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 failed to load',
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,66 @@ 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-chartfail { border-style: solid; background: var(--dsw-alias-bg-module-platform); }
597
+ .cwd-chartfail .cwd-charttext { color: var(--dsw-alias-label-primary); }
598
+ .cwd-fallback { display: flex; flex-direction: column; align-items: center; gap: 2px; max-width: 360px; }
599
+ .cwd-retry { display: inline-flex; align-items: center; gap: 6px; flex: none; margin-top: 12px; height: 34px; padding: 0 14px; border: .5px solid color-mix(in srgb, var(--dsw-alias-state-business-primary) 38%, 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: 12.5px; line-height: 20px; font-weight: 500; cursor: pointer; }
600
+ .cwd-retry:hover { background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 22%, transparent); }
601
+ .cwd-retry:active { background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 30%, transparent); }
602
+ .cwd-retry:focus-visible { outline: 2px solid color-mix(in srgb, var(--dsw-alias-state-business-primary) 60%, transparent); outline-offset: 2px; }
603
+ .cwd-trendstats { display: flex; flex: 1 1 auto; flex-wrap: wrap; gap: 2px 14px; min-width: 0; }
604
+ .cwd-trendstat { display: flex; align-items: baseline; gap: 5px; font-size: 11px; line-height: 17px; }
605
+ .cwd-trendstat span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
606
+ .cwd-trendstat span:first-child { flex: none; color: var(--dsw-alias-label-tertiary); }
607
+ .cwd-trendstat span:last-child { font-variant-numeric: tabular-nums; }
608
+ .cwd-chartbox { position: relative; flex: 1; min-height: 120px; min-width: 0; overflow: hidden; border-radius: 10px; background: var(--dsw-alias-bg-module-platform); }
609
+ /* The daily pane shares the SVG contract above (absolute child, determinate height): a flexed chart
610
+ next to a scrolled column is exactly how the container used to grow. */
611
+ .cwd-block-kline { flex: 1 1 0; display: flex; flex-direction: column; min-height: 220px; }
612
+ .cwd-klinebox { position: relative; flex: 1; min-height: 140px; min-width: 0; overflow: hidden; border-radius: 10px; background: var(--dsw-alias-bg-module-platform); }
613
+ .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; }
614
+ .cwd-candle-up { fill: var(--capital-watchlist-up); stroke: var(--capital-watchlist-up); stroke-width: 1; }
615
+ .cwd-candle-down { fill: var(--capital-watchlist-down); stroke: var(--capital-watchlist-down); stroke-width: 1; }
616
+ .cwd-maline { fill: none; stroke-width: 1.1; stroke-linejoin: round; }
617
+ .cwd-ma5 { color: var(--dsw-alias-label-primary); stroke: var(--dsw-alias-label-primary); }
618
+ .cwd-ma10 { color: var(--dsw-alias-state-warn-primary); stroke: var(--dsw-alias-state-warn-primary); }
619
+ .cwd-ma20 { color: var(--dsw-alias-brand-primary); stroke: var(--dsw-alias-brand-primary); }
620
+ .cwd-ma60 { color: var(--dsw-alias-label-tertiary); stroke: var(--dsw-alias-label-tertiary); }
621
+ /* ⛔ 绝对定位不是为了叠层:SVG 一旦参与流式布局,viewBox 的宽高比会反推父盒高度,
622
+ 量测回写就把容器越撑越大(实测逐帧增长)。它必须永远影响不了自己的容器。 */
623
+ .cwd-chartsvg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: pan-y; }
624
+ .cwd-chartaxis { fill: var(--dsw-alias-label-tertiary); font-size: 10.5px; font-variant-numeric: tabular-nums; }
625
+ .cwd-chartbaselabel { fill: var(--dsw-alias-label-secondary); }
626
+ .cwd-chartgrid { stroke: color-mix(in srgb, var(--dsw-alias-border-l2) 55%, transparent); stroke-width: 1; shape-rendering: crispEdges; }
627
+ .cwd-chartsep { stroke: var(--dsw-alias-border-l2); stroke-width: 1; stroke-dasharray: 2 3; }
628
+ .cwd-chartline { fill: none; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
629
+ .cwd-chartavg { fill: none; stroke: var(--dsw-alias-state-business-primary); stroke-width: 1; stroke-dasharray: 3 3; opacity: .85; }
630
+ .cwd-chartbase { stroke: var(--dsw-alias-label-tertiary); stroke-width: 1; opacity: .7; }
631
+ .cwd-chartcross { stroke: var(--dsw-alias-label-tertiary); stroke-width: 1; stroke-dasharray: 3 3; opacity: .8; }
632
+ .cwd-chartdot { fill: currentColor; }
633
+ .cwd-vol-up { fill: var(--capital-watchlist-up); opacity: .55; }
634
+ .cwd-vol-down { fill: var(--capital-watchlist-down); opacity: .55; }
635
+ .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; }
636
+ .cwd-charttiptime { font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
637
+ .cwd-charttipprice { font-size: 13px; line-height: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
638
+ .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
639
  .cwd-empty { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 34px 18px; text-align: center; }
540
640
  .cwd-emptytitle { font-size: 14px; line-height: 20px; font-weight: 600; }
541
641
  .cwd-emptyhint { margin: 6px 0 0; font-size: 12.5px; line-height: 19px; color: var(--dsw-alias-label-tertiary); }
@@ -548,7 +648,7 @@ const CSS = `
548
648
  .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
649
  .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
650
  .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; } }
651
+ @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
652
  @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
653
  `
554
654
 
@@ -588,6 +688,9 @@ async function call(path, { query, body, signal } = {}) {
588
688
  : (response.status === 401 || response.status === 403) ? 'unauthorized' : 'fuyao_unavailable'
589
689
  const error = new Error(code)
590
690
  error.code = code
691
+ // The host's sentence already names what failed (timeout / garbled payload / upstream down);
692
+ // the pane prints it under the title instead of guessing from the code.
693
+ error.detail = typeof payload.message === 'string' && payload.message.length > 0 ? payload.message : null
591
694
  error.candidates = payload.candidates
592
695
  error.limit = payload.limit
593
696
  throw error
@@ -1403,6 +1506,9 @@ function WatchlistDialog({ useDialog, surface, t, inputActions }) {
1403
1506
  const DESK_PANEL_ID = `${ENTRY_NAME}:desk`
1404
1507
  const DESK_GROUPS_KEY = 'capital.watchlist.desk.groups.v1'
1405
1508
  const DESK_ALL = '__all__'
1509
+ /** Monotonic request id for the desk's series: a late answer must not overwrite a newer selection. */
1510
+ let deskTrendSequence = 0
1511
+ let deskKlineSequence = 0
1406
1512
 
1407
1513
  function readDeskGroups() {
1408
1514
  const empty = { names: [], assignments: {} }
@@ -1440,6 +1546,424 @@ const deskPctText = (value) => (value === null ? '—' : `${value > 0 ? '+' : ''
1440
1546
  /** Comma grouping is the market convention here, so it does not follow the UI locale. */
1441
1547
  const deskPriceFormat = new Intl.NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
1442
1548
  const deskPriceText = (quote) => (quote !== null && quote !== undefined && typeof quote.price === 'number' && Number.isFinite(quote.price) ? deskPriceFormat.format(quote.price) : '—')
1549
+ /** Any number → grouped text; every price on the desk keeps two decimals, indices included. */
1550
+ const deskNumberText = (value) => (typeof value === 'number' && Number.isFinite(value) ? deskPriceFormat.format(value) : '—')
1551
+
1552
+ /** 万 / 亿 scaling for totals; the suffix stays Chinese in both locales, like the market comma. */
1553
+ function deskScaledText(value, digits = 2) {
1554
+ if (typeof value !== 'number' || !Number.isFinite(value)) return '—'
1555
+ const size = Math.abs(value)
1556
+ if (size >= 1e8) return `${(value / 1e8).toFixed(digits)}亿`
1557
+ if (size >= 1e4) return `${(value / 1e4).toFixed(digits)}万`
1558
+ return new Intl.NumberFormat('en-US', { maximumFractionDigits: digits }).format(value)
1559
+ }
1560
+
1561
+ const deskMinutesOf = (time) => (typeof time === 'string' && time.length >= 5 ? Number(time.slice(0, 2)) * 60 + Number(time.slice(3, 5)) : 0)
1562
+
1563
+ function deskVolumeText(value, unit, t) {
1564
+ const text = deskScaledText(value)
1565
+ if (text === '—') return text
1566
+ if (unit === 'lot') return `${text}${t('desk.lot')}`
1567
+ if (unit === 'share') return `${text}${t('desk.share')}`
1568
+ return text
1569
+ }
1570
+
1571
+ function deskAmountText(value, currency) {
1572
+ const text = deskScaledText(value)
1573
+ if (text === '—') return text
1574
+ return currency === null || currency === undefined || currency === 'CNY' ? text : `${text} ${currency}`
1575
+ }
1576
+
1577
+ /**
1578
+ * The x axis is the trading clock, not the point count: a 09:32 print must stay near the left edge
1579
+ * instead of stretching over the whole pane (that is what turns four points into four fat bars).
1580
+ * The lunch break takes no width, so a slot is one trading minute and `total` is the day's length.
1581
+ */
1582
+ const TREND_SESSIONS = {
1583
+ 'a-share': [[570, 690], [780, 900]],
1584
+ hk: [[570, 720], [780, 960]],
1585
+ us: [[570, 960]],
1586
+ }
1587
+
1588
+ const deskClockText = (minutes) => `${String(Math.floor(minutes / 60)).padStart(2, '0')}:${String(minutes % 60).padStart(2, '0')}`
1589
+
1590
+ function deskSessionOf(market) {
1591
+ const spans = []
1592
+ let total = 0
1593
+ for (const [open, close] of TREND_SESSIONS[market] ?? TREND_SESSIONS.us) {
1594
+ spans.push([open, close, total])
1595
+ total += close - open
1596
+ }
1597
+ return { spans, total }
1598
+ }
1599
+
1600
+ /** Minute of day → compressed slot; a print outside the session (the HK closing auction) lands on the edge. */
1601
+ function deskSlotOf(session, minutes) {
1602
+ for (const [open, close, base] of session.spans) {
1603
+ if (minutes <= open) return base
1604
+ if (minutes < close) return base + minutes - open
1605
+ }
1606
+ return session.total
1607
+ }
1608
+
1609
+ /** Half-hour grid; a tick landing on the previous tick's slot (11:30 and 13:00 share one) is dropped. */
1610
+ function deskTicksOf(session) {
1611
+ const ticks = []
1612
+ for (const [open, close, base] of session.spans) {
1613
+ for (let minutes = open; minutes <= close; minutes += 30) {
1614
+ const slot = base + minutes - open
1615
+ if (ticks.length === 0 || ticks[ticks.length - 1].slot !== slot) ticks.push({ time: deskClockText(minutes), slot })
1616
+ }
1617
+ }
1618
+ return ticks
1619
+ }
1620
+
1621
+ /**
1622
+ * Same-session trend drawn in plain SVG: price line + area, previous-close baseline, VWAP line,
1623
+ * volume histogram and a pointer crosshair. Geometry is computed in pixels (the box is measured),
1624
+ * so labels and dashes stay crisp at any width; nothing here fetches or invents a point.
1625
+ */
1626
+ function IntradayChart({ data, t }) {
1627
+ const [box, setBox] = useState({ width: 720, height: 300 })
1628
+ const [cursor, setCursor] = useState(null)
1629
+ const host = useRef(null)
1630
+
1631
+ useEffect(() => {
1632
+ const element = host.current
1633
+ if (element === null || element === undefined) return undefined
1634
+ // Integer `clientWidth` rounding plus a content-sized box is exactly how a chart grows by a
1635
+ // pixel per frame; measure the fractional rect and ignore sub-2px jitter. Returning the same
1636
+ // object makes React bail out, so a wobbling layout can never re-enter this loop.
1637
+ const measure = () => {
1638
+ const rect = element.getBoundingClientRect()
1639
+ if (!(rect.width > 0) || !(rect.height > 0)) return
1640
+ const width = Math.max(280, Math.round(rect.width))
1641
+ const height = Math.max(180, Math.round(rect.height))
1642
+ setBox((current) => (Math.abs(current.width - width) < 2 && Math.abs(current.height - height) < 2 ? current : { width, height }))
1643
+ }
1644
+ measure()
1645
+ if (typeof ResizeObserver === 'undefined') return undefined
1646
+ const observer = new ResizeObserver(measure)
1647
+ observer.observe(element)
1648
+ return () => observer.disconnect()
1649
+ }, [])
1650
+
1651
+ const points = data.points
1652
+ const prevClose = data.prev_close
1653
+ const width = box.width
1654
+ const height = box.height
1655
+ // Gutters fit `24,547.66` on the left and `+10.00%` on the right at 10.5px without clipping.
1656
+ const left = 66
1657
+ const right = 54
1658
+ const top = 12
1659
+ const axisHeight = 18
1660
+ const volumeHeight = Math.round(Math.min(70, Math.max(30, height * 0.22)))
1661
+ // Reserve the bottom axis band: the volume pane must stop above the tick labels, not under them.
1662
+ const priceHeight = Math.max(60, height - top - axisHeight - volumeHeight - 10)
1663
+ const plotWidth = Math.max(60, width - left - right)
1664
+ const session = deskSessionOf(data.market)
1665
+ const slotWidth = plotWidth / session.total
1666
+
1667
+ const values = points.map((point) => point[1])
1668
+ const floorValue = Math.min(prevClose, ...values)
1669
+ const peakValue = Math.max(prevClose, ...values)
1670
+ const margin = (peakValue - floorValue) * 0.06 || Math.max(peakValue * 0.002, 0.01)
1671
+ const low = floorValue - margin
1672
+ const high = peakValue + margin
1673
+ const scaleY = (value) => top + ((high - value) / (high - low)) * priceHeight
1674
+ const slots = points.map((point) => deskSlotOf(session, deskMinutesOf(point[0])))
1675
+ const scaleX = (slot) => left + slot * slotWidth
1676
+ const firstX = scaleX(slots[0]).toFixed(1)
1677
+ const lastX = scaleX(slots[points.length - 1]).toFixed(1)
1678
+
1679
+ const tone = data.last === null || data.last >= prevClose ? 'up' : 'down'
1680
+ const stroke = tone === 'up' ? 'var(--capital-watchlist-up)' : 'var(--capital-watchlist-down)'
1681
+ const pricePath = points.map((point, index) => `${index === 0 ? 'M' : 'L'}${scaleX(slots[index]).toFixed(1)} ${scaleY(point[1]).toFixed(1)}`).join('')
1682
+ const bottom = (top + priceHeight).toFixed(1)
1683
+ const areaPath = `${pricePath}L${lastX} ${bottom}L${firstX} ${bottom}Z`
1684
+ 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)}`), '')
1685
+
1686
+ const volumeTop = top + priceHeight + 10
1687
+ const maxVolume = Math.max(1, ...points.map((point) => point[3] ?? 0))
1688
+ // One bar per trading minute: thin by construction, never sized by how many points happened to arrive.
1689
+ const barWidth = Math.max(1, Math.min(10, slotWidth * 0.72))
1690
+ const baseY = scaleY(prevClose)
1691
+ const gridLines = [0, 1, 2, 3, 4].map((step) => {
1692
+ const value = low + ((high - low) * step) / 4
1693
+ return { value, y: scaleY(value), pct: ((value - prevClose) / prevClose) * 100 }
1694
+ }).filter((line) => Math.abs(line.y - baseY) > 9)
1695
+
1696
+ const sessionBreak = session.spans.length > 1 ? session.spans[1][2] : null
1697
+ const allTicks = deskTicksOf(session)
1698
+ const tickStep = width >= 620 ? 1 : 2
1699
+ const ticks = allTicks.filter((tick, order) => order % tickStep === 0 || order === allTicks.length - 1)
1700
+
1701
+ const focus = cursor === null || cursor < 0 || cursor >= points.length ? null : points[cursor]
1702
+ const focusX = focus === null ? 0 : scaleX(slots[cursor])
1703
+ const focusY = focus === null ? 0 : scaleY(focus[1])
1704
+ const tipLeft = Math.min(width - 172, Math.max(8, focusX + 12))
1705
+ 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)}`
1706
+
1707
+ const onMove = (event) => {
1708
+ const rect = event.currentTarget.getBoundingClientRect()
1709
+ if (!(rect.width > 0)) return
1710
+ const slot = Math.max(0, Math.min(session.total, ((event.clientX - rect.left - left) / plotWidth) * session.total))
1711
+ let nearest = 0
1712
+ for (let index = 1; index < slots.length; index += 1) {
1713
+ if (Math.abs(slots[index] - slot) < Math.abs(slots[nearest] - slot)) nearest = index
1714
+ }
1715
+ setCursor(nearest)
1716
+ }
1717
+
1718
+ return h('div', { className: 'cwd-chartbox', ref: host },
1719
+ h('svg', {
1720
+ className: 'cwd-chartsvg',
1721
+ viewBox: `0 0 ${width} ${height}`,
1722
+ role: 'img',
1723
+ 'aria-label': summary,
1724
+ onPointerMove: onMove,
1725
+ onPointerLeave: () => setCursor(null),
1726
+ },
1727
+ h('defs', null,
1728
+ h('linearGradient', { id: 'cwd-trend-fill', x1: '0', y1: '0', x2: '0', y2: '1' },
1729
+ h('stop', { offset: '0%', style: { stopColor: stroke, stopOpacity: 0.2 } }),
1730
+ h('stop', { offset: '100%', style: { stopColor: stroke, stopOpacity: 0 } }))),
1731
+ gridLines.map((line) => h('g', { key: `grid-${line.value.toFixed(4)}` },
1732
+ h('line', { className: 'cwd-chartgrid', x1: left, x2: left + plotWidth, y1: line.y, y2: line.y }),
1733
+ h('text', { className: 'cwd-chartaxis', x: left - 8, y: line.y + 3.5, textAnchor: 'end' }, deskNumberText(line.value)),
1734
+ h('text', { className: 'cwd-chartaxis', x: left + plotWidth + 8, y: line.y + 3.5 }, `${line.pct > 0 ? '+' : ''}${line.pct.toFixed(2)}%`))),
1735
+ ticks.map((tick) => h('line', {
1736
+ key: `grid-${tick.time}`,
1737
+ className: 'cwd-chartgrid',
1738
+ x1: scaleX(tick.slot),
1739
+ x2: scaleX(tick.slot),
1740
+ y1: top,
1741
+ y2: volumeTop + volumeHeight,
1742
+ })),
1743
+ sessionBreak === null ? null : h('line', {
1744
+ className: 'cwd-chartsep',
1745
+ x1: scaleX(sessionBreak),
1746
+ x2: scaleX(sessionBreak),
1747
+ y1: top,
1748
+ y2: volumeTop + volumeHeight,
1749
+ }),
1750
+ h('path', { className: 'cwd-chartarea', d: areaPath, fill: 'url(#cwd-trend-fill)' }),
1751
+ points.map((point, index) => {
1752
+ const value = point[3] ?? 0
1753
+ const barHeight = Math.max(0, (value / maxVolume) * volumeHeight)
1754
+ const previous = index === 0 ? prevClose : points[index - 1][1]
1755
+ const center = scaleX(slots[index] + 0.5)
1756
+ return h('rect', {
1757
+ key: `vol-${index}`,
1758
+ className: point[1] >= previous ? 'cwd-vol-up' : 'cwd-vol-down',
1759
+ x: (Math.min(left + plotWidth - barWidth, Math.max(left, center - barWidth / 2))).toFixed(1),
1760
+ y: (volumeTop + volumeHeight - barHeight).toFixed(1),
1761
+ width: barWidth.toFixed(1),
1762
+ height: Math.max(0.5, barHeight).toFixed(1),
1763
+ })
1764
+ }),
1765
+ h('path', { className: 'cwd-chartline', d: pricePath, style: { stroke } }),
1766
+ averagePath === '' ? null : h('path', { className: 'cwd-chartavg', d: averagePath }),
1767
+ h('line', { className: 'cwd-chartbase', x1: left, x2: left + plotWidth, y1: baseY, y2: baseY, strokeDasharray: '4 3' }),
1768
+ h('text', { className: 'cwd-chartaxis cwd-chartbaselabel', x: left - 8, y: baseY + 3.5, textAnchor: 'end' }, deskNumberText(prevClose)),
1769
+ ticks.map((tick) => h('text', {
1770
+ key: `tick-${tick.time}`,
1771
+ className: 'cwd-chartaxis',
1772
+ x: scaleX(tick.slot),
1773
+ y: height - 5,
1774
+ textAnchor: tick.slot === 0 ? 'start' : tick.slot >= session.total ? 'end' : 'middle',
1775
+ }, tick.time)),
1776
+ focus === null ? null : h('g', null,
1777
+ h('line', { className: 'cwd-chartcross', x1: focusX, x2: focusX, y1: top, y2: volumeTop + volumeHeight }),
1778
+ h('line', { className: 'cwd-chartcross', x1: left, x2: left + plotWidth, y1: focusY, y2: focusY }),
1779
+ h('circle', { className: `cwd-chartdot ${tone === 'up' ? 'cwd-up' : 'cwd-down'}`, cx: focusX, cy: focusY, r: 3 })),
1780
+ ),
1781
+ focus === null ? null : h('div', { className: 'cwd-charttip', style: { left: `${tipLeft}px` } },
1782
+ h('div', { className: 'cwd-charttiptime' }, focus[0]),
1783
+ h('div', { className: `cwd-charttipprice ${tone === 'up' ? 'cwd-up' : 'cwd-down'}` },
1784
+ `${deskNumberText(focus[1])} ${deskPctText(((focus[1] - prevClose) / prevClose) * 100)}`),
1785
+ focus[2] === null ? null : h('div', { className: 'cwd-charttiprow' }, h('span', null, t('desk.trendAvg')), h('span', null, deskNumberText(focus[2]))),
1786
+ 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)))))
1787
+ }
1788
+
1789
+ /** Moving averages over a close series; the leading `window-1` slots stay null so a line never starts at the first bar. */
1790
+ function movingAverage(bars, window) {
1791
+ const values = new Array(bars.length).fill(null)
1792
+ let sum = 0
1793
+ for (let index = 0; index < bars.length; index += 1) {
1794
+ sum += bars[index].close
1795
+ if (index >= window) sum -= bars[index - window].close
1796
+ if (index >= window - 1) values[index] = sum / window
1797
+ }
1798
+ return values
1799
+ }
1800
+
1801
+ /** Four lines is what a 700px pane can keep apart; MA30 would sit on top of MA20 most of the time. */
1802
+ const MA_WINDOWS = [5, 10, 20, 60]
1803
+
1804
+ /**
1805
+ * Daily candles for the desk. Same pixel geometry and the same measured box as the intraday pane
1806
+ * (absolute SVG, 2px deadband, no intrinsic sizing), so the two charts stay aligned and neither can
1807
+ * push its container. Candles are red on up and green on down, the A-share convention used above.
1808
+ */
1809
+ function DailyChart({ data, t }) {
1810
+ const [box, setBox] = useState({ width: 720, height: 300 })
1811
+ const [cursor, setCursor] = useState(null)
1812
+ const host = useRef(null)
1813
+
1814
+ useEffect(() => {
1815
+ const element = host.current
1816
+ if (element === null || element === undefined) return undefined
1817
+ const measure = () => {
1818
+ const rect = element.getBoundingClientRect()
1819
+ if (!(rect.width > 0) || !(rect.height > 0)) return
1820
+ const width = Math.max(280, Math.round(rect.width))
1821
+ const height = Math.max(180, Math.round(rect.height))
1822
+ setBox((current) => (Math.abs(current.width - width) < 2 && Math.abs(current.height - height) < 2 ? current : { width, height }))
1823
+ }
1824
+ measure()
1825
+ if (typeof ResizeObserver === 'undefined') return undefined
1826
+ const observer = new ResizeObserver(measure)
1827
+ observer.observe(element)
1828
+ return () => observer.disconnect()
1829
+ }, [])
1830
+
1831
+ const bars = data.bars
1832
+ const width = box.width
1833
+ const height = box.height
1834
+ const left = 66
1835
+ const right = 54
1836
+ const top = 10
1837
+ const axisHeight = 18
1838
+ const volumeHeight = Math.round(Math.min(64, Math.max(28, height * 0.2)))
1839
+ const priceHeight = Math.max(60, height - top - axisHeight - volumeHeight - 12)
1840
+ const plotWidth = Math.max(60, width - left - right)
1841
+ const slot = plotWidth / Math.max(1, bars.length)
1842
+ // Candles keep a gap so a dense series still reads as separate days instead of a solid block.
1843
+ const barWidth = Math.max(1, Math.min(14, slot * 0.62))
1844
+
1845
+ const highest = Math.max(...bars.map((bar) => bar.high))
1846
+ const lowest = Math.min(...bars.map((bar) => bar.low))
1847
+ const margin = (highest - lowest) * 0.06 || Math.max(highest * 0.01, 0.01)
1848
+ const high = highest + margin
1849
+ const low = lowest - margin
1850
+ const scaleY = (value) => top + ((high - value) / (high - low)) * priceHeight
1851
+ const scaleX = (index) => left + (index + 0.5) * slot
1852
+
1853
+ const volumeTop = top + priceHeight + 12
1854
+ const maxVolume = Math.max(1, ...bars.map((bar) => bar.volume))
1855
+ const scaleVolume = (value) => (value / maxVolume) * volumeHeight
1856
+
1857
+ const maSeries = MA_WINDOWS.map((window) => ({ window, values: movingAverage(bars, window) }))
1858
+ const lineOf = (values) => values.reduce((path, value, index) => (value === null ? path : `${path}${path === '' ? 'M' : 'L'}${scaleX(index).toFixed(1)} ${scaleY(value).toFixed(1)}`), '')
1859
+
1860
+ // Month boundaries only: twelve labels over 120 bars would collide, and every broker labels months.
1861
+ const monthTicks = []
1862
+ for (let index = 0; index < bars.length; index += 1) {
1863
+ const month = bars[index].date.slice(5, 7)
1864
+ if (index === 0 || month !== bars[index - 1].date.slice(5, 7)) monthTicks.push({ index, month })
1865
+ }
1866
+ // The year-prefixed first label is twice as wide as the others, so it only earns its place when the
1867
+ // next month boundary is far enough away — a partial first month (five bars of May) collides with it.
1868
+ const firstGapPx = monthTicks.length > 1 ? (monthTicks[1].index - monthTicks[0].index) * slot : Number.POSITIVE_INFINITY
1869
+ const ticks = monthTicks.map((tick, order) => ({
1870
+ index: tick.index,
1871
+ label: order === 0 && firstGapPx >= 56 ? `${bars[tick.index].date.slice(0, 4)}/${tick.month}` : tick.month,
1872
+ }))
1873
+
1874
+ const gridLines = [0, 1, 2, 3, 4].map((step) => {
1875
+ const value = high - ((high - low) * step) / 4
1876
+ return { value, y: scaleY(value) }
1877
+ })
1878
+
1879
+ const focus = cursor === null || cursor < 0 || cursor >= bars.length ? null : bars[cursor]
1880
+ const focusX = focus === null ? 0 : scaleX(cursor)
1881
+ const focusY = focus === null ? 0 : scaleY(focus.close)
1882
+ const focusPrev = cursor === null || cursor <= 0 ? null : bars[cursor - 1].close
1883
+ const focusPct = focus === null || focusPrev === null || focusPrev <= 0 ? null : ((focus.close - focusPrev) / focusPrev) * 100
1884
+ const tipLeft = Math.min(width - 186, Math.max(8, focusX + 12))
1885
+ const summary = `${data.thscode} ${t('desk.daily')} · ${bars.length} · ${deskNumberText(bars[bars.length - 1].close)}`
1886
+
1887
+ const onMove = (event) => {
1888
+ const rect = event.currentTarget.getBoundingClientRect()
1889
+ if (!(rect.width > 0)) return
1890
+ const index = Math.round((event.clientX - rect.left - left) / slot - 0.5)
1891
+ setCursor(Math.max(0, Math.min(bars.length - 1, index)))
1892
+ }
1893
+
1894
+ return h('div', { className: 'cwd-klinebox', ref: host },
1895
+ h('svg', {
1896
+ className: 'cwd-chartsvg',
1897
+ viewBox: `0 0 ${width} ${height}`,
1898
+ role: 'img',
1899
+ 'aria-label': summary,
1900
+ onPointerMove: onMove,
1901
+ onPointerLeave: () => setCursor(null),
1902
+ },
1903
+ gridLines.map((line) => h('g', { key: `grid-${line.value.toFixed(4)}` },
1904
+ h('line', { className: 'cwd-chartgrid', x1: left, x2: left + plotWidth, y1: line.y, y2: line.y }),
1905
+ h('text', { className: 'cwd-chartaxis', x: left - 8, y: line.y + 3.5, textAnchor: 'end' }, deskNumberText(line.value)))),
1906
+ ticks.map((tick) => h('g', { key: `tick-${tick.index}` },
1907
+ h('line', { className: 'cwd-chartgrid', x1: scaleX(tick.index), x2: scaleX(tick.index), y1: top, y2: volumeTop + volumeHeight }),
1908
+ h('text', {
1909
+ className: 'cwd-chartaxis',
1910
+ x: scaleX(tick.index),
1911
+ y: height - 5,
1912
+ textAnchor: tick.index === 0 ? 'start' : 'middle',
1913
+ }, tick.label))),
1914
+ // Volume first: candles read on top of the histogram, never the other way round.
1915
+ bars.map((bar, index) => {
1916
+ const barHeight = Math.max(0.5, scaleVolume(bar.volume))
1917
+ return h('rect', {
1918
+ key: `vol-${bar.date}`,
1919
+ className: bar.close >= bar.open ? 'cwd-vol-up' : 'cwd-vol-down',
1920
+ x: (scaleX(index) - barWidth / 2).toFixed(1),
1921
+ y: (volumeTop + volumeHeight - barHeight).toFixed(1),
1922
+ width: barWidth.toFixed(1),
1923
+ height: barHeight.toFixed(1),
1924
+ })
1925
+ }),
1926
+ h('text', { className: 'cwd-chartaxis', x: left - 8, y: volumeTop + 8, textAnchor: 'end' }, deskScaledText(maxVolume)),
1927
+ bars.map((bar, index) => {
1928
+ const open = scaleY(bar.open)
1929
+ const close = scaleY(bar.close)
1930
+ const bodyTop = Math.min(open, close)
1931
+ const bodyHeight = Math.max(0.8, Math.abs(close - open))
1932
+ return h('g', { key: `bar-${bar.date}`, className: bar.close >= bar.open ? 'cwd-candle-up' : 'cwd-candle-down' },
1933
+ h('line', {
1934
+ x1: scaleX(index).toFixed(1),
1935
+ x2: scaleX(index).toFixed(1),
1936
+ y1: scaleY(bar.high).toFixed(1),
1937
+ y2: scaleY(bar.low).toFixed(1),
1938
+ }),
1939
+ h('rect', {
1940
+ x: (scaleX(index) - barWidth / 2).toFixed(1),
1941
+ y: bodyTop.toFixed(1),
1942
+ width: barWidth.toFixed(1),
1943
+ height: bodyHeight.toFixed(1),
1944
+ }))
1945
+ }),
1946
+ maSeries.map((series) => {
1947
+ const path = lineOf(series.values)
1948
+ return path === '' ? null : h('path', { key: `ma-${series.window}`, className: `cwd-maline cwd-ma${series.window}`, d: path })
1949
+ }),
1950
+ focus === null ? null : h('g', null,
1951
+ h('line', { className: 'cwd-chartcross', x1: focusX, x2: focusX, y1: top, y2: volumeTop + volumeHeight }),
1952
+ h('line', { className: 'cwd-chartcross', x1: left, x2: left + plotWidth, y1: focusY, y2: focusY })),
1953
+ ),
1954
+ focus === null ? null : h('div', { className: 'cwd-charttip', style: { left: `${tipLeft}px` } },
1955
+ h('div', { className: 'cwd-charttiptime' }, focus.date),
1956
+ h('div', { className: `cwd-charttipprice ${deskToneOf(focusPct)}` },
1957
+ `${deskNumberText(focus.close)} ${deskPctText(focusPct)}`),
1958
+ h('div', { className: 'cwd-charttiprow' },
1959
+ h('span', null, t('desk.kOpen')), h('span', null, deskNumberText(focus.open)),
1960
+ h('span', null, t('desk.kHigh')), h('span', null, deskNumberText(focus.high))),
1961
+ h('div', { className: 'cwd-charttiprow' },
1962
+ h('span', null, t('desk.kLow')), h('span', null, deskNumberText(focus.low)),
1963
+ h('span', null, t('desk.kClose')), h('span', null, deskNumberText(focus.close))),
1964
+ h('div', { className: 'cwd-charttiprow' },
1965
+ h('span', null, t('desk.trendVolume')), h('span', null, deskVolumeText(focus.volume, data.volume_unit, t)))))
1966
+ }
1443
1967
 
1444
1968
  /** Sidebar glyph: an axis plus a rising line reads as quotes without inventing a wallet/pie shape. */
1445
1969
  function WatchlistDeskIcon({ size = 18 }) {
@@ -1475,6 +1999,10 @@ function WatchlistDeskPage({ t }) {
1475
1999
  const [selected, setSelected] = useState(null)
1476
2000
  const [pendingRemove, setPendingRemove] = useState(null)
1477
2001
  const [rowMenu, setRowMenu] = useState(null)
2002
+ const [trend, setTrend] = useState({ status: 'idle', data: null, code: null, detail: null })
2003
+ const [kline, setKline] = useState({ status: 'idle', data: null, code: null, detail: null })
2004
+ // Folded = the intraday pane keeps only its title row, so the daily pane gets the whole column.
2005
+ const [trendFolded, setTrendFolded] = useState(false)
1478
2006
  const alive = useRef(true)
1479
2007
 
1480
2008
  useEffect(() => {
@@ -1496,6 +2024,58 @@ function WatchlistDeskPage({ t }) {
1496
2024
  setError(payload.error !== undefined && payload.error !== null && typeof payload.error.code === 'string' ? payload.error.code : null)
1497
2025
  }
1498
2026
 
2027
+ /**
2028
+ * The series follows the selection: one request per click (the host caches it for a minute),
2029
+ * no polling and no prefetch. A stale answer is dropped by sequence, not merged.
2030
+ */
2031
+ const loadTrend = async (thscode, options = {}) => {
2032
+ if (typeof thscode !== 'string' || thscode.length === 0) {
2033
+ setTrend({ status: 'idle', data: null, code: null, detail: null })
2034
+ setKline({ status: 'idle', data: null, code: null, detail: null })
2035
+ return
2036
+ }
2037
+ const request = (deskTrendSequence += 1)
2038
+ setTrend((previous) => ({ status: 'loading', data: previous.data !== null && previous.data.thscode === thscode ? previous.data : null, code: null, detail: null }))
2039
+ try {
2040
+ const query = `thscode=${encodeURIComponent(thscode)}${options.bust === true ? '&refresh=1' : ''}`
2041
+ const payload = await call('/trend', { query })
2042
+ if (!alive.current || request !== deskTrendSequence) return
2043
+ setTrend({ status: 'ready', data: payload, code: null, detail: null })
2044
+ } catch (failure) {
2045
+ if (!alive.current || request !== deskTrendSequence) return
2046
+ const code = typeof failure?.code === 'string' ? failure.code : 'trend_unavailable'
2047
+ const detail = typeof failure?.detail === 'string' && failure.detail.length > 0 ? failure.detail : null
2048
+ setTrend({ status: code === 'trend_unavailable' ? 'unavailable' : 'error', data: null, code, detail })
2049
+ }
2050
+ }
2051
+
2052
+ /** Same shape as `loadTrend`: the daily pane has its own request, so one slow history never blocks a tick. */
2053
+ const loadKline = async (thscode, options = {}) => {
2054
+ if (typeof thscode !== 'string' || thscode.length === 0) {
2055
+ setKline({ status: 'idle', data: null, code: null, detail: null })
2056
+ return
2057
+ }
2058
+ const request = (deskKlineSequence += 1)
2059
+ setKline((previous) => ({ status: 'loading', data: previous.data !== null && previous.data.thscode === thscode ? previous.data : null, code: null, detail: null }))
2060
+ try {
2061
+ const query = `thscode=${encodeURIComponent(thscode)}${options.bust === true ? '&refresh=1' : ''}`
2062
+ const payload = await call('/kline', { query })
2063
+ if (!alive.current || request !== deskKlineSequence) return
2064
+ setKline({ status: 'ready', data: payload, code: null, detail: null })
2065
+ } catch (failure) {
2066
+ if (!alive.current || request !== deskKlineSequence) return
2067
+ const code = typeof failure?.code === 'string' ? failure.code : 'kline_unavailable'
2068
+ const detail = typeof failure?.detail === 'string' && failure.detail.length > 0 ? failure.detail : null
2069
+ setKline({ status: code === 'kline_unavailable' ? 'unavailable' : 'error', data: null, code, detail })
2070
+ }
2071
+ }
2072
+
2073
+ const selectRow = (thscode) => {
2074
+ setSelected(thscode)
2075
+ void loadTrend(thscode)
2076
+ void loadKline(thscode)
2077
+ }
2078
+
1499
2079
  // Opening the panel is the user request: read the list, then quote it once. No polling.
1500
2080
  useEffect(() => {
1501
2081
  let cancelled = false
@@ -1506,7 +2086,12 @@ function WatchlistDeskPage({ t }) {
1506
2086
  const landed = cleanRows(listed.items) ?? []
1507
2087
  setItems(landed)
1508
2088
  // 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)))
2089
+ const first = typeof landed[0]?.thscode === 'string' ? landed[0].thscode : null
2090
+ setSelected((value) => (value !== null ? value : first))
2091
+ if (first !== null) {
2092
+ void loadTrend(first)
2093
+ void loadKline(first)
2094
+ }
1510
2095
  } catch (failure) {
1511
2096
  if (!cancelled) setError(failure.code ?? 'load_failed')
1512
2097
  return
@@ -1530,6 +2115,10 @@ function WatchlistDeskPage({ t }) {
1530
2115
  try {
1531
2116
  const payload = await call('/refresh', { body: {} })
1532
2117
  if (alive.current) applyRefresh(payload)
2118
+ if (alive.current && selected !== null) {
2119
+ void loadTrend(selected, { bust: true })
2120
+ void loadKline(selected, { bust: true })
2121
+ }
1533
2122
  } catch (failure) {
1534
2123
  if (alive.current) setError(failure.code ?? 'fuyao_unavailable')
1535
2124
  } finally {
@@ -1541,7 +2130,10 @@ function WatchlistDeskPage({ t }) {
1541
2130
  const before = items
1542
2131
  setPendingRemove(null)
1543
2132
  setItems(before.filter((row) => row.thscode !== thscode))
1544
- if (selected === thscode) setSelected(null)
2133
+ if (selected === thscode) {
2134
+ setSelected(null)
2135
+ setTrend({ status: 'idle', data: null, code: null, detail: null })
2136
+ }
1545
2137
  try {
1546
2138
  await call('/remove', { body: { thscode } })
1547
2139
  } catch {
@@ -1603,8 +2195,17 @@ function WatchlistDeskPage({ t }) {
1603
2195
  const groupMenuItems = [{ id: DESK_ALL, label: t('desk.allGroups'), icon: activeGroup === DESK_ALL ? h(IconChecklistOutlineRegular, { size: 14 }) : undefined }]
1604
2196
  .concat(groups.names.map((name) => ({ id: name, label: name, icon: activeGroup === name ? h(IconChecklistOutlineRegular, { size: 14 }) : undefined })))
1605
2197
 
2198
+ // The row you are looking at is the freshest thing in the panel: once its intraday payload lands,
2199
+ // the list shows that price too, so one instrument never carries two numbers on the same screen.
2200
+ const liveQuote = (item) => {
2201
+ if (trend.status !== 'ready' || trend.data === null || trend.data.thscode !== item.thscode || typeof trend.data.last !== 'number') return item.quote
2202
+ const prevClose = trend.data.prev_close
2203
+ return { price: trend.data.last, change_pct: prevClose > 0 ? ((trend.data.last - prevClose) / prevClose) * 100 : null }
2204
+ }
2205
+
1606
2206
  const rows = visible.map((item, index) => {
1607
- const pct = deskPctOf(item.quote)
2207
+ const quote = liveQuote(item)
2208
+ const pct = deskPctOf(quote)
1608
2209
  const failure = failures[item.thscode]
1609
2210
  const names = deskGroupsOf(groups, item.thscode)
1610
2211
  const isSelected = selected === item.thscode
@@ -1615,19 +2216,19 @@ function WatchlistDeskPage({ t }) {
1615
2216
  className: 'cwd-row',
1616
2217
  role: 'listitem',
1617
2218
  'aria-current': isSelected ? 'true' : undefined,
1618
- onClick: (event) => { if (event.target.closest('.cwd-rowactions') === null) setSelected(item.thscode) },
2219
+ onClick: (event) => { if (event.target.closest('.cwd-rowactions') === null) selectRow(item.thscode) },
1619
2220
  },
1620
2221
  h('button', {
1621
2222
  type: 'button',
1622
2223
  className: 'cwd-cellname',
1623
2224
  'aria-pressed': isSelected,
1624
- onClick: () => setSelected(item.thscode),
2225
+ onClick: () => selectRow(item.thscode),
1625
2226
  },
1626
2227
  h('span', { className: 'cwd-nameline' },
1627
2228
  h('span', { className: 'cwd-nametext', title: item.name }, scrubInvisible(item.name)),
1628
2229
  h(TypeTag, { assetType: item.asset_type, t })),
1629
2230
  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)),
2231
+ h('div', { className: failure === undefined ? 'cwd-price' : 'cwd-price cwd-stale', title: quoteTitle }, deskPriceText(quote)),
1631
2232
  h('div', { className: `cwd-pct ${deskToneOf(pct)}`, title: quoteTitle }, deskPctText(pct)),
1632
2233
  // One trigger per row: pin, group checkboxes and remove live in the official Menu.
1633
2234
  h('div', { className: 'cwd-rowactions' },
@@ -1680,8 +2281,96 @@ function WatchlistDeskPage({ t }) {
1680
2281
  ? h('div', { className: 'cwd-empty' }, h('div', { className: 'cwd-emptytitle' }, t('desk.noMatch')), h('p', { className: 'cwd-emptyhint' }, t('desk.noMatchHint')))
1681
2282
  : h('div', { className: 'cwd-tablebody', role: 'list', 'aria-label': t('desk.title') }, rows)
1682
2283
 
1683
- const detailNames = current === null ? [] : deskGroupsOf(groups, current.thscode)
1684
- const detailPct = current === null ? null : deskPctOf(current.quote)
2284
+
2285
+ // The block note states the session fact (live / closed / previous) and the clock the axis uses.
2286
+ const trendData = trend.status === 'ready' ? trend.data : null
2287
+ // The chart is fetched later than the list, so for the selected row it is the fresher vintage:
2288
+ // the headline price, its percentage and the as-of stamp all come from the same series as the
2289
+ // pane below, instead of ageing by every minute the panel sits idle.
2290
+ const trendOwns = trendData !== null && current !== null && trendData.thscode === current.thscode && typeof trendData.last === 'number'
2291
+ const detailQuote = current === null ? null : liveQuote(current)
2292
+ const detailPct = deskPctOf(detailQuote)
2293
+ const detailPrint = trendOwns ? trendData.points[trendData.points.length - 1][0] : null
2294
+ // One clock on the panel: when the number above was printed. The zone suffix only appears when
2295
+ // that clock is not the reader's own (the US session runs on ET); A-share and HK print on it.
2296
+ const printZone = trendOwns && trendData.market === 'us' ? ` ${t('desk.trendZoneUs')}` : ''
2297
+ const detailAt = trendOwns
2298
+ ? `${String(trendData.session_date ?? '').slice(5)} ${detailPrint}${printZone}`.trim()
2299
+ : current === null || current.quote === null || current.quote === undefined ? t('desk.notRefreshed') : (formatTime(current.quote.captured_at) || t('desk.notRefreshed'))
2300
+ const trendZone = trendData === null || trendData.market === 'a-share' ? '' : ` ${t(trendData.market === 'us' ? 'desk.trendZoneUs' : 'desk.trendZoneHk')}`
2301
+ const trendNote = trendData === null
2302
+ ? (trend.status === 'loading' ? t('desk.trendLoading') : trend.status === 'error' ? t('desk.trendError') : '')
2303
+ : trendData.session_status === 'live'
2304
+ ? `${trendData.stale ? t('desk.trendStale') : t('desk.trendLive')}${trendZone} · ${trendData.points[trendData.points.length - 1][0]}`
2305
+ : trendData.session_status === 'closed'
2306
+ ? `${trendData.session_date ?? ''} ${t('desk.trendClosed')}${trendZone}`
2307
+ : `${t('desk.trendPrevious')} ${trendData.session_date ?? ''}${trendZone}`
2308
+
2309
+ const trendStats = trendData === null ? null : h('div', { className: 'cwd-trendstats' },
2310
+ ...[
2311
+ [t('desk.trendOpen'), deskNumberText(trendData.open)],
2312
+ [t('desk.trendHigh'), deskNumberText(trendData.high)],
2313
+ [t('desk.trendLow'), deskNumberText(trendData.low)],
2314
+ [t('desk.trendAvg'), deskNumberText(trendData.avg)],
2315
+ [t('desk.trendVolume'), deskVolumeText(trendData.volume, trendData.volume_unit, t)],
2316
+ [t('desk.trendAmount'), deskAmountText(trendData.amount, trendData.currency)],
2317
+ ].map(([label, value]) => h('div', { key: label, className: 'cwd-trendstat' },
2318
+ h('span', null, label), h('span', { title: value }, value))))
2319
+
2320
+ /**
2321
+ * One look for both panes when there is nothing to draw: the host's own sentence says what went
2322
+ * wrong, and the retry is a real button — inside an empty 300px box a borderless pill reads as
2323
+ * plain text, which is exactly what makes a dead pane look unrecoverable.
2324
+ */
2325
+ const chartFallback = (state, labels, retry = null) => {
2326
+ const title = state.status === 'error' ? labels.error : state.status === 'loading' ? labels.loading : labels.unavailable
2327
+ const reason = state.status === 'error' ? state.detail : state.status === 'unavailable' ? labels.hint : null
2328
+ const showRetry = state.status === 'error' && retry !== null
2329
+ return h('div', { className: showRetry ? 'cwd-chart cwd-chartfail' : 'cwd-chart' },
2330
+ h('div', { className: 'cwd-fallback' },
2331
+ h('div', { className: 'cwd-charttext' }, title),
2332
+ reason === null || reason === undefined || reason.length === 0 ? null : h('div', { className: 'cwd-charthint' }, reason),
2333
+ showRetry
2334
+ ? h('button', { type: 'button', className: 'cwd-retry', onClick: retry.onClick },
2335
+ h(IconRefreshOutlineRegular, { size: 14 }),
2336
+ h('span', null, t('desk.retry')))
2337
+ : null))
2338
+ }
2339
+
2340
+ const trendBody = trendData !== null
2341
+ ? h(IntradayChart, { key: trendData.thscode, data: trendData, t })
2342
+ : chartFallback(trend, {
2343
+ error: t('desk.trendError'),
2344
+ loading: t('desk.trendLoading'),
2345
+ unavailable: t('desk.trendUnavailable'),
2346
+ hint: t('desk.trendUnavailableHint'),
2347
+ }, { onClick: () => { void loadTrend(selected, { bust: true }) } })
2348
+ const klineData = kline.status === 'ready' && Array.isArray(kline.data?.bars) && kline.data.bars.length > 0 ? kline.data : null
2349
+ const klineNote = klineData === null
2350
+ ? (kline.status === 'loading' ? t('desk.klineLoading') : kline.status === 'error' ? t('desk.klineError') : '')
2351
+ : t('desk.adjustQfq')
2352
+ // The legend reads the same series the paths draw, so the numbers and the lines cannot disagree.
2353
+ const klineLegend = klineData === null ? null : h('div', { className: 'cwd-malegend' },
2354
+ ...MA_WINDOWS.map((window) => {
2355
+ const values = movingAverage(klineData.bars, window)
2356
+ const last = values[values.length - 1]
2357
+ return h('span', { key: window, className: `cwd-malegenditem cwd-ma${window}` }, `MA${window} ${last === null || last === undefined ? '—' : deskNumberText(last)}`)
2358
+ }))
2359
+ const klineBody = klineData !== null
2360
+ ? h(DailyChart, { key: klineData.thscode, data: klineData, t })
2361
+ : chartFallback(kline, {
2362
+ error: t('desk.klineError'),
2363
+ loading: t('desk.klineLoading'),
2364
+ unavailable: t('desk.klineUnavailable'),
2365
+ hint: t('desk.klineUnavailableHint'),
2366
+ }, { onClick: () => { void loadKline(selected, { bust: true }) } })
2367
+ const klineBlock = h('div', { className: 'cwd-block cwd-block-kline' },
2368
+ h('div', { className: 'cwd-blockhead' },
2369
+ h('span', { className: 'cwd-blocktitle' }, t('desk.daily')),
2370
+ klineLegend,
2371
+ h('span', { className: 'cwd-blocknote' }, klineNote)),
2372
+ klineBody)
2373
+
1685
2374
  const detail = current === null
1686
2375
  ? h('div', { className: 'cwd-card' }, h('div', { className: 'cwd-empty' },
1687
2376
  h('div', { className: 'cwd-emptytitle' }, t('desk.selectHint')),
@@ -1693,25 +2382,30 @@ function WatchlistDeskPage({ t }) {
1693
2382
  h('span', { className: 'cwd-detailtext', title: current.name }, scrubInvisible(current.name)),
1694
2383
  h(TypeTag, { assetType: current.asset_type, t })),
1695
2384
  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' },
2385
+ // The price row owns the right half of the header: two facts sit beside it instead of under it,
2386
+ // which is what buys both panes their height back.
2387
+ h('div', { className: 'cwd-quoterow' },
2388
+ h('div', { className: 'cwd-bigquote' },
2389
+ h('span', { className: 'cwd-bigprice' }, deskPriceText(detailQuote)),
2390
+ h('span', { className: `cwd-bigpct ${deskToneOf(detailPct)}` }, deskPctText(detailPct))),
2391
+ h('div', { className: 'cwd-meta' },
2392
+ h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.capturedAt')), h('div', { className: 'cwd-metavalue' }, detailAt)),
2393
+ h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.kind')), h('div', { className: 'cwd-metavalue' }, typeLabel(current.asset_type, t))))),
2394
+ h('div', { className: trendFolded ? 'cwd-block cwd-block-chart cwd-folded' : 'cwd-block cwd-block-chart' },
1705
2395
  h('div', { className: 'cwd-blockhead' },
1706
2396
  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')))))
2397
+ trendFolded ? null : trendStats,
2398
+ h('span', { className: 'cwd-blocknote' }, trendNote),
2399
+ // Two panes in one column: folding the upper one hands the height to the daily pane instead
2400
+ // of pushing the card into a scrollbar.
2401
+ h('button', {
2402
+ type: 'button',
2403
+ className: 'cwd-blockfold',
2404
+ 'aria-expanded': trendFolded ? 'false' : 'true',
2405
+ onClick: () => setTrendFolded(!trendFolded),
2406
+ }, trendFolded ? t('desk.unfold') : t('desk.fold'))),
2407
+ trendFolded ? null : trendBody),
2408
+ klineBlock))
1715
2409
 
1716
2410
  return h('div', { className: 'cwd-page' },
1717
2411
  h('div', { className: 'cwd-inner' },