Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-deboer committed Aug 10, 2017
1 parent d320ac3 commit df562bc
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 119 deletions.
41 changes: 20 additions & 21 deletions pkg/ui/src/components/ClusterPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { linkForResource } from '../routes'
import IconLogs from 'material-ui/svg-icons/action/receipt'
import IconShell from 'material-ui/svg-icons/hardware/computer'
import IconEdit from 'material-ui/svg-icons/editor/mode-edit'
import IconDelete from 'material-ui/svg-icons/action/delete'

import Popover from 'material-ui/Popover'
import Paper from 'material-ui/Paper'
Expand Down Expand Up @@ -538,27 +537,27 @@ class ClusterPage extends React.Component {
}
})))

class DeleteButton extends React.Component {
// class DeleteButton extends React.Component {

constructor(props) {
super(props);
this.state = {
disabled: props.disabled,
}
}

setDisabled = (disabled) => {
this.setState({disabled: disabled})
}

render() {
let { props } = this
return <FloatingActionButton {...props} disabled={this.state.disabled}>
<IconDelete/>
</FloatingActionButton>
}

}
// constructor(props) {
// super(props);
// this.state = {
// disabled: props.disabled,
// }
// }

// setDisabled = (disabled) => {
// this.setState({disabled: disabled})
// }

// render() {
// let { props } = this
// return <FloatingActionButton {...props} disabled={this.state.disabled}>
// <IconDelete/>
// </FloatingActionButton>
// }

// }


function renderFilters(props) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/src/components/ConfirmationDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import Dialog from 'material-ui/Dialog'
import FlatButton from 'material-ui/FlatButton'
import RaisedButton from 'material-ui/RaisedButton'
import { grey300, grey800, red900 } from 'material-ui/styles/colors'
import { grey300, grey800 } from 'material-ui/styles/colors'
import { Link } from 'react-router-dom'
import { linkForResource } from '../routes'

Expand Down
1 change: 0 additions & 1 deletion pkg/ui/src/components/EventViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
TableHeader,
TableHeaderColumn
} from 'material-ui/Table'
import * as moment from 'moment'
import sizeMe from 'react-sizeme'
import { eventType as eventTypeIcons } from './icons'
import { toHumanizedAge } from '../converters'
Expand Down
3 changes: 1 addition & 2 deletions pkg/ui/src/components/FilterBox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import {blueA400, grey200, grey300, grey500, grey800, blueA100, red900, white } from 'material-ui/styles/colors'
import { Link } from 'react-router-dom'
import {blueA400, blueA100 } from 'material-ui/styles/colors'
import ChipInput from 'material-ui-chip-input'
import Chip from 'material-ui/Chip'

Expand Down
5 changes: 1 addition & 4 deletions pkg/ui/src/components/ScaleDialog.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React from 'react'
import ReactDOM from 'react-dom'
import Dialog from 'material-ui/Dialog'
import FlatButton from 'material-ui/FlatButton'
import RaisedButton from 'material-ui/RaisedButton'
import TextField from 'material-ui/TextField'
import { grey300, grey800, red900 } from 'material-ui/styles/colors'
import { Link } from 'react-router-dom'
import { linkForResource } from '../routes'
import { grey300, grey800 } from 'material-ui/styles/colors'

export default class ScaleDialog extends React.PureComponent {

Expand Down
8 changes: 0 additions & 8 deletions pkg/ui/src/components/WorkloadCountsPanel.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import React from 'react'
import ReactDOM from 'react-dom'
import Dialog from 'material-ui/Dialog'
import FlatButton from 'material-ui/FlatButton'
import RaisedButton from 'material-ui/RaisedButton'
import TextField from 'material-ui/TextField'
import { grey300, grey800, red900 } from 'material-ui/styles/colors'
import { Link } from 'react-router-dom'
import { linkForResource } from '../routes'

export default class WorkloadCountsPanel extends React.PureComponent {

Expand Down
3 changes: 1 addition & 2 deletions pkg/ui/src/components/configuration-pane/DataPanel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import {Card, CardHeader, CardText} from 'material-ui/Card'
import { grey100, grey600 } from 'material-ui/styles/colors'
import { grey100 } from 'material-ui/styles/colors'
import {
Table,
TableBody,
Expand All @@ -9,7 +9,6 @@ import {
} from 'material-ui/Table'
import IconButton from 'material-ui/IconButton'
import IconMore from 'material-ui/svg-icons/navigation/more-horiz'
import IconCopy from 'material-ui/svg-icons/content/content-copy'
import Popover from 'material-ui/Popover'
import Paper from 'material-ui/Paper'
import Subheader from 'material-ui/Subheader'
Expand Down
14 changes: 7 additions & 7 deletions pkg/ui/src/components/dashboard/DiscreteBarChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ export default class DiscreteBarChart extends React.PureComponent {
.range([height, 0])

// Define and draw axes
var yAxis = d3.svg.axis()
.scale(y)
.orient('left')
.ticks(5)
.tickSize(-width, 0, 0)
.tickFormat( function(d) { return d } )
// var yAxis = d3.svg.axis()
// .scale(y)
// .orient('left')
// .ticks(5)
// .tickSize(-width, 0, 0)
// .tickFormat( function(d) { return d } )

var xAxis = d3.svg.axis()
.scale(x)
Expand Down Expand Up @@ -269,7 +269,7 @@ export default class DiscreteBarChart extends React.PureComponent {
return y(buckets) + y(0.0001)/*y(d.dy)*/
})

var rect = groups.selectAll('rect')
groups.selectAll('rect')
.data(function(d) { return d})
.enter()
.append('rect')
Expand Down
76 changes: 33 additions & 43 deletions pkg/ui/src/components/dashboard/HexagonChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function renderHexChart(items) {
let el = ReactFauxDOM.createElement('div')
let height = 100

var d;
let itemCount = items.length

// how many hexes will fit in each size increment?
Expand Down Expand Up @@ -55,7 +54,6 @@ function renderHexChart(items) {
return this.stream.point(x * dx / 2, -(y - (2 - (y & 1)) / 3) * dy / 2)
}
}))
let identity_generator = d3.geo.path().projection(function(d) { return d })

let svg = d3.select(el).append('svg').attr('width', width).attr('height', height)
let vis = svg.append('g').attr('transform', `translate(${radius+2},${radius+2})`)
Expand Down Expand Up @@ -197,13 +195,18 @@ function computeBorders(features, allFeatures) {
let prevPointKey = ''
let currentSeg = firstSegment
points.push(currentSeg[0])
// let processedSegments = {}

let reversed = false
let removeCurrentSegment = function(segs, currentSeg) {
let _filter = function(e) { return e !== currentSeg._key }
return segs.filter(_filter)
}

while (!!currentSeg) {
delete segments[currentSeg._key]

segmentKeysByPoint[currentSeg._k1] = segmentKeysByPoint[currentSeg._k1].filter(e => e !== currentSeg._key)
segmentKeysByPoint[currentSeg._k2] = segmentKeysByPoint[currentSeg._k2].filter(e => e !== currentSeg._key)
segmentKeysByPoint[currentSeg._k1] = removeCurrentSegment(segmentKeysByPoint[currentSeg._k1], currentSeg)
segmentKeysByPoint[currentSeg._k2] = removeCurrentSegment(segmentKeysByPoint[currentSeg._k2], currentSeg)

let pointToAdd = prevPointKey === currentSeg._k2 ? currentSeg[0] : currentSeg[1]

Expand All @@ -212,7 +215,6 @@ function computeBorders(features, allFeatures) {
} else {
points.push(pointToAdd)
}
// processedSegments[currentSeg._key]=true
// Now find the next segment
let pointKey = prevPointKey === currentSeg._k2 ? currentSeg._k1 : currentSeg._k2
let nextSegKey = segmentKeysByPoint[pointKey][0]
Expand All @@ -228,18 +230,6 @@ function computeBorders(features, allFeatures) {
return points
}

function lineDistance(x1,y1, x2, y2) {
var xs = 0;
var ys = 0;

xs = x2 - x1;
xs = xs * xs;

ys = y2 - y1;
ys = ys * ys;

return Math.sqrt(xs + ys);
}
/**
* Calculate the neighboring item indicies
* for a given item index; note that some
Expand Down Expand Up @@ -267,15 +257,15 @@ function neighbors(d, rows, itemCount) {
return n
}

function group(n, itemCount) {
if (n <= (itemCount / 3)) {
return 0
} else if (n <= (2 * itemCount / 3)) {
return 1
} else {
return 2
}
}
// function group(n, itemCount) {
// if (n <= (itemCount / 3)) {
// return 0
// } else if (n <= (2 * itemCount / 3)) {
// return 1
// } else {
// return 2
// }
// }

/**
*
Expand Down Expand Up @@ -308,19 +298,19 @@ function newHex(d) {
* i.e., the ending point of one segment matches the starting point of the next segment.
* @param {Array} segments an array of line segments, in the form of [[x1,y1],[x2,y2]]
*/
function segmentsContiguous(segments) {
let prevSeg = null
let consecutive = 0
for (let seg of segments) {
if (prevSeg) {
if (prevSeg[1][0] === seg[0][0] && prevSeg[1][1] === seg[0][1]) {
++consecutive
} else {
console.warn(`break after ${consecutive}: [${prevSeg[1][0]},${prevSeg[1][1]}] !== [${seg[0][0]},${seg[0][1]}]`)
consecutive = 0
}
}
prevSeg = seg
}
return consecutive === segments.length
}
// function segmentsContiguous(segments) {
// let prevSeg = null
// let consecutive = 0
// for (let seg of segments) {
// if (prevSeg) {
// if (prevSeg[1][0] === seg[0][0] && prevSeg[1][1] === seg[0][1]) {
// ++consecutive
// } else {
// console.warn(`break after ${consecutive}: [${prevSeg[1][0]},${prevSeg[1][1]}] !== [${seg[0][0]},${seg[0][1]}]`)
// consecutive = 0
// }
// }
// prevSeg = seg
// }
// return consecutive === segments.length
// }
5 changes: 0 additions & 5 deletions pkg/ui/src/components/dashboard/NodeHeatmap.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React from 'react'
// import { GridGenerator, HexGrid, Layout, Path, Hexagon, Text, Pattern, Hex } from 'react-hexgrid'
import { PieChart, Pie, Cell, ResponsiveContainer } from 'recharts'
import { blueA400, grey200, blueA100, red900, white } from 'material-ui/styles/colors'
import { zoneLabel } from '../../utils/filter-utils'
import UtilizationPieChart from './UtilizationPieChart'
import HexagonChart from './HexagonChart'
import d3 from 'd3'
import ReactFauxDOM from 'react-faux-dom'
import './NodeHeatmap.css'

const styles = {
Expand Down
14 changes: 1 addition & 13 deletions pkg/ui/src/components/dashboard/UtilizationPieChart.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import React from 'react'
import { PieChart, Pie, Cell, ResponsiveContainer } from 'recharts'
import { blueA400, grey600, blueA100, red900, white } from 'material-ui/styles/colors'
import IconButton from 'material-ui/IconButton'
import { blueA400, grey600 } from 'material-ui/styles/colors'
import './UtilizationPieChart.css'

const styles = {
legend: {
paddingTop: 20,
},
pieChartDiv: {
height: 100,
textAlign: 'center',
position: 'relative',
}
}

export default class UtilizationPieChart extends React.PureComponent {

render() {
Expand Down
17 changes: 8 additions & 9 deletions pkg/ui/src/components/filter-table/TableSortLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { TableHeaderColumn } from 'material-ui/Table'
import SortDesc from 'material-ui/svg-icons/navigation/arrow-drop-up'
import SortAsc from 'material-ui/svg-icons/navigation/arrow-drop-down'
import Sortable from 'material-ui/svg-icons/action/swap-vert'
import IconButton from 'material-ui/IconButton'
import FlatButton from 'material-ui/FlatButton'

const orderIcons = {
Expand Down Expand Up @@ -108,14 +107,14 @@ export default class TableSortLabel extends React.Component {

let { props } = this;

let iconStyle = {...styles.icon, ...props.iconStyle}
if (props.sortable) {
if (!props.active) {
iconStyle = {...iconStyle, ...styles.inactiveIcon, ...props.iconInactiveStyle}
}
} else {
iconStyle = {...styles.icon, ...styles.unsortableIcon}
}
// let iconStyle = {...styles.icon, ...props.iconStyle}
// if (props.sortable) {
// if (!props.active) {
// iconStyle = {...iconStyle, ...styles.inactiveIcon, ...props.iconInactiveStyle}
// }
// } else {
// iconStyle = {...styles.icon, ...styles.unsortableIcon}
// }

return (
<TableHeaderColumn style={props.style} key={props.key}>
Expand Down
7 changes: 4 additions & 3 deletions pkg/ui/src/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ export function decodeBase64(input) {
var enc1, enc2, enc3, enc4 = ""
var i = 0
// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
var base64test = /[^A-Za-z0-9\+\/\=]/g
// var base64test = /[^A-Za-z0-9\+\/\=]/g
var base64test = /[^A-Za-z0-9+/=]/g
if (base64test.exec(input)) {
alert("There were invalid base64 characters in the input text.\n" +
console.warn("There were invalid base64 characters in the input text.\n" +
"Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
"Expect errors in decoding.")
}
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "")
input = input.replace(base64test, "")
do {
enc1 = keyStr.indexOf(input.charAt(i++))
enc2 = keyStr.indexOf(input.charAt(i++))
Expand Down

0 comments on commit df562bc

Please sign in to comment.