Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wisdom-components
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
wisdom-components
Commits
dcc62474
Commit
dcc62474
authored
Mar 14, 2024
by
周宏民
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pref: 图表宽高为0 时不显示,宽高变化时resize()
parent
d5b6ff85
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
12 deletions
+31
-12
package.json
packages/base-components/BasicChart/package.json
+2
-1
ECharts.js
packages/base-components/BasicChart/src/ECharts.js
+29
-11
No files found.
packages/base-components/BasicChart/package.json
View file @
dcc62474
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
"test"
:
"echo
\"
Error: run tests from root
\"
&& exit 1"
"test"
:
"echo
\"
Error: run tests from root
\"
&& exit 1"
},
},
"dependencies"
:
{
"dependencies"
:
{
"@babel/runtime"
:
"^7.17.9"
"@babel/runtime"
:
"^7.17.9"
,
"rc-resize-observer"
:
"1.4.0"
}
}
}
}
packages/base-components/BasicChart/src/ECharts.js
View file @
dcc62474
import
React
,
{
memo
,
useMemo
}
from
'react'
;
/*
* @Title:
* @Author: hongmye
* @Date: 2023-09-27 11:51:16
*/
import
{
ConfigProvider
}
from
'antd'
;
import
{
ConfigProvider
}
from
'antd'
;
import
classNames
from
'classnames'
;
import
classNames
from
'classnames'
;
import
ReactEcharts
from
'echarts-for-react'
;
import
ReactEcharts
from
'echarts-for-react'
;
import
{
omit
}
from
'lodash'
;
import
{
omit
}
from
'lodash'
;
import
ResizeObserver
from
'rc-resize-observer'
;
import
React
,
{
memo
,
useMemo
,
useState
}
from
'react'
;
import
buildOption
from
'./utils'
;
import
buildOption
from
'./utils'
;
const
ECharts
=
memo
(
const
ECharts
=
memo
(
React
.
forwardRef
((
props
,
ref
)
=>
{
React
.
forwardRef
((
props
,
ref
)
=>
{
const
{
getPrefixCls
}
=
React
.
useContext
(
ConfigProvider
.
ConfigContext
);
const
{
getPrefixCls
}
=
React
.
useContext
(
ConfigProvider
.
ConfigContext
);
const
prefixCls
=
getPrefixCls
(
'basic-chart'
);
const
prefixCls
=
getPrefixCls
(
'basic-chart'
);
const
[
isShow
,
setIsShow
]
=
useState
(
'hidden'
);
const
chartProps
=
omit
(
props
,
[
'className'
,
'option'
]);
const
chartProps
=
omit
(
props
,
[
'className'
,
'option'
]);
const
option
=
useMemo
(()
=>
{
const
option
=
useMemo
(()
=>
{
return
buildOption
(
props
.
option
);
return
buildOption
(
props
.
option
);
},
[
props
.
option
]);
},
[
props
.
option
]);
// const chartProps = pick(props, ['option', 'notMerge', 'lazyUpdate', 'style', 'className', 'theme', 'onChartReady', 'loadingOption', 'showLoading', 'onEvents', 'opts']);
if
(
ref
&&
ref
.
current
&&
ref
.
current
.
getEchartsInstance
)
{
if
(
ref
&&
ref
.
current
&&
ref
.
current
.
getEchartsInstance
)
{
ref
.
current
.
getEchartsInstance
().
clear
();
ref
.
current
.
getEchartsInstance
().
clear
();
ref
.
current
.
getEchartsInstance
().
setOption
(
option
);
ref
.
current
.
getEchartsInstance
().
setOption
(
option
);
ref
.
current
.
getEchartsInstance
().
resize
();
ref
.
current
.
getEchartsInstance
().
resize
();
}
}
const
onResize
=
({
width
,
height
})
=>
{
if
(
width
&&
height
)
{
setIsShow
(
'visible'
);
ref
?.
current
?.
getEchartsInstance
&&
ref
.
current
.
getEchartsInstance
().
resize
();
}
else
{
setIsShow
(
'hidden'
);
}
};
return
(
return
(
<
ReactEcharts
<
ResizeObserver
onResize
=
{
onResize
}
>
ref
=
{
ref
}
<
div
style
=
{{
width
:
'100%'
,
height
:
'100%'
,
visibility
:
isShow
}}
>
className
=
{
classNames
(
prefixCls
,
props
.
className
)}
<
ReactEcharts
option
=
{
option
}
ref
=
{
ref
}
style
=
{{
width
:
'100%'
,
height
:
'100%'
}}
className
=
{
classNames
(
prefixCls
,
props
.
className
)}
{...
chartProps
}
style
=
{{
width
:
'100%'
,
height
:
'100%'
}}
/
>
option
=
{
option
}
{...
chartProps
}
/
>
<
/div
>
<
/ResizeObserver
>
);
);
}),
}),
);
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment