Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: icicle layout #64

Merged
merged 5 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/components/FlameGraph/FlameGraph.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Dimmer, Loader, Divider, Container, Button, Input } from 'semantic-ui-react'
import { Dimmer, Loader, Divider, Container, Button, Input, Dropdown } from 'semantic-ui-react'
import { pushBreadcrumb, popBreadcrumb } from '../../actions/Navbar'
import { connect } from 'react-redux'
import { flamegraph } from 'd3-flame-graph'
import { select } from 'd3-selection'
import 'd3-flame-graph/dist/d3-flamegraph.css'
import './flamegraph.less'
import queryString from 'query-string'
import { layout } from '../../config.jsx'

const styles = {
container: {
Expand All @@ -50,15 +51,23 @@ class FlameGraph extends Component {
'handleSearchClick',
'handleOnKeyDown',
'updateSearchQuery',
'handleLayoutChange',
].forEach((k) => {
this[k] = this[k].bind(this);
});

const preferredLayout = () => {
if(localStorage.getItem('layout')){
return localStorage.getItem('layout');
} else return layout.flame;
}

this.state = {
data: {},
loading: false,
chart: null,
searchTerm: '',
layout: preferredLayout()
};
}

Expand Down Expand Up @@ -128,6 +137,7 @@ class FlameGraph extends Component {
.transitionDuration(750)
.sort(true)
.title('')
.inverted(this.state.layout === layout.icicle)

var details = document.getElementById("details")
chart.details(details)
Expand Down Expand Up @@ -171,19 +181,39 @@ class FlameGraph extends Component {
this.props.history.push({search: params.toString(),});
}

handleLayoutChange(event, data) {
this.setState({layout: data.value}, () => {
this.state.chart
.inverted(this.state.layout === layout.icicle)
.resetZoom()
localStorage.setItem('layout', this.state.layout)
})
}

render() {
const searchButton =
<Button color='red' size='small' onClick={this.handleSearchClick}>
<Button.Content>Search</Button.Content>
</Button>

const layoutOptions = [
bahtiyarkaba marked this conversation as resolved.
Show resolved Hide resolved
{
text: "Flame",
value: layout.flame
},
{
text: "Icicle",
value: layout.icicle
}
]

return (
<div>
<Dimmer page inverted active={this.state.loading}>
<Loader size='huge' inverted>Loading</Loader>
</Dimmer>
<Container style={styles.container}>
<Container textAlign='right'>
<Dropdown selection options={layoutOptions} onChange={this.handleLayoutChange} defaultValue={this.state.layout} compact button />
<Button inverted color='red' size='small' onClick={this.handleResetClick}>
<Button.Content>
Reset Zoom
Expand Down
4 changes: 4 additions & 0 deletions src/config.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const layout = {
flame: 'flame',
icicle: 'icicle',
}