Skip to content

Commit eafc872

Browse files
Per-row formatting support
1 parent a59c691 commit eafc872

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "LightPivotTable",
33
"author": "ZitRo",
4-
"version": "1.6.12",
4+
"version": "1.7.0",
55
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
66
"main": "test/testServer.js",
77
"repository": {

source/js/DataController.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,23 @@ DataController.prototype.setDrillThroughHandler = function (handler) {
142142
*/
143143
DataController.prototype.resetDimensionProps = function () {
144144

145-
var data, columnProps;
145+
var data, columnProps, rowProps;
146146

147147
if (!(data = this._dataStack[this._dataStack.length - 1].data)) {
148148
console.error("Unable to get dimension props for given data set.");
149149
return;
150150
}
151151

152-
columnProps = new Array(data.info.leftHeaderColumnsNumber || 0); // fill left headers as empty
153-
for (var i = 0; i < columnProps.length; i++) { columnProps[i] = {}; }
152+
columnProps = []; // fill left headers as empty
153+
rowProps = []; // fill left headers as empty
154154

155155
var cloneObj = function (obj) {
156156
var i, newObj = {};
157157
for (i in obj) newObj[i] = obj[i];
158158
return newObj;
159159
};
160160

161-
var parse = function (obj, props) {
161+
var parse = function (dimProps, obj, props) {
162162
var tObj, clonedProps, i;
163163
if (obj["children"] && obj["children"].length > 0) {
164164
for (i in obj.children) {
@@ -172,16 +172,18 @@ DataController.prototype.resetDimensionProps = function () {
172172
if (tObj["total"]) clonedProps["summary"]
173173
= (tObj["total"] || "").toLowerCase().replace(/:.*/, ""); // what is "max:Days"?
174174
if (tObj["type"]) clonedProps["type"] = tObj["type"];
175-
parse(tObj, clonedProps);
175+
parse(dimProps, tObj, clonedProps);
176176
}
177177
} else {
178-
columnProps.push(cloneObj(props));
178+
dimProps.push(cloneObj(props));
179179
}
180180
};
181181

182-
parse({ children: data.dimensions[0] }, {});
182+
parse(columnProps, { children: data.dimensions[0] }, {});
183+
parse(rowProps, { children: data.dimensions[1] }, {});
183184

184185
data.columnProps = columnProps;
186+
data.rowProps = rowProps;
185187

186188
};
187189

@@ -474,12 +476,15 @@ DataController.prototype.resetRawData = function () {
474476
rowLevels = _.controller.getPivotProperty(["rowLevels"]),
475477
formatColumn = {
476478
// "<spec>": { style: "<style>" }
479+
},
480+
formatRow = {
481+
// "<spec>": { style: "<style>" } // unused
477482
};
478-
var fillLevels = function (obj) {
483+
var fillLevels = function (temp, obj) {
479484
if (typeof obj === "undefined") return;
480485
for (var i in obj["childLevels"]) {
481486
if (obj["childLevels"][i] && obj["childLevels"][i]["spec"]) {
482-
formatColumn[(obj["childLevels"][i]["spec"] || "").replace(/[^.]*$/, "")] = {
487+
temp[(obj["childLevels"][i]["spec"] || "").replace(/[^.]*$/, "")] = {
483488
style: obj["childLevels"][i]["levelStyle"] || "",
484489
headStyle: obj["childLevels"][i]["levelHeaderStyle"] || ""
485490
};
@@ -488,8 +493,8 @@ DataController.prototype.resetRawData = function () {
488493
}
489494
};
490495
for (i in colLevels) {
491-
fillLevels({ childLevels: [colLevels[i]] });
492-
fillLevels({ childLevels: [rowLevels[i]] });
496+
fillLevels(formatColumn, { childLevels: [colLevels[i]] });
497+
fillLevels(formatRow, { childLevels: [rowLevels[i]] });
493498
}
494499
for (y = 0; y < rawData.length; y++) {
495500
for (x = 0; x < xEnd; x++) {
@@ -569,6 +574,9 @@ DataController.prototype.resetRawData = function () {
569574
this.SUMMARY_SHOWN = false;
570575
this._dataStack[this._dataStack.length - 1].SUMMARY_SHOWN = false;
571576

577+
for (i = 0; i < data.info.leftHeaderColumnsNumber; i++) { data.columnProps.unshift({}); }
578+
for (i = 0; i < data.info.topHeaderRowsNumber; i++) { data.rowProps.unshift({}); }
579+
572580
/**
573581
* @param {number} columnIndex
574582
* @returns {Function}

source/js/PivotView.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ PivotView.prototype.renderRawData = function (data) {
10331033
rawData = data["rawData"],
10341034
info = data["info"],
10351035
columnProps = data["columnProps"],
1036+
rowProps = data["rowProps"],
10361037
colorScale =
10371038
data["conditionalFormatting"] ? data["conditionalFormatting"]["colorScale"] : undefined,
10381039

@@ -1106,7 +1107,7 @@ PivotView.prototype.renderRawData = function (data) {
11061107
+ p + "</a>";
11071108
});
11081109
} else if (!LISTING) { // number
1109-
if (format === "%date%") { // Cach? internal date
1110+
if (format === "%date%") { // Caché internal date
11101111
var d = new Date(_.getUnixDateFromCacheFormat(value));
11111112
if (isNaN(d.getTime())) { element.textContent = value; return; }
11121113
element.textContent = d.getHours() + d.getMinutes() + d.getSeconds() === 0
@@ -1283,7 +1284,7 @@ PivotView.prototype.renderRawData = function (data) {
12831284
if (!rawData[y][x].isCaption) formatContent(
12841285
rawData[y][x].value,
12851286
th,
1286-
columnProps[x].format
1287+
rowProps[y].format || columnProps[x].format
12871288
);
12881289
}
12891290

@@ -1379,7 +1380,7 @@ PivotView.prototype.renderRawData = function (data) {
13791380
formatContent(
13801381
rawData[y][x].value,
13811382
div,
1382-
columnProps[x].format
1383+
(rowProps[y] && rowProps[y].format) || columnProps[x].format
13831384
);
13841385
if (
13851386
colorScale
@@ -1392,8 +1393,9 @@ PivotView.prototype.renderRawData = function (data) {
13921393
+ "," + Math.round((colorScale.to.b - colorScale.from.b)*ratio + colorScale.from.b)
13931394
+ ");" + (colorScale.invert ? "color: white;" : "");
13941395
}
1395-
if (columnProps[x].style) {
1396-
cellStyle += columnProps[x].style;
1396+
if (columnProps[x].style || (rowProps[y] && rowProps[y].style)) {
1397+
cellStyle += ((rowProps[y] && rowProps[y].style) || "") +
1398+
((rowProps[y] && rowProps[y].style) ? " " : "") + (columnProps[x].style || "");
13971399
}
13981400
if (rawData[y][x].style) {
13991401
cellStyle += rawData[y][x].style;

0 commit comments

Comments
 (0)