HighChart = function(containerId, options) {
new Application.highChart(containerId, options);
};
if (Application === "undefined" || !Application) {
var Application = {};
}
Application.highChart = function() {
this._init.apply(this, arguments);
};
Application.highChart.prototype = {
_containerId : null,
_options : null,
_workId : null,
_fileName : null,
_highChartContainerId : null,
_appProperty : null,
_default : {
filterNamespace : "http://linkdata.org/",
propertyFilterNamespace : "http://linkdata.org/property",
propertyFilterExpression : "Expression",
subjectUriPhrase : "http://atted.jp/data/locus/",
subjectPPDBUriPhrase : "http://ppdb.agr.gifu-u.ac.jp/ppdb/cgi-bin/display.cgi?organism=At&gene=",
selectSubjectClass : "selectSubject",
drawArea : "drawArea"
},
_init : function(containerId, options) {
this._containerId = containerId;
this._options = $.extend({}, this._default, options);
this._workId = this._options.workId;
this._fileName = this._options.fileName;
var date = new Date();
this._highChartContainerId = "high_chart_" + date.getTime();
this._initAppProperty(this._options);
this._initView();
this._initSelect();
},
_initAppProperty : function(opts) {
var obj = {
workId : opts.workId,
fileName : opts.fileName
};
this._appProperty = new Application.motifProperty(obj);
},
_initView : function() {
var self = this;
var sb = [];
sb[sb.length] = "<div class='row'>";
sb[sb.length] = "<div class='label left'>Select Subject</div>";
sb[sb.length] = "<div class='left'>";
sb[sb.length] = "<select class='" + self._default.selectSubjectClass + "'>";
sb[sb.length] = "<option value='" + -1 + "'>-- Select Subject --</option>";
$.each(LinkData.getSubjects(self._workId, self._fileName), function(subKey, subValue) {
var label = self._getLabel(subValue);
sb[sb.length] = "<option value='" + subValue + "'>" + label + "</option>";
});
sb[sb.length] = "</select>";
sb[sb.length] = "</div>";
sb[sb.length] = "</div>";
sb[sb.length] = "<div id='" + self._highChartContainerId + "'></div>";
$("#" + this._containerId).append(sb.join(""));
},
_initSelect : function() {
var self = this;
$select = $("#" + self._containerId + " ." + self._default.selectSubjectClass);
$select.change(function() {
var subject = $("option:selected", this).val();
var dataArray = self._getDataArray(self._workId, self._fileName, subject);
var xCategory = self._getXCategory(self._workId, self._fileName, subject);
self._drawChart(self._highChartContainerId, dataArray, xCategory);
});
},
_getDataArray : function(workId, fileName, subject) {
var self = this;
var tripleList = LinkData.getTriplesBySubject(workId, fileName, subject);
var dataArray = [];
var dataObject = {};
var array = [];
var duplicateProperty = [];
$.each (tripleList, function(tKey, tValue) {
var property = tValue.property;
if (property.indexOf(self._options.filterNamespace) == -1) {
return;
}
if ($.inArray(property, duplicateProperty) > -1) {
return;
}
if (property.indexOf(self._options.propertyFilterNamespace) == -1 || property.indexOf(self._options.propertyFilterExpression) > -1) {
array.push(parseFloat(tValue.object));
duplicateProperty.push(property);
}