node-red-contrib-prib-functions 0.18.0 → 0.20.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/codeql-analysis.yml +3 -3
- package/.github/workflows/npmpublish.yml +6 -6
- package/.vs/VSWorkspaceState.json +7 -0
- package/.vs/node-red-contrib-prib-functions/v17/.wsuo +0 -0
- package/README.md +22 -19
- package/arima/index.js +18 -0
- package/dataAnalysis/arrayAllRowsSwap.js +15 -0
- package/dataAnalysis/arrayCompareToPrecision.js +34 -0
- package/dataAnalysis/arrayDifference.js +14 -0
- package/dataAnalysis/arrayDifferenceSeasonal.js +15 -0
- package/dataAnalysis/arrayDifferenceSeasonalSecondOrder.js +20 -0
- package/dataAnalysis/arrayDifferenceSecondOrder.js +14 -0
- package/dataAnalysis/arrayForEachRange.js +38 -0
- package/dataAnalysis/arrayOverlay.js +13 -0
- package/dataAnalysis/arrayProduct.js +11 -0
- package/dataAnalysis/arrayRandom.js +14 -0
- package/dataAnalysis/arrayReduceRange.js +11 -0
- package/dataAnalysis/arrayScale.js +11 -0
- package/dataAnalysis/arraySum.js +11 -0
- package/dataAnalysis/arraySumSquared.js +11 -0
- package/dataAnalysis/arraySwap.js +11 -0
- package/dataAnalysis/dataAnalysis.html +31 -14
- package/dataAnalysis/dataAnalysis.js +10 -1
- package/dataAnalysis/generateMatrixFunction.js +89 -0
- package/dataAnalysis/generateVectorFunction.js +25 -0
- package/dataAnalysis/pca.js +546 -0
- package/dataAnalysis/svd.js +239 -0
- package/documentation/loadInjector.png +0 -0
- package/echart/echart.html +68 -0
- package/echart/echart.js +85 -0
- package/echart/icons/chart-671.png +0 -0
- package/echart/lib/echarts.js +95886 -0
- package/lib/Chart.js +177 -0
- package/lib/Column.js +99 -0
- package/lib/GraphDB.js +14 -0
- package/lib/Table.js +185 -0
- package/lib/objectExtensions.js +361 -0
- package/matrix/matrix.js +50 -50
- package/matrix/matrixNode.html +144 -154
- package/matrix/matrixNode.js +26 -9
- package/monitor/BarGauge.js +8 -0
- package/monitor/Dataset.js +29 -0
- package/monitor/DialGauge.js +109 -0
- package/monitor/DialNeedle.js +36 -0
- package/monitor/Format.js +74 -0
- package/monitor/centerElement.js +14 -0
- package/monitor/compareElements.js +95 -0
- package/monitor/defs.js +23 -0
- package/monitor/extensions.js +906 -0
- package/monitor/functions.js +36 -0
- package/monitor/json2xml.js +103 -0
- package/monitor/monitorSystem.html +198 -0
- package/monitor/monitorSystem.js +322 -0
- package/monitor/svgHTML.js +179 -0
- package/monitor/svgObjects.js +64 -0
- package/package.json +31 -8
- package/test/00-objectExtensions.js +94 -0
- package/test/01-base.js +88 -0
- package/test/04-tables.js +33 -0
- package/test/data/.config.nodes.json +608 -0
- package/test/data/.config.nodes.json.backup +608 -0
- package/test/data/.config.runtime.json +4 -0
- package/test/data/.config.runtime.json.backup +3 -0
- package/test/data/.config.users.json +21 -0
- package/test/data/.config.users.json.backup +21 -0
- package/test/data/.flow.json.backup +3433 -0
- package/test/data/float32vector10.npy +0 -0
- package/test/data/flow.json +3433 -0
- package/test/data/int2matrix2x3.npy +0 -0
- package/test/data/package-lock.json +158 -0
- package/test/data/package.json +11 -0
- package/test/data/settings.js +544 -0
- package/test/dataAnalysisExtensions.js +472 -0
- package/test/dataAnalysisPCA.js +54 -0
- package/test/dataAnalysisSVD.js +31 -0
- package/test/euclideanDistance.js +2 -2
- package/test/matrix/02base.js +36 -0
- package/test/transformNumPy.js +132 -0
- package/testing/data/countries.csv +250 -0
- package/testing/hostAvailable.html +0 -2
- package/testing/load-injector.html +76 -21
- package/testing/load-injector.js +35 -54
- package/testing/test.js +1 -0
- package/transform/NumPy.js +303 -0
- package/transform/transform.html +73 -19
- package/transform/transform.js +144 -8
- package/documentation/LoadInjector.JPG +0 -0
package/lib/Chart.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
const { action, children } = require("../monitor/defs");
|
|
2
|
+
|
|
3
|
+
const getColourPallet=()=>{
|
|
4
|
+
const colourPallet=[];
|
|
5
|
+
const delta=255/5;
|
|
6
|
+
for(let i=0;i<5;i++)
|
|
7
|
+
for(let j=0;j<5;j++)
|
|
8
|
+
for(let k=0;k<5;k++)
|
|
9
|
+
colourPallet.push('rgb(' + Math.floor(i*delta) + ',' + Math.floor(j*delta) + ','+ Math.floor(k*delta) +')')
|
|
10
|
+
return colourPallet
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const baseColours =["Chartreuse","red","yellow","blue","pink","Cyan","Magenta","orange"]
|
|
14
|
+
const colourPallet=getColourPallet()
|
|
15
|
+
|
|
16
|
+
const getColors=(number)=>{
|
|
17
|
+
if(number<baseColours.length) return baseColours
|
|
18
|
+
const colours=[],r=colourPallet.length/number
|
|
19
|
+
for(let i=0; i<number; i++)
|
|
20
|
+
colours[i]=colourPallet[Math.floor(i*r)];
|
|
21
|
+
return colours
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function Chart(properties){
|
|
25
|
+
Object.assign(this,{
|
|
26
|
+
height:1000,
|
|
27
|
+
width:1000,
|
|
28
|
+
labels:[],
|
|
29
|
+
fontSize:12,
|
|
30
|
+
scale:.4,
|
|
31
|
+
xGap:100,yGap:100,
|
|
32
|
+
type:"line",
|
|
33
|
+
normaliseDimension:"all"
|
|
34
|
+
},properties)
|
|
35
|
+
this.density??=Math.min(this.height,this.width)
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
Chart.prototype.getLabels=function(x=this.width/2, y=this.yGap, fontSize=this.fontSize/this.scale){
|
|
39
|
+
if(!this.colours) this.colours=getColors(this.labels.length)
|
|
40
|
+
return this.labels.reduce((previous,label,i)=>{
|
|
41
|
+
const yPos=y+i*(2+fontSize)
|
|
42
|
+
previous.children.push({action:"rect",fill:this.colours[i],x:x,y:yPos,width:fontSize,height:fontSize})
|
|
43
|
+
previous.children.push({action:"text",x:x+2+fontSize,y:yPos,"font-size":fontSize,"dominant-baseline":"hanging","text-anchor":"left",children:[label]})
|
|
44
|
+
return previous
|
|
45
|
+
},{action:"g",id:"ledgend",children:[]})
|
|
46
|
+
}
|
|
47
|
+
Chart.prototype.getAxis=function(){
|
|
48
|
+
let ticks=[]
|
|
49
|
+
this.strokeWidth??=5
|
|
50
|
+
const w=this.width??1
|
|
51
|
+
const h=this.height??1
|
|
52
|
+
for(let tick=this.xGap; tick<this.width; tick+=this.xGap) {
|
|
53
|
+
ticks.push([["M",tick,-2*this.strokeWidth],["L",tick,2*this.strokeWidth]])
|
|
54
|
+
}
|
|
55
|
+
for(let tick=this.yGap; tick<this.height; tick+=this.yGap) {
|
|
56
|
+
ticks.push([["M",-2*this.strokeWidth,tick],["L",2*this.strokeWidth,tick]])
|
|
57
|
+
}
|
|
58
|
+
return {id:"axis",action:"path",stroke:"black","stroke-width":this.strokeWidth,
|
|
59
|
+
d:[["M",0,0],["L",0,this.height],["M",0,0],["L",this.width,0]].concat(ticks)}
|
|
60
|
+
}
|
|
61
|
+
Chart.prototype.getLinePath=function(points=[]){
|
|
62
|
+
if(!points.length) return []
|
|
63
|
+
const path=points.map((r)=>["L"].concat(r))
|
|
64
|
+
path[0][0]="M"
|
|
65
|
+
return path
|
|
66
|
+
}
|
|
67
|
+
Chart.prototype.getLine=function(points=[],colour=black){
|
|
68
|
+
return {action:"path",d:getLinePath(points),stroke:colour}
|
|
69
|
+
}
|
|
70
|
+
Chart.prototype.getLineUpdate=function(points=[],colour=black){
|
|
71
|
+
return {action:"update",d:getLinePath(points)}
|
|
72
|
+
}
|
|
73
|
+
Chart.prototype.getYPoints=function(points=this.normalisedData){
|
|
74
|
+
if(!points) {
|
|
75
|
+
this.normalise()
|
|
76
|
+
points=this.normalisedData
|
|
77
|
+
}
|
|
78
|
+
if(!points.length) return [] // no columns
|
|
79
|
+
const xScale=this.width/(points[0].length-1)
|
|
80
|
+
const lines=points.map(y=>([["M",0,y[0]*this.height]]))
|
|
81
|
+
for(let c=1;c<points.length;c++) {
|
|
82
|
+
const column=lines[c]
|
|
83
|
+
points[c].forEach((y,x)=>column.push(["L",x*xScale,y*this.height]))
|
|
84
|
+
}
|
|
85
|
+
return lines
|
|
86
|
+
}
|
|
87
|
+
Chart.prototype.getYLines=function(){
|
|
88
|
+
if(this.data.length==0 || this.data[0].length==0) return []
|
|
89
|
+
if(!this.colours) this.colours=getColors(this.data[0].length)
|
|
90
|
+
return this.getYPoints().reduce((a,c,i)=>{
|
|
91
|
+
a.push({action:"path",id:"l"+i,d:c,stroke:this.colours[i],fill:"none","stroke-width":2*this.strokeWidth})
|
|
92
|
+
return a
|
|
93
|
+
},[])
|
|
94
|
+
}
|
|
95
|
+
Chart.prototype.getYLinesUpdate=function(){
|
|
96
|
+
return this.getYPoints().reduce((a,c,i)=>{a.push({action:"update",id:"l"+i,d:c});return a},[])
|
|
97
|
+
}
|
|
98
|
+
Chart.prototype.scalePoints=function(points,...ratios){
|
|
99
|
+
return points.map(p=> ratios.map((r,i)=>r*p[i]))
|
|
100
|
+
}
|
|
101
|
+
Chart.prototype.normalise=function(points=this.data){
|
|
102
|
+
const _this=this
|
|
103
|
+
if(points.length<1){
|
|
104
|
+
this.normalisedData=[]
|
|
105
|
+
return this.normalisedData
|
|
106
|
+
}
|
|
107
|
+
this.mins=[...points[0]]
|
|
108
|
+
this.maxs=[...points[0]]
|
|
109
|
+
for(let i=1; i<points.length;i++){
|
|
110
|
+
const row=points[i]
|
|
111
|
+
row.forEach((c,ci)=>{
|
|
112
|
+
if(c<_this.mins[ci]) _this.mins[ci]=c
|
|
113
|
+
else if(c>_this.maxs[ci]) _this.maxs[ci]=c
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
this.ranges=this.mins.map((min,i)=> _this.maxs[i]-min)
|
|
117
|
+
this.min=Math.min(...this.mins)
|
|
118
|
+
this.max=Math.max(...this.maxs)
|
|
119
|
+
this.range=this.max-this.min
|
|
120
|
+
this.normalisedData=this.ranges.map(c=>new Float32Array(points.length))
|
|
121
|
+
if(this.normaliseDimension="all") {
|
|
122
|
+
points.forEach((row,rowIndex)=>
|
|
123
|
+
row.forEach((inCell,columnIndex)=>
|
|
124
|
+
_this.normalisedData[columnIndex][rowIndex]=_this.range?((inCell-_this.min)/_this.range):0
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
} else {
|
|
128
|
+
this.ranges.forEach((range,columnIndex)=>{
|
|
129
|
+
const min=_this.mins[columnIndex]
|
|
130
|
+
points.forEach((row,rowIndex)=>
|
|
131
|
+
_this.normalisedData[columnIndex][rowIndex]=range?(row[columnIndex]- min)/range:0
|
|
132
|
+
)
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
return this.normalisedData
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
Chart.prototype.normalise2ChartBoundaries=function (points=this.normalisedData) {
|
|
139
|
+
return this.normalisedData.map(row=>row.map(v=>v*this.density))
|
|
140
|
+
}
|
|
141
|
+
Chart.prototype.getBubbles=function (points,colour) {
|
|
142
|
+
return points.map((a,row,i)=>({action:"circle",fill:colour,cx:row[0],cy:row[1],r:row[2],stroke:this.outline,"stroke-width":1, opacity:0.5}))
|
|
143
|
+
}
|
|
144
|
+
Chart.prototype.get=function () {
|
|
145
|
+
if(this.getData) {
|
|
146
|
+
this.data=this.getData()
|
|
147
|
+
this.normalisedData=null
|
|
148
|
+
}
|
|
149
|
+
if(!this.base) {
|
|
150
|
+
this.base=[]
|
|
151
|
+
if(!["pie"].includes(this.type)) this.base.push(this.getAxis())
|
|
152
|
+
}
|
|
153
|
+
const scaledHeight=this.scale*this.height
|
|
154
|
+
return {action:"g",height:scaledHeight+2*this.fontSize,id:"chart",
|
|
155
|
+
transform:{scale:{x:this.scale,y:this.scale},translate:{y:scaledHeight}},
|
|
156
|
+
children:[
|
|
157
|
+
{action:"g",children:this.base.concat(this.getYLines()),transform:{scale:{x:1,y:-1}}},
|
|
158
|
+
this.getLabels()
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
Chart.prototype.getUpdate=function () {
|
|
163
|
+
if(this.getDataUpdate) {
|
|
164
|
+
this.data=this.getDataUpdate()
|
|
165
|
+
this.normalisedData=null
|
|
166
|
+
} else if(this.getData) {
|
|
167
|
+
this.data=this.getData()
|
|
168
|
+
this.normalisedData=null
|
|
169
|
+
}
|
|
170
|
+
return this.getYLinesUpdate()
|
|
171
|
+
}
|
|
172
|
+
Chart.prototype.setData=function (points) {
|
|
173
|
+
this.data=points
|
|
174
|
+
this.normalise()
|
|
175
|
+
return this
|
|
176
|
+
}
|
|
177
|
+
module.exports=Chart
|
package/lib/Column.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
require("../lib/objectExtensions")
|
|
2
|
+
const dataConversionFunction ={
|
|
3
|
+
real: parseFloat,
|
|
4
|
+
int: parseFloat,
|
|
5
|
+
number: parseFloat,
|
|
6
|
+
timestamp: (value)=>Date.parse(value.substr(0,4)+'/'+value.substr(5,2)+'/'+value.substr(8,11))
|
|
7
|
+
+ parseInt(value.substr(21,3)),
|
|
8
|
+
time:Date.parse,
|
|
9
|
+
datetime:Date.parse,
|
|
10
|
+
date: Date.parse
|
|
11
|
+
}
|
|
12
|
+
function Column(properties) {
|
|
13
|
+
Object.assign(this,{type:null,index:[]},properties)
|
|
14
|
+
if(this.table==null) this.error("no table object")
|
|
15
|
+
if(this.columnIndex==null) this.error("no columnIndex")
|
|
16
|
+
if(this.name==null) this.error("no column name")
|
|
17
|
+
if(this.title==null) this.title=this.name
|
|
18
|
+
if(!this.types.includes(this.type)) this.error("invalid type: "+this.type+ " types: "+this.MeasureTypes.join(","))
|
|
19
|
+
}
|
|
20
|
+
Column.prototype.getNormalised=function(value){
|
|
21
|
+
try{
|
|
22
|
+
return this.normaliseRatio*(value-this.min)
|
|
23
|
+
} catch(ex){}
|
|
24
|
+
if(!this.max) throw Error("maximum value not set")
|
|
25
|
+
if(!this.min) throw Error("minimum value not set")
|
|
26
|
+
if(!this.range) throw Error("range value not set")
|
|
27
|
+
if(!this.normaliseRatio) throw Error("normalised ratio not set")
|
|
28
|
+
}
|
|
29
|
+
Column.prototype.buildColumnnar=function(){
|
|
30
|
+
const index=this.index
|
|
31
|
+
let max=this.table.data[0][index],min=max
|
|
32
|
+
this.columnar=this.table.data.reduce((a,row)=>{
|
|
33
|
+
const v=row[index]
|
|
34
|
+
if(v==null) return
|
|
35
|
+
try{
|
|
36
|
+
a[v].push(row)
|
|
37
|
+
} catch(ex) {
|
|
38
|
+
a[v]=[row]
|
|
39
|
+
}
|
|
40
|
+
if(max<v) max=v
|
|
41
|
+
else if(min>v) min=v
|
|
42
|
+
},{})
|
|
43
|
+
this.setMin(min).setMax(max)
|
|
44
|
+
}
|
|
45
|
+
Column.prototype.getMax=function(){
|
|
46
|
+
if(this.max) return this.max
|
|
47
|
+
if(!this.columnar) ths.buildColumnar()
|
|
48
|
+
return this.max
|
|
49
|
+
}
|
|
50
|
+
Column.prototype.setMax=function(value){
|
|
51
|
+
this.max=value
|
|
52
|
+
return this.setRange()
|
|
53
|
+
}
|
|
54
|
+
Column.prototype.setMin=function(value){
|
|
55
|
+
this.min=value
|
|
56
|
+
return this.setRange()
|
|
57
|
+
}
|
|
58
|
+
Column.prototype.setRange=function(min=this.min,max=this.max){
|
|
59
|
+
if(this.isMetric) {
|
|
60
|
+
this.range=max-min
|
|
61
|
+
this.normaliseRatio=this.range?1:1/this.range
|
|
62
|
+
}
|
|
63
|
+
return this
|
|
64
|
+
}
|
|
65
|
+
Column.prototype.onError=function(call){
|
|
66
|
+
if(this.errorStack) this.errorStack.push(call)
|
|
67
|
+
else this.errorStack=[this.call]
|
|
68
|
+
return this
|
|
69
|
+
}
|
|
70
|
+
Column.prototype.error=function(ex="no error message"){
|
|
71
|
+
if(this.errorStack){
|
|
72
|
+
this.errorStack.forEach((callFunction)=>{
|
|
73
|
+
try{
|
|
74
|
+
callFunction(ex)
|
|
75
|
+
}catch(ex) {}
|
|
76
|
+
})
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
if(typeof ex == "string") throw Error(ex)
|
|
80
|
+
throw ex
|
|
81
|
+
}
|
|
82
|
+
Column.prototype.timeTypes=['timestamp','time','date','datetime']
|
|
83
|
+
Column.prototype.isTime=(type=this.type)=>{
|
|
84
|
+
if(Column.prototype.timeTypes.includes(type)) return true
|
|
85
|
+
throw Error(column.name +" not time type")
|
|
86
|
+
}
|
|
87
|
+
Column.prototype.types=['real','double','int','number','bigint',"string"]
|
|
88
|
+
Column.prototype.numericTypes=['real','double','int','number','bigint']
|
|
89
|
+
Column.prototype.isNumeric=(type=this.type)=>{
|
|
90
|
+
if(Column.prototype.numericTypes.includes(type)) return true
|
|
91
|
+
throw Error(column.name +" not numeric")
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
Column.prototype.MeasureTypes=['real','double','int','number','bigint','timestamp','date']
|
|
95
|
+
Column.prototype.isMeasure=(type=this.type)=>{
|
|
96
|
+
if(Column.prototype.measureTypes.includes(type)) return true
|
|
97
|
+
throw Error(column.name +" not a measure")
|
|
98
|
+
}
|
|
99
|
+
module.exports=Column
|
package/lib/GraphDB.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require("../lib/objectExtensions")
|
|
2
|
+
function GraphDB(properties){
|
|
3
|
+
Object.assign(this,{type:null,vertices:[],edges:[]},properties)
|
|
4
|
+
|
|
5
|
+
}
|
|
6
|
+
GraphDB.prototype.addVertex=function(vertex) {
|
|
7
|
+
this.vertices.addList(vertex)
|
|
8
|
+
}
|
|
9
|
+
GraphDB.prototype.addEdge=function(from,to) {
|
|
10
|
+
this.edges.addList({from:from,to:to})
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
this.addErrorFunctions()
|
|
14
|
+
module.exports=GraphDB
|
package/lib/Table.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
const Column=require("../lib/Column")
|
|
2
|
+
function Table(properties) {
|
|
3
|
+
Object.assign(this,{columns:[],columnNames:{},data:[],lists:{}},properties)
|
|
4
|
+
}
|
|
5
|
+
Table.prototype.error=function(ex){
|
|
6
|
+
if(this.errorStack){
|
|
7
|
+
this.errorStack.forEach((callFunction)=>{
|
|
8
|
+
try{
|
|
9
|
+
callFunction(ex)
|
|
10
|
+
}catch(ex) {}
|
|
11
|
+
})
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
if(typeof ex == "string") throw Error(msg)
|
|
15
|
+
throw ex
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Table.prototype.onError=function(call){
|
|
19
|
+
if(this.errorStack) this.errorStack.push(call)
|
|
20
|
+
else this.errorStack=[this.call]
|
|
21
|
+
return this
|
|
22
|
+
}
|
|
23
|
+
Table.prototype.error=function(msg="no error message"){
|
|
24
|
+
const ex=typeof msg == "string"?msg=Error(msg):msg
|
|
25
|
+
if(this.errorStack){
|
|
26
|
+
this.errorStack.forEach((callFunction)=>{
|
|
27
|
+
try{
|
|
28
|
+
callFunction(msg)
|
|
29
|
+
}catch(ex2) {}
|
|
30
|
+
})
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
throw ex
|
|
34
|
+
}
|
|
35
|
+
Table.prototype.addColumn=function(values){
|
|
36
|
+
values.table=this
|
|
37
|
+
values.columnIndex=this.columns.length
|
|
38
|
+
const column=new Column(values)
|
|
39
|
+
if(column.name in this.columnNames) return this.error("dupicate column "+column.name)
|
|
40
|
+
this.columnNames[column.name]=this.columns.length
|
|
41
|
+
this.columns.push(column)
|
|
42
|
+
return this
|
|
43
|
+
}
|
|
44
|
+
Table.prototype.getcolumn=function(name){
|
|
45
|
+
return this.columns[this.columnNames[name]]
|
|
46
|
+
}
|
|
47
|
+
Table.prototype.columnNumbers=function(list=[],error=this.error){
|
|
48
|
+
try{
|
|
49
|
+
return list.map(c=>this.columnNames[c])
|
|
50
|
+
} catch(ex){
|
|
51
|
+
error(ex)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
Table.prototype.forColumnNames=function(list=[],callFunction,error=this.error,workArea={}){
|
|
55
|
+
this.forColumnNumbers(this.columnNumbers(list),callFunction,error)
|
|
56
|
+
return this
|
|
57
|
+
}
|
|
58
|
+
Table.prototype.forColumnNumbers=function(list=[],callFunction,error=this.error){
|
|
59
|
+
list.forEach((columnNumber,i)=>{
|
|
60
|
+
try{
|
|
61
|
+
callFunction.apply(this,[this.columns[columnNumber],i,error,workArea])
|
|
62
|
+
} catch(ex){
|
|
63
|
+
error(ex)
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
return this
|
|
67
|
+
}
|
|
68
|
+
Table.prototype.forEachColumn=function(callFunction,columns=this.columns,filter,error=this.error,workArea={}){
|
|
69
|
+
for(let i=0; i<columns.length; i++) {
|
|
70
|
+
const column=columns[i]
|
|
71
|
+
try{
|
|
72
|
+
if(filter && filter(column) ) continue
|
|
73
|
+
callFunction.apply(this,[column,i,error,workArea])
|
|
74
|
+
} catch(ex){
|
|
75
|
+
onEror(ex)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return this
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
Table.prototype.forEachRow=function(callFunction,filter,error=this.error,workArea={}){
|
|
82
|
+
for(let i= 0; i<this.data.length; i++) {
|
|
83
|
+
const row=this.data[i]
|
|
84
|
+
try{
|
|
85
|
+
if(filter && filter(row) )continue
|
|
86
|
+
callFunction.apply(this,[row,i,error,workArea])
|
|
87
|
+
} catch(ex){
|
|
88
|
+
error(ex)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return this
|
|
92
|
+
}
|
|
93
|
+
Table.prototype.forEachRowColumns=function(columnNumbers,callFunction,filter,error=this.error,workArea={}){
|
|
94
|
+
this.forEachRow((row,i)=>{
|
|
95
|
+
if(filter && filter(row) ) return
|
|
96
|
+
const newRow=columnNumbers.map((columnIndex)=>row[columnIndex])
|
|
97
|
+
callFunction.apply(this,[newRow,i,row,workArea,error])
|
|
98
|
+
},error)
|
|
99
|
+
return this
|
|
100
|
+
}
|
|
101
|
+
Table.prototype.forEachRowDelta=function(callFunction,filter,error=this.error,workArea={}){
|
|
102
|
+
if(data.length<2) return
|
|
103
|
+
let last=this.data[0]
|
|
104
|
+
for(let i=1; i<this.data.length; i++){
|
|
105
|
+
const current=this.data[i]
|
|
106
|
+
if(filter && filter(current) ) continue
|
|
107
|
+
try{
|
|
108
|
+
const row=[]
|
|
109
|
+
this.list.delta.numbers().forEach(i=>{
|
|
110
|
+
row.push(current[i]-last[i])
|
|
111
|
+
})
|
|
112
|
+
callFunction.apply(this,[row,i])
|
|
113
|
+
} catch(ex){
|
|
114
|
+
error(ex)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return this
|
|
118
|
+
}
|
|
119
|
+
Table.prototype.buildColumnIndices=function(){
|
|
120
|
+
this.columns.forEach((column,i)=>column.buildColumnnar())
|
|
121
|
+
return this
|
|
122
|
+
}
|
|
123
|
+
Table.prototype.forEachRowGroup=function(callFunction,filter,error=this.error,workArea={}){
|
|
124
|
+
if(this.data.length==0) return [];
|
|
125
|
+
const group=this.lists.group.numbers
|
|
126
|
+
let sums=[]
|
|
127
|
+
groupValues=group.map(c=>row[c])
|
|
128
|
+
data.forEachRow((row,i,error,workArea)=>{
|
|
129
|
+
if(filter && filter(current) ) return
|
|
130
|
+
let diff=group.find((c,i)=>groupValues[i]!=row[c])
|
|
131
|
+
if(diff) {
|
|
132
|
+
callFunction(groupValues,sums,error)
|
|
133
|
+
for(;diff<group.length;diff++){
|
|
134
|
+
groupValues[diff]!=row[group[diff]]
|
|
135
|
+
}
|
|
136
|
+
workArea.groupValues=group.map(c=>row[c])
|
|
137
|
+
} else {
|
|
138
|
+
cnt++
|
|
139
|
+
measures.forEach((c,i)=>workArea.sums[i]+=row[c])
|
|
140
|
+
}
|
|
141
|
+
},null,error,workArea)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
for(let i=0; i<this.data.length; i++) {
|
|
145
|
+
const column=this.table.columns[i]
|
|
146
|
+
try{
|
|
147
|
+
const l=data.find((element,idx) => element!=data[group[idx]] )
|
|
148
|
+
if(l) {
|
|
149
|
+
measureFunctions.forEach((measureFunction,mIndx)=>{
|
|
150
|
+
measures[mIndx]=measureFunction(measures[mIndx],row)
|
|
151
|
+
})
|
|
152
|
+
continue
|
|
153
|
+
}
|
|
154
|
+
callFunction.apply(this,[data,measures])
|
|
155
|
+
data=group.map(c=>this.data[c])
|
|
156
|
+
} catch(ex){
|
|
157
|
+
error(ex)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return this
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
Table.prototype.getSelectHTML=function(list=[],onClick,filter=(column)=>true,multiple='multiple="multiple"'){
|
|
164
|
+
let options=""
|
|
165
|
+
if(typeof list == "string") list=this.grouping.split(',')
|
|
166
|
+
this.forEachColumn((column,i)=>{
|
|
167
|
+
if(filter(column==true)) return
|
|
168
|
+
options+='<option value="'+column.name+'" '+(list.includes(column.name)?'selected="selected"':"")+'>'+column.title+'</option>'
|
|
169
|
+
})
|
|
170
|
+
return '<select '+multiple+' onclick="'+onClick+'"/>'+options+'</select>'
|
|
171
|
+
}
|
|
172
|
+
Table.prototype.setDelta=function(list){
|
|
173
|
+
setListProperty("delta",list,(c)=>c.isMeasure())
|
|
174
|
+
return this
|
|
175
|
+
}
|
|
176
|
+
Table.prototype.setGroup=function(list){
|
|
177
|
+
setListProperty("group",list)
|
|
178
|
+
return this
|
|
179
|
+
}
|
|
180
|
+
Table.prototype.setListProperty=function(property,list,filter=()=>true) {
|
|
181
|
+
const listArrray={names:list instanceof Array?list:list.join(","),numbers:[]}
|
|
182
|
+
this.lists[property].numbers=this.columnNumbers(listArrray.names)
|
|
183
|
+
return this
|
|
184
|
+
}
|
|
185
|
+
module.exports=Table
|