diff --git a/Chart/Chart.js b/Chart/Chart.js index 1b9da05..1f25c93 100644 --- a/Chart/Chart.js +++ b/Chart/Chart.js @@ -7,19 +7,19 @@ this.title = { visible: true, - text: "Title", + text: "", anchor: "middle", position: "center" }; this.subtitle = { visible: true, - text: "This is a short subtitle", + text: "", anchor: "middle", position: "center" }; this.footer = { visible: true, - text: "(c) Orange Management Solutions", + text: "", anchor: "end", position: "right" }; @@ -107,7 +107,7 @@ jsOMS.Chart.prototype.setAxis = function (id, axis) { - this.axis[id] = axis; + this.axis[id] = jsOMS.merge(this.axis[id], axis); // Setting axis dimensions in case dataset existss if (Object.keys(this.dataset).length > 0) { @@ -143,7 +143,7 @@ jsOMS.Chart.prototype.setTitle = function (title) { - this.title = title; + this.title = jsOMS.merge(this.title, title); }; jsOMS.Chart.prototype.getTitle = function () @@ -183,7 +183,7 @@ jsOMS.Chart.prototype.setLegend = function (legend) { - this.legend = legend; + this.legend = jsOMS.merge(this.legend, legend); }; jsOMS.Chart.prototype.getLegend = function () @@ -332,7 +332,7 @@ let temp, pos = 0, topmargin = 0; /* No subtitle without title */ - if (this.subtitle !== undefined && this.subtitle.visible && this.title !== undefined && this.title.visible) { + if (this.subtitle !== undefined && this.subtitle.text !== '' && this.subtitle.visible && this.title !== undefined && this.title.text !== '' && this.title.visible) { pos = this.calculateHorizontalPosition(this.subtitle.position); temp = svg.append("text") @@ -353,7 +353,7 @@ } } - if (this.title !== undefined && this.title.visible) { + if (this.title !== undefined && this.title.text !== '' && this.title.visible) { pos = this.calculateHorizontalPosition(this.title.position); temp = svg.append("text") @@ -371,7 +371,7 @@ } } - if (this.footer !== undefined && this.footer.visible) { + if (this.footer !== undefined && this.footer.text !== '' && this.footer.visible) { let spacer = 0; // if no x axis available an element less will be drawn and the footer diff --git a/Chart/LineChart.js b/Chart/LineChart.js index 48aee3d..8f19222 100644 --- a/Chart/LineChart.js +++ b/Chart/LineChart.js @@ -68,6 +68,7 @@ height: box.height }; + // todo: allow ordinal data axis x = d3.scale.linear().range([ 0, this.chart.dimension.width @@ -83,6 +84,7 @@ ]); // axis + // todo: implement manual tick (e.g. .ticks(6)) setting for axis xAxis1 = d3.svg.axis().scale(x).tickFormat(function (d) { return self.chart.axis.x.tick.prefix + d; @@ -329,7 +331,8 @@ for (i = k = 1; k <= 3; i = ++k) { count = i; data.push(dataGen()); } - +/* var mychart = new jsOMS.Chart.LineChart('chart'); mychart.getChart().setData(data); mychart.draw(); +*/ \ No newline at end of file diff --git a/Chart/PieChart.js b/Chart/PieChart.js index 6759378..a63ccf5 100644 --- a/Chart/PieChart.js +++ b/Chart/PieChart.js @@ -87,8 +87,8 @@ return pie(d.points); }).enter().append('path') .attr("transform", "translate(" - + (this.chart.dimension.width / 2) + "," - + (this.chart.dimension.height / 2 - this.chart.margin.bottom - this.chart.margin.top + 10) + ")") + + ((this.chart.dimension.width - this.chart.margin.left - this.chart.margin.right) / 2 ) + "," + + ((this.chart.dimension.height - this.chart.margin.bottom - this.chart.margin.top) / 2) + ")") .attr('fill', function (d) { return self.chart.color(d.data.name); @@ -142,6 +142,10 @@ for (i = k = 1; k <= 1; i = ++k) { data.push(dataGen()); } +/* + var mychart = new jsOMS.Chart.PieChart('chart'); mychart.getChart().setData(data); mychart.draw(); + +*/ diff --git a/Message/Request/Request.js b/Message/Request/Request.js index 1dba3e2..a3ad82d 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -314,12 +314,18 @@ { if (self.xhr.readyState === 4 && self.xhr.status === 200) { self.success(self.xhr); + } else if(self.xhr.readyState === 2) { + // todo: handle server received request + } else if(self.xhr.readyState === 3) { + // todo: server is handling request + } else { + // todo: create handler for error returns + console.log(self.xhr) } }; if (this.type === jsOMS.Message.Request.RequestType.JSON) { if (typeof this.requestHeader !== 'undefined' && this.requestHeader['Content-Type'] === 'application/json') { - console.log(JSON.stringify(this.data)); self.xhr.send(JSON.stringify(this.data)); } else { self.xhr.send(this.queryfy(this.data)); diff --git a/Utils/oLib.js b/Utils/oLib.js index fa06261..712f206 100644 --- a/Utils/oLib.js +++ b/Utils/oLib.js @@ -264,20 +264,36 @@ */ jsOMS.merge = function (target, source) { - for (var p in source) { + let out = jsOMS.clone(target); + + for (let p in source) { try { - if (source[p].constructor == Object) { - target[p] = merge(target[p], source[p]); + // Property in destination object set; update its value. + if ( source[p].constructor==Object ) { + out[p] = jsOMS.merge(out[p], source[p]); } else { - target[p] = source[p]; + out[p] = source[p]; + } - } catch (e) { - target[p] = source[p]; + } catch(e) { + // Property in destination object not set; create it and set its value. + out[p] = source[p]; + } } - return target; + return out; }; + + /** + * todo: implement deep clone/copy + * @param obj + * @returns {*} + */ + jsOMS.clone = function (obj) + { + return obj; + } }(window.jsOMS = window.jsOMS || {}));