-
Notifications
You must be signed in to change notification settings - Fork 84
Open
Description
I've noticed in much of the documentation and examples the common definition of reusable properties, such as: width, height, tickFormat, etc. These functions are bulky and not particularly dry in my opinion.
The following proof of concept illustrates the concept:
d3.chart("SomeChart", {
initialize: function(options) {
// Configurable properties.
this.prop("width");
this.prop("height");
// Configure dimensions.
this.width(960);
this.height(120);
},
// Create re-usable methods that act as getters/setters.
prop: function(name, callback) {
this[name] = function(val) {
if (arguments.length === 0) {
return this["_" + name];
}
// Reassign the value.
this["_" + name] = val;
if (callback) {
callback.call(this, val);
}
return this;
};
}
});
Is this a common enough task to warrant a convenience method within d3.chart itself? I think it could easily cut down on a significant amount of common repeated methods.
Metadata
Metadata
Assignees
Labels
No labels