Permalink
Browse files

Don't assume MochiKit export to global namespace

MochiKit allows you to set MochiKit = {__export__: false}; to avoid
cluttering the global namespace. This patch allows PlotKit to work even
if that option is set, by always using fully qualified MochiKit
identifiers.
  • Loading branch information...
1 parent ca5e856 commit 400368da0605010617602c4bafe4b256870bcdce Martin Kleppmann committed Apr 13, 2009
Showing with 37 additions and 33 deletions.
  1. +1 −1 PlotKit/Base.js
  2. +14 −14 PlotKit/Canvas.js
  3. +4 −4 PlotKit/EasyPlot.js
  4. +7 −7 PlotKit/Layout.js
  5. +7 −6 PlotKit/SVG.js
  6. +4 −1 PlotKit/SweetCanvas.js
View
@@ -193,7 +193,7 @@ MochiKit.Base.update(PlotKit.Base, {
var makeColor = function(color, fraction) {
return color.lighterColorWithLevel(fraction);
};
- return MochiKit.Base.map(partial(makeColor, baseColor), fractions);
+ return MochiKit.Base.map(MochiKit.Base.partial(makeColor, baseColor), fractions);
},
excanvasSupported: function() {
View
@@ -156,7 +156,7 @@ PlotKit.CanvasRenderer.prototype.render = function() {
this.isFirstRender = false;
if (this.maxTries-- > 0) {
this.renderDelay = MochiKit.Async.wait(this.IEDelay);
- this.renderDelay.addCallback(bind(this.render, this));
+ this.renderDelay.addCallback(MochiKit.Base.bind(this.render, this));
}
return;
}
@@ -202,7 +202,7 @@ PlotKit.CanvasRenderer.prototype._renderBarChartWrap = function(data, plotFunc)
plotFunc(context, obj);
};
- MochiKit.Iter.forEach(data, bind(forEachFunc, this));
+ MochiKit.Iter.forEach(data, MochiKit.Base.bind(forEachFunc, this));
context.restore();
}
};
@@ -379,7 +379,7 @@ PlotKit.CanvasRenderer.prototype._renderAxis = function() {
context.closePath();
context.stroke();
- var label = DIV(labelStyle, tick[1]);
+ var label = MochiKit.DOM.DIV(labelStyle, tick[1]);
label.style.top = (y - this.options.axisLabelFontSize) + "px";
label.style.left = (x - this.options.padding.left - this.options.axisTickSize) + "px";
label.style.textAlign = "right";
@@ -388,7 +388,7 @@ PlotKit.CanvasRenderer.prototype._renderAxis = function() {
this.ylabels.push(label);
};
- MochiKit.Iter.forEach(this.layout.yticks, bind(drawTick, this));
+ MochiKit.Iter.forEach(this.layout.yticks, MochiKit.Base.bind(drawTick, this));
}
context.beginPath();
@@ -411,7 +411,7 @@ PlotKit.CanvasRenderer.prototype._renderAxis = function() {
context.closePath();
context.stroke();
- var label = DIV(labelStyle, tick[1]);
+ var label = MochiKit.DOM.DIV(labelStyle, tick[1]);
label.style.top = (y + this.options.axisTickSize) + "px";
label.style.left = (x - this.options.axisLabelWidth/2) + "px";
label.style.textAlign = "center";
@@ -420,7 +420,7 @@ PlotKit.CanvasRenderer.prototype._renderAxis = function() {
this.xlabels.push(label);
};
- MochiKit.Iter.forEach(this.layout.xticks, bind(drawTick, this));
+ MochiKit.Iter.forEach(this.layout.xticks, MochiKit.Base.bind(drawTick, this));
}
context.beginPath();
@@ -506,7 +506,7 @@ PlotKit.CanvasRenderer.prototype._renderPieAxis = function() {
attrib["top"] = (labely - this.options.axisLabelFontSize) + "px";
}
- var label = DIV({'style': attrib}, this.layout.xticks[i][1]);
+ var label = MochiKit.DOM.DIV({'style': attrib}, this.layout.xticks[i][1]);
this.xlabels.push(label);
MochiKit.DOM.appendChildNodes(this.container, label);
}
@@ -535,7 +535,7 @@ PlotKit.CanvasRenderer.prototype.clear = function() {
catch (e) {
this.isFirstRender = false;
this.clearDelay = MochiKit.Async.wait(this.IEDelay);
- this.clearDelay.addCallback(bind(this.clear, this));
+ this.clearDelay.addCallback(MochiKit.Base.bind(this.clear, this));
return;
}
}
@@ -599,16 +599,16 @@ PlotKit.CanvasRenderer.prototype.onmouseover = function(e) {
var layoutObject = this._resolveObject(e);
var eventObject = this._createEventObject(layoutObject, e);
if (eventObject != null)
- signal(this, "onmouseover", eventObject);
+ MochiKit.Signal.signal(this, "onmouseover", eventObject);
};
PlotKit.CanvasRenderer.prototype.onmouseout = function(e) {
var layoutObject = this._resolveObject(e);
var eventObject = this._createEventObject(layoutObject, e);
if (eventObject == null)
- signal(this, "onmouseout", e);
+ MochiKit.Signal.signal(this, "onmouseout", e);
else
- signal(this, "onmouseout", eventObject);
+ MochiKit.Signal.signal(this, "onmouseout", eventObject);
};
@@ -622,13 +622,13 @@ PlotKit.CanvasRenderer.prototype.onmousemove = function(e) {
}
if ((layoutObject != null) && (this.event_isinside == null))
- signal(this, "onmouseover", eventObject);
+ MochiKit.Signal.signal(this, "onmouseover", eventObject);
if ((layoutObject == null) && (this.event_isinside != null))
- signal(this, "onmouseout", eventObject);
+ MochiKit.Signal.signal(this, "onmouseout", eventObject);
if ((layoutObject != null) && (this.event_isinside != null))
- signal(this, "onmousemove", eventObject);
+ MochiKit.Signal.signal(this, "onmousemove", eventObject);
this.event_isinside = layoutObject;
//log("move", x, y);
View
@@ -61,27 +61,27 @@ PlotKit.EasyPlot = function(style, options, divElem, datasources) {
}
// load data sources
- if (isArrayLike(datasources)) {
+ if (MochiKit.Base.isArrayLike(datasources)) {
for (var i = 0; i < datasources.length; i++) {
if (typeof(datasources[i]) == "string") {
this.deferredCount++;
// load CSV via ajax
var d = MochiKit.Async.doSimpleXMLHttpRequest(datasources[i]);
d.addCallback(MochiKit.Base.bind(PlotKit.EasyPlot.onDataLoaded, this));
}
- else if (isArrayLike(datasources[i])) {
+ else if (MochiKit.Base.isArrayLike(datasources[i])) {
this.layout.addDataset("data-" + i, datasources[i]);
}
}
}
- else if (!isUndefinedOrNull(datasources)) {
+ else if (!MochiKit.Base.isUndefinedOrNull(datasources)) {
throw "Passed datasources are not Array like";
}
// setup canvas to render
if (CanvasRenderer.isSupported()) {
- this.element = CANVAS({"id": this.divElem.getAttribute("id") + "-canvas",
+ this.element = MochiKit.DOM.CANVAS({"id": this.divElem.getAttribute("id") + "-canvas",
"width": this.width,
"height": this.height}, "");
this.divElem.appendChild(this.element);
View
@@ -504,7 +504,7 @@ PlotKit.Layout.prototype._evaluateLineCharts = function() {
for (var setName in this.datasets) {
var dataset = this.datasets[setName];
if (PlotKit.Base.isFuncLike(dataset)) continue;
- dataset.sort(function(a, b) { return compare(parseFloat(a[0]), parseFloat(b[0])); });
+ dataset.sort(function(a, b) { return MochiKit.Base.compare(parseFloat(a[0]), parseFloat(b[0])); });
for (var j = 0; j < dataset.length; j++) {
var item = dataset[j];
var point = {
@@ -532,8 +532,8 @@ PlotKit.Layout.prototype._evaluateLineCharts = function() {
// Create the pie charts
PlotKit.Layout.prototype._evaluatePieCharts = function() {
- var map = PlotKit.Base.map;
- var items = PlotKit.Base.items;
+ var map = MochiKit.Base.map;
+ var items = MochiKit.Base.items;
var sum = MochiKit.Iter.sum;
var getter = MochiKit.Base.itemgetter;
@@ -579,7 +579,7 @@ PlotKit.Layout.prototype._evaluateLineTicksForXAxis = function() {
this.xticks.push([pos, label]);
}
};
- MochiKit.Iter.forEach(this.options.xTicks, bind(makeTicks, this));
+ MochiKit.Iter.forEach(this.options.xTicks, MochiKit.Base.bind(makeTicks, this));
}
else if (this.options.xNumberOfTicks) {
// we use defined number of ticks as hint to auto generate
@@ -617,7 +617,7 @@ PlotKit.Layout.prototype._evaluateLineTicksForYAxis = function() {
this.yticks.push([pos, label]);
}
};
- MochiKit.Iter.forEach(this.options.yTicks, bind(makeTicks, this));
+ MochiKit.Iter.forEach(this.options.yTicks, MochiKit.Base.bind(makeTicks, this));
}
else if (this.options.yNumberOfTicks) {
// We use the optionally defined number of ticks as a guide
@@ -651,7 +651,7 @@ PlotKit.Layout.prototype._evaluateBarTicks = function() {
var centerInBar = function(tick) {
return [tick[0] + (this.minxdelta * this.xscale)/2, tick[1]];
};
- this.xticks = MochiKit.Base.map(bind(centerInBar, this), this.xticks);
+ this.xticks = MochiKit.Base.map(MochiKit.Base.bind(centerInBar, this), this.xticks);
if (this.options.barOrientation == "horizontal") {
// swap scales
@@ -686,7 +686,7 @@ PlotKit.Layout.prototype._evaluatePieTicks = function() {
if (slice) {
if (isNil(label))
label = tick.v.toString();
- label = SPAN(null, label, " (" + formatter(slice.fraction) + ")");
+ label = MochiKit.DOM.SPAN(null, label, " (" + formatter(slice.fraction) + ")");
this.xticks.push([tick.v, label]);
}
}
View
@@ -54,6 +54,7 @@ PlotKit.SVGRenderer.SVGNS = 'http://www.w3.org/2000/svg';
PlotKit.SVGRenderer.prototype.__init__ = function(element, layout, options) {
var isNil = MochiKit.Base.isUndefinedOrNull;
+ var Color = MochiKit.Color.Color;
// default options
this.options = {
@@ -179,7 +180,7 @@ PlotKit.SVGRenderer.prototype._renderBarOrLine = function(data, plotFunc, startF
plotFunc(attrs, obj);
};
- MochiKit.Iter.forEach(data, bind(forEachFunc, this));
+ MochiKit.Iter.forEach(data, MochiKit.Base.bind(forEachFunc, this));
if (endFunc)
endFunc(attrs);
}
@@ -337,7 +338,7 @@ PlotKit.SVGRenderer.prototype._renderAxis = function() {
this._drawLine(x, y, x - 3, y, lineAttrs);
if (this.options.axisLabelUseDiv) {
- var label = DIV(labelStyle, tick[1]);
+ var label = MochiKit.DOM.DIV(labelStyle, tick[1]);
label.style.top = (y - this.options.axisLabelFontSize) + "px";
label.style.left = (x - this.options.padding.left + this.options.axisTickSize) + "px";
label.style.textAlign = "left";
@@ -378,7 +379,7 @@ PlotKit.SVGRenderer.prototype._renderAxis = function() {
}
};
- MochiKit.Iter.forEach(this.layout.yticks, bind(drawTick, this));
+ MochiKit.Iter.forEach(this.layout.yticks, MochiKit.Base.bind(drawTick, this));
}
this._drawLine(this.area.x, this.area.y, this.area.x, this.area.y + this.area.h, lineAttrs);
@@ -392,7 +393,7 @@ PlotKit.SVGRenderer.prototype._renderAxis = function() {
this._drawLine(x, y, x, y + this.options.axisTickSize, lineAttrs);
if (this.options.axisLabelUseDiv) {
- var label = DIV(labelStyle, tick[1]);
+ var label = MochiKit.DOM.DIV(labelStyle, tick[1]);
label.style.top = (y + this.options.axisTickSize) + "px";
label.style.left = (x - this.options.axisLabelWidth/2) + "px";
label.style.textAlign = "center";
@@ -417,7 +418,7 @@ PlotKit.SVGRenderer.prototype._renderAxis = function() {
}
};
- MochiKit.Iter.forEach(this.layout.xticks, bind(drawTick, this));
+ MochiKit.Iter.forEach(this.layout.xticks, MochiKit.Base.bind(drawTick, this));
}
this._drawLine(this.area.x, this.area.y + this.area.h, this.area.x + this.area.w, this.area.y + this.area.h, lineAttrs)
@@ -526,7 +527,7 @@ PlotKit.SVGRenderer.prototype._renderPieAxis = function() {
}
if (this.options.axisLabelUseDiv) {
- var label = DIV({'style': attrib}, this.layout.xticks[i][1]);
+ var label = MochiKit.DOM.DIV({'style': attrib}, this.layout.xticks[i][1]);
this.xlabels.push(label);
MochiKit.DOM.appendChildNodes(this.container, label);
}
View
@@ -69,6 +69,7 @@ PlotKit.SweetCanvasRenderer.prototype.__init__ = function(el, layout, opts) {
PlotKit.SweetCanvasRenderer.prototype._renderBarChart = function() {
var bind = MochiKit.Base.bind;
+ var Color = MochiKit.Color.Color;
var shadowColor = Color.blackColor().colorWithAlpha(0.1).toRGBString();
var prepareFakeShadow = function(context, x, y, w, h) {
@@ -135,6 +136,7 @@ PlotKit.SweetCanvasRenderer.prototype._renderBarChart = function() {
};
PlotKit.SweetCanvasRenderer.prototype._renderLineChart = function() {
+ var Color = MochiKit.Color.Color;
var context = this.element.getContext("2d");
var colorCount = this.options.colorScheme.length;
var colorScheme = this.options.colorScheme;
@@ -160,7 +162,7 @@ PlotKit.SweetCanvasRenderer.prototype._renderLineChart = function() {
ctx_.lineTo(this.area.w * point.x + this.area.x,
this.area.h * point.y + this.area.y);
};
- MochiKit.Iter.forEach(this.layout.points, partial(addPoint, ctx), this);
+ MochiKit.Iter.forEach(this.layout.points, MochiKit.Base.partial(addPoint, ctx), this);
ctx.lineTo(this.area.w + this.area.x,
this.area.h + this.area.y);
ctx.lineTo(this.area.x, this.area.y + this.area.h);
@@ -203,6 +205,7 @@ PlotKit.SweetCanvasRenderer.prototype._renderLineChart = function() {
};
PlotKit.SweetCanvasRenderer.prototype._renderPieChart = function() {
+ var Color = MochiKit.Color.Color;
var context = this.element.getContext("2d");
var colorCount = this.options.colorScheme.length;

0 comments on commit 400368d

Please sign in to comment.