timwis / vizwit

An interactive data visualization tool
http://vizwit.io
GNU General Public License v2.0
100 stars 35 forks source link

Add date/time chart #198

Closed timwis closed 6 years ago

timwis commented 7 years ago

Using Chart.js

timwis commented 7 years ago

I've got it rendering the data properly, but having a hard time setting up the "select date range" interaction. Posted on SO.

timwis commented 7 years ago

Chartjs doesn't have a way to select the date range, apparently. So we'll need to add that functionality ourselves (per the reply on SO above) or switch to another charting library. Britecharts is new and its "brush" chart has it.

timwis commented 7 years ago

Made some progress on selecting a range in a time series chart.

canvas.onpointerdown = function (evt) {
  const points = chart.getElementsAtEventForMode(evt, 'nearest', { intersect: false })
  const label = chart.data.labels[points[0]._index]
  console.log('down', label)
}

canvas.onpointerup = function (evt) {
  const points = chart.getElementsAtEventForMode(evt, 'nearest', { intersect: false })
  const label = chart.data.labels[points[0]._index]
  console.log('up', label)
}

Not sure pointer events are best practise (haven't encountered them before) relative to mouseup/mousedown but hopefully they're a way to handle touch events too.

Only thing missing here, really, is the visual indicator.

EDIT: demo of progress so far

timwis commented 6 years ago

Saved by plottable.js! See v2 branch for progress :D