Polish in prep for PR

pull/2940/head
Deniz Kusefoglu 2018-03-12 10:59:22 -07:00
parent 5c3275000c
commit ce5d6ca770
3 changed files with 26 additions and 30 deletions

View File

@ -15,7 +15,7 @@ import getRange, {getStackedRange} from 'shared/parsing/getRangeForDygraph'
import {DISPLAY_OPTIONS} from 'src/dashboards/constants' import {DISPLAY_OPTIONS} from 'src/dashboards/constants'
import {buildDefaultYLabel} from 'shared/presenters' import {buildDefaultYLabel} from 'shared/presenters'
import {numberValueFormatter} from 'src/utils/formatting' import {numberValueFormatter} from 'src/utils/formatting'
import {NULL_HOVER_TIME} from 'src/shared/constants/tableGraph'
import { import {
OPTIONS, OPTIONS,
LINE_COLORS, LINE_COLORS,
@ -188,20 +188,16 @@ class Dygraph extends Component {
onZoom(this.formatTimeRange(lower), this.formatTimeRange(upper)) onZoom(this.formatTimeRange(lower), this.formatTimeRange(upper))
} }
clampWithinGraphTimerange = timestamp => {
const [xRangeStart] = this.dygraph.xAxisRange()
return Math.max(xRangeStart, timestamp)
}
eventToTimestamp = ({pageX: pxBetweenMouseAndPage}) => { eventToTimestamp = ({pageX: pxBetweenMouseAndPage}) => {
const {left: pxBetweenGraphAndPage} = this.graphRef.getBoundingClientRect() const {left: pxBetweenGraphAndPage} = this.graphRef.getBoundingClientRect()
const graphXCoordinate = pxBetweenMouseAndPage - pxBetweenGraphAndPage const graphXCoordinate = pxBetweenMouseAndPage - pxBetweenGraphAndPage
const timestamp = this.dygraph.toDataXCoord(graphXCoordinate) const timestamp = this.dygraph.toDataXCoord(graphXCoordinate)
const clamped = this.clampWithinGraphTimerange(timestamp) const [xRangeStart] = this.dygraph.xAxisRange()
const clamped = Math.max(xRangeStart, timestamp)
return `${clamped}` return `${clamped}`
} }
highlightCallback = e => { handleMouseMove = e => {
const {onSetHoverTime} = this.props const {onSetHoverTime} = this.props
const newTime = this.eventToTimestamp(e) const newTime = this.eventToTimestamp(e)
if (onSetHoverTime) { if (onSetHoverTime) {
@ -210,10 +206,10 @@ class Dygraph extends Component {
this.setState({isNotHovering: false}) this.setState({isNotHovering: false})
} }
unhighlightCallback = () => { handleMouseOut = () => {
const {onSetHoverTime} = this.props const {onSetHoverTime} = this.props
if (onSetHoverTime) { if (onSetHoverTime) {
onSetHoverTime('0') onSetHoverTime(NULL_HOVER_TIME)
} }
this.setState({isNotHovering: true}) this.setState({isNotHovering: true})
} }
@ -361,8 +357,8 @@ class Dygraph extends Component {
}} }}
className="dygraph-child-container" className="dygraph-child-container"
style={dygraphStyle} style={dygraphStyle}
onMouseMove={this.highlightCallback} onMouseMove={this.handleMouseMove}
onMouseOut={this.unhighlightCallback} onMouseOut={this.handleMouseOut}
/> />
{staticLegend && {staticLegend &&
<StaticLegend <StaticLegend

View File

@ -3,6 +3,11 @@ import _ from 'lodash'
import classnames from 'classnames' import classnames from 'classnames'
import {timeSeriesToTableGraph} from 'src/utils/timeSeriesToDygraph' import {timeSeriesToTableGraph} from 'src/utils/timeSeriesToDygraph'
import {
NULL_COLUMN_INDEX,
NULL_ROW_INDEX,
NULL_HOVER_TIME,
} from 'src/shared/constants/tableGraph'
import {MultiGrid} from 'react-virtualized' import {MultiGrid} from 'react-virtualized'
@ -10,8 +15,8 @@ class TableGraph extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = {
hoveredColumnIndex: -1, hoveredColumnIndex: NULL_COLUMN_INDEX,
hoveredRowIndex: -1, hoveredRowIndex: NULL_ROW_INDEX,
} }
} }
@ -32,8 +37,11 @@ class TableGraph extends Component {
} }
handleMouseOut = () => { handleMouseOut = () => {
this.props.onSetHoverTime('0') this.props.onSetHoverTime(NULL_HOVER_TIME)
this.setState({hoveredColumnIndex: -1, hoveredRowIndex: -1}) this.setState({
hoveredColumnIndex: NULL_COLUMN_INDEX,
hoveredRowIndex: NULL_ROW_INDEX,
})
} }
cellRenderer = ({columnIndex, rowIndex, key, style, parent}) => { cellRenderer = ({columnIndex, rowIndex, key, style, parent}) => {
@ -99,21 +107,21 @@ class TableGraph extends Component {
> >
{data.length > 1 && {data.length > 1 &&
<MultiGrid <MultiGrid
fixedColumnCount={1}
fixedRowCount={1}
cellRenderer={this.cellRenderer}
columnCount={columnCount} columnCount={columnCount}
columnWidth={COLUMN_WIDTH} columnWidth={COLUMN_WIDTH}
height={tableHeight}
rowCount={rowCount} rowCount={rowCount}
rowHeight={ROW_HEIGHT} rowHeight={ROW_HEIGHT}
height={tableHeight}
width={tableWidth}
fixedColumnCount={1}
fixedRowCount={1}
enableFixedColumnScroll={true} enableFixedColumnScroll={true}
enableFixedRowScroll={true} enableFixedRowScroll={true}
scrollToRow={hoverTimeRow}
cellRenderer={this.cellRenderer}
hoveredColumnIndex={hoveredColumnIndex} hoveredColumnIndex={hoveredColumnIndex}
hoveredRowIndex={hoveredRowIndex} hoveredRowIndex={hoveredRowIndex}
scrollToRow={hoverTimeRow}
hoverTime={hoverTime} hoverTime={hoverTime}
width={tableWidth}
/>} />}
</div> </div>
) )

View File

@ -445,11 +445,3 @@ export const cellSupportsAnnotations = cellType => {
] ]
return !!supportedTypes.find(type => type === cellType) return !!supportedTypes.find(type => type === cellType)
} }
export const DYGRAPH_CELL_TYPES = [
'line',
'line-stacked',
'line-stepplot',
'line-plus-single-stat',
'bar',
]