artus9033 / chartjs-plugin-dragdata

Draggable data points plugin for Chart.js
MIT License
266 stars 56 forks source link

Extra data being removed for the range bar #81

Closed fairking closed 2 months ago

fairking commented 2 years ago

If additional data passed to the chart they being removed on drag and the chart not considered as a floatingBar.

data: [ point.from, point.to, point.value ]
  1. Consider the data has 2 or more indexes samplePoint.length >= 2:
    floatingBar = (samplePoint !== null) && Array.isArray(samplePoint) && samplePoint.length >= 2
  2. Return original dataPoint:
    if (diffFromLeft <= diffFromRight) {
            dataPoint[0] = newVal
            return dataPoint
        } else {
            dataPoint[1] = newVal
            return dataPoint
        }
  3. data argument is not used in code:
    function calcPosition(e, chartInstance, datasetIndex, index, data) {
chrispahm commented 2 years ago

@fairking great find! Also thanks for creating a PR, will review ASAP

fairking commented 2 years ago

Please consider to remove white spaces when compare changes: https://github.com/chrispahm/chartjs-plugin-dragdata/pull/82/commits/480c8aded35d840a717a8b159406770d832c7e26?diff=unified&w=1

artus9033 commented 2 months ago

Hi @fairking, as the new maintainer, I wanted to pick this one up. Certainly, the changes you suggest would solve the issue, yet AFAIK they are not officially supported (the docs state that the shape of a data point for the floating bar chart should [number, number]). Anyway, since supporting that doesn't come at any cost and chart.js's floating bar controller source also does not seem to prevent this, I will take a look into it.

artus9033 commented 2 months ago

Since in the meantime there have been numerous changes and your PR also includes some unrelated things, I will just apply your suggestions in a new PR.