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

Added interaction mode to 'nearest' to fixed cluttered tooltips #1402

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion cypress/tests/widgets/chart-options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import should from 'should'

/* eslint-disable cypress/no-unnecessary-waiting */
describe('Node/-RED Dashboard 2.0 - Chart Widget - chart options', () => {
it('sets tooltip `mode` to "x" for line charts', () => {
it('sets tooltip `mode` to "nearest" for line charts', () => {
joepavitt marked this conversation as resolved.
Show resolved Hide resolved
const chartName = 'line-chart-1'
const overrides = [
{
Expand Down
16 changes: 14 additions & 2 deletions ui/src/widgets/ui-chart/UIChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default {
chart: null,
hasData: false,
histogram: [], // populate later for bins per series
chartUpdateDebounceTimeout: null
chartUpdateDebounceTimeout: null,
tooltipDataset: []
}
},
computed: {
Expand Down Expand Up @@ -217,10 +218,21 @@ export default {
}
return true
},
filter: (tooltipItem) => {
filter: (tooltipItem, tooltipIndex) => {
if (this.props.chartType === 'histogram') {
// don't show tooltips for empty data points
return tooltipItem.parsed.y !== undefined && tooltipItem.parsed.y > 0
} else if (this.props.chartType === 'line') {
if (tooltipIndex === 0) {
// first element in the loop
this.tooltipDataset = []
}
if (this.tooltipDataset.indexOf(tooltipItem.datasetIndex) === -1) {
this.tooltipDataset.push(tooltipItem.datasetIndex)
return true
} else {
return false
}
}
return true
}
Expand Down