Skip to content

Commit d70f6fc

Browse files
summary by columns feature
1 parent 110b9b4 commit d70f6fc

File tree

5 files changed

+93
-16
lines changed

5 files changed

+93
-16
lines changed

example/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
MDX2JSONSource: "http://localhost:57772/SAMPLES", // MDX2JSON server address
9191
basicMDX: typeof req === "object" ? req.basicMDX : req
9292
}
93+
//, showSummary: true // show summary by column
9394
//, drillDownTarget: "<dashboard name>" - undocumented, deepSee only
9495
};
9596

export/LightPivotTable.xml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<Class name="DeepSee.LightPivotTable">
1313
<Super>%DeepSee.Component.Portlet.abstractPortlet</Super>
14-
<TimeChanged>63521,5059.885023</TimeChanged>
14+
<TimeChanged>63521,73483.405523</TimeChanged>
1515
<TimeCreated>63515,61322.546099</TimeCreated>
1616

1717
<Parameter name="INCLUDEFILES">
@@ -22,6 +22,10 @@
2222
<Type>%String</Type>
2323
</Property>
2424

25+
<Property name="ShowSummary">
26+
<Type>%Boolean</Type>
27+
</Property>
28+
2529
<Method name="%OnGetPortletName">
2630
<ClassMethod>1</ClassMethod>
2731
<ReturnType>%String</ReturnType>
@@ -43,7 +47,8 @@
4347
<Implementation><![CDATA[
4448
kill pInfo // $LB(name,value,type,caption,title)
4549
46-
set pInfo($I(pInfo)) = $LB("dataSource","/SAMPLES","%String",$$$Text("MDX2JSON source","%DeepSee"),"THIS IS TITLE")
50+
set pInfo($I(pInfo)) = $LB("DataSource", "/SAMPLES", "%String", $$$Text("MDX2JSON source", "%DeepSee"), "Set the URL of MDX2JSON source. Example: ""/SAMPLES""")
51+
set pInfo($I(pInfo)) = $LB("ShowSummary", 1, "%Boolean", $$$Text("Show summary?", "%DeepSee"), "Show summary row")
4752
4853
quit $$$OK
4954
]]></Implementation>
@@ -175,6 +180,8 @@
175180
}
176181
}
177182
if (info["drillDownDataSource"]) setup["drillDownTarget"] = info["drillDownDataSource"];
183+
setup["showSummary"] = !!parseInt(container.getAttribute("show-summary"));
184+
178185
post(source + "/DataSource", { DataSource: info["dataSource"] }, function (data) {
179186
180187
//console.log(data);
@@ -197,10 +204,22 @@
197204
<Implementation><![CDATA[
198205
set ..renderFlag = ..renderFlag + 1
199206
200-
set ..DataSource = $get(..settings("dataSource"))
207+
// copy ..settings into properties
208+
#dim propName As %String = $order(..settings(""))
209+
while (propName '= "")
210+
{
211+
if ("" '= $get(..settings(propName)))
212+
try
213+
{
214+
set $property($this, propName) = ..settings(propName)
215+
}
216+
catch {}
217+
218+
set propName = $order(..settings(propName))
219+
}
201220
202221
&html<
203-
<div data-source="#(..DataSource)#" class="lpt-container" style="position: absolute; left: 0; bottom: 0; width: 100%; height: 100%;">
222+
<div data-source="#(..DataSource)#" show-summary="#(..ShowSummary)#" class="lpt-container" style="position: absolute; left: 0; bottom: 0; width: 100%; height: 100%;">
204223
205224
</div>
206225
>

gulpfile.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ gulp.task("gatherScripts", ["clean"], function () {
1717
return gulp.src("source/js/*.js")
1818
.pipe(concat("lightPivotTable.js"))
1919
.pipe(wrap("LightPivotTable = (function(){<%= contents %> return LightPivotTable;}());"))
20-
.pipe(uglify())
20+
.pipe(uglify({
21+
output: {
22+
ascii_only: true
23+
}
24+
}))
2125
.pipe(gulp.dest("build/js/"));
2226
});
2327

source/js/DataController.js

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
var DataController = function (dataSource, dataChangeTrigger) {
1+
/**
2+
* @param {LightPivotTable} controller
3+
* @param {function} dataChangeTrigger
4+
* @constructor
5+
*/
6+
var DataController = function (controller, dataChangeTrigger) {
27

38
if (dataChangeTrigger && typeof dataChangeTrigger !== "function") {
49
throw new Error("dataChangeTrigger parameter must be a function");
510
}
611

712
this._dataStack = [];
813

14+
this.controller = controller;
15+
916
this.pushData();
1017
this.dataChangeTrigger = dataChangeTrigger;
1118

19+
this.SUMMARY_SHOWN = false;
20+
1221
};
1322

1423
/**
@@ -85,14 +94,14 @@ DataController.prototype.setData = function (data) {
8594

8695
DataController.prototype.resetRawData = function () {
8796

88-
var data;
97+
var data, summary, y, x;
8998

9099
if (!(data = this._dataStack[this._dataStack.length - 1].data)) {
91100
console.error("Unable to create raw data for given data set.");
92101
return;
93102
}
94103

95-
var rd0 = [], rd1 = [], num = 2, rawData = [];
104+
var rd0 = [], rd1 = [], groupNum = 2, rawData = [];
96105

97106
var transpose = function (a) {
98107
return Object.keys(a[0]).map(function (c) {
@@ -118,9 +127,9 @@ DataController.prototype.resetRawData = function () {
118127
var cnum;
119128

120129
for (var i in c) {
121-
cnum = num;
130+
cnum = groupNum;
122131
if (c[i].children) {
123-
num++;
132+
groupNum++;
124133
dim1raw(a, c[i].children, arr.concat({
125134
group: cnum,
126135
source: c[i],
@@ -129,12 +138,12 @@ DataController.prototype.resetRawData = function () {
129138
}));
130139
} else {
131140
a.push(arr.concat({
132-
group: num,
141+
group: groupNum,
133142
source: c[i],
134143
isCaption: true,
135144
value: c[i].caption || ""
136145
}));
137-
num++;
146+
groupNum++;
138147
}
139148
}
140149

@@ -149,9 +158,9 @@ DataController.prototype.resetRawData = function () {
149158
yw = (rd1[0] || []).length;
150159

151160
// render columns, rows and data
152-
for (var y = 0; y < xh + yh; y++) {
161+
for (y = 0; y < xh + yh; y++) {
153162
if (!rawData[y]) rawData[y] = [];
154-
for (var x = 0; x < yw + xw; x++) {
163+
for (x = 0; x < yw + xw; x++) {
155164
if (x < yw) {
156165
if (y < xh) {
157166
rawData[y][x] = {
@@ -176,6 +185,40 @@ DataController.prototype.resetRawData = function () {
176185

177186
data.info.topHeaderRowsNumber = xh;
178187
data.info.leftHeaderColumnsNumber = yw;
188+
this.SUMMARY_SHOWN = false;
189+
190+
if (this.controller.CONFIG["showSummary"] && rawData.length - xh > 1 // xh - see above
191+
&& (rawData[rawData.length - 1][0] || {})["isCaption"]) {
192+
this.SUMMARY_SHOWN = true;
193+
rawData.push(summary = []);
194+
x = rawData.length - 2;
195+
for (var i in rawData[x]) {
196+
if (rawData[x][i].isCaption) {
197+
summary[i] = {
198+
group: groupNum,
199+
isCaption: true,
200+
source: {},
201+
value: "Σ"
202+
}
203+
} else {
204+
summary[i] = {
205+
value: (function countSummaryByColumn(array, iStart, iEnd, column) {
206+
var sum = 0;
207+
for (var i = iStart; i < iEnd; i++) {
208+
if (!isFinite(array[i][column]["value"])) {
209+
sum = 0;
210+
break;
211+
}
212+
sum += parseFloat(array[i][column]["value"]) || 0;
213+
}
214+
return sum || "";
215+
})(rawData, xh, rawData.length - xh, i)
216+
}
217+
}
218+
}
219+
groupNum++;
220+
}
221+
179222
data.rawData = data._rawDataOrigin = rawData;
180223

181224
return data.rawData;
@@ -206,10 +249,15 @@ DataController.prototype.sortByColumn = function (columnIndex) {
206249
order = this.SORT_STATE.order = 0;
207250
}
208251

209-
var newRawData = data._rawDataOrigin.slice(data.info.topHeaderRowsNumber),
252+
var newRawData = data._rawDataOrigin.slice(
253+
data.info.topHeaderRowsNumber,
254+
data._rawDataOrigin.length - (this.SUMMARY_SHOWN ? 1 : 0)
255+
),
210256
xIndex = data.info.leftHeaderColumnsNumber + columnIndex,
211257
order = this.SORT_STATE.order === -1 ? 1 : this.SORT_STATE.order === 1 ? 0 : -1;
212258

259+
260+
213261
this.SORT_STATE.order = order;
214262
this.SORT_STATE.column = columnIndex;
215263

@@ -228,7 +276,10 @@ DataController.prototype.sortByColumn = function (columnIndex) {
228276
});
229277

230278
data.rawData = data._rawDataOrigin.slice(0, data.info.topHeaderRowsNumber)
231-
.concat(newRawData);
279+
.concat(newRawData)
280+
.concat(this.SUMMARY_SHOWN ? [data._rawDataOrigin[data._rawDataOrigin.length - 1]] : []);
281+
282+
console.log(data.rawData);
232283

233284
this._trigger();
234285

source/js/PivotView.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ PivotView.prototype._cellClickHandler = function (x, y) {
173173
console.warn("Unable to get filters for cell (%d, %d)", x, y);
174174
}
175175

176+
if (!f1) return;
177+
176178
if (this.controller.CONFIG["drillDownTarget"]) {
177179
window.location = location.origin + location.pathname + "?DASHBOARD="
178180
+ encodeURIComponent(this.controller.CONFIG["drillDownTarget"]) + "&SETTINGS=FILTER:"

0 commit comments

Comments
 (0)