-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { IChartInfo } from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/interface'; | ||
import area from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/area'; | ||
import bar from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/bar'; | ||
import column from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/column'; | ||
import pie from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/pie'; | ||
import rose from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/rose'; | ||
import radar from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/radar'; | ||
import scatter from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/scatter'; | ||
import heatmap from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/heatmap'; | ||
import markArea from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/mark-area'; | ||
import markLine from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/mark-line'; | ||
import markPoint from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/mark-point'; | ||
import gauge from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/gauge'; | ||
import funnel from '../../../../../vchart-theme/__tests__/runtime/browser/test-page/charts/funnel'; | ||
|
||
export const charts: IChartInfo[] = [ | ||
area, | ||
column, | ||
pie, | ||
bar, | ||
rose, | ||
radar, | ||
scatter, | ||
//heatmap, | ||
gauge, | ||
funnel, | ||
markArea, | ||
markLine, | ||
markPoint | ||
]; |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,53 @@ | ||
import type { ITheme } from '@visactor/vchart'; | ||
// eslint-disable-next-line no-duplicate-imports | ||
import VChart from '@visactor/vchart'; | ||
import type { IInitVChartSemiThemeOption } from './interface'; | ||
import { generateThemeName, getCurrentMode, observeAttribute } from './util'; | ||
import { generateThemeName, getCurrentMode, observeAttribute, observeThemeSwitch } from './util'; | ||
import { generateVChartSemiTheme } from './generator'; | ||
|
||
export * from './theme-map'; | ||
export * from './generator'; | ||
export * from './light'; | ||
export * from './dark'; | ||
|
||
export const initVChartSemiTheme = ( | ||
options: IInitVChartSemiThemeOption = { isWatchingMode: true, isWatchingThemeSwitch: true } | ||
) => { | ||
switchVChartSemiTheme(options?.defaultMode); | ||
export const initVChartSemiTheme = (options?: IInitVChartSemiThemeOption) => { | ||
const { defaultMode, isWatchingMode = true, isWatchingThemeSwitch = false } = options ?? {}; | ||
|
||
if (options?.isWatchingMode) { | ||
observeAttribute(document.body, 'theme-mode', () => { | ||
switchVChartSemiTheme(); | ||
switchVChartSemiTheme(false, defaultMode); | ||
|
||
if (isWatchingMode) { | ||
observeAttribute(document.body, 'theme-mode', () => switchVChartSemiTheme()); | ||
} | ||
if (isWatchingThemeSwitch) { | ||
observeThemeSwitch(() => { | ||
const mode = getCurrentMode(); | ||
const cacheColorScheme = JSON.stringify(generateVChartSemiTheme(mode).colorScheme); | ||
// 轮询直到监测到主题变化 | ||
let times = 0; | ||
const timer = setInterval(() => { | ||
const theme = generateVChartSemiTheme(mode); | ||
if (times > 50 || cacheColorScheme !== JSON.stringify(theme.colorScheme)) { | ||
switchVChartSemiTheme(true, mode, theme); | ||
clearInterval(timer); | ||
} | ||
times++; | ||
}, 100); | ||
}); | ||
} | ||
}; | ||
|
||
export const switchVChartSemiTheme = (mode?: 'light' | 'dark') => { | ||
export const switchVChartSemiTheme = (force?: boolean, mode?: 'light' | 'dark', theme?: ITheme) => { | ||
if (!mode) { | ||
mode = getCurrentMode(); | ||
} | ||
const themeName = generateThemeName(mode); | ||
if (!force && VChart.ThemeManager.getCurrentTheme() === themeName) { | ||
return; | ||
} else if (force) { | ||
VChart.ThemeManager.removeTheme(themeName); | ||
} | ||
if (!VChart.ThemeManager.themeExist(themeName)) { | ||
VChart.ThemeManager.registerTheme(themeName, generateVChartSemiTheme(mode)); | ||
VChart.ThemeManager.registerTheme(themeName, theme ?? generateVChartSemiTheme(mode)); | ||
} | ||
VChart.ThemeManager.setCurrentTheme(themeName); | ||
}; |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.