Show and hide filtered series on graph

pull/10616/head
Andrew Watkins 2017-06-29 16:08:54 -07:00
parent d381312b9c
commit 5bd50fd587
1 changed files with 14 additions and 9 deletions

View File

@ -26,8 +26,8 @@ export default class Dygraph extends Component {
isSnipped: false,
}
this.getTimeSeries = ::this.getTimeSeries
this.sync = ::this.sync
this.getTimeSeries = ::this.getTimeSeries
this.handleSortLegend = ::this.handleSortLegend
this.handleLegendInputChange = ::this.handleLegendInputChange
this.handleSnipLabel = ::this.handleSnipLabel
@ -68,8 +68,6 @@ export default class Dygraph extends Component {
finalLineColors = LINE_COLORS
}
const dygraphComponent = this // eslint-disable-line consistent-this
const defaultOptions = {
plugins: [
new Dygraphs.Plugins.Crosshair({
@ -221,6 +219,8 @@ export default class Dygraph extends Component {
ruleValues,
isBarGraph,
} = this.props
const {filterText, legend} = this.state
const dygraph = this.dygraph
if (!dygraph) {
throw new Error(
@ -229,8 +229,15 @@ export default class Dygraph extends Component {
}
const timeSeries = this.getTimeSeries()
const visibility = timeSeries.map(() => true).map((b, i) => {
if (!legend.series[i]) {
return b
}
dygraph.updateOptions({
return !!legend.series[i].label.match(filterText)
})
const updateOptions = {
labels,
file: timeSeries,
axes: {
@ -246,12 +253,10 @@ export default class Dygraph extends Component {
underlayCallback: options.underlayCallback,
series: dygraphSeries,
plotter: isBarGraph ? multiColumnBarPlotter : null,
})
visibility,
}
// part of optional workaround for preventing updateOptions from breaking legend
// if (this.lastMouseMoveEvent) {
// dygraph.mouseMove_(this.lastMouseMoveEvent)
// }
dygraph.updateOptions(updateOptions)
dygraph.resize()
const {w} = this.dygraph.getArea()
this.props.setResolution(w)