Skip to content

Commit 2cc94b5

Browse files
author
mbrill-nt
committed
Animate Button now works upon first click.
1 parent d8ee61a commit 2cc94b5

File tree

2 files changed

+59
-55
lines changed

2 files changed

+59
-55
lines changed

src/panel/ServiceDependencyGraphPanelController.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface PanelState {
3232
}
3333

3434
export class ServiceDependencyGraphPanelController extends PureComponent<Props, PanelState> {
35+
3536
cy: cytoscape.Core | undefined;
3637

3738
ref: any;
@@ -204,6 +205,7 @@ export class ServiceDependencyGraphPanelController extends PureComponent<Props,
204205
controller={this}
205206
animate={false}
206207
showStatistics={false}
208+
settings={this.props.options}
207209
/>
208210
</div>
209211
</div>

src/panel/serviceDependencyGraph/ServiceDependencyGraph.tsx

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface PanelState {
1818
controller: ServiceDependencyGraphPanelController;
1919
cy?: cytoscape.Core | undefined;
2020
graphCanvas?: CanvasDrawer | undefined;
21-
animateButton?: string;
21+
animateButtonClass?: string,
2222
showStatistics: boolean;
2323
data: any;
2424
}
@@ -45,15 +45,23 @@ export class ServiceDependencyGraph extends PureComponent<PanelState, PanelState
4545

4646
initResize = true;
4747

48-
constructor(props: PanelState) {
49-
super(props);
50-
this.state = {
51-
...props,
52-
animateButton: 'fa fa-play-circle',
53-
showStatistics: false,
54-
};
55-
this.ref = React.createRef();
56-
this.templateSrv = getTemplateSrv();
48+
constructor(props: PanelState){
49+
super(props);
50+
51+
var animateButtonClass = "fa fa-play-circle";
52+
if(props.animate) {
53+
animateButtonClass = "fa fa-pause-circle";
54+
}
55+
56+
this.state = {
57+
...props,
58+
showStatistics: false,
59+
animateButtonClass: animateButtonClass,
60+
animate: false
61+
};
62+
63+
this.ref = React.createRef();
64+
this.templateSrv = getTemplateSrv();
5765
}
5866

5967
componentDidMount() {
@@ -210,19 +218,18 @@ export class ServiceDependencyGraph extends PureComponent<PanelState, PanelState
210218
}
211219

212220
toggleAnimation() {
213-
this.props.controller.state.options.animate = !this.state.controller.state.options.animate;
214-
215-
if (this.state.controller.state.options.animate) {
221+
var newValue = !this.state.animate
222+
var animateButtonClass = "fa fa-play-circle"
223+
if (newValue) {
216224
this.state.graphCanvas.startAnimation();
217-
this.setState({
218-
animateButton: 'fa fa-pause-circle',
219-
});
225+
animateButtonClass = "fa fa-pause-circle"
220226
} else {
221227
this.state.graphCanvas.stopAnimation();
222-
this.setState({
223-
animateButton: 'fa fa-play-circle',
224-
});
225228
}
229+
this.setState({
230+
animate: newValue,
231+
animateButtonClass: animateButtonClass
232+
});
226233
}
227234

228235
runLayout(unlockNodes = false) {
@@ -268,7 +275,6 @@ export class ServiceDependencyGraph extends PureComponent<PanelState, PanelState
268275
zoom: zoomLevel,
269276
});
270277
this.state.cy.zoom(zoomLevel);
271-
this.state.cy.center()
272278
}
273279

274280
updateStatisticTable() {
@@ -366,42 +372,38 @@ export class ServiceDependencyGraph extends PureComponent<PanelState, PanelState
366372
this._updateGraph(this.props.data);
367373
}
368374
return (
369-
<div className="graph-container" ng-show="!ctrl.getError()">
370-
<div className="service-dependency-graph">
371-
<div
372-
className="canvas-container"
373-
ref={ref => (this.ref = ref)}
374-
style={{ height: '100%', width: '100%' }}
375-
></div>
376-
<div className="zoom-button-container">
377-
<button className="btn navbar-button width-100" onClick={() => this.toggleAnimation()}>
378-
<i className={this.state.animateButton}></i>
379-
</button>
380-
<button className="btn navbar-button width-100" onClick={() => this.runLayout()}>
381-
<i className="fa fa-sitemap"></i>
382-
</button>
383-
<button className="btn navbar-button width-100" onClick={() => this.fit()}>
384-
<i className="fa fa-dot-circle-o"></i>
385-
</button>
386-
<button className="btn navbar-button width-100" onClick={() => this.zoom(+1)}>
387-
<i className="fa fa-plus"></i>
388-
</button>
389-
<button className="btn navbar-button width-100" onClick={() => this.zoom(-1)}>
390-
<i className="fa fa-minus"></i>
391-
</button>
392-
</div>
375+
<div className="graph-container">
376+
<div className="service-dependency-graph">
377+
<div className="canvas-container" ref={ ref => this.ref = ref} >
378+
379+
</div>
380+
<div className="zoom-button-container">
381+
<button className="btn navbar-button width-100" onClick={() => this.toggleAnimation()}>
382+
<i className={this.state.animateButtonClass}></i>
383+
</button>
384+
<button className="btn navbar-button width-100" onClick={() => this.runLayout()}>
385+
<i className="fa fa-sitemap"></i>
386+
</button>
387+
<button className="btn navbar-button width-100" onClick={() => this.fit()}>
388+
<i className="fa fa-dot-circle-o"></i>
389+
</button>
390+
<button className="btn navbar-button width-100" onClick={() => this.zoom(+1)}>
391+
<i className="fa fa-plus"></i>
392+
</button>
393+
<button className="btn navbar-button width-100" onClick={() => this.zoom(-1)}>
394+
<i className="fa fa-minus"></i>
395+
</button>
396+
</div>
397+
</div>
398+
<Statistics show = {this.state.showStatistics}
399+
selectionId = { this.selectionId }
400+
resolvedDrillDownLink= {this.resolvedDrillDownLink}
401+
selectionStatistics = { this.selectionStatistics }
402+
currentType = { this.currentType }
403+
showBaselines = {false}
404+
receiving = { this.receiving }
405+
sending = {this.sending}/>
393406
</div>
394-
<Statistics
395-
show={this.state.showStatistics}
396-
selectionId={this.selectionId}
397-
resolvedDrillDownLink={this.resolvedDrillDownLink}
398-
selectionStatistics={this.selectionStatistics}
399-
currentType={this.currentType}
400-
showBaselines={false}
401-
receiving={this.receiving}
402-
sending={this.sending}
403-
/>
404-
</div>
405407
);
406408
}
407409
}

0 commit comments

Comments
 (0)