-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
159 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,61 @@ | ||
import { VisText } from '@antv/gpt-vis'; | ||
import { Descriptions, Space } from 'antd'; | ||
import { ConfigProvider, Descriptions, Space, theme } from 'antd'; | ||
import { usePrefersColor } from 'dumi'; | ||
import React from 'react'; | ||
|
||
export default () => { | ||
// dumi 文档当前的主题色 | ||
const [color] = usePrefersColor(); | ||
return ( | ||
<Descriptions bordered column={2} size="small"> | ||
<Descriptions.Item label="指标名 metric_name"> | ||
<VisText type="metric_name">DAU</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="指标值 metric_value"> | ||
<VisText type="metric_value" origin={9012334}> | ||
90.1w | ||
</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="其他指标 other_metric_value"> | ||
<VisText type="other_metric_value">30%</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="差值 delta_value"> | ||
<Space> | ||
<VisText type="delta_value_pos">100.33</VisText> | ||
<VisText type="delta_value_neg">100.33</VisText> | ||
</Space> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="比率 ratio_value"> | ||
<Space> | ||
<VisText type="ratio_value_pos">30%</VisText> | ||
<VisText type="ratio_value_neg">30%</VisText> | ||
</Space> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="贡献度 contribute_ratio"> | ||
<VisText type="contribute_ratio">20%</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="趋势描述 trend_desc"> | ||
<VisText type="trend_desc" origin={[1, 2, 6, 18, 24, 48]}> | ||
趋势上涨 | ||
</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="维度值 dim_value"> | ||
<VisText type="dim_value">杭州</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="时间描述 time_desc"> | ||
<VisText type="time_desc">2021-10-11</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="占比 proportion"> | ||
<VisText type="proportion">30%</VisText> | ||
</Descriptions.Item> | ||
</Descriptions> | ||
// 适配 antd 主题。待整体文档 demo 都适配主题后可以删除 | ||
// https://github.com/antvis/GPT-Vis/pull/24 | ||
<ConfigProvider | ||
theme={{ | ||
algorithm: color === 'dark' ? theme.darkAlgorithm : theme.defaultAlgorithm, | ||
}} | ||
> | ||
<Descriptions bordered column={2} size="small"> | ||
<Descriptions.Item label="指标名 metric_name"> | ||
<VisText type="metric_name">DAU</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="指标值 metric_value"> | ||
<VisText type="metric_value" origin={9012334}> | ||
90.1w | ||
</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="其他指标 other_metric_value"> | ||
<VisText type="other_metric_value">30%</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="差值 delta_value"> | ||
<Space> | ||
<VisText type="delta_value_pos">100.33</VisText> | ||
<VisText type="delta_value_neg">100.33</VisText> | ||
</Space> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="比率 ratio_value"> | ||
<Space> | ||
<VisText type="ratio_value_pos">30%</VisText> | ||
<VisText type="ratio_value_neg">30%</VisText> | ||
</Space> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="贡献度 contribute_ratio"> | ||
<VisText type="contribute_ratio">20%</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="趋势描述 trend_desc"> | ||
<VisText type="trend_desc" origin={[1, 2, 6, 18, 24, 48]}> | ||
趋势上涨 | ||
</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="维度值 dim_value"> | ||
<VisText type="dim_value">杭州</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="时间描述 time_desc"> | ||
<VisText type="time_desc">2021-10-11</VisText> | ||
</Descriptions.Item> | ||
<Descriptions.Item label="占比 proportion"> | ||
<VisText type="proportion">30%</VisText> | ||
</Descriptions.Item> | ||
</Descriptions> | ||
</ConfigProvider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export const TEXT_THEME = { | ||
fontSizeBase: 14, | ||
chart: { | ||
proportionShadowColor: '#CDDDFD', | ||
proportionFillColor: '#3471F9', | ||
lineStrokeColor: '#5B8FF9', | ||
}, | ||
light: { | ||
primaryColor: '#1677FF', | ||
default88Color: 'rgba(0, 0, 0, 0.88)', | ||
default65Color: 'rgba(0, 0, 0, 0.65)', | ||
posColor: '#FA541C', | ||
negColor: '#13A8A8', | ||
conclusionColor: '#1F0352', | ||
}, | ||
dark: { | ||
primaryColor: '#4B91FF', | ||
default88Color: 'rgba(255, 255, 255, 0.88)', | ||
default65Color: 'rgba(255, 255, 255, 0.65)', | ||
posColor: '#FA541C', | ||
negColor: '#13A8A8', | ||
conclusionColor: '#D8C3F3', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { findKey, get } from 'lodash'; | ||
import { DEFAULT_VIS_TEXT_CONFIG } from '../config'; | ||
import { TEXT_THEME } from '../theme'; | ||
|
||
/** | ||
* 自动适配暗黑模式 | ||
* @params type 类型 | ||
* @params color 当前颜色 | ||
* @params theme 当前主题 | ||
*/ | ||
export const getThemeColor = ({ | ||
type, | ||
color, | ||
theme, | ||
}: { | ||
type?: string; | ||
color: string | undefined; | ||
theme: 'dark' | 'light'; | ||
}) => { | ||
// 仅暗黑主题才处理 | ||
if (type && color && theme === 'dark') { | ||
const defaultLightColor = get(DEFAULT_VIS_TEXT_CONFIG, [type, 'color']); | ||
// 仅当前颜色为默认的浅色主题时才处理 | ||
if (color === defaultLightColor) { | ||
// 找到浅色主题的 token | ||
const token = findKey(TEXT_THEME.light, (i) => i === color); | ||
// 返回暗黑主题的对应 token 的颜色 | ||
if (token) return TEXT_THEME.dark[token as keyof typeof TEXT_THEME.dark]; | ||
} | ||
} | ||
return color; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './getThemeColor'; | ||
export * from './useAntdDarkAlgorithm'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ConfigProvider, theme as antdTheme } from 'antd'; | ||
import { isArray } from 'lodash'; | ||
import { useContext } from 'react'; | ||
|
||
const { darkAlgorithm } = antdTheme; | ||
|
||
/** 判断是否运用了 antd dark algorithm */ | ||
export const useAntdDarkAlgorithm = () => { | ||
const config = useContext(ConfigProvider.ConfigContext); | ||
const currentAlgorithm = config.theme?.algorithm; | ||
|
||
if (isArray(currentAlgorithm) && currentAlgorithm.includes(darkAlgorithm)) return true; | ||
return currentAlgorithm === darkAlgorithm; | ||
}; |