Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
VisualDL
提交
72fbe8be
V
VisualDL
项目概览
PaddlePaddle
/
VisualDL
大约 2 年 前同步成功
通知
89
Star
4655
Fork
642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
2
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
V
VisualDL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
72fbe8be
编写于
12月 06, 2022
作者:
R
RotPublic
提交者:
GitHub
12月 06, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixhistoram (#1177)
上级
26e029ae
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
37 deletion
+32
-37
frontend/packages/core/src/components/StackChart.tsx
frontend/packages/core/src/components/StackChart.tsx
+32
-37
未找到文件。
frontend/packages/core/src/components/StackChart.tsx
浏览文件 @
72fbe8be
...
...
@@ -18,16 +18,7 @@
import
*
as
chart
from
'
~/utils/chart
'
;
import
type
{
EChartsOption
,
ECharts
,
CustomSeriesOption
,
CustomSeriesRenderItem
,
AxisPointerComponentOption
,
TooltipComponentOption
,
GridComponentOption
,
Color
as
ZRColor
}
from
'
echarts
'
;
import
type
{
EChartsOption
as
EChartOption
,
ECharts
}
from
'
echarts
'
;
import
React
,
{
useCallback
,
useEffect
,
useImperativeHandle
,
useMemo
,
useRef
,
useState
}
from
'
react
'
;
import
{
WithStyled
,
primaryColor
,
transitionProps
}
from
'
~/utils/style
'
;
import
useECharts
,
{
Options
,
Wrapper
,
useChartTheme
}
from
'
~/hooks/useECharts
'
;
...
...
@@ -36,7 +27,6 @@ import GridLoader from 'react-spinners/GridLoader';
import
defaultsDeep
from
'
lodash/defaultsDeep
'
;
import
styled
from
'
styled-components
'
;
import
useThrottleFn
from
'
~/hooks/useThrottleFn
'
;
import
type
{
LinesSeriesOption
}
from
'
echarts/charts
'
;
const
Tooltip
=
styled
.
div
`
position: absolute;
...
...
@@ -48,14 +38,23 @@ const Tooltip = styled.div`
display: none;
${
transitionProps
([
'
color
'
,
'
background-color
'
])}
`
;
type
RenderItem
=
CustomSeriesRenderItem
;
// type RenderItem = EChartOption.SeriesCustom.RenderItem;
type
RenderItem
=
any
;
type
GetValue
=
(
i
:
number
)
=>
number
;
type
GetCoord
=
(
p
:
[
number
,
number
])
=>
[
number
,
number
];
export
type
StackChartProps
=
{
options
?:
EChart
s
Option
;
options
?:
EChartOption
;
title
?:
string
;
// data?: Partial<Omit<NonNullable<EChartOption<EChartOption.SeriesCustom>['series']>[number], 'data'>> & {
// minZ: number;
// maxZ: number;
// minX: number;
// maxX: number;
// minY: number;
// maxY: number;
// data: number[][];
// };
data
?:
any
;
loading
?:
boolean
;
zoom
?:
boolean
;
...
...
@@ -116,11 +115,11 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
[
getPoint
,
rawData
]
);
const
renderItem
=
useCallback
(
(
params
,
api
)
=>
{
const
renderItem
=
useCallback
<
RenderItem
>
(
(
params
:
any
,
api
:
any
)
=>
{
const
points
=
makePolyPoints
(
params
.
dataIndex
as
number
,
api
.
value
as
GetValue
,
api
.
coord
as
GetCoord
);
return
{
type
:
'
p
ath
'
,
type
:
'
p
olygon
'
,
silent
:
true
,
z
:
api
.
value
?.(
1
),
shape
:
{
...
...
@@ -147,9 +146,8 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
useEffect
(()
=>
{
dotsRef
.
current
=
dots
;
},
[
dots
]);
const
AxisPointer
=
options
?.
axisPointer
as
AxisPointerComponentOption
;
const
pointerLabelFormatter
=
AxisPointer
.
label
?.
formatter
;
const
axisPointer
:
any
=
options
?.
axisPointer
;
const
pointerLabelFormatter
=
axisPointer
?.
label
?.
formatter
;
// formatter change will cause echarts rerender axis pointer label
// so we need to use 2 refs instead of dots and highlight to get rid of dependencies of these two variables
...
...
@@ -161,15 +159,14 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
if
(
'
string
'
===
typeof
pointerLabelFormatter
)
{
return
pointerLabelFormatter
;
}
// return pointerLabelFormatter(params, dotsRef.current[highLightRef.current]);
return
pointerLabelFormatter
(
params
);
return
pointerLabelFormatter
(
params
,
dotsRef
.
current
[
highLightRef
.
current
]);
},
[
pointerLabelFormatter
]
);
const
theme
=
useChartTheme
();
const
chartOptions
=
useMemo
<
ECharts
Option
>
(()
=>
{
const
chartOptions
:
any
=
useMemo
<
EChart
Option
>
(()
=>
{
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const
{
color
,
colorAlt
,
toolbox
,
series
,
...
defaults
}
=
chart
;
...
...
@@ -240,8 +237,7 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
const
mouseout
=
useCallback
(()
=>
{
setHighlight
(
null
);
setDots
([]);
const
formatters
=
chartOptions
.
tooltip
as
TooltipComponentOption
;
if
(
formatters
.
formatter
)
{
if
(
chartOptions
.
tooltip
?.
formatter
)
{
setTooltip
(
''
);
if
(
tooltipRef
.
current
)
{
tooltipRef
.
current
.
style
.
display
=
'
none
'
;
...
...
@@ -257,13 +253,13 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
}
const
{
offsetX
,
offsetY
}
=
e
;
if
(
offsetY
<
negativeY
+
(
(
chartOptions
[
'
grid
'
]
as
GridComponentOption
)
?.
top
as
number
)
??
0
)
{
if
(
offsetY
<
negativeY
+
(
chartOptions
?.
grid
?.
top
as
number
)
??
0
)
{
mouseout
();
return
;
}
const
[
x
,
y
]
=
echarts
.
convertFromPixel
(
'
grid
'
,
[
offsetX
,
offsetY
])
as
[
number
,
number
];
const
seriesData
=
echart
?.
getOption
().
series
as
LinesSeriesOption
;
const
data
=
(
seriesData
.
data
as
number
[][])
??
[];
const
[
x
,
y
]
=
echarts
.
convertFromPixel
(
'
grid
'
as
any
,
[
offsetX
,
offsetY
])
as
[
number
,
number
];
const
seriesData
:
any
=
echarts
.
getOption
().
series
;
const
data
=
(
seriesData
[
0
]
.
data
as
number
[][])
??
[];
// find right on top step
const
steps
=
data
.
map
(
row
=>
row
[
1
]).
sort
((
a
,
b
)
=>
a
-
b
);
...
...
@@ -300,11 +296,10 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
}
// set tooltip
const
formatters
=
chartOptions
.
tooltip
as
TooltipComponentOption
;
if
(
formatters
.
formatter
)
{
if
(
chartOptions
.
tooltip
?.
formatter
)
{
setTooltip
(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
highlight
==
null
?
''
:
(
formatters
.
formatter
as
any
)?.(
dots
[
highlight
])
highlight
==
null
?
''
:
(
chartOptions
.
tooltip
?
.
formatter
as
any
)?.(
dots
[
highlight
])
);
if
(
tooltipRef
.
current
)
{
if
(
step
==
null
)
{
...
...
@@ -384,9 +379,9 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
}
});
}
else
{
const
seriesData
=
echart
.
getOption
().
series
as
LinesSeriesOption
;
const
data
=
(
seriesData
.
data
as
number
[][])
??
[];
const
getCoord
:
GetCoord
=
pt
=>
echart
.
convertToPixel
(
'
grid
'
,
pt
)
as
[
number
,
number
];
const
seriesData
:
any
=
echart
.
getOption
().
series
;
const
data
=
(
seriesData
[
0
]?
.
data
as
number
[][])
??
[];
const
getCoord
:
GetCoord
=
pt
=>
echart
.
convertToPixel
(
'
grid
'
as
any
,
pt
)
as
[
number
,
number
];
const
getValue
:
GetValue
=
i
=>
data
[
highlight
][
i
];
echart
.
setOption
({
graphic
:
{
...
...
@@ -430,7 +425,7 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
}
});
}
else
{
const
getCoord
:
GetCoord
=
pt
=>
echart
.
convertToPixel
(
'
grid
'
,
pt
)
as
[
number
,
number
];
const
getCoord
:
GetCoord
=
pt
=>
echart
.
convertToPixel
(
'
grid
'
as
any
,
pt
)
as
[
number
,
number
];
echart
.
setOption
({
graphic
:
{
elements
:
dots
.
map
((
dot
,
i
)
=>
{
...
...
@@ -449,7 +444,7 @@ const StackChart = React.forwardRef<StackChartRef, StackChartProps & WithStyled>
},
style
:
{
fill
:
'
#fff
'
,
stroke
:
(
chartOptions
.
color
as
ZRColor
[])
?.[
0
],
stroke
:
chartOptions
.
color
?.[
0
],
lineWidth
:
2
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录