| 1234567891011121314151617181920212223242526272829303132333435 |
- /**
- * v2.9.2 **SVG 图表渲染器**的 Vue 侧接入(P21)。
- *
- * 旧页在 `app.js:523` 建同一份上下文:
- * `const CH = window.__charts({ t, fmt, esc, dv, EN, displayText, verb })`
- * 之后用 `CH.rateChart / quadChart / ramChart / waterfall / attribBar` 出 **内联 SVG**。
- * 这里保持**同一份 charts.js 原文**(`lib/legacy/charts.js`)与**同一组入参**,
- * 使 Vue 版图表与 v2.9.2 逐像素同源(不再用 ECharts 画这几张)。
- */
- import './legacy/charts.js'
- import { t } from '../i18n/zh'
- import { fmt } from './render'
- import { dv, esc } from './vib'
- type ChartFactory = (ctx: Record<string, unknown>) => Record<string, (...a: any[]) => string>
- const G: any = (typeof window !== 'undefined') ? window : globalThis
- const factory = G.__charts
- let VERB = 0
- const CH: Record<string, (...a: any[]) => string> = factory
- ? factory({ t, fmt, esc, dv, EN: false, displayText: (x: unknown) => (x == null ? '' : String(x)), verb: () => { VERB++ } })
- : {}
- /** 取一张旧图(返回 SVG 字符串)。缺函数时返回空串,页面自行降级。 */
- export function chart(name: 'rateChart' | 'quadChart' | 'ramChart' | 'waterfall' | 'attribBar', ...args: any[]): string {
- const fn = CH[name]
- if (typeof fn !== 'function') return ''
- try { return fn(...args) } catch (e) { return '' }
- }
- /** 旧页的 `<div class="panel span2"><h3>…</h3>{SVG}<p class="small muted">…</p></div>` 包装。 */
- export function chartPanel(title: string, svg: string, note = ''): string {
- return `<div class="panel span2"><h3>${title}</h3>${svg}` +
- (note ? `<p class="small muted" style="margin-top:6px">${note}</p>` : '') + '</div>'
- }
|