Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
8d9b7cfd
Commit
8d9b7cfd
authored
Nov 01, 2017
by
nikogu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update Pie responsive depend on root node width
parent
bdffd006
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
14 deletions
+46
-14
src/components/Charts/Pie/index.js
src/components/Charts/Pie/index.js
+38
-4
src/components/Charts/Pie/index.less
src/components/Charts/Pie/index.less
+8
-10
No files found.
src/components/Charts/Pie/index.js
View file @
8d9b7cfd
...
@@ -3,6 +3,7 @@ import G2 from 'g2';
...
@@ -3,6 +3,7 @@ import G2 from 'g2';
import
{
Divider
}
from
'
antd
'
;
import
{
Divider
}
from
'
antd
'
;
import
classNames
from
'
classnames
'
;
import
classNames
from
'
classnames
'
;
import
ReactFitText
from
'
react-fittext
'
;
import
ReactFitText
from
'
react-fittext
'
;
import
Debounce
from
'
lodash-decorators/debounce
'
;
import
equal
from
'
../equal
'
;
import
equal
from
'
../equal
'
;
import
styles
from
'
./index.less
'
;
import
styles
from
'
./index.less
'
;
...
@@ -10,10 +11,13 @@ import styles from './index.less';
...
@@ -10,10 +11,13 @@ import styles from './index.less';
class
Pie
extends
Component
{
class
Pie
extends
Component
{
state
=
{
state
=
{
legendData
:
[],
legendData
:
[],
legendBlock
:
true
,
};
};
componentDidMount
()
{
componentDidMount
()
{
this
.
renderChart
(
this
.
props
.
data
);
this
.
renderChart
();
this
.
resize
();
window
.
addEventListener
(
'
resize
'
,
this
.
resize
);
}
}
componentWillReceiveProps
(
nextProps
)
{
componentWillReceiveProps
(
nextProps
)
{
...
@@ -23,15 +27,42 @@ class Pie extends Component {
...
@@ -23,15 +27,42 @@ class Pie extends Component {
}
}
componentWillUnmount
()
{
componentWillUnmount
()
{
window
.
removeEventListener
(
'
resize
'
,
this
.
resize
);
if
(
this
.
chart
)
{
if
(
this
.
chart
)
{
this
.
chart
.
destroy
();
this
.
chart
.
destroy
();
}
}
}
}
@
Debounce
(
200
)
resize
=
()
=>
{
const
{
hasLegend
}
=
this
.
props
;
if
(
!
hasLegend
||
!
this
.
node
)
{
return
;
}
// antd xs size
if
(
this
.
root
.
parentNode
.
clientWidth
<=
480
)
{
if
(
!
this
.
state
.
legendBlock
)
{
this
.
setState
({
legendBlock
:
true
,
});
this
.
renderChart
();
}
}
else
if
(
this
.
state
.
legendBlock
)
{
this
.
setState
({
legendBlock
:
false
,
});
this
.
renderChart
();
}
}
handleRef
=
(
n
)
=>
{
handleRef
=
(
n
)
=>
{
this
.
node
=
n
;
this
.
node
=
n
;
}
}
handleRoot
=
(
n
)
=>
{
this
.
root
=
n
;
}
handleLegendClick
=
(
item
,
i
)
=>
{
handleLegendClick
=
(
item
,
i
)
=>
{
const
newItem
=
item
;
const
newItem
=
item
;
newItem
.
checked
=
!
newItem
.
checked
;
newItem
.
checked
=
!
newItem
.
checked
;
...
@@ -50,7 +81,9 @@ class Pie extends Component {
...
@@ -50,7 +81,9 @@ class Pie extends Component {
});
});
}
}
renderChart
(
data
)
{
renderChart
(
d
)
{
let
data
=
d
||
this
.
props
.
data
;
const
{
const
{
height
=
0
,
height
=
0
,
hasLegend
,
hasLegend
,
...
@@ -167,13 +200,14 @@ class Pie extends Component {
...
@@ -167,13 +200,14 @@ class Pie extends Component {
render
()
{
render
()
{
const
{
valueFormat
,
subTitle
,
total
,
hasLegend
,
className
,
style
}
=
this
.
props
;
const
{
valueFormat
,
subTitle
,
total
,
hasLegend
,
className
,
style
}
=
this
.
props
;
const
{
legendData
}
=
this
.
state
;
const
{
legendData
,
legendBlock
}
=
this
.
state
;
const
pieClassName
=
classNames
(
styles
.
pie
,
className
,
{
const
pieClassName
=
classNames
(
styles
.
pie
,
className
,
{
[
styles
.
hasLegend
]:
!!
hasLegend
,
[
styles
.
hasLegend
]:
!!
hasLegend
,
[
styles
.
legendBlock
]:
legendBlock
,
});
});
return
(
return
(
<
div
className
=
{
pieClassName
}
style
=
{
style
}
>
<
div
ref
=
{
this
.
handleRoot
}
className
=
{
pieClassName
}
style
=
{
style
}
>
<
ReactFitText
maxFontSize
=
{
25
}
>
<
ReactFitText
maxFontSize
=
{
25
}
>
<
div
className
=
{
styles
.
chart
}
>
<
div
className
=
{
styles
.
chart
}
>
<
div
ref
=
{
this
.
handleRef
}
style
=
{{
fontSize
:
0
}}
/
>
<
div
ref
=
{
this
.
handleRef
}
style
=
{{
fontSize
:
0
}}
/
>
...
...
src/components/Charts/Pie/index.less
View file @
8d9b7cfd
...
@@ -81,15 +81,13 @@
...
@@ -81,15 +81,13 @@
}
}
}
}
@media screen and (max-width: @screen-sm) {
.legendBlock {
.pie {
&.hasLegend .chart {
&.hasLegend .chart {
width: 100%;
width: 100%;
margin: 0 0 32px 0;
margin: 0 0 32px 0;
}
}
.legend {
.legend {
position: static;
position: static;
transform: none;
transform: none;
}
}
}
}
}
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