From 173a2d473943266a690296a187240c64eeef9e96 Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba" Date: Tue, 18 Aug 2015 15:32:49 -0500 Subject: [PATCH 1/5] adding machine learning support machine learning support for regressions --- ext/ml.js | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/ml.js b/ext/ml.js index 7e96221..6fd4902 100644 --- a/ext/ml.js +++ b/ext/ml.js @@ -58,4 +58,3 @@ jx.ml.mapreduce = function(data,fn_map,fn_reduce){ * The modules developed below will perform linear regression and logistic regression */ jx.ml.regression = {} - From e71d0615c378b4644bb5ced925f0201c9c0e1c6f Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba" Date: Fri, 11 Sep 2015 01:45:04 -0400 Subject: [PATCH 2/5] jqplot wrapper and rpc refactoring including HttpClient as the entry point so users will access it via HttpClient.instance. We think it's more descriptive --- ext/chart.js | 235 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 ext/chart.js diff --git a/ext/chart.js b/ext/chart.js new file mode 100644 index 0000000..05a578b --- /dev/null +++ b/ext/chart.js @@ -0,0 +1,235 @@ +/** + * This is a charting wrapper, it is designed to simplify the interface to d3 + * dependencies: + * - jqplot.js charting library http://d3js.org for documentation and more + * - utils.js has utilities and design patterns used for internal purposes + * - dom.js creates legend objects + */ + +if(!jx){ + var jx = {} +} +jx.chart = {} ; + + +jx.jqplot = {} +/*** +* adding dependencies and libraries in case they are overwhelming for users +* This +*/ +jx.jqplot.init = function(){ + body = document.getElementsByTagName('head') ; + + if(body != null){ + body = body [0] + link = jx.dom.get.instance('LINK') ; + link.href = 'https://the-phi.com/pub/js/jqplot/jqplot.css' ; + link.rel = 'stylesheet' + link.type = 'type/css' + document.head.appendChild(link); + var url = [ + 'https://the-phi.com/pub/js/jqplot/excanvas.js', + 'https://the-phi.com/pub/js/jqplot/jqplot.js', + 'https://the-phi.com/pub/js/jqplot/plugins/jqplot.mobile.js', + 'https://the-phi.com/pub/js/jqplot/plugins/jqplot.barRenderer.js', + 'https://the-phi.com/pub/js/jqplot/plugins/jqplot.donutRenderer.js', + 'https://the-phi.com/pub/js/jqplot/plugins/jqplot.categoryAxisRenderer.js', + 'https://the-phi.com/pub/js/jqplot/plugins/jqplot.canvasAxisLabelRenderer.js', + 'https://the-phi.com/pub/js/jqplot/plugins/jqplot.pointLabels.js', + 'https://the-phi.com/pub/js/jqplot/plugins/jqplot.canvasTextRenderer.js' + ] ; + // for(i in url){ + // script = jx.dom.get.instance('SCRIPT') ; + // script.setAttribute('src',url[i]) ; + // script.language = 'javascript' + // document.head.appendChild(script) + // } + jx.utils.patterns.visitor(url,function(_url_){ + script = jx.dom.get.instance('SCRIPT') ; + script.setAttribute('src',_url_) ; + script.language = 'javascript' + document.write(script.innerHTML) + + // document.head.appendChild(script) + }) + + } +} +jx.jqplot.line = {} +jx.jqplot.line.options= function(){ + var options = { + series:[{showMarker:true}], + grid:{ + drawGridLines:false, + background:'white', + borderColor:'white' + }, + seriesDefaults:{ + rendererOptions: { + smooth: true, + animation: { + show: true + } + }, + pointLabels: {show: false} + }, + axes:{ + xaxis:{ + tickOptions:{ + showGridline: true + }, + // label:'Angle (radians)' + + renderer: $.jqplot.CategoryAxisRenderer, + min:0, + pad:2 + }, + yaxis:{ + // label:'Cosine' + min:0, + tickOptions:{ + showGridline: false + }, + labelRenderer: $.jqplot.CanvasAxisLabelRenderer + } + }, + legend:{} + } ; + return options; +} +/** +* @id DOM identifier +* @series matrix of values to be ploted +* @labels xaxis labels +* @lnames names of series (vectors in the matrix) +*/ +jx.jqplot.line.render = function(id,series,labels,lnames){ + jx.dom.set.value(id,'') + var options = jx.jqplot.line.options() ; + options.axes.xaxis.ticks = labels ; + if(series.length > 1){ + options.legend.show = true + options.legend.location = 'ne' + options.legend.placement = 'outsideGrid' + options.series = lnames; + } + $.jqplot(id,series,options) +} + + +jx.jqplot.bar = {} +jx.jqplot.bar.options = function(){ + var options = { + grid:{ + background:'white', + drawGridLines:false, + borderColor:'white' + + + }, + seriesDefaults:{ + renderer:$.jqplot.BarRenderer, + + rendererOptions: { + highlightMouseDown: true, + // smooth: true, + animation: { + speed:900, + show: true + } + + }, + pointLabels: {show: true} + }, + axes: { + xaxis: { + tickOptions:{ + showGridline: false + }, + renderer: $.jqplot.CategoryAxisRenderer, + // ticks:labels, + showTickMarks:false, + pad:0 + }, + yaxis:{ + tickOptions:{ + showGridline: true + } + } + + }, + legend: { + // show: keys.length > 1, + location: 'ne', + xoffset:2, + placement: 'outsideGrid' + } + } + return options; +} +/** +* Creating a bar chart (columns actually) +* @id DOM identifier +* @series array of matrices of values (in the y-axis) +* @labels x-axis labels +* @lnames names of vectors in the series +*/ +jx.jqplot.bar.render = function(id,series,labels,lnames){ + jx.dom.set.value(id,'') + var options = jx.jqplot.bar.options() + options.axes.xaxis.ticks = labels ; + options.legend.show = true + options.series = lnames; + $.jqplot(id, series,options) + +} +jx.jqplot.stackedBar = {} +jx.jqplot.stackedBar.options = jx.jqplot.bar.options ; +jx.jqplot.stackedBar.render = function(id,series,label,lnames){ + jx.dom.set.value(id,'') + var options = jx.jqplot.stackedBar.options() + options.axes.xaxis.ticks = labels ; + options.legend.show = true + + options.series = lnames; + options.stackSeries= true, + // options.seriesDefaults.label = lnames[0]; + options.seriesDefaults.pointLabels.show= false; + $.jqplot(id, series,options) + +} + +jx.jqplot.donut = {} +jx.jqplot.donut.options= function(){ + var options = { + grid:{ + drawGridLines:false, + background:'transparent', + borderColor:'white' + }, + + seriesDefaults: { + + renderer:$.jqplot.DonutRenderer, + rendererOptions:{ + // fill:false, + sliceMargin: 3, + startAngle: -90, + showDataLabels: true, + // dataLabels: 'value' + } + }, + legend: { show:true, location: 'e' } + } + return options; +} +/** +* @id DOM identifier +* @series vector of values +* @labels labels of the values in the series +*/ +jx.jqplot.donut.render = function(id,series){ + jx.dom.set.value(id,'') + var options = jx.jqplot.donut.options() ; + $.jqplot(id,series,options) +} From f5a075fe99a27ef46695c802b813f8b173fc9f4b Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba" Date: Fri, 11 Sep 2015 01:48:48 -0400 Subject: [PATCH 3/5] refactoring and improving interfaces @TODO: add upload file handling --- rpc.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rpc.js b/rpc.js index 8b7bb68..c66d303 100755 --- a/rpc.js +++ b/rpc.js @@ -112,6 +112,15 @@ jx.ajax.get.instance = function(){ } + this.put = function(url,callback){ + this.send(url,callback,'PUT') ; + } + this.get = function(url,callback){ + this.send(url,callback,'GET') ; + } + this.post = function(url,callback){ + this.send(url,callback,'POST') ; + } }//-- end of the factory method return new factory() ; } @@ -119,3 +128,4 @@ jx.ajax.get.instance = function(){ // // backward compatibility jx.ajax.getInstance = jx.ajax.get.instance ; +HttpClient = jx.ajax.get ; From 579818d7aa81721f9f68389f113388bde599d458 Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba" Date: Sun, 13 Sep 2015 04:17:45 -0400 Subject: [PATCH 4/5] jx.dom.remove enhancement bug fix: jx.dom.remove must return the item that was removed just in case it needs to be processed --- dom.js | 1 + 1 file changed, 1 insertion(+) diff --git a/dom.js b/dom.js index 4c2530d..ca825f5 100644 --- a/dom.js +++ b/dom.js @@ -42,6 +42,7 @@ jx.dom.remove = function(id){ _item = id ; } _item.parentNode.removeChild(_item) ; + return _item ; } From a236f732cbecb63116793e2a4e5018511890b894 Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba" Date: Thu, 24 Sep 2015 10:00:29 -0400 Subject: [PATCH 5/5] added a convenience method (jx.utils.join) The function is designed to perform a cartesian product of 2 vectors of the same length. The preconditions must be enforced as always by the calling code @pre : v1.length == v2.length && v1.constructor == v2.constructor && v1.constructor == Array --- utils.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/utils.js b/utils.js index d92ea73..bc10207 100644 --- a/utils.js +++ b/utils.js @@ -89,6 +89,20 @@ jx.utils.unique = function (list,getKey){ }) } } +jx.utils.join = function(x,y){ + if(x.length != y.length){ + return [] + }else{ + var rec = x ; + for(var i in rec){ + // + //@TODO: Consider the case we are adding to a matrix + // + rec[i] = [x[i],y[i]] + } + return rec ; + } +} /** * Implementation of a few standard design patterns. Their use is user/dependent * For more information on how/when to use a design pattern please use google/wikipedia ;-) @@ -169,3 +183,4 @@ jx.utils.patterns.observer = function(lobservers,init){ * @return array containing casted type */ jx.utils.cast = jx.utils.patterns.visitor ; +