Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-995 RequireJS + Google Material Charts #1289

Merged
merged 1 commit into from
Dec 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/google/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

this._tag = "div";

this._chartLibrary = "visualization";
this._selection = {};
}
Common.prototype = Object.create(HTMLWidget.prototype);
Expand Down Expand Up @@ -136,7 +137,7 @@
if (this._chart) {
return;
}
this._chart = new google.visualization[this._chartType](domNode);
this._chart = new google[this._chartLibrary][this._chartType](domNode);

var context = this;
google.visualization.events.addListener(this._chart, "select", function () {
Expand Down
2 changes: 1 addition & 1 deletion src/google/Common2D.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["d3", "../google/Common", "../api/I2DChart", "goog!visualization,1,packages:[corechart]"], factory);
define(["d3", "../google/Common", "../api/I2DChart"], factory);
} else {
root.google_Common2D = factory(root.d3, root.google_Common, root.api_I2DChart);
}
Expand Down
2 changes: 1 addition & 1 deletion src/google/CommonND.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["d3", "../google/Common", "../api/INDChart", "goog!visualization,1,packages:[corechart]"], factory);
define(["d3", "../google/Common", "../api/INDChart"], factory);
} else {
root.google_CommonND = factory(root.d3, root.google_Common, root.api_INDChart);
}
Expand Down
52 changes: 52 additions & 0 deletions src/google/MaterialBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"use strict";
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["d3", "require", "./CommonND"], factory);
} else {
root.google_MaterialBar = factory(root.d3, root.require, root.google_CommonND);
}
}(this, function (d3, require, CommonND) {

function MaterialBar() {
CommonND.call(this);

this._chartLibrary = "charts";
this._chartType = "Bar";
}
MaterialBar.prototype = Object.create(CommonND.prototype);
MaterialBar.prototype.constructor = MaterialBar;
MaterialBar.prototype._class += " google_MaterialBar";

MaterialBar.prototype.getChartOptions = function () {
var retVal = CommonND.prototype.getChartOptions.apply(this, arguments);
retVal.bars = "horizontal";
return retVal;
};

function materialHack(callback, depth) {
depth = depth || 0;
try {
require([(document.location.protocol === "https:" ? "https" : "http") + "://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js", "goog!visualization,1.1,packages:[bar]"], function () {
try {
require(["./CommonND"], function () {
callback();
});
} catch (e) {
materialHack(callback, depth + 1);
}
});
} catch (e) {
materialHack(callback, depth + 1);
}
}

MaterialBar.prototype.render = function (callback) {
var context = this;
var args = arguments;
materialHack(function() {
CommonND.prototype.render.apply(context, args);
});
};

return MaterialBar;
}));
8 changes: 8 additions & 0 deletions test/googleFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
.data(DataFactory.ND.subjects.data)
);
});
},
material: function (callback) {
require(["test/DataFactory", "src/google/MaterialBar"], function (DataFactory, Bar) {
callback(new Bar()
.columns(DataFactory.ND.subjects.columns)
.data(DataFactory.ND.subjects.data)
);
});
}
},
Line: {
Expand Down