govau / datavizkit

A fully featured data visualisation toolset built on top of Highcharts and React. Guide at http://datavizkit.surge.sh/.
MIT License
10 stars 2 forks source link

Implement a Dataset Controller Interface #190

Open elisechant opened 7 years ago

elisechant commented 7 years ago

Currently datavizkit only draws charts, where the application consuming it manages the data rehydration.

Proposed features:

Proposed shape: controllers.line

elisechant commented 7 years ago

maybe something like:

class BubbleDatasetController {
  constructor(data) {
    this._data = [];
    this.setData(data);
    return this;
  }
  getData() {
    return this._data;
  }
  setData(data) {
    if (data && data.length > 0) {
      this._data = this.transform(data).map(d => {
        // data points
        return {
          x: this.deriveX(),
          y: this.deriveY(),
          z: this.deriveZ(),
          color: this.deriveColor(),
        }
      });
    }
    return this._data;
  }
  transform(data) {
    return data;
  }
  deriveX() {
    throw new Error('Must define deriveX.');
  }
  deriveY() {
    throw new Error('Must define deriveY.');
  }
  deriveZ() {
    throw new Error('Must define deriveZ.');
  }
  deriveColor() {
    throw new Error('Must define deriveColor.');
  }
}

class SpecificBubbleDatasetController extends BubbleDatasetController {
  deriveX() {
    return '';
  }
  deriveY() {
    return '';
  }
  deriveZ() {
    return '';
  }
  deriveColor() {
    return '';
  }
}

export default SpecificBubbleDatasetController;