Skip to content

Instantly share code, notes, and snippets.

@panda01
Last active January 7, 2016 19:12
Show Gist options
  • Save panda01/eb120050eabdacef3438 to your computer and use it in GitHub Desktop.
Save panda01/eb120050eabdacef3438 to your computer and use it in GitHub Desktop.
Charts!!!
const Vector = require('vector');
const Tangible = require('tangible')
class Chart extends Tangible {
constructor(options) {
super(null, new Vector(options.width, options.height));
}
get margin() { return this._margin; }
set margin(obj) {
// only do a partial update if necessary
this._margin = _.assign({}, this.margin, obj);
}
get xAxis() { return this._xAxis; }
set xAxis(axis) {
this._xAxis = axis;
}
get yAxis() { return this._yAxis; }
set yAxis(axis) {
this._yAxis = axis;
}
get xScale() { return this._xScale; }
set xScale(scale) {
this._xScale = scale;
}
get yScale() { return this._yScale; }
set yScale(scale) {
this._yScale = scale;
}
}
const Vector = require('vector');
class Tangible {
constructor(position, dimension) {
this.pos = position;
this.dim = dimension;
}
get pos() { return this._pos; }
set pos(vector) {
this._pos = vector ? vector : new Vector();
}
get dim() { return this._dim; }
set dim(vector) {
this._dim = vector ? vector : new Vector();
}
}
class Vector {
constructor(x, y) {
this.x = x;
this.y = y;
}
get x() { return this._x; }
set x(val) {
// Should these accept decimals?
this._x = val ? parseInt(val, 10) : 0;
}
get y() { return this._y; }
set y(val) {
this._y = val ? parseInt(val, 10) : 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment