feat(ui): refine menu tabs and chart themes

This commit is contained in:
XiaoDaiGua-Ray 2026-11-05 12:19:06 +08:00
parent 82511cf6f5
commit cb2aa865e8
No known key found for this signature in database
35 changed files with 2498 additions and 1641 deletions

View File

@ -0,0 +1,289 @@
import { flushPromises, mount } from '@vue/test-utils'
import { init } from 'echarts/core'
import type { ECharts } from 'echarts/core'
import { nextTick, ref } from 'vue'
import { RChart, useChart } from '../../packages/ui/src/RChart'
import { USE_CHART_PROVIDER_KEY } from '../../packages/ui/src/RChart/src/config'
import { provideUiServices } from '../../packages/ui/src/services'
vi.mock('echarts/core', async (importOriginal) => {
const actual = await importOriginal<typeof import('echarts/core')>()
return { ...actual, init: vi.fn() }
})
const charts: ReturnType<typeof fakeChart>[] = []
const fakeChart = (element: HTMLElement) => {
let disposed = false
let option = {}
return {
getDom: () => element,
getOption: () => option,
isDisposed: () => disposed,
dispose: vi.fn(() => {
disposed = true
}),
setOption: vi.fn((next) => {
option = { ...option, ...next }
}),
setTheme: vi.fn(),
resize: vi.fn(),
showLoading: vi.fn(),
hideLoading: vi.fn(),
}
}
beforeEach(() => {
charts.length = 0
vi.mocked(init).mockReset()
vi.mocked(init).mockImplementation((element) => {
const chart = fakeChart(element as HTMLElement)
charts.push(chart)
return chart as unknown as ECharts
})
})
afterEach(() => {
vi.unstubAllGlobals()
})
it('updates the live chart on style and color mode changes and resumes only on render', async () => {
const dark = ref(false)
const style = ref('ray-modern')
const [register, actions] = useChart()
const wrapper = mount({
setup() {
provideUiServices({
dark: () => dark.value,
chartTheme: () => style.value,
})
return () => <RChart intersectionObserver={false} onRegister={register} />
},
})
try {
await flushPromises()
expect(init).toHaveBeenLastCalledWith(
expect.anything(),
'ray-modern',
expect.anything(),
)
expect(actions.getChartInstance().echartInst).toBe(charts[0])
style.value = 'ray-material'
await nextTick()
dark.value = true
await nextTick()
expect(charts[0].setTheme.mock.calls).toEqual([
['ray-material'],
['ray-material-dark'],
])
expect(init).toHaveBeenCalledTimes(1)
expect(actions.isDisposed()).toBe(false)
actions.dispose()
style.value = 'ray-plain'
await flushPromises()
expect(charts[0].dispose).toHaveBeenCalledOnce()
expect(init).toHaveBeenCalledTimes(1)
actions.render()
await flushPromises()
expect(init).toHaveBeenLastCalledWith(
expect.anything(),
'ray-plain-dark',
expect.anything(),
)
expect(actions.getChartInstance().echartInst).toBe(charts[1])
} finally {
wrapper.unmount()
}
})
it('applies options and custom loading before callbacks, and preserves caller ARIA settings', async () => {
const calls: string[] = []
const wrapper = mount(RChart, {
props: {
intersectionObserver: false,
loading: true,
loadingOptions: {
text: 'Collecting data',
color: '#123456',
showSpinner: false,
},
options: {
aria: { label: { description: 'Weekly sales' }, decal: { decals: [] } },
},
showAria: true,
onRegister: () => calls.push('register'),
onSuccess: (chart) => {
expect(chart.getOption()).toMatchObject({ aria: { enabled: true } })
calls.push('success')
},
onFinally: () => calls.push('finally'),
},
})
try {
await flushPromises()
expect(calls).toEqual(['register', 'success', 'finally'])
expect(charts[0].getOption()).toMatchObject({
aria: {
enabled: true,
label: { description: 'Weekly sales' },
decal: { show: true, decals: [] },
},
})
expect(charts[0].showLoading).toHaveBeenCalledWith(
'default',
expect.objectContaining({
text: 'Collecting data',
color: '#123456',
showSpinner: false,
}),
)
charts[0].getDom().setAttribute('aria-label', 'Weekly sales')
await wrapper.setProps({ showAria: false })
expect(charts[0].getDom().hasAttribute('aria-label')).toBe(false)
expect(charts[0].getOption()).toMatchObject({ aria: { enabled: false } })
} finally {
wrapper.unmount()
}
})
it('reports a deferred setOption failure and disposes the partial instance', async () => {
const error = new Error('Invalid option')
const onError = vi.fn()
const onFinally = vi.fn()
const onSuccess = vi.fn()
const onRegister = vi.fn()
const errorHandler = vi.fn()
vi.mocked(init).mockImplementationOnce((element) => {
const chart = fakeChart(element as HTMLElement)
chart.setOption.mockImplementationOnce(() => {
throw error
})
charts.push(chart)
return chart as unknown as ECharts
})
const wrapper = mount(RChart, {
props: {
intersectionObserver: false,
onError,
onFinally,
onRegister,
onSuccess,
},
global: { config: { errorHandler } },
})
try {
await flushPromises()
expect(charts[0].dispose).toHaveBeenCalledOnce()
expect(onError).toHaveBeenCalledOnce()
expect(onFinally).toHaveBeenCalledOnce()
expect(onSuccess).not.toHaveBeenCalled()
expect(onRegister).not.toHaveBeenCalled()
expect(errorHandler.mock.calls[0][0].cause).toBe(error)
} finally {
wrapper.unmount()
}
})
it('defers offscreen initialization, even when the theme changes', async () => {
let visible: () => void = () => {}
const disconnect = vi.fn()
class Observer {
constructor(callback: IntersectionObserverCallback) {
visible = () =>
callback(
[{ isIntersecting: true } as IntersectionObserverEntry],
this as unknown as IntersectionObserver,
)
}
observe() {}
disconnect = disconnect
}
vi.stubGlobal('IntersectionObserver', Observer)
const dark = ref(false)
const wrapper = mount({
setup() {
provideUiServices({ dark: () => dark.value })
return () => <RChart theme="default" />
},
})
try {
await flushPromises()
dark.value = true
await nextTick()
expect(init).not.toHaveBeenCalled()
visible()
await flushPromises()
expect(disconnect).toHaveBeenCalled()
expect(init).toHaveBeenLastCalledWith(
expect.anything(),
'dark',
expect.anything(),
)
dark.value = false
await nextTick()
expect(charts[0].setTheme).toHaveBeenCalledWith('default')
} finally {
wrapper.unmount()
}
})
it('honors a fixed Provider theme when appearance changes', async () => {
const dark = ref(false)
const wrapper = mount(
{
setup() {
provideUiServices({ dark: () => dark.value })
return () => <RChart intersectionObserver={false} theme="default" />
},
},
{
global: {
provide: { [USE_CHART_PROVIDER_KEY]: { theme: 'ray-naive-dark' } },
},
},
)
try {
await flushPromises()
dark.value = true
await nextTick()
expect(init).toHaveBeenLastCalledWith(
expect.anything(),
'ray-naive-dark',
expect.anything(),
)
expect(charts[0].setTheme).not.toHaveBeenCalled()
} finally {
wrapper.unmount()
}
})

View File

@ -20,12 +20,12 @@ import { RouterView } from 'vue-router'
export default defineComponent({
name: 'App',
setup() {
const { getAppTheme } = useSettingGetters()
const { getAppTheme, getThemeStyle } = useSettingGetters()
const { t } = useI18n()
provideUiServices({
dark: () => getAppTheme.value,
chartTheme: APP_THEME.echartTheme,
chartTheme: () => APP_THEME.echartTheme ?? `ray-${getThemeStyle.value}`,
translate: t,
columnStorage: createStorage(window.localStorage, APP_CATCH_KEY_PREFIX),
reportError: (message) => window.$message?.error(message),

View File

@ -50,10 +50,7 @@ export const APP_THEME: AppTheme = {
/**
*
* @description
* 配置 echart 主题颜色。
* 约定配置时以:主题名称为文件名,其文件夹下两个主题风格的 json 文件。并且暗色主题必须为 xxx-dark.json。
*
* [文档地址](https://xiaodaigua-ray.github.io/ray-template-doc/ray-template-docs/advanced/echart-themes.html)
* 默认跟随界面风格;可指定已注册的 ECharts 主题名覆盖,暗色变体使用 -dark 后缀。
*/
echartTheme: 'macarons',
echartTheme: null,
}

View File

@ -90,12 +90,13 @@ const DocumentationExample = defineComponent({
name: 'DocumentationExample',
setup() {
const { t } = useI18n()
const { getAppTheme, getLocaleLanguage } = useSettingGetters()
const { getAppTheme, getLocaleLanguage, getThemeStyle } =
useSettingGetters()
provideUiServices({
dark: () => getAppTheme.value,
locale: () => getLocaleLanguage.value,
chartTheme: APP_THEME.echartTheme,
chartTheme: () => APP_THEME.echartTheme ?? `ray-${getThemeStyle.value}`,
translate: t,
iconUrl: (name, prefix) =>
`${iconSprites[name.split('/')[0] as IconPackage]}#${prefix}-${name}`,

View File

@ -9,10 +9,19 @@ import {
import { useMenuActions, useMenuGetters, useRuntimeGetters } from '@/store'
import type { AppMenuOption, MenuTagOptions } from '@/types'
import { ShellTab } from '@ray-template/admin-shell'
import { NButton, NDropdown, NFlex, NLayoutHeader, NScrollbar } from 'naive-ui'
import { usePreferredReducedMotion, useResizeObserver } from '@vueuse/core'
import { NDropdown, NFlex, NLayoutHeader, NScrollbar } from 'naive-ui'
import type { ScrollbarInst } from 'naive-ui'
import { useTemplateRef } from 'vue'
const Chevron = ({ direction }: { direction: 'left' | 'right' }) => (
<RIcon
name="directional/expanded"
size={18}
customClassName={`menu-tag__chevron--${direction}`}
/>
)
export default defineComponent({
name: 'AppMenuTag',
setup(_, { expose }) {
@ -48,7 +57,7 @@ export default defineComponent({
{
label: t('maximize'),
key: 'maximizeLayoutContent',
icon: () => <RIcon name="action/fullscreen_fold" size="1em" />,
icon: () => <RIcon name="action/fullscreen" size="1em" />,
},
{
label: t('reload'),
@ -58,7 +67,7 @@ export default defineComponent({
{
label: t('newWindow'),
key: 'windowOpenTab',
icon: () => <RIcon name="action/shared" size="1em" />,
icon: () => <RIcon name="navigation/window" size="1em" />,
},
{
type: 'divider',
@ -93,7 +102,7 @@ export default defineComponent({
{
label: t('closeAll'),
key: 'closeAll',
icon: () => <RIcon name="directional/resize_h" size="1em" />,
icon: () => <RIcon name="action/close_all" size="1em" />,
disabled: getMenuTagOptions.value.length < 2,
},
])
@ -176,20 +185,34 @@ export default defineComponent({
changeMenuModelValue(option.fullPath, option)
}
const getScrollElement = () =>
tagsRef.value?.closest<HTMLElement>('.n-scrollbar-container')
const scroller = computed(() =>
tagsRef.value?.closest<HTMLElement>('.n-scrollbar-container'),
)
const scrollState = reactive({ left: false, right: false })
const reducedMotion = usePreferredReducedMotion()
const syncScroll = () => {
const element = scroller.value
if (!element) return
scrollState.left = element.scrollLeft > 1
scrollState.right =
element.scrollWidth - element.clientWidth - element.scrollLeft > 1
}
useResizeObserver([scroller, tagsRef], syncScroll)
const scrollX = (direction: 'left' | 'right') => {
const scroller = getScrollElement()
const element = scroller.value
if (!scroller) return
if (!element || !scrollState[direction]) return
const distance = Math.max(100, element.clientWidth * 0.75)
scrollRef.value?.scrollTo({
left: Math.max(
0,
scroller.scrollLeft + (direction === 'left' ? -200 : 200),
),
behavior: 'smooth',
left:
element.scrollLeft + (direction === 'left' ? -distance : distance),
behavior: reducedMotion.value === 'reduce' ? 'auto' : 'smooth',
})
}
@ -224,13 +247,15 @@ export default defineComponent({
}
const positionMenuTag = () => {
const scroller = getScrollElement()
const element = scroller.value
const active = tagsRef.value?.querySelector('.menu-tag__item--active')
if (!active || !scroller) return
syncScroll()
if (!active || !element) return
const tab = active.getBoundingClientRect()
const viewport = scroller.getBoundingClientRect()
const viewport = element.getBoundingClientRect()
const delta =
tab.left < viewport.left
? tab.left - viewport.left
@ -238,17 +263,15 @@ export default defineComponent({
if (delta)
scrollRef.value?.scrollTo({
left: scroller.scrollLeft + delta,
behavior: 'smooth',
left: element.scrollLeft + delta,
behavior: reducedMotion.value === 'reduce' ? 'auto' : 'smooth',
})
}
watch(
[getMenuKey, () => getMenuTagOptions.value.length, tagsRef],
positionMenuTag,
{
flush: 'post',
},
{ flush: 'post' },
)
expose()
@ -261,6 +284,8 @@ export default defineComponent({
menuTagClick,
moreOptions,
scrollX,
scrollState,
syncScroll,
scrollRef,
tagsRef,
actionDropdownSelect,
@ -309,18 +334,19 @@ export default defineComponent({
justify="space-between"
inline
>
<NButton
quaternary
class="override-button__menu-tag"
<button
type="button"
class="menu-tag__control menu-tag__control--scroll"
aria-label={$t('menuTag.scrollLeft')}
aria-disabled={!this.scrollState.left}
title={$t('menuTag.scrollLeft')}
onClick={() => this.scrollX('left')}
>
{{
icon: () => <RIcon name="directional/left_arrow" />,
}}
</NButton>
<Chevron direction="left" />
</button>
<NScrollbar
xScrollable
onScroll={this.syncScroll}
ref="scrollRef"
class="menu-tag__scroll"
themeOverrides={{ width: '0px', height: '0px' }}
@ -356,67 +382,60 @@ export default defineComponent({
})}
</div>
</NScrollbar>
<NFlex align="center" inline wrap={false} size={[0, 0]}>
<NButton
quaternary
class="override-button__menu-tag"
aria-label={$t('menuTag.scrollRight')}
onClick={() => this.scrollX('right')}
>
{{
icon: () => <RIcon name="directional/right_arrow" />,
}}
</NButton>
<NButton
quaternary
class="override-button__menu-tag"
<button
type="button"
class="menu-tag__control menu-tag__control--scroll"
aria-label={$t('menuTag.scrollRight')}
aria-disabled={!this.scrollState.right}
title={$t('menuTag.scrollRight')}
onClick={() => this.scrollX('right')}
>
<Chevron direction="right" />
</button>
<div class="menu-tag__tools">
<button
type="button"
class="menu-tag__control"
aria-label={$t('layout.maximize')}
{...{ title: $t('layout.maximize') }}
title={$t('layout.maximize')}
onClick={() => this.maximize(true)}
>
{{
icon: () => <RIcon name="action/fullscreen_fold" />,
}}
</NButton>
<NButton
quaternary
class="override-button__menu-tag"
<RIcon name="action/fullscreen" size={16} />
</button>
<button
type="button"
class="menu-tag__control"
aria-label={$t('menuTag.reload')}
onClick={() => {
reload()
}}
title={$t('menuTag.reload')}
onClick={() => reload()}
>
{{
icon: () => (
<RIcon
name="action/reload"
customClassName={`${
!globalMainLayoutLoad
? 'menu-tag__right-setting--spinning'
: ''
}`}
/>
),
}}
</NButton>
<RIcon
name="action/reload"
size={16}
customClassName={
globalMainLayoutLoad
? ''
: 'menu-tag__right-setting--spinning'
}
/>
</button>
<RMoreDropdown
class="menu-tag__dropdown"
options={this.moreOptions}
trigger="click"
onSelect={this.actionDropdownSelect.bind(this)}
onSelect={actionDropdownSelect}
>
<NButton
quaternary
class="override-button__menu-tag"
<button
type="button"
class="menu-tag__control"
aria-label={$t('menuTag.actions')}
title={$t('menuTag.actions')}
onClick={this.setCurrentContextmenuIndex}
>
{{
icon: () => <RIcon name="action/more" />,
}}
</NButton>
<RIcon name="action/more" size={16} />
</button>
</RMoreDropdown>
</NFlex>
</div>
</NFlex>
</div>
</NLayoutHeader>

View File

@ -0,0 +1,5 @@
{
"actions": "Chart actions",
"download": "Download image",
"loading": "Loading…"
}

View File

@ -194,6 +194,12 @@
"submit": "Submit"
},
"chart": {
"orders": "Orders",
"visits": "Visits",
"search": "Search",
"direct": "Direct",
"email": "Email",
"ads": "Ads",
"sales": "Weekly sales trend",
"mount": "Render chart",
"dispose": "Dispose chart",

View File

@ -0,0 +1,5 @@
{
"actions": "图表操作",
"download": "下载图片",
"loading": "正在加载…"
}

View File

@ -194,6 +194,12 @@
"submit": "提交"
},
"chart": {
"orders": "订单",
"visits": "访问",
"search": "搜索",
"direct": "直接访问",
"email": "邮件",
"ads": "广告",
"sales": "每周销售趋势",
"mount": "渲染图表",
"dispose": "卸载图表",

View File

@ -74,5 +74,5 @@ export interface AppTheme {
dark: GlobalThemeOverrides
light: GlobalThemeOverrides
}
echartTheme: string
echartTheme: string | null
}

View File

@ -1,17 +1,31 @@
.echart {
width: 100%;
height: 100%;
display: grid;
gap: 20px;
min-width: 0;
& .n-card {
margin-top: 18px;
.chart--container {
width: 100%;
height: 280px;
}
&:first-child {
margin-top: 0;
&__lead {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 12px;
min-width: 0;
.chart--container {
height: clamp(320px, 52vh, 460px);
}
}
& .chart--container {
width: 100%;
height: clamp(300px, 55vh, 500px);
&__examples {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
gap: 16px;
.n-card {
min-width: 0;
}
}
}

View File

@ -2,136 +2,86 @@ import DemoPage from '../components/DemoPage'
import DemoResult from '../components/DemoResult'
import './index.scss'
import { RChart, useChart } from '@/components'
import type { RChartType } from '@/components'
import { useI18n } from '@/hooks'
import { NButton, NCard, NFlex, NSwitch } from 'naive-ui'
const Echart = defineComponent({
name: 'REchart',
setup() {
const [register, { getChartInstance, dispose, render, isDisposed }] =
useChart()
const [
register2,
{
getChartInstance: getChartInstance2,
dispose: dispose2,
render: render2,
isDisposed: isDisposed2,
},
] = useChart()
const [register, { dispose, render }] = useChart()
const [register2, { dispose: dispose2, render: render2 }] = useChart()
const { t } = useI18n('demoDetails.chart')
const chartLoading = ref(false)
const chartAria = ref(false)
const state = reactive({
loading: false,
loading1: false,
lineVisible: true,
barVisible: true,
lineReady: false,
lineVisible: false,
barReady: false,
barVisible: false,
revision: 1,
})
const baseOptions: GlobalEChartsCoreOption = {
legend: {},
tooltip: {},
const baseOptions = computed<GlobalEChartsCoreOption>(() => ({
legend: { type: 'scroll', top: 0 },
tooltip: { trigger: 'axis' },
grid: { left: 44, right: 14, top: 42, bottom: 26 },
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
},
yAxis: {
type: 'value',
},
yAxis: { type: 'value' },
series: [
{
name: '日期',
name: t('orders'),
data: [120, 200, 150, 80, 70, 110, 130],
type: 'bar',
showBackground: true,
backgroundStyle: {
color: 'rgba(180, 180, 180, 0.2)',
},
barMaxWidth: 24,
},
{
name: '数量',
name: t('visits'),
data: [12, 220, 250, 180, 20, 10, 190],
type: 'bar',
showBackground: true,
backgroundStyle: {
color: 'rgba(180, 180, 180, 0.2)',
},
barMaxWidth: 24,
},
],
}
const basePieOptions: GlobalEChartsCoreOption = {
title: {
text: 'Referer of a Website',
subtext: 'Fake Data',
left: 'center',
},
tooltip: {
trigger: 'item',
},
legend: {
orient: 'vertical',
left: 'left',
},
}))
const pieOptions = computed<GlobalEChartsCoreOption>(() => ({
tooltip: { trigger: 'item' },
legend: { type: 'scroll', bottom: 0 },
series: [
{
name: 'Access From',
type: 'pie',
radius: '50%',
radius: ['40%', '68%'],
center: ['50%', '46%'],
label: { show: false },
data: [
{
value: 1048,
name: 'Search Engine',
},
{
value: 735,
name: 'Direct',
},
{
value: 580,
name: 'Email',
},
{
value: 484,
name: 'Union Ads',
},
{
value: 300,
name: 'Video Ads',
},
{ value: 1048, name: t('search') },
{ value: 735, name: t('direct') },
{ value: 580, name: t('email') },
{ value: 484, name: t('ads') },
],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)',
},
},
},
],
}
}))
const baseLineOptions = ref({
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985',
},
},
},
legend: {
data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine'],
type: 'scroll',
bottom: 0,
},
grid: {
left: '4%',
right: '4%',
top: '2%',
outerBounds: {
bottom: '10%',
},
outerBoundsMode: 'auto',
left: 52,
right: 20,
top: 20,
bottom: 58,
},
xAxis: [
{
@ -190,10 +140,6 @@ const Echart = defineComponent({
name: 'Search Engine',
type: 'line',
stack: 'Total',
label: {
show: true,
position: 'top',
},
areaStyle: {},
emphasis: {
focus: 'series',
@ -211,15 +157,6 @@ const Echart = defineComponent({
chartAria.value = bool
}
const mountChart = () => {
if (isDisposed()) {
render()
state.lineVisible = true
} else {
window.$message.warning('图表已渲染~')
}
}
const unmountChart = () => {
dispose()
state.lineVisible = false
@ -249,22 +186,20 @@ const Echart = defineComponent({
handleLoadingShow,
chartAria,
handleAriaShow,
basePieOptions,
pieOptions,
baseLineOptions,
...toRefs(state),
mountChart,
mountChart: render,
unmountChart,
updateChartOptions,
register,
register2,
dispose2,
render2,
isDisposed2,
}
},
render() {
const { register, register2, dispose2, render2, isDisposed2, loading1 } =
this
const { register, register2, dispose2, render2, loading1 } = this
return (
<DemoPage
@ -273,9 +208,12 @@ const Echart = defineComponent({
eyebrow="RAY TEMPLATE / EXAMPLES"
>
<div class="echart">
<NCard title={this.$t('demoDetails.chart.sales')}>
<NFlex style={['padding: 18px 0']}>
<NButton disabled={this.lineVisible} onClick={this.mountChart}>
<section class="echart__lead">
<NFlex align="center">
<NButton
disabled={!this.lineReady || this.lineVisible}
onClick={this.mountChart}
>
{this.$t('demoDetails.chart.mount')}
</NButton>
<NButton disabled={!this.lineVisible} onClick={this.unmountChart}>
@ -302,6 +240,10 @@ const Echart = defineComponent({
<div class="chart--container">
<RChart
onRegister={register}
onSuccess={() => {
this.lineReady = true
this.lineVisible = true
}}
title={this.$t('demoDetails.chart.sales')}
autoChangeTheme
options={this.baseLineOptions}
@ -317,72 +259,71 @@ const Echart = defineComponent({
})
: this.$t('demoDetails.chart.unmounted')}
</DemoResult>
</NCard>
<NCard title={this.$t('demoDetails.chart.fixedTheme')}>
<NFlex vertical>
<NFlex>
<NButton
onClick={() => {
if (isDisposed2()) {
render2()
</section>
<div class="echart__examples">
<NCard title={this.$t('demoDetails.chart.fixedTheme')}>
<NFlex vertical>
<NFlex>
<NButton
disabled={!this.barReady || this.barVisible}
onClick={render2}
>
{this.$t('demoDetails.chart.mount')}
</NButton>
<NButton
disabled={!this.barVisible}
onClick={() => {
dispose2()
this.barVisible = false
}}
>
{this.$t('demoDetails.chart.dispose')}
</NButton>
</NFlex>
<div class="chart--container">
<RChart
onRegister={register2}
onSuccess={() => {
this.barReady = true
this.barVisible = true
} else {
window.$message.warning('不可以重复渲染图表~')
}
}}
>
{this.$t('demoDetails.chart.mount')}
</NButton>
<NButton
disabled={!this.barVisible}
onClick={() => {
dispose2()
this.barVisible = false
}}
>
{this.$t('demoDetails.chart.dispose')}
</NButton>
}}
theme="ray-naive"
options={this.baseOptions}
/>
</div>
</NFlex>
</NCard>
<NCard title={this.$t('demoDetails.chart.showLoading')}>
<NSwitch
v-model:value={this.chartLoading}
onUpdateValue={this.handleLoadingShow.bind(this)}
style={['padding: 18px 0']}
>
{{
checked: () => this.$t('demoDetails.chart.stopLoading'),
unchecked: () => this.$t('demoDetails.chart.showLoading'),
}}
</NSwitch>
<div class="chart--container">
<RChart
onRegister={register2}
autoChangeTheme={false}
theme="default"
options={this.baseOptions}
/>
<RChart loading={this.loading} options={this.pieOptions} />
</div>
</NFlex>
</NCard>
<NCard title={this.$t('demoDetails.chart.showLoading')}>
<NSwitch
v-model:value={this.chartLoading}
onUpdateValue={this.handleLoadingShow.bind(this)}
style={['padding: 18px 0']}
>
{{
checked: () => this.$t('demoDetails.chart.stopLoading'),
unchecked: () => this.$t('demoDetails.chart.showLoading'),
}}
</NSwitch>
<div class="chart--container">
<RChart loading={this.loading} options={this.baseOptions} />
</div>
</NCard>
<NCard title={this.$t('demoDetails.chart.pattern')}>
<NSwitch
v-model:value={this.chartAria}
onUpdateValue={this.handleAriaShow.bind(this)}
style={['padding: 18px 0']}
>
{{
checked: () => this.$t('demoDetails.chart.hidePattern'),
unchecked: () => this.$t('demoDetails.chart.pattern'),
}}
</NSwitch>
<div class="chart--container">
<RChart options={this.baseOptions} showAria={this.chartAria} />
</div>
</NCard>
</NCard>
<NCard title={this.$t('demoDetails.chart.pattern')}>
<NSwitch
v-model:value={this.chartAria}
onUpdateValue={this.handleAriaShow.bind(this)}
style={['padding: 18px 0']}
>
{{
checked: () => this.$t('demoDetails.chart.hidePattern'),
unchecked: () => this.$t('demoDetails.chart.pattern'),
}}
</NSwitch>
<div class="chart--container">
<RChart options={this.baseOptions} showAria={this.chartAria} />
</div>
</NCard>
</div>
</div>
</DemoPage>
)

View File

@ -42,27 +42,29 @@ export default defineComponent({
| 属性 | 默认 | 说明 |
| ---------------------------------------------------- | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| `options` | `{}` | ECharts 配置。`showAria` 默认 `false`,模板会写入 `aria.enabled` 和 `aria.decal.show`。 |
| `options` | `{}` | ECharts 配置。`showAria` 默认 `false`,组件控制 `aria.enabled` 和 `aria.decal.show`,保留其余 ARIA 配置。 |
| `width` / `height` | `'100%'` | CSS 尺寸,数字按像素。 |
| `use` | `[]` | 额外 ECharts 注册项。内置柱、线、饼、K 线、散点、象形柱、Canvas,以及标题、提示、网格、数据集、图例等基础模块。 |
| `intersectionObserver` | `true` | 进入观察范围后挂载图表;隐藏区域的实例可能尚不可用。 |
| `intersectionObserver` | `true` | 进入观察范围后挂载图表;隐藏区域的实例可能尚不可用;浏览器不支持观察时直接挂载。 |
| `intersectionObserverTarget` / `intersectionOptions` | 容器 / `{ threshold: 0.1 }` | 自定义观察目标与参数。 |
| `autoResize` / `autoResizeObserverTarget` | `true` / 外层容器 | 容器尺寸变化后节流 resize。 |
| `autoResize` / `autoResizeObserverTarget` | `true` / 绘图容器 | 容器尺寸变化后节流 resize。 |
| `watchOptions` / `watchDeep` | `true` / `true` | 是否订阅 options,是否深层观察。 |
| `watchOptionsThrottleWait` | `500` | options 更新节流间隔(毫秒)。 |
| `nextTick` | `true` | 初始化前等待 Vue 更新。 |
| `setChartOptions` | `{ notMerge: true, lazyUpdate: true, silent: false, replaceMerge: [] }` | ECharts `setOption` 的控制参数。 |
| `theme` / `autoChangeTheme` | `null` / `true` | 默认用应用的 ECharts 主题及暗色变体。固定主题请传注册后的主题名。 |
| `loading` / `loadingOptions` | `false` / 模板加载样式 | 是否显示 ECharts 加载层及参数。 |
| `theme` / `autoChangeTheme` | `null` / `true` | 默认跟随应用的四套风格及明暗设置。固定主题请传注册名。 |
| `loading` / `loadingOptions` | `false` / 当前图表主题 | 是否显示 ECharts 加载层;传入的字段覆盖默认样式。 |
Provider 指定主题时优先。当前实现中 `theme="default"` 在 `autoChangeTheme=true` 时会传内建 `dark`,设为 `false` 才使用空主题名;需要明确的渲染效果时建议传实际主题名。切换主题可能重建实例,持有实例引用的代码应重新读取或注册。
默认使用 `ray-modern`、`ray-naive`、`ray-material` 或 `ray-plain`,各有 `-dark` 变体。`theme="default"` 使用 ECharts 内建主题,`autoChangeTheme=true` 时随应用明暗变化;显式指定其他注册名时固定使用该主题。设置 `autoChangeTheme=false` 可禁用自动选择暗色变体。旧版 `macarons` 与 `macarons-dark` 已移除。
切换主题会调用 ECharts 6 的 `setTheme`,保留实例和事件监听。ECharts 会重建内部选项模型,图例选择、缩放和通过合并模式写入的增量配置可能被重置。需要保留这些值时,将它们作为完整 `options` 提供。
## 卡片预设和回调
- `preset="card"` 使用 Naive UI Card,支持 `title`(字符串或渲染函数)、`bordered`(默认 `true`)、`contentStyle`。`cardExtra` 插槽可替换右上角。
- 默认菜单含图片下载;`downloadOptions` 接受 ECharts `getDataURL` 参数和可选 `filename`。传入 `dropdownOptions` 会替换菜单,选择项通过 `onDropdownSelect(key, option)` 通知。
- `onSuccess(instance)`、`onError()`、`onFinally()` 对应初始化结果;错误仍可能向调用侧抛出。`onRegister(instance, render, dispose)` 在可用实例建立后调用。
- 初始化成功后依次触发 `onRegister(instance, render, dispose)`、`onSuccess(instance)` 和 `onFinally()`。初始化失败会释放实例,调用 `onError()` 和 `onFinally()`,并通过 Vue 错误处理链报告异常。首次应用 options 同步渲染,使注册回调能立即读取图表;后续更新按 `setChartOptions` 处理。
`useChart()` 返回 `[register, actions]`。`getChartInstance()` 返回 `{ echartInst, render, dispose }`,注册前会抛错。`isDisposed()` 检查底层实例,`dispose()` 释放图表和监听,`render()` 调用组件挂载逻辑;已存在实例时不要用它替代更新 `options` 或 `setOption`。图表随组件卸载清理。
`useChart()` 返回 `[register, actions]`。`getChartInstance()` 返回 `{ echartInst, render, dispose }`,注册前会抛错。`isDisposed()` 检查底层实例,`dispose()` 释放图表并停止观察,`render()` 恢复挂载;已存在实例时不要用它替代更新 `options` 或 `setOption`。图表随组件卸载清理。
[Props](https://github.com/XiaoDaiGua-Ray/ray-template/blob/main/packages/ui/src/RChart/src/props.ts) · [组件实现](https://github.com/XiaoDaiGua-Ray/ray-template/blob/main/packages/ui/src/RChart/src/Chart.tsx) · [useChart](https://github.com/XiaoDaiGua-Ray/ray-template/blob/main/packages/ui/src/RChart/src/hooks/useChart.ts)

View File

@ -7,7 +7,7 @@
.menu-tag-space {
box-sizing: border-box;
width: 100%;
padding-inline: var(--ray-shell-tab-gutter, 18px);
padding-inline: min(var(--ray-shell-tab-gutter, 18px), 3vw);
}
.menu-tag__scroll {
@ -146,11 +146,65 @@
animation: elementRotate 0.8s linear infinite;
}
.override-button__menu-tag {
padding: 0 6px;
.menu-tag__tools {
display: flex;
flex: none;
align-items: center;
gap: 2px;
margin-inline-start: 4px;
padding-inline-start: 6px;
border-inline-start: 1px solid var(--r-line);
}
.menu-tag__control {
display: grid;
flex: none;
place-items: center;
inline-size: 28px;
block-size: 28px;
padding: 0;
border: 1px solid transparent;
border-radius: var(--r-control-radius);
background: transparent;
color: var(--r-text-secondary);
cursor: pointer;
&:not([aria-disabled='true']):is(:hover, :focus-visible) {
background: var(--r-surface-hover);
color: var(--r-text);
}
&:not([aria-disabled='true']):active {
background: var(--r-surface-muted);
color: var(--r-selected-text);
}
&[aria-disabled='true'] {
color: var(--r-text-muted);
opacity: 0.55;
cursor: default;
}
&--scroll:not([aria-disabled='true']) {
border-color: var(--r-line);
background: var(--r-surface-muted);
}
}
.menu-tag__chevron--left {
rotate: 90deg;
}
.menu-tag__chevron--right {
rotate: -90deg;
}
@media (forced-colors: active) {
.menu-tag__control[aria-disabled='true'] {
color: GrayText;
opacity: 1;
}
.menu-tag__item--active {
border-color: Highlight;
}
@ -163,6 +217,10 @@
}
@media (prefers-reduced-motion: reduce) {
.menu-tag__right-setting--spinning {
animation: none;
}
.menu-tag__close,
.menu-tag__close::before {
transition: none;

View File

@ -2,6 +2,8 @@
操作、方向、导航、状态和系统图标来自 [Iconfont · 迈鼎icon](https://www.iconfont.cn/collections/detail?cid=51731) 的 IconPark 线性图形。原作者为 [ByteDance IconPark](https://github.com/bytedance/IconPark),Copyright 2019-present Bytedance Inc.;开源许可见 [Apache 2.0](LICENSE-ICONPARK)。表内 ID 对应该合辑的具体条目。入包时保留原始绘制路径,去掉透明画布路径和导出属性。按实际图形边界重设正方形视图框,让常规图标的主体约占八成半;省略号和展开箭头保留更多留白。轮廓补少量描边,使小尺寸下的线条更清楚,填充和描边均使用 `currentColor`。
`action/close_all` 是本仓库绘制的叠页关闭图标。
品牌标识沿用仓库已有的 SVG。不要将品牌标识与这批通用线性图标的来源或许可混用。
| 图标路径 | 含义 | Iconfont ID |

View File

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M7 3h12a2 2 0 0 1 2 2v12" />
<rect x="3" y="7" width="14" height="14" rx="2" />
<path d="m8 12 4 4m0-4-4 4" />
</svg>

After

Width:  |  Height:  |  Size: 294 B

View File

@ -3,6 +3,7 @@ export const iconNames = [
'action/add',
'action/adjustment',
'action/close',
'action/close_all',
'action/close_left',
'action/close_other',
'action/close_right',

View File

@ -1,32 +1,12 @@
import {
computed,
defineComponent,
nextTick as flushView,
inject,
onBeforeMount,
onBeforeUnmount,
onMounted,
ref,
shallowRef,
unref,
watch,
watchEffect,
} from 'vue'
import './index.scss'
import { completeSize } from '@ray-template/composables/element'
import { call, renderNode } from '@ray-template/composables/vue'
import { downloadBase64File } from '@ray-template/utils'
import type { AnyFn } from '@ray-template/utils/types'
import {
useEventListener,
useIntersectionObserver,
useResizeObserver,
watchThrottled,
} from '@vueuse/core'
import type {
UseIntersectionObserverReturn,
UseResizeObserverReturn,
} from '@vueuse/core'
// 提示框, 标题, 直角坐标系, 数据集, 内置数据转换器等组件(组件后缀都为 Component)
import {
BarChart,
CandlestickChart,
@ -45,517 +25,441 @@ import {
TooltipComponent,
TransformComponent,
} from 'echarts/components'
import { init, registerTheme, use } from 'echarts/core' // echarts 核心模块
import type { ECharts, EChartsCoreOption } from 'echarts/core'
// 系列类型(后缀都为 SeriesOption)
import { LegacyGridContainLabel, UniversalTransition } from 'echarts/features' // 标签自动布局, 全局过渡动画等特性
import { CanvasRenderer } from 'echarts/renderers' // echarts 渲染器
import type { AriaComponentOption } from 'echarts/components'
import { init, registerTheme, use } from 'echarts/core'
import type { ECharts } from 'echarts/core'
import { LegacyGridContainLabel, UniversalTransition } from 'echarts/features'
import { CanvasRenderer } from 'echarts/renderers'
import { throttle } from 'lodash-es'
import type { DebouncedFunc } from 'lodash-es'
import { NCard } from 'naive-ui'
import type { DropdownOption, DropdownProps } from 'naive-ui'
import { useTemplateRef } from 'vue'
import type { WatchStopHandle } from 'vue'
import { RMoreDropdown } from '../../RMoreDropdown'
import { NButton, NCard, NDropdown } from 'naive-ui'
import type { DropdownOption } from 'naive-ui'
import {
computed,
defineComponent,
nextTick as flushView,
inject,
onActivated,
onBeforeUnmount,
onMounted,
ref,
shallowRef,
toValue,
useTemplateRef,
watch,
} from 'vue'
import { RIcon } from '../../RIcon'
import { useUiServices } from '../../services'
import { USE_CHART_PROVIDER_KEY } from './config'
import props from './props'
import { getCustomEchartTheme, loadingOptions, setEchartOptions } from './utils'
// 获取 chart 主题
const echartThemes = getCustomEchartTheme()
// download 下载功能 key
const __CHART_DOWN_LOAD_CHART__ = '__R_CHART_DOWN_LOAD_CHART__'
use([
TitleComponent,
TooltipComponent,
GridComponent,
DatasetComponent,
TransformComponent,
LegendComponent,
ToolboxComponent,
AriaComponent,
BarChart,
LineChart,
PieChart,
CandlestickChart,
ScatterChart,
PictorialBarChart,
LegacyGridContainLabel,
UniversalTransition,
CanvasRenderer,
])
// 注册主题
echartThemes.forEach((curr) => {
registerTheme(curr.name, curr.theme)
})
const themes = new Map(
getCustomEchartTheme().map(({ name, theme }) => [name, theme]),
)
for (const [name, theme] of themes) registerTheme(name, theme)
const DOWNLOAD_KEY = '__R_CHART_DOWN_LOAD_CHART__'
export default defineComponent({
name: 'RChart',
props,
setup(props, { expose }) {
const { dark, chartTheme: echartTheme = 'macarons' } = useUiServices()
const getAppTheme = computed(() => dark?.() ?? false)
// echart 容器实例
const { dark, chartTheme, translate } = useUiServices()
const provider = inject(USE_CHART_PROVIDER_KEY, {})
const chartRef = useTemplateRef<HTMLElement>('chartRef')
// echart 父容器实例
const rayChartWrapperRef = useTemplateRef<HTMLElement>('rayChartWrapperRef')
// echart 实例
const echartInstanceRef = shallowRef<ECharts>()
// resize 防抖方法实例
let resizeThrottleReturn: DebouncedFunc<AnyFn> | null
// resize observer 实例
let resizeObserverReturn: UseResizeObserverReturn | null
// 当前配置主题
// watch props 回调
let watchThrottledCallback: WatchStopHandle | null
// 下拉框配置项
const moreDropDownOptions = computed<DropdownProps['options']>(() => [
{
label: '下载图片',
key: __CHART_DOWN_LOAD_CHART__,
disabled: !(
echartInstanceRef.value && echartInstanceRef.value.getDom()
),
},
const instance = shallowRef<ECharts>()
const renderRequest = ref<number | null>(null)
const ready = shallowRef<{ element: HTMLElement; request: number }>()
let requestId = 0
let mounted = false
const liveChart = () => {
const chart = instance.value
return chart && !chart.isDisposed() ? chart : void 0
}
const theme = computed(() => {
if (provider.theme) return provider.theme
const isDark = props.autoChangeTheme && dark?.()
if (props.theme === 'default') return isDark ? 'dark' : 'default'
if (props.theme) return props.theme
const base = toValue(chartTheme) ?? 'ray-modern'
const darkVariant = `${base}-dark`
return isDark && themes.has(darkVariant) ? darkVariant : base
})
const cssVars = computed(() => ({
'--r-chart-width': completeSize(props.width),
'--r-chart-height': completeSize(props.height),
}))
const loadingStyle = computed(() =>
loadingOptions(
themes.get(theme.value),
theme.value === 'dark' || theme.value.endsWith('-dark'),
translate?.('chart.loading') ?? 'Loading…',
props.loadingOptions,
),
)
const downloadLabel = computed(
() => translate?.('chart.download') ?? 'Download image',
)
const moreLabel = computed(
() => translate?.('chart.actions') ?? 'Chart actions',
)
const moreOptions = computed<DropdownOption[]>(() => [
{ label: downloadLabel.value, key: DOWNLOAD_KEY, disabled: !liveChart() },
])
const cssVarsRef = computed(() => {
const ariaOptions = computed(() => {
const aria = props.options.aria as AriaComponentOption | undefined
return {
'--r-chart-width': completeSize(props.width),
'--r-chart-height': completeSize(props.height),
...aria,
enabled: props.showAria,
decal: { ...aria?.decal, show: props.showAria },
}
})
// 目标是否可见
const targetIsVisible = ref(false)
// intersectionObserver 实例
let intersectionObserverReturn: UseIntersectionObserverReturn | null
// 缓存一些配置信息
const __catch = {
aria: props.showAria,
const syncAriaLabel = (chart: ECharts) => {
if (!props.showAria || ariaOptions.value.label?.enabled === false)
chart.getDom().removeAttribute('aria-label')
}
const chartProvideOptions = inject(USE_CHART_PROVIDER_KEY, {})
/**
*
* @description
* 注册 echart 组件、图利、渲染器等。
*
* 会自动合并拓展 echart 组件。
* 该方法必须在注册图表之前调用。
*/
const registerChartCore = async () => {
use([
TitleComponent,
TooltipComponent,
GridComponent,
DatasetComponent,
TransformComponent,
LegendComponent,
ToolboxComponent,
AriaComponent,
]) // 注册组件
use([
BarChart,
LineChart,
PieChart,
CandlestickChart,
ScatterChart,
PictorialBarChart,
]) // 注册 chart series type
use([LegacyGridContainLabel, UniversalTransition]) // 注册布局, 过度效果
use([CanvasRenderer]) // 注册渲染器
try {
use(props.use?.filter(Boolean))
} catch (e) {
console.error('[RChart register error]: ', e)
}
}
/**
*
* @description
* 更具当前主题渲染 chart。
*
* 如果手动配置了 theme 属性,autoChangeTheme 属性则会失效;
* 但是,如果配置 theme 属性为 default,则会根据当前主题色渲染 chart 默认主题。
*
* 当 Boolean(theme) 为 false,则会尝试获取 echartTheme 属性;
* 但是,如果未获取到 echartTheme 属性,则会使用默认样式。
*/
const updateChartTheme = () => {
const { theme: providerTheme } = chartProvideOptions || {}
if (echartInstanceRef.value) {
destroyChart()
}
// 如果配置了全局配置主题,则忽略后面所有逻辑
if (providerTheme) {
renderChart(providerTheme)
return
}
if (props.theme === 'default') {
props.autoChangeTheme ? renderChart('dark') : renderChart('')
return
}
if (!props.theme) {
const theme = props.autoChangeTheme
? getAppTheme.value
? `${echartTheme}-dark`
: echartTheme
: echartTheme
renderChart(theme)
} else {
renderChart(props.theme)
}
}
/**
*
* @param ops 待合并 chart options
*
* @description
* 合并 chart options。
*
* 如果启用了 showAria 则会自动合并 aria 配置项。
*/
const combineChartOptions = (ops: EChartsCoreOption) => {
let options = unref(ops)
const assign = (opts: object) => Object.assign({}, options, opts)
// 拦截 aria 配置项
options = assign({
aria: {
enabled: props.showAria,
decal: {
show: props.showAria,
},
const applyOptions = (chart: ECharts, initial = false) => {
chart.setOption(
{ ...props.options, aria: ariaOptions.value },
{
...setEchartOptions(),
...props.setChartOptions,
// 初始化回调需要在图表可读取和导出后执行。
...(initial && { lazyUpdate: false }),
},
})
return options
)
syncAriaLabel(chart)
}
const updateLoading = (chart: ECharts) => {
if (props.loading) chart.showLoading('default', loadingStyle.value)
else chart.hideLoading()
}
/**
*
* @description
* 渲染 echart。
*/
const renderChart = (theme: string = echartTheme) => {
// 获取 dom 容器
const element = chartRef.value as HTMLElement
// 获取配置项
const options = combineChartOptions(props.options)
// 获取 dom 容器实际宽高
const { height, width } = element.getBoundingClientRect()
const { onSuccess, onError } = props
const destroyChart = () => {
const chart = liveChart()
instance.value = void 0
chart?.getDom().removeAttribute('aria-label')
chart?.dispose()
}
const render = () => {
if (mounted && !liveChart()) renderRequest.value = ++requestId
}
const dispose = () => {
renderRequest.value = null
ready.value = void 0
resizeChart.cancel()
destroyChart()
}
const initialize = (element: HTMLElement) => {
let chart: ECharts
try {
// 注册 chart
echartInstanceRef.value = init(element, theme, {
// 如果款度为 0,则以 200px 填充
width: width === 0 ? 200 : void 0,
// 如果高度为 0,则以 200px 填充
height: height === 0 ? 200 : void 0,
use(props.use.filter(Boolean))
chart = init(element, theme.value, {
width: element.clientWidth || 200,
height: element.clientHeight || 200,
})
instance.value = chart
applyOptions(chart, true)
updateLoading(chart)
} catch (error) {
destroyChart()
try {
props.onError && call(props.onError)
} finally {
props.onFinally && call(props.onFinally)
}
throw new Error('[RChart] 图表初始化失败', { cause: error })
}
try {
props.onRegister && call(props.onRegister, chart, render, dispose)
if (chart === liveChart() && props.onSuccess)
call(props.onSuccess, chart)
} finally {
props.onFinally && call(props.onFinally)
}
}
watch(
[
chartRef,
renderRequest,
() => props.intersectionObserver,
() => props.intersectionObserverTarget,
() => props.intersectionOptions,
],
([element, request, observe, target, options], _, onCleanup) => {
ready.value = void 0
const chart = liveChart()
if (chart && chart.getDom() !== element) destroyChart()
if (!element || request === null || liveChart()) return
const markReady = () => {
ready.value = { element, request }
}
if (!observe) {
markReady()
return
}
let active = true
const observer = useIntersectionObserver(
target ?? element,
(entries) => {
if (
!active ||
request !== renderRequest.value ||
element !== chartRef.value
)
return
if (entries.at(-1)?.isIntersecting) {
observer.stop()
markReady()
}
},
{ ...options, immediate: true },
)
onCleanup(() => {
active = false
observer.stop()
})
// 渲染成功回调
if (onSuccess) {
call(onSuccess, echartInstanceRef.value)
}
// 是否强制下一队列渲染图表
const { nextTick: deferOptions } = props
if (deferOptions) {
flushView(() => {
options && echartInstanceRef.value?.setOption(options)
})
} else {
options && echartInstanceRef.value?.setOption(options)
}
} catch (e) {
// 渲染失败回调
if (onError) {
call(onError)
}
throw new Error(`[RChart render error]: ${e}`, { cause: e })
} finally {
const { onFinally } = props
if (onFinally) {
call(onFinally)
}
}
}
/**
*
* @description
* chart 是否已经销毁。
* 如果销毁则返回 true, 否则返回 false。
*/
const isDisposed = () => {
return !!echartInstanceRef.value?.isDisposed()
}
/**
*
* @description
* 销毁 chart 实例,释放资源。
*/
const destroyChart = () => {
if (!isDisposed()) {
echartInstanceRef.value?.dispose()
}
}
/**
*
* @description
* 重置 echarts 尺寸。
*/
const resizeChart = () => {
if (echartInstanceRef.value) {
echartInstanceRef.value.resize()
}
}
/**
*
* @param key moreDropDownOptions key
* @param option moreDropDownOptions current click option
*
* @description
* 预设 card 风格下拉框点击。
* 当前仅实现下载图片功能。
*/
const dropdownSelect = (key: string | number, option: DropdownOption) => {
if (key === __CHART_DOWN_LOAD_CHART__ && !isDisposed()) {
const { filename, ...args } = props.downloadOptions
downloadBase64File(
echartInstanceRef.value!.getDataURL(args),
filename ?? `${new Date().getTime()}`,
)
}
const { onDropdownSelect } = props
if (onDropdownSelect) {
call(onDropdownSelect, key, option)
}
}
/**
*
* @description
* 挂载 chart 方法。
*/
const mount = () => {
// 注册事件
if (props.autoResize) {
if (!resizeThrottleReturn) {
resizeThrottleReturn = throttle(resizeChart, 500)
}
/**
*
* 监听内容区域尺寸变化更新 chart。
* 如果没有传入 autoResizeObserverTarget 属性,则默认监听容器尺寸变化。
*/
if (!resizeObserverReturn) {
resizeObserverReturn = useResizeObserver(
props.autoResizeObserverTarget || rayChartWrapperRef,
resizeThrottleReturn as AnyFn,
)
}
}
// 避免重复渲染
if (echartInstanceRef.value?.getDom()) {
return
}
// 如果目标不可见并且启用了 intersectionObserver 则不渲染
if (!targetIsVisible.value && props.intersectionObserver) {
return
}
// 根据主题渲染 chart
updateChartTheme()
// 初始化完成后移除 intersectionObserver 监听
intersectionObserverReturn?.stop()
// 注册 register,用于 useChart hook
const { onRegister } = props
if (onRegister && echartInstanceRef.value) {
call(onRegister, echartInstanceRef.value, mount, unmount)
}
}
/**
*
* @description
* 卸载 chart 方法。
*/
const unmount = () => {
// 卸载 echarts
destroyChart()
// 注销防抖
resizeThrottleReturn?.cancel()
// 注销 observer 监听
resizeObserverReturn?.stop()
intersectionObserverReturn?.stop()
intersectionObserverReturn = null
resizeThrottleReturn = null
resizeObserverReturn = null
}
// 监听全局主题变化,然后重新渲染对应主题 echarts
watch(
() => getAppTheme.value,
() => {
/**
*
* @description
* Q: 为什么需要重新卸载再渲染?
* A: 因为 echarts 官方文档并未提供动态渲染方法。
* 虽然原型上有 setTheme 方法,但是官方标记是仅限于在类 ECharts 中访问。
* 所以,只能先卸载后重新渲染。
*/
if (props.autoChangeTheme) {
destroyChart()
updateChartTheme()
}
if (!observer.isSupported.value) markReady()
},
{ flush: 'post' },
)
watchEffect(() => {
// 是否启用了可视区域监听
if (props.intersectionObserver) {
intersectionObserverReturn?.stop()
watch(
ready,
async (target) => {
if (!target) return
intersectionObserverReturn = useIntersectionObserver(
props.intersectionObserverTarget || rayChartWrapperRef,
([entry]) => {
targetIsVisible.value = entry.isIntersecting
},
props.intersectionOptions,
const { nextTick: defer } = props
if (defer) await flushView()
if (
target === ready.value &&
target.request === renderRequest.value &&
target.element === chartRef.value &&
!liveChart()
)
} else {
intersectionObserverReturn?.stop()
initialize(target.element)
},
{ flush: 'post' },
)
const resizeChart = throttle(() => {
const chart = liveChart()
const element = chartRef.value
if (!props.autoResize || !chart || chart.getDom() !== element) return
if (element.clientWidth && element.clientHeight) {
chart.resize({
width: element.clientWidth,
height: element.clientHeight,
})
}
}, 100)
const resizeObserver = useResizeObserver(
() =>
renderRequest.value !== null && props.autoResize
? (toValue(props.autoResizeObserverTarget) ?? chartRef.value)
: null,
resizeChart,
)
// 监听 options 变化
if (props.watchOptions) {
watchThrottledCallback?.()
watchThrottledCallback = watchThrottled(
() => props.options,
(ndata) => {
// 重新组合 options
const options = combineChartOptions(ndata)
const setOpt = Object.assign(
{},
setEchartOptions(),
props.setChartOptions,
)
// 如果 options 发生变动更新 echarts
echartInstanceRef.value?.setOption(options, setOpt)
},
{
// 深度监听 options
deep: props.watchDeep,
throttle: props.watchOptionsThrottleWait,
},
)
} else {
watchThrottledCallback?.()
}
// 监听 loading 变化
props.loading
? echartInstanceRef.value?.showLoading(
loadingOptions(props.loadingOptions, getAppTheme.value),
)
: echartInstanceRef.value?.hideLoading()
// 贴花是否启用
if (props.showAria !== __catch.aria && echartInstanceRef.value) {
echartInstanceRef.value.setOption(combineChartOptions(props.options))
__catch.aria = props.showAria
}
// 当前图表容器是否处于可见状态,如果可见则渲染图表
if (targetIsVisible.value && !isDisposed()) {
mount()
}
useEventListener('resize', () => {
if (!resizeObserver.isSupported.value) resizeChart()
})
onActivated(resizeChart)
watch(
[
() => props.watchOptions && renderRequest.value !== null,
() => props.watchDeep,
() => props.watchOptionsThrottleWait,
],
([enabled, deep, wait], _, onCleanup) => {
if (!enabled) return
const update = throttle((chart: ECharts) => {
if (chart === liveChart()) applyOptions(chart)
}, wait)
const stop = watch(
() => props.options,
() => {
const chart = liveChart()
if (chart) update(chart)
},
{ deep, flush: 'post' },
)
onCleanup(() => {
stop()
update.cancel()
})
},
{ immediate: true },
)
watch(
theme,
(name) => {
const chart = liveChart()
if (!chart) return
chart.setTheme(name)
// ECharts 6 重建选项模型时可能丢掉之后合并的 ARIA 开关。
const aria = chart.getOption().aria as AriaComponentOption | undefined
if (aria?.enabled !== props.showAria)
chart.setOption({ aria: ariaOptions.value }, { silent: true })
syncAriaLabel(chart)
},
{ flush: 'post' },
)
watch(
[() => props.loading, loadingStyle],
() => {
const chart = liveChart()
if (chart) updateLoading(chart)
},
{ flush: 'post' },
)
watch(
() => props.showAria,
() => {
const chart = liveChart()
if (!chart) return
chart.setOption({ aria: ariaOptions.value })
syncAriaLabel(chart)
},
{ flush: 'post' },
)
const dropdownSelect = (key: string | number, option: DropdownOption) => {
const chart = liveChart()
if (key === DOWNLOAD_KEY && chart) {
const { filename, ...args } = props.downloadOptions
const dataUrl = chart.getDataURL(args)
if (dataUrl) {
const extension = dataUrl.match(/^data:image\/([a-z]+)/)?.[1] ?? 'png'
downloadBase64File(
dataUrl,
filename ?? `chart-${Date.now()}.${extension}`,
)
}
}
if (props.onDropdownSelect) call(props.onDropdownSelect, key, option)
}
expose()
onBeforeMount(async () => {
// 注册 echarts 组件与渲染器
await registerChartCore()
})
onMounted(() => {
// 初始化渲染
mount()
mounted = true
render()
})
onBeforeUnmount(() => {
unmount()
watchThrottledCallback?.()
mounted = false
dispose()
})
return {
chartRef,
cssVarsRef,
rayChartWrapperRef,
moreDropDownOptions,
dropdownSelect,
}
return { chartRef, cssVars, moreOptions, moreLabel, dropdownSelect }
},
render() {
const {
title,
contentStyle,
preset,
moreDropDownOptions,
dropdownSelect,
bordered,
dropdownOptions,
} = this
const { title, contentStyle, preset, bordered, dropdownOptions } = this
const { cardExtra } = this.$slots
const container = <div class="r-chart__container" ref="chartRef" />
return preset === 'card' ? (
<NCard
class="r-chart"
ref="rayChartWrapperRef"
style={[this.cssVarsRef]}
class="r-chart r-chart--card"
style={this.cssVars}
contentClass="r-chart__body"
contentStyle={contentStyle}
bordered={bordered}
embedded
>
{{
default: renderNode(
<div class="r-chart__container" ref="chartRef"></div>,
),
header: renderNode(title, {
defaultElement: <div style="display: none;"></div>,
}),
'header-extra': renderNode(cardExtra, {
defaultElement: (
<RMoreDropdown
iconSize={18}
cursor="pointer"
options={dropdownOptions || moreDropDownOptions}
default: () => container,
header: title ? renderNode(title) : void 0,
'header-extra':
cardExtra ??
(() => (
<NDropdown
options={dropdownOptions ?? this.moreOptions}
trigger="click"
onSelect={dropdownSelect.bind(this)}
onSelect={this.dropdownSelect}
placement="bottom-end"
/>
),
}),
>
<NButton
quaternary
size="small"
aria-label={this.moreLabel}
{...{ title: this.moreLabel }}
>
{{ icon: () => <RIcon name="action/more" size={16} /> }}
</NButton>
</NDropdown>
)),
}}
</NCard>
) : (
<div class="r-chart" style={[this.cssVarsRef]} ref="rayChartWrapperRef">
<div class="r-chart__container" ref="chartRef"></div>
<div class="r-chart" style={this.cssVars}>
{container}
</div>
)
},

View File

@ -1,14 +1,15 @@
.r-chart {
width: var(--r-chart-width);
height: var(--r-chart-height);
border: none;
outline: none;
box-sizing: border-box;
transition: width 0.35s var(--r-bezier);
min-width: 0;
& .r-chart__container {
&__body {
min-height: 0;
}
&__container {
contain: inline-size;
width: 100%;
height: 100%;
box-sizing: border-box;
}
}

View File

@ -16,7 +16,7 @@ import type {
RChartDownloadOptions,
RChartPresetType,
} from './types'
import { loadingOptions, setEchartOptions } from './utils'
import { setEchartOptions } from './utils'
const props = {
/**
@ -43,7 +43,7 @@ const props = {
* @default null
*/
intersectionObserverTarget: {
type: Object as PropType<MaybeComputedElementRef<MaybeElement>>,
type: [Object, Function] as PropType<MaybeComputedElementRef<MaybeElement>>,
default: null,
},
/**
@ -59,9 +59,7 @@ const props = {
*/
intersectionOptions: {
type: Object as PropType<UseIntersectionObserverOptions>,
default: {
threshold: 0.1,
},
default: () => ({ threshold: 0.1 }),
},
/**
*
@ -191,8 +189,7 @@ const props = {
*
* @description
* 是否启用 chart 无障碍模式。
* 该组建默认拦截 aria 配置项的 enabled 属性与 decal.show 属性。
* 也就意味着,你不能通过配置 options 管理该组件的无障碍模式,只能通过该配置项统一管理。
* 统一控制 aria.enabled 和 aria.decal.show,其余 aria 设置由 options 提供。
*
* @default false
*/
@ -257,7 +254,7 @@ const props = {
*
* @description
* 是否自动跟随模板主题切换。
* 该配置项会覆盖 theme 配置项。
* 显式注册的主题名不受该配置项影响;default 跟随明暗切换。
*
* @default true
*/
@ -309,8 +306,8 @@ const props = {
* @default {}
*/
loadingOptions: {
type: Object as PropType<LoadingOptions>,
default: () => loadingOptions(),
type: Object as PropType<Partial<LoadingOptions>>,
default: () => ({}),
},
/**
*
@ -323,7 +320,7 @@ const props = {
* @default null
*/
autoResizeObserverTarget: {
type: Object as PropType<MaybeComputedElementRef<MaybeElement>>,
type: [Object, Function] as PropType<MaybeComputedElementRef<MaybeElement>>,
default: null,
},
/**

View File

@ -1,20 +1,14 @@
## Echart Theme 编辑器
# RChart 主题
官网地址: https://echarts.apache.org/zh/theme-builder.html
四套风格分别放在 `modern/`、`naive/`、`material/`、`plain/`,每套都有明、暗两份独立 JSON。文件名是 ECharts 注册名,例如 `modern/ray-modern.json` → `ray-modern`,`modern/ray-modern-dark.json` → `ray-modern-dark`。
## 流程
| 风格 | 配色与绘图样式 |
| --- | --- |
| Modern | Ray 蓝、冷色网格、虚线分隔、轻量面积填充 |
| Naive | 翡翠绿、实线网格、较小圆角 |
| Material | 紫色调、加粗折线、较大圆角与柔和面积填充 |
| Plain | 低饱和色、点线网格、直角柱和无阴影提示框 |
1. 配置、选择主题
2. 点击下载主题
3. 选择 json 类型,然后复制
4. 在 packages/ui/src/RChart/src/themes 包中创建对应的 json 文件,文件名为主题名称
使用 [ECharts 主题编辑器](https://echarts.apache.org/zh/theme-builder.html) 调整时,导出 JSON 放在对应目录。加载器按文件名自动注册;不同目录也不要使用相同的文件名。只有明色文件时继续使用该主题;提供 `-dark.json` 后随应用明暗切换。业务 `options` 中显式设置的颜色和样式仍优先。
## 注意
### 一份主题
如果有且仅有一份 echart theme,则会视为明暗主题色都共用一套主题色。
### 两份主题
下载好的主题应该分为:xxx 与 xxx-dark 两份。这样模板会自动根据配置主题色切换明暗主题。
旧版 `macarons` 与 `macarons-dark` 已移除。原先写死主题名的页面可移除 `theme` 以跟随界面风格,或改成新主题的注册名。

View File

@ -1,392 +0,0 @@
{
"color": [
"#fc97af",
"#87f7cf",
"#f7f494",
"#72ccff",
"#f7c5a0",
"#d4a4eb",
"#d2f5a6",
"#76f2f2",
"#9b8bba",
"#e098c7",
"#8fd3e8",
"#71669e",
"#cc70af",
"#7cb4cc",
"#7EC4FF",
"#5FCBB0",
"#49C4BF",
"#F0C9CA",
"#34DC90",
"#3295E0",
"#EAB62E",
"#76C3F3",
"#2DC2C0",
"#FCC43F",
"#84CFFF"
],
"backgroundColor": "transparent",
"textStyle": {},
"title": {
"textStyle": {
"color": "#ffffff"
},
"subtextStyle": {
"color": "#dddddd"
}
},
"line": {
"itemStyle": {
"borderWidth": "4"
},
"lineStyle": {
"width": "3"
},
"symbolSize": "0",
"symbol": "circle",
"smooth": true
},
"radar": {
"itemStyle": {
"borderWidth": "4"
},
"lineStyle": {
"width": "3"
},
"symbolSize": "0",
"symbol": "circle",
"smooth": true
},
"bar": {
"itemStyle": {
"barBorderWidth": 0,
"barBorderColor": "#ccc"
}
},
"pie": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"scatter": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"boxplot": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"parallel": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"sankey": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"funnel": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"gauge": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"candlestick": {
"itemStyle": {
"color": "#fc97af",
"color0": "transparent",
"borderColor": "#fc97af",
"borderColor0": "#87f7cf",
"borderWidth": "2"
}
},
"graph": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
},
"lineStyle": {
"width": "1",
"color": "#ffffff"
},
"symbolSize": "0",
"symbol": "circle",
"smooth": true,
"color": [
"#fc97af",
"#87f7cf",
"#f7f494",
"#72ccff",
"#f7c5a0",
"#d4a4eb",
"#d2f5a6",
"#76f2f2"
],
"label": {
"color": "#293441"
}
},
"map": {
"itemStyle": {
"areaColor": "#f3f3f3",
"borderColor": "#999999",
"borderWidth": 0.5
},
"label": {
"color": "#893448"
},
"emphasis": {
"itemStyle": {
"areaColor": "rgba(255,178,72,1)",
"borderColor": "#eb8146",
"borderWidth": 1
},
"label": {
"color": "rgb(137,52,72)"
}
}
},
"geo": {
"itemStyle": {
"areaColor": "#f3f3f3",
"borderColor": "#999999",
"borderWidth": 0.5
},
"label": {
"color": "#893448"
},
"emphasis": {
"itemStyle": {
"areaColor": "rgba(255,178,72,1)",
"borderColor": "#eb8146",
"borderWidth": 1
},
"label": {
"color": "rgb(137,52,72)"
}
}
},
"categoryAxis": {
"axisLine": {
"show": true,
"lineStyle": {
"color": "#666666"
}
},
"axisTick": {
"show": false,
"lineStyle": {
"color": "#333"
}
},
"axisLabel": {
"show": true,
"color": "#aaaaaa"
},
"splitLine": {
"show": false,
"lineStyle": {
"color": ["#e6e6e6"]
}
},
"splitArea": {
"show": false,
"areaStyle": {
"color": ["rgba(250,250,250,0.05)", "rgba(200,200,200,0.02)"]
}
}
},
"valueAxis": {
"axisLine": {
"show": true,
"lineStyle": {
"color": "#666666"
}
},
"axisTick": {
"show": false,
"lineStyle": {
"color": "#333"
}
},
"axisLabel": {
"show": true,
"color": "#aaaaaa"
},
"splitLine": {
"show": false,
"lineStyle": {
"color": ["#e6e6e6"]
}
},
"splitArea": {
"show": false,
"areaStyle": {
"color": ["rgba(250,250,250,0.05)", "rgba(200,200,200,0.02)"]
}
}
},
"logAxis": {
"axisLine": {
"show": true,
"lineStyle": {
"color": "#666666"
}
},
"axisTick": {
"show": false,
"lineStyle": {
"color": "#333"
}
},
"axisLabel": {
"show": true,
"color": "#aaaaaa"
},
"splitLine": {
"show": false,
"lineStyle": {
"color": ["#e6e6e6"]
}
},
"splitArea": {
"show": false,
"areaStyle": {
"color": ["rgba(250,250,250,0.05)", "rgba(200,200,200,0.02)"]
}
}
},
"timeAxis": {
"axisLine": {
"show": true,
"lineStyle": {
"color": "#666666"
}
},
"axisTick": {
"show": false,
"lineStyle": {
"color": "#333"
}
},
"axisLabel": {
"show": true,
"color": "#aaaaaa"
},
"splitLine": {
"show": false,
"lineStyle": {
"color": ["#e6e6e6"]
}
},
"splitArea": {
"show": false,
"areaStyle": {
"color": ["rgba(250,250,250,0.05)", "rgba(200,200,200,0.02)"]
}
}
},
"toolbox": {
"iconStyle": {
"borderColor": "#999999"
},
"emphasis": {
"iconStyle": {
"borderColor": "#666666"
}
}
},
"legend": {
"textStyle": {
"color": "#999999"
},
"pageTextStyle": {
"color": "#999999"
}
},
"tooltip": {
"axisPointer": {
"lineStyle": {
"color": "#cccccc",
"width": 1
},
"crossStyle": {
"color": "#cccccc",
"width": 1
}
}
},
"timeline": {
"lineStyle": {
"color": "#87f7cf",
"width": 1
},
"itemStyle": {
"color": "#87f7cf",
"borderWidth": 1
},
"controlStyle": {
"color": "#87f7cf",
"borderColor": "#87f7cf",
"borderWidth": 0.5
},
"checkpointStyle": {
"color": "#fc97af",
"borderColor": "#fc97af"
},
"label": {
"color": "#87f7cf"
},
"emphasis": {
"itemStyle": {
"color": "#f7f494"
},
"controlStyle": {
"color": "#87f7cf",
"borderColor": "#87f7cf",
"borderWidth": 0.5
},
"label": {
"color": "#87f7cf"
}
}
},
"visualMap": {
"color": ["#fc97af", "#87f7cf"]
},
"dataZoom": {
"backgroundColor": "rgba(255,255,255,0)",
"dataBackgroundColor": "rgba(114,204,255,1)",
"fillerColor": "rgba(114,204,255,0.2)",
"handleColor": "#72ccff",
"handleSize": "100%",
"textStyle": {
"color": "#333333"
}
},
"markPoint": {
"label": {
"color": "#293441"
},
"emphasis": {
"label": {
"color": "#293441"
}
}
}
}

View File

@ -1,402 +0,0 @@
{
"color": [
"#2ec7c9",
"#b6a2de",
"#5ab1ef",
"#ffb980",
"#d87a80",
"#8d98b3",
"#e5cf0d",
"#97b552",
"#95706d",
"#dc69aa",
"#07a2a4",
"#9a7fd1",
"#588dd5",
"#f5994e",
"#c05050",
"#59678c",
"#c9ab00",
"#7eb00a",
"#6f5553",
"#c14089",
"#516b91",
"#59c4e6",
"#edafda",
"#93b7e3",
"#a5e7f0",
"#cbb0e3"
],
"backgroundColor": "transparent",
"textStyle": {},
"title": {
"textStyle": {
"color": "#008acd"
},
"subtextStyle": {
"color": "#aaaaaa"
}
},
"line": {
"itemStyle": {
"borderWidth": 1
},
"lineStyle": {
"width": 2
},
"symbolSize": 3,
"symbol": "emptyCircle",
"smooth": true
},
"radar": {
"itemStyle": {
"borderWidth": 1
},
"lineStyle": {
"width": 2
},
"symbolSize": 3,
"symbol": "emptyCircle",
"smooth": true
},
"bar": {
"itemStyle": {
"barBorderWidth": 0,
"barBorderColor": "#ccc"
}
},
"pie": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"scatter": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"boxplot": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"parallel": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"sankey": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"funnel": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"gauge": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
}
},
"candlestick": {
"itemStyle": {
"color": "#d87a80",
"color0": "#2ec7c9",
"borderColor": "#d87a80",
"borderColor0": "#2ec7c9",
"borderWidth": 1
}
},
"graph": {
"itemStyle": {
"borderWidth": 0,
"borderColor": "#ccc"
},
"lineStyle": {
"width": 1,
"color": "#aaa"
},
"symbolSize": 3,
"symbol": "emptyCircle",
"smooth": true,
"color": [
"#2ec7c9",
"#b6a2de",
"#5ab1ef",
"#ffb980",
"#d87a80",
"#8d98b3",
"#e5cf0d",
"#97b552",
"#95706d",
"#dc69aa",
"#07a2a4",
"#9a7fd1",
"#588dd5",
"#f5994e",
"#c05050",
"#59678c",
"#c9ab00",
"#7eb00a",
"#6f5553",
"#c14089"
],
"label": {
"color": "#eee"
}
},
"map": {
"itemStyle": {
"areaColor": "#dddddd",
"borderColor": "#eeeeee",
"borderWidth": 0.5
},
"label": {
"color": "#d87a80"
},
"emphasis": {
"itemStyle": {
"areaColor": "rgba(254,153,78,1)",
"borderColor": "#444",
"borderWidth": 1
},
"label": {
"color": "rgb(100,0,0)"
}
}
},
"geo": {
"itemStyle": {
"areaColor": "#dddddd",
"borderColor": "#eeeeee",
"borderWidth": 0.5
},
"label": {
"color": "#d87a80"
},
"emphasis": {
"itemStyle": {
"areaColor": "rgba(254,153,78,1)",
"borderColor": "#444",
"borderWidth": 1
},
"label": {
"color": "rgb(100,0,0)"
}
}
},
"categoryAxis": {
"axisLine": {
"show": true,
"lineStyle": {
"color": "#008acd"
}
},
"axisTick": {
"show": true,
"lineStyle": {
"color": "#333"
}
},
"axisLabel": {
"show": true,
"color": "#333"
},
"splitLine": {
"show": false,
"lineStyle": {
"color": ["#eee"]
}
},
"splitArea": {
"show": false,
"areaStyle": {
"color": ["rgba(250,250,250,0.3)", "rgba(200,200,200,0.3)"]
}
}
},
"valueAxis": {
"axisLine": {
"show": true,
"lineStyle": {
"color": "#008acd"
}
},
"axisTick": {
"show": true,
"lineStyle": {
"color": "#333"
}
},
"axisLabel": {
"show": true,
"color": "#333"
},
"splitLine": {
"show": true,
"lineStyle": {
"color": ["#eee"]
}
},
"splitArea": {
"show": true,
"areaStyle": {
"color": ["rgba(250,250,250,0.3)", "rgba(200,200,200,0.3)"]
}
}
},
"logAxis": {
"axisLine": {
"show": true,
"lineStyle": {
"color": "#008acd"
}
},
"axisTick": {
"show": true,
"lineStyle": {
"color": "#333"
}
},
"axisLabel": {
"show": true,
"color": "#333"
},
"splitLine": {
"show": true,
"lineStyle": {
"color": ["#eee"]
}
},
"splitArea": {
"show": true,
"areaStyle": {
"color": ["rgba(250,250,250,0.3)", "rgba(200,200,200,0.3)"]
}
}
},
"timeAxis": {
"axisLine": {
"show": true,
"lineStyle": {
"color": "#008acd"
}
},
"axisTick": {
"show": true,
"lineStyle": {
"color": "#333"
}
},
"axisLabel": {
"show": true,
"color": "#333"
},
"splitLine": {
"show": true,
"lineStyle": {
"color": ["#eee"]
}
},
"splitArea": {
"show": false,
"areaStyle": {
"color": ["rgba(250,250,250,0.3)", "rgba(200,200,200,0.3)"]
}
}
},
"toolbox": {
"iconStyle": {
"borderColor": "#2ec7c9"
},
"emphasis": {
"iconStyle": {
"borderColor": "#18a4a6"
}
}
},
"legend": {
"textStyle": {
"color": "#333333"
}
},
"tooltip": {
"axisPointer": {
"lineStyle": {
"color": "#008acd",
"width": "1"
},
"crossStyle": {
"color": "#008acd",
"width": "1"
}
}
},
"timeline": {
"lineStyle": {
"color": "#008acd",
"width": 1
},
"itemStyle": {
"color": "#008acd",
"borderWidth": 1
},
"controlStyle": {
"color": "#008acd",
"borderColor": "#008acd",
"borderWidth": 0.5
},
"checkpointStyle": {
"color": "#2ec7c9",
"borderColor": "#2ec7c9"
},
"label": {
"color": "#008acd"
},
"emphasis": {
"itemStyle": {
"color": "#a9334c"
},
"controlStyle": {
"color": "#008acd",
"borderColor": "#008acd",
"borderWidth": 0.5
},
"label": {
"color": "#008acd"
}
}
},
"visualMap": {
"color": ["#5ab1ef", "#e0ffff"]
},
"dataZoom": {
"backgroundColor": "rgba(47,69,84,0)",
"dataBackgroundColor": "#efefff",
"fillerColor": "rgba(182,162,222,0.2)",
"handleColor": "#008acd",
"handleSize": "100%",
"textStyle": {
"color": "#333333"
}
},
"markPoint": {
"label": {
"color": "#eee"
},
"emphasis": {
"label": {
"color": "#eee"
}
}
}
}

View File

@ -0,0 +1,179 @@
{
"color": [
"#d6bbff",
"#82d3c6",
"#f4add5",
"#a1c2ff",
"#f7c185",
"#c3ca8d"
],
"darkMode": true,
"backgroundColor": "#241e2c",
"textStyle": {
"color": "#f1e7fa",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\""
},
"title": {
"textStyle": {
"color": "#f1e7fa",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontWeight": 600,
"fontSize": 16
},
"subtextStyle": {
"color": "#ded0e8",
"fontSize": 12
}
},
"legend": {
"itemWidth": 14,
"itemHeight": 8,
"itemGap": 16,
"textStyle": {
"color": "#ded0e8",
"fontSize": 12
}
},
"tooltip": {
"confine": true,
"backgroundColor": "#2b2433",
"borderColor": "#867791",
"borderRadius": 16,
"borderWidth": 1,
"padding": [
9,
12
],
"shadowBlur": 14,
"shadowColor": "rgba(0, 0, 0, 0.16)",
"textStyle": {
"color": "#f1e7fa",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontSize": 12
},
"axisPointer": {
"lineStyle": {
"color": "#867791",
"type": "solid"
},
"crossStyle": {
"color": "#867791",
"type": "solid"
},
"label": {
"backgroundColor": "#ded0e8",
"color": "#241e2c"
}
}
},
"categoryAxis": {
"axisLine": {
"lineStyle": {
"color": "#867791"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#ded0e8",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#473c52",
"type": "solid"
}
}
},
"valueAxis": {
"axisLine": {
"lineStyle": {
"color": "#867791"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#ded0e8",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#473c52",
"type": "solid"
}
}
},
"timeAxis": {
"axisLine": {
"lineStyle": {
"color": "#867791"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#ded0e8",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#473c52",
"type": "solid"
}
}
},
"logAxis": {
"axisLine": {
"lineStyle": {
"color": "#867791"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#ded0e8",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#473c52",
"type": "solid"
}
}
},
"line": {
"symbol": "circle",
"symbolSize": 7,
"lineStyle": {
"width": 3
},
"areaStyle": {
"opacity": 0.18
}
},
"bar": {
"itemStyle": {
"borderRadius": 7
},
"backgroundStyle": {
"color": "#302838",
"borderRadius": 7
}
},
"pie": {
"itemStyle": {
"borderRadius": 7,
"borderWidth": 2,
"borderColor": "#241e2c"
}
}
}

View File

@ -0,0 +1,179 @@
{
"color": [
"#655292",
"#27776d",
"#9e5079",
"#406baa",
"#9a611d",
"#6f7441"
],
"darkMode": false,
"backgroundColor": "#fffaff",
"textStyle": {
"color": "#201a29",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\""
},
"title": {
"textStyle": {
"color": "#201a29",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontWeight": 600,
"fontSize": 16
},
"subtextStyle": {
"color": "#433a50",
"fontSize": 12
}
},
"legend": {
"itemWidth": 14,
"itemHeight": 8,
"itemGap": 16,
"textStyle": {
"color": "#433a50",
"fontSize": 12
}
},
"tooltip": {
"confine": true,
"backgroundColor": "#fffaff",
"borderColor": "#8c8199",
"borderRadius": 16,
"borderWidth": 1,
"padding": [
9,
12
],
"shadowBlur": 14,
"shadowColor": "rgba(0, 0, 0, 0.16)",
"textStyle": {
"color": "#201a29",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontSize": 12
},
"axisPointer": {
"lineStyle": {
"color": "#8c8199",
"type": "solid"
},
"crossStyle": {
"color": "#8c8199",
"type": "solid"
},
"label": {
"backgroundColor": "#433a50",
"color": "#fffaff"
}
}
},
"categoryAxis": {
"axisLine": {
"lineStyle": {
"color": "#8c8199"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#433a50",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#e1d8ea",
"type": "solid"
}
}
},
"valueAxis": {
"axisLine": {
"lineStyle": {
"color": "#8c8199"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#433a50",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#e1d8ea",
"type": "solid"
}
}
},
"timeAxis": {
"axisLine": {
"lineStyle": {
"color": "#8c8199"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#433a50",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#e1d8ea",
"type": "solid"
}
}
},
"logAxis": {
"axisLine": {
"lineStyle": {
"color": "#8c8199"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#433a50",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#e1d8ea",
"type": "solid"
}
}
},
"line": {
"symbol": "circle",
"symbolSize": 7,
"lineStyle": {
"width": 3
},
"areaStyle": {
"opacity": 0.18
}
},
"bar": {
"itemStyle": {
"borderRadius": 7
},
"backgroundStyle": {
"color": "#efe8f7",
"borderRadius": 7
}
},
"pie": {
"itemStyle": {
"borderRadius": 7,
"borderWidth": 2,
"borderColor": "#fffaff"
}
}
}

View File

@ -0,0 +1,179 @@
{
"color": [
"#aabaff",
"#56d8c5",
"#c8a2fa",
"#f2bc6c",
"#f593ae",
"#91bad6"
],
"darkMode": true,
"backgroundColor": "#172131",
"textStyle": {
"color": "#e9eef7",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\""
},
"title": {
"textStyle": {
"color": "#e9eef7",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontWeight": 600,
"fontSize": 16
},
"subtextStyle": {
"color": "#b3c0d3",
"fontSize": 12
}
},
"legend": {
"itemWidth": 14,
"itemHeight": 8,
"itemGap": 16,
"textStyle": {
"color": "#b3c0d3",
"fontSize": 12
}
},
"tooltip": {
"confine": true,
"backgroundColor": "#192638",
"borderColor": "#687b96",
"borderRadius": 10,
"borderWidth": 1,
"padding": [
9,
12
],
"shadowBlur": 14,
"shadowColor": "rgba(0, 0, 0, 0.16)",
"textStyle": {
"color": "#e9eef7",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontSize": 12
},
"axisPointer": {
"lineStyle": {
"color": "#687b96",
"type": "dashed"
},
"crossStyle": {
"color": "#687b96",
"type": "dashed"
},
"label": {
"backgroundColor": "#b3c0d3",
"color": "#172131"
}
}
},
"categoryAxis": {
"axisLine": {
"lineStyle": {
"color": "#687b96"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#b3c0d3",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#2c394d",
"type": "dashed"
}
}
},
"valueAxis": {
"axisLine": {
"lineStyle": {
"color": "#687b96"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#b3c0d3",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#2c394d",
"type": "dashed"
}
}
},
"timeAxis": {
"axisLine": {
"lineStyle": {
"color": "#687b96"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#b3c0d3",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#2c394d",
"type": "dashed"
}
}
},
"logAxis": {
"axisLine": {
"lineStyle": {
"color": "#687b96"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#b3c0d3",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#2c394d",
"type": "dashed"
}
}
},
"line": {
"symbol": "circle",
"symbolSize": 5,
"lineStyle": {
"width": 2
},
"areaStyle": {
"opacity": 0.13
}
},
"bar": {
"itemStyle": {
"borderRadius": 4
},
"backgroundStyle": {
"color": "#1c293b",
"borderRadius": 4
}
},
"pie": {
"itemStyle": {
"borderRadius": 4,
"borderWidth": 2,
"borderColor": "#172131"
}
}
}

View File

@ -0,0 +1,179 @@
{
"color": [
"#3b63d9",
"#087e79",
"#8655bb",
"#b46a12",
"#bf5270",
"#50718a"
],
"darkMode": false,
"backgroundColor": "#ffffff",
"textStyle": {
"color": "#1d2a3e",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\""
},
"title": {
"textStyle": {
"color": "#1d2a3e",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontWeight": 600,
"fontSize": 16
},
"subtextStyle": {
"color": "#52647c",
"fontSize": 12
}
},
"legend": {
"itemWidth": 14,
"itemHeight": 8,
"itemGap": 16,
"textStyle": {
"color": "#52647c",
"fontSize": 12
}
},
"tooltip": {
"confine": true,
"backgroundColor": "#ffffff",
"borderColor": "#8492a8",
"borderRadius": 10,
"borderWidth": 1,
"padding": [
9,
12
],
"shadowBlur": 14,
"shadowColor": "rgba(0, 0, 0, 0.16)",
"textStyle": {
"color": "#1d2a3e",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontSize": 12
},
"axisPointer": {
"lineStyle": {
"color": "#8492a8",
"type": "dashed"
},
"crossStyle": {
"color": "#8492a8",
"type": "dashed"
},
"label": {
"backgroundColor": "#52647c",
"color": "#ffffff"
}
}
},
"categoryAxis": {
"axisLine": {
"lineStyle": {
"color": "#8492a8"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#52647c",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#e4e9f1",
"type": "dashed"
}
}
},
"valueAxis": {
"axisLine": {
"lineStyle": {
"color": "#8492a8"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#52647c",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#e4e9f1",
"type": "dashed"
}
}
},
"timeAxis": {
"axisLine": {
"lineStyle": {
"color": "#8492a8"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#52647c",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#e4e9f1",
"type": "dashed"
}
}
},
"logAxis": {
"axisLine": {
"lineStyle": {
"color": "#8492a8"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "#52647c",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "#e4e9f1",
"type": "dashed"
}
}
},
"line": {
"symbol": "circle",
"symbolSize": 5,
"lineStyle": {
"width": 2
},
"areaStyle": {
"opacity": 0.13
}
},
"bar": {
"itemStyle": {
"borderRadius": 4
},
"backgroundStyle": {
"color": "#f7f9fc",
"borderRadius": 4
}
},
"pie": {
"itemStyle": {
"borderRadius": 4,
"borderWidth": 2,
"borderColor": "#ffffff"
}
}
}

View File

@ -0,0 +1,179 @@
{
"color": [
"#63e2b7",
"#76baff",
"#f2c97d",
"#d49ee7",
"#f0909b",
"#93bdba"
],
"darkMode": true,
"backgroundColor": "rgb(24, 24, 28)",
"textStyle": {
"color": "rgba(255, 255, 255, 0.9)",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\""
},
"title": {
"textStyle": {
"color": "rgba(255, 255, 255, 0.9)",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontWeight": 600,
"fontSize": 16
},
"subtextStyle": {
"color": "rgba(255, 255, 255, 0.82)",
"fontSize": 12
}
},
"legend": {
"itemWidth": 14,
"itemHeight": 8,
"itemGap": 16,
"textStyle": {
"color": "rgba(255, 255, 255, 0.82)",
"fontSize": 12
}
},
"tooltip": {
"confine": true,
"backgroundColor": "rgb(72, 72, 78)",
"borderColor": "rgba(255, 255, 255, 0.24)",
"borderRadius": 6,
"borderWidth": 1,
"padding": [
9,
12
],
"shadowBlur": 14,
"shadowColor": "rgba(0, 0, 0, 0.16)",
"textStyle": {
"color": "rgba(255, 255, 255, 0.9)",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontSize": 12
},
"axisPointer": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.24)",
"type": "solid"
},
"crossStyle": {
"color": "rgba(255, 255, 255, 0.24)",
"type": "solid"
},
"label": {
"backgroundColor": "rgba(255, 255, 255, 0.82)",
"color": "rgb(24, 24, 28)"
}
}
},
"categoryAxis": {
"axisLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.24)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgba(255, 255, 255, 0.82)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.09)",
"type": "solid"
}
}
},
"valueAxis": {
"axisLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.24)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgba(255, 255, 255, 0.82)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.09)",
"type": "solid"
}
}
},
"timeAxis": {
"axisLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.24)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgba(255, 255, 255, 0.82)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.09)",
"type": "solid"
}
}
},
"logAxis": {
"axisLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.24)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgba(255, 255, 255, 0.82)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.09)",
"type": "solid"
}
}
},
"line": {
"symbol": "circle",
"symbolSize": 5,
"lineStyle": {
"width": 2
},
"areaStyle": {
"opacity": 0.1
}
},
"bar": {
"itemStyle": {
"borderRadius": 2
},
"backgroundStyle": {
"color": "rgba(255, 255, 255, 0.06)",
"borderRadius": 2
}
},
"pie": {
"itemStyle": {
"borderRadius": 2,
"borderWidth": 2,
"borderColor": "rgb(24, 24, 28)"
}
}
}

View File

@ -0,0 +1,179 @@
{
"color": [
"#16824a",
"#2872b4",
"#ab6415",
"#9953a6",
"#bd4d59",
"#487775"
],
"darkMode": false,
"backgroundColor": "#fff",
"textStyle": {
"color": "rgb(31, 34, 37)",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\""
},
"title": {
"textStyle": {
"color": "rgb(31, 34, 37)",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontWeight": 600,
"fontSize": 16
},
"subtextStyle": {
"color": "rgb(51, 54, 57)",
"fontSize": 12
}
},
"legend": {
"itemWidth": 14,
"itemHeight": 8,
"itemGap": 16,
"textStyle": {
"color": "rgb(51, 54, 57)",
"fontSize": 12
}
},
"tooltip": {
"confine": true,
"backgroundColor": "#fff",
"borderColor": "rgb(224, 224, 230)",
"borderRadius": 6,
"borderWidth": 1,
"padding": [
9,
12
],
"shadowBlur": 14,
"shadowColor": "rgba(0, 0, 0, 0.16)",
"textStyle": {
"color": "rgb(31, 34, 37)",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontSize": 12
},
"axisPointer": {
"lineStyle": {
"color": "rgb(224, 224, 230)",
"type": "solid"
},
"crossStyle": {
"color": "rgb(224, 224, 230)",
"type": "solid"
},
"label": {
"backgroundColor": "rgb(51, 54, 57)",
"color": "#fff"
}
}
},
"categoryAxis": {
"axisLine": {
"lineStyle": {
"color": "rgb(224, 224, 230)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgb(51, 54, 57)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgb(239, 239, 245)",
"type": "solid"
}
}
},
"valueAxis": {
"axisLine": {
"lineStyle": {
"color": "rgb(224, 224, 230)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgb(51, 54, 57)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgb(239, 239, 245)",
"type": "solid"
}
}
},
"timeAxis": {
"axisLine": {
"lineStyle": {
"color": "rgb(224, 224, 230)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgb(51, 54, 57)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgb(239, 239, 245)",
"type": "solid"
}
}
},
"logAxis": {
"axisLine": {
"lineStyle": {
"color": "rgb(224, 224, 230)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgb(51, 54, 57)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgb(239, 239, 245)",
"type": "solid"
}
}
},
"line": {
"symbol": "circle",
"symbolSize": 5,
"lineStyle": {
"width": 2
},
"areaStyle": {
"opacity": 0.1
}
},
"bar": {
"itemStyle": {
"borderRadius": 2
},
"backgroundStyle": {
"color": "rgb(250, 250, 252)",
"borderRadius": 2
}
},
"pie": {
"itemStyle": {
"borderRadius": 2,
"borderWidth": 2,
"borderColor": "#fff"
}
}
}

View File

@ -0,0 +1,179 @@
{
"color": [
"#e0e0e0",
"#88bbc1",
"#baa5ca",
"#d2ab8d",
"#aaa797",
"#a6bb93"
],
"darkMode": true,
"backgroundColor": "#202020",
"textStyle": {
"color": "rgba(255, 255, 255, 0.9)",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\""
},
"title": {
"textStyle": {
"color": "rgba(255, 255, 255, 0.9)",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontWeight": 600,
"fontSize": 16
},
"subtextStyle": {
"color": "rgba(255, 255, 255, 0.82)",
"fontSize": 12
}
},
"legend": {
"itemWidth": 14,
"itemHeight": 8,
"itemGap": 16,
"textStyle": {
"color": "rgba(255, 255, 255, 0.82)",
"fontSize": 12
}
},
"tooltip": {
"confine": true,
"backgroundColor": "#252525",
"borderColor": "rgba(255, 255, 255, 0.24)",
"borderRadius": 2,
"borderWidth": 1,
"padding": [
9,
12
],
"shadowBlur": 0,
"shadowColor": "rgba(0, 0, 0, 0.16)",
"textStyle": {
"color": "rgba(255, 255, 255, 0.9)",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontSize": 12
},
"axisPointer": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.24)",
"type": "dotted"
},
"crossStyle": {
"color": "rgba(255, 255, 255, 0.24)",
"type": "dotted"
},
"label": {
"backgroundColor": "rgba(255, 255, 255, 0.82)",
"color": "#202020"
}
}
},
"categoryAxis": {
"axisLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.24)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgba(255, 255, 255, 0.82)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.09)",
"type": "dotted"
}
}
},
"valueAxis": {
"axisLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.24)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgba(255, 255, 255, 0.82)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.09)",
"type": "dotted"
}
}
},
"timeAxis": {
"axisLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.24)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgba(255, 255, 255, 0.82)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.09)",
"type": "dotted"
}
}
},
"logAxis": {
"axisLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.24)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgba(255, 255, 255, 0.82)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgba(255, 255, 255, 0.09)",
"type": "dotted"
}
}
},
"line": {
"symbol": "diamond",
"symbolSize": 5,
"lineStyle": {
"width": 2
},
"areaStyle": {
"opacity": 0.06
}
},
"bar": {
"itemStyle": {
"borderRadius": 0
},
"backgroundStyle": {
"color": "#2b2b2b",
"borderRadius": 0
}
},
"pie": {
"itemStyle": {
"borderRadius": 0,
"borderWidth": 1,
"borderColor": "#202020"
}
}
}

View File

@ -0,0 +1,179 @@
{
"color": [
"#454545",
"#47747b",
"#766485",
"#926441",
"#807e73",
"#617456"
],
"darkMode": false,
"backgroundColor": "#fff",
"textStyle": {
"color": "rgb(31, 34, 37)",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\""
},
"title": {
"textStyle": {
"color": "rgb(31, 34, 37)",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontWeight": 600,
"fontSize": 16
},
"subtextStyle": {
"color": "rgb(51, 54, 57)",
"fontSize": 12
}
},
"legend": {
"itemWidth": 14,
"itemHeight": 8,
"itemGap": 16,
"textStyle": {
"color": "rgb(51, 54, 57)",
"fontSize": 12
}
},
"tooltip": {
"confine": true,
"backgroundColor": "#fff",
"borderColor": "rgb(224, 224, 230)",
"borderRadius": 2,
"borderWidth": 1,
"padding": [
9,
12
],
"shadowBlur": 0,
"shadowColor": "rgba(0, 0, 0, 0.16)",
"textStyle": {
"color": "rgb(31, 34, 37)",
"fontFamily": "v-sans, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"fontSize": 12
},
"axisPointer": {
"lineStyle": {
"color": "rgb(224, 224, 230)",
"type": "dotted"
},
"crossStyle": {
"color": "rgb(224, 224, 230)",
"type": "dotted"
},
"label": {
"backgroundColor": "rgb(51, 54, 57)",
"color": "#fff"
}
}
},
"categoryAxis": {
"axisLine": {
"lineStyle": {
"color": "rgb(224, 224, 230)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgb(51, 54, 57)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgb(239, 239, 245)",
"type": "dotted"
}
}
},
"valueAxis": {
"axisLine": {
"lineStyle": {
"color": "rgb(224, 224, 230)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgb(51, 54, 57)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgb(239, 239, 245)",
"type": "dotted"
}
}
},
"timeAxis": {
"axisLine": {
"lineStyle": {
"color": "rgb(224, 224, 230)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgb(51, 54, 57)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgb(239, 239, 245)",
"type": "dotted"
}
}
},
"logAxis": {
"axisLine": {
"lineStyle": {
"color": "rgb(224, 224, 230)"
}
},
"axisTick": {
"show": false
},
"axisLabel": {
"color": "rgb(51, 54, 57)",
"margin": 10,
"fontSize": 12
},
"splitLine": {
"lineStyle": {
"color": "rgb(239, 239, 245)",
"type": "dotted"
}
}
},
"line": {
"symbol": "diamond",
"symbolSize": 5,
"lineStyle": {
"width": 2
},
"areaStyle": {
"opacity": 0.06
}
},
"bar": {
"itemStyle": {
"borderRadius": 0
},
"backgroundStyle": {
"color": "#eeeeee",
"borderRadius": 0
}
},
"pie": {
"itemStyle": {
"borderRadius": 0,
"borderWidth": 1,
"borderColor": "#fff"
}
}
}

View File

@ -27,8 +27,7 @@ export interface LoadingOptions {
fontFamily: string // 字体系列
}
export type ChartTheme =
'macarons-dark' | 'macarons' | 'default' | string | null
export type ChartTheme = string | null
export interface RChartInst {
/**

View File

@ -1,42 +1,19 @@
import type { ChartThemeRawArray, ChartThemeRawModules } from '../types'
import type { ChartThemeRawArray } from '../types'
/**
*
* @see https://echarts.apache.org/zh/theme-builder.html
*
* @description
* 自动注册所有主题。
*
* 默认以文件名当作主题名称。
*
* 主题编辑器使用方法:
* 1. 配置、选择主题
* 2. 点击下载主题
* 3. 选择 json 类型,然后复制
* 4. 在 echart-themes 包中创建对应的 json 文件,文件名为主题名称
*/
export const getCustomEchartTheme = () => {
// 获取所有主题
const themeRawModules: Record<string, ChartThemeRawModules> =
import.meta.glob('../themes/**/*.json', {
eager: true,
})
const regex = /\/([^/]+)\.json$/
export const getCustomEchartTheme = (): ChartThemeRawArray[] => {
const modules = import.meta.glob<ChartThemeRawArray['theme']>(
'../themes/**/*.json',
{ eager: true, import: 'default' },
)
const names = new Set<string>()
const rawThemes = Object.keys(themeRawModules).reduce((pre, curr) => {
const name = curr.match(regex)?.[1]
return Object.entries(modules).map(([path, theme]) => {
const name = path.slice(path.lastIndexOf('/') + 1, -'.json'.length)
if (name) {
pre.push({
name,
theme: themeRawModules[curr].default,
})
if (names.has(name)) throw new Error(`[RChart] 重复的主题名:${name}`)
return pre
} else {
throw new Error(`[RChart Theme Error]: name ${curr} is invalid!`)
}
}, [] as ChartThemeRawArray[])
names.add(name)
return rawThemes
return { name, theme }
})
}

View File

@ -1,31 +1,27 @@
import type { LoadingOptions } from '../types'
import { color } from 'echarts/core'
import type { ChartThemeRawArray, LoadingOptions } from '../types'
/**
*
* @param options 加载自定义配置项
* @param theme 是否使用暗色主题
*
* @description
* chart 加载配置项。
*
* @see https://echarts.apache.org/zh/api.html#echartsInstance.showLoading
*
* @example
* const options = loadingOptions({ ...LoadingOptions })
*/
export const loadingOptions = (options?: LoadingOptions, theme = false) => {
return Object.assign({}, options, {
text: 'loading',
color: '#c23531',
textColor: theme ? '#fff' : '#000',
maskColor: theme ? 'rgba(0, 0, 0, 0.8)' : 'rgba(255, 255, 255, 0.8)',
export const loadingOptions = (
theme: ChartThemeRawArray['theme'] | undefined,
dark: boolean,
text: string,
overrides: Partial<LoadingOptions>,
): LoadingOptions => {
return {
text,
color: theme?.color?.[0] ?? (dark ? '#aabaff' : '#3b63d9'),
textColor: theme?.textStyle?.color ?? (dark ? '#e9eef7' : '#1d2a3e'),
maskColor:
color.modifyAlpha(theme?.backgroundColor, 0.9) ??
(dark ? 'rgba(23, 33, 49, 0.9)' : 'rgba(255, 255, 255, 0.9)'),
zlevel: 0,
fontSize: 12,
showSpinner: true,
spinnerRadius: 10,
lineWidth: 5,
spinnerRadius: 9,
lineWidth: 2,
fontWeight: 'normal',
fontStyle: 'normal',
fontFamily: 'sans-serif',
})
fontFamily: theme?.textStyle?.fontFamily ?? 'sans-serif',
...overrides,
}
}

View File

@ -6,7 +6,7 @@ import type { InjectionKey } from 'vue'
export interface UiServices {
locale?: () => string
dark?: () => boolean
chartTheme?: string
chartTheme?: string | (() => string)
translate?: (key: string, params?: Record<string, unknown>) => string
columnStorage?: ReturnType<typeof createStorage>
reportError?: (message: string) => void