Skip to content

Commit 2294016

Browse files
committed
Fixed Overlay Button placement issue.
1 parent 36c092d commit 2294016

File tree

2 files changed

+76
-18
lines changed

2 files changed

+76
-18
lines changed

example/DrillDown.js

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class DrillDown extends React.Component {
1313
super(props);
1414

1515
this.state = {
16+
showOverlaybtn: true,
17+
overlayZindex: 1,
1618
// Absolute position of Overlay Button
1719
positionH: (this.props.overlayBtn && this.props.overlayBtn.placement && this.props.overlayBtn.placement.includes('-')) ? this.props.overlayBtn.placement.split('-')[1] : 'right',
1820
positionV: (this.props.overlayBtn && this.props.overlayBtn.placement && this.props.overlayBtn.placement.includes('-')) ? this.props.overlayBtn.placement.split('-')[0] : 'top',
@@ -46,7 +48,7 @@ class DrillDown extends React.Component {
4648
if(typeof this.state.mappedIds[0] == 'number') {
4749
for (let i = 0; i < this.state.mappedIds.length; i++) {
4850
let plotPosition = this.state.mappedIds[i];
49-
if(!this.state.showDrillDown && index == i && plotPosition && plotPosition < idArrLength) {
51+
if(!this.state.showDrillDown && index == i && plotPosition != null && plotPosition < idArrLength) {
5052
this.setState({
5153
showDrillDown: true,
5254
selectedChild: plotPosition
@@ -68,6 +70,23 @@ class DrillDown extends React.Component {
6870
}
6971
}
7072

73+
renderComplete() {
74+
if(this.props && this.props.toggleParentOverlayBtnVisibility) {
75+
this.props.toggleParentOverlayBtnVisibility(false);
76+
}
77+
}
78+
79+
toggleParentOverlayBtnVisibility(visibility) {
80+
this.setState({showOverlaybtn: visibility});
81+
}
82+
83+
onClickOverlayBtn() {
84+
this.setState({ showDrillDown: false });
85+
if(this.props && this.props.toggleParentOverlayBtnVisibility && this.state.showDrillDown) {
86+
this.props.toggleParentOverlayBtnVisibility(true);
87+
}
88+
}
89+
7190
render() {
7291
// In-line style for overlay button
7392
const btnStyle = {
@@ -80,13 +99,11 @@ class DrillDown extends React.Component {
8099
fontWeight: `${this.state.fontWeight}`,
81100
position: 'absolute',
82101
[this.state.positionH]: `${this.state.margin}`,
83-
// left: `${this.props.width - 50}px`,
84102
[this.state.positionV]: `${this.state.margin}`,
85103
cursor: 'pointer',
104+
// zIndex: this.state.overlayZindex
86105
};
87106

88-
console.log(btnStyle);
89-
90107
// In-line style for root element of DrillDown component
91108
const rootStyle = {
92109
position: 'relative',
@@ -101,15 +118,23 @@ class DrillDown extends React.Component {
101118
{/* Displaying Correct Drilled Down Chart. */}
102119
{ React.cloneElement(
103120
this.props.children[this.state.selectedChild],
104-
{ width: this.props.width, height: this.props.height }
121+
{
122+
width: this.props.width,
123+
height: this.props.height,
124+
onRender: this.renderComplete.bind(this),
125+
// overlayBtn: this.props.overlayBtn,
126+
toggleParentOverlayBtnVisibility: this.toggleParentOverlayBtnVisibility.bind(this)
127+
}
105128
)}
106-
<span style={ btnStyle }
107-
onClick={() => this.setState({ showDrillDown: false })}>
108-
{
109-
this.props.overlayBtn && this.props.overlayBtn.message ?
110-
this.props.overlayBtn.message : 'Back'
111-
}
112-
</span>
129+
{ this.state.showOverlaybtn ?
130+
<span style={ btnStyle }
131+
onClick={this.onClickOverlayBtn.bind(this)}>
132+
{
133+
this.props.overlayBtn && this.props.overlayBtn.message ?
134+
this.props.overlayBtn.message : 'Back'
135+
}
136+
</span> : null
137+
}
113138
</div>
114139
);
115140
} else {

example/Example.js

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const thirdDataSource = {
118118
}]
119119
};
120120

121-
const mappedIdsIntegers = [1, null, 2, null, 0];
121+
const mappedIdsIntegers = [0, 1, 2, 3, null];
122122

123123
const mappedIdsObjects = [
124124
{
@@ -140,7 +140,7 @@ class Example extends React.Component {
140140
super(props);
141141

142142
this.state = {
143-
mappedIds: mappedIdsObjects,
143+
mappedIds: mappedIdsIntegers,
144144
dataSource: {
145145
chart: {
146146
caption: 'PARENT',
@@ -174,7 +174,7 @@ class Example extends React.Component {
174174

175175
render() {
176176
return (
177-
<div style={{display: 'flex', flexDirection: 'row'}}>
177+
<div style={{ display: 'flex', flexDirection: 'row' }}>
178178
<DrillDown
179179
type="column2d"
180180
width='600'
@@ -193,13 +193,27 @@ class Example extends React.Component {
193193
dataSource={this.state.dataSource}
194194
mappedIds={this.state.mappedIds}>
195195
{/* Further Drilled Down */}
196-
<DrillDown
196+
<DrillDown
197197
type="column2d"
198198
width='600'
199199
height='400'
200200
dataFormat="JSON"
201+
overlayBtn={{ //This object holds the style of the overlay back button.
202+
message: 'REVERT',
203+
fontSize: '14px',
204+
placement: 'top-right',
205+
margin: '10px'
206+
// position
207+
}}
201208
dataSource={zerothDataScource}
202-
mappedIds={[0, 2, 1]}>
209+
mappedIds={[0, 1, 2]}>
210+
<DrillDown
211+
type="column2d"
212+
width='600'
213+
height='400'
214+
dataFormat="JSON"
215+
dataSource={zerothDataScource}
216+
mappedIds={[0, 1, 2]}>
203217
<ReactFC
204218
type="bar2d"
205219
width='800'
@@ -218,6 +232,25 @@ class Example extends React.Component {
218232
height='100'
219233
dataFormat="JSON"
220234
dataSource={thirdDataSource} />
235+
</DrillDown>
236+
<ReactFC
237+
type="bar2d"
238+
width='800'
239+
height='300'
240+
dataFormat="JSON"
241+
dataSource={firstDataSource} />
242+
<ReactFC
243+
type="pie2d"
244+
width='200'
245+
height='400'
246+
dataFormat="JSON"
247+
dataSource={secondDataSource} />
248+
<ReactFC
249+
type="column2d"
250+
width='100'
251+
height='100'
252+
dataFormat="JSON"
253+
dataSource={thirdDataSource} />
221254
</DrillDown>
222255
<ReactFC
223256
type="pie2d"
@@ -238,7 +271,7 @@ class Example extends React.Component {
238271
dataFormat="JSON"
239272
dataSource={thirdDataSource} />
240273
</DrillDown>
241-
<div style={{height: 300, backgroundColor:'red', width: 400}}></div>
274+
<div style={{ height: 300, backgroundColor: 'red', width: 400 }}></div>
242275
</div>
243276
)
244277
}

0 commit comments

Comments
 (0)