@vue-pivottable/multi-value-renderer 0.4.0 → 0.5.0-beta.0
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/README.md +50 -2
- package/dist/core.js +5 -87
- package/dist/core.mjs +7 -89
- package/dist/index.js +5 -3
- package/dist/index.mjs +6 -4
- package/dist/multiAggregator-1pTQ492r.js +106 -0
- package/dist/multiAggregator-t4E8vUde.cjs +105 -0
- package/dist/vue2.js +31 -4
- package/dist/vue2.mjs +31 -4
- package/dist/vue3.js +31 -5
- package/dist/vue3.mjs +31 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -174,17 +174,65 @@ Or customize with your own CSS targeting these classes:
|
|
|
174
174
|
|
|
175
175
|
## Available Aggregators
|
|
176
176
|
|
|
177
|
-
The renderer
|
|
177
|
+
The renderer supports all aggregators from vue-pivottable:
|
|
178
|
+
|
|
179
|
+
### Single-Input Aggregators
|
|
178
180
|
|
|
179
181
|
- `Count`
|
|
182
|
+
- `Count Unique Values`
|
|
183
|
+
- `List Unique Values`
|
|
180
184
|
- `Sum`
|
|
185
|
+
- `Integer Sum`
|
|
181
186
|
- `Average`
|
|
187
|
+
- `Median`
|
|
182
188
|
- `Minimum`
|
|
183
189
|
- `Maximum`
|
|
184
|
-
- `
|
|
190
|
+
- `First`
|
|
191
|
+
- `Last`
|
|
185
192
|
- `Sample Variance`
|
|
186
193
|
- `Sample Standard Deviation`
|
|
187
194
|
|
|
195
|
+
### Multi-Input Aggregators
|
|
196
|
+
|
|
197
|
+
Multi-input aggregators (like `Sum over Sum`) compute relationships between two fields. When selected, an additional field selector appears in the UI.
|
|
198
|
+
|
|
199
|
+
- `Sum over Sum` - Calculates sum(field1) / sum(field2)
|
|
200
|
+
- `Sum as Fraction of Total`
|
|
201
|
+
- `Sum as Fraction of Rows`
|
|
202
|
+
- `Sum as Fraction of Columns`
|
|
203
|
+
- `Count as Fraction of Total`
|
|
204
|
+
- `Count as Fraction of Rows`
|
|
205
|
+
- `Count as Fraction of Columns`
|
|
206
|
+
|
|
207
|
+
#### Configuration Format
|
|
208
|
+
|
|
209
|
+
For multi-input aggregators, use an object format in `aggregatorMap`:
|
|
210
|
+
|
|
211
|
+
```js
|
|
212
|
+
const aggregatorMap = {
|
|
213
|
+
// Single-input: string format
|
|
214
|
+
sales: 'Sum',
|
|
215
|
+
quantity: 'Average',
|
|
216
|
+
|
|
217
|
+
// Multi-input: object format with fields array
|
|
218
|
+
unit_price: {
|
|
219
|
+
aggregator: 'Sum over Sum',
|
|
220
|
+
fields: ['sales', 'quantity'] // sum(sales) / sum(quantity)
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
#### Helper Function
|
|
226
|
+
|
|
227
|
+
Use `getAggregatorNumInputs` to check if an aggregator requires multiple inputs:
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
import { getAggregatorNumInputs } from '@vue-pivottable/multi-value-renderer/vue3'
|
|
231
|
+
|
|
232
|
+
const numInputs = getAggregatorNumInputs(aggregators['Sum over Sum'])
|
|
233
|
+
// Returns 2 for multi-input aggregators
|
|
234
|
+
```
|
|
235
|
+
|
|
188
236
|
## License
|
|
189
237
|
|
|
190
238
|
MIT
|
package/dist/core.js
CHANGED
|
@@ -1,89 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
|
|
4
|
-
const defaultAggregator = "Sum";
|
|
5
|
-
return function multiAggregatorFactory(vals) {
|
|
6
|
-
return function(data, rowKey, colKey) {
|
|
7
|
-
const subAggregators = {};
|
|
8
|
-
const results = {};
|
|
9
|
-
vals.forEach((val) => {
|
|
10
|
-
const aggName = aggregatorMap[val] || defaultAggregator;
|
|
11
|
-
const aggFactory = aggregators[aggName];
|
|
12
|
-
if (aggFactory) {
|
|
13
|
-
subAggregators[val] = aggFactory([val])(data, rowKey, colKey);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
return {
|
|
17
|
-
push(record) {
|
|
18
|
-
vals.forEach((val) => {
|
|
19
|
-
if (subAggregators[val]) {
|
|
20
|
-
subAggregators[val].push(record);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
},
|
|
24
|
-
value() {
|
|
25
|
-
vals.forEach((val) => {
|
|
26
|
-
if (subAggregators[val]) {
|
|
27
|
-
results[val] = subAggregators[val].value();
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
return results;
|
|
31
|
-
},
|
|
32
|
-
format(values) {
|
|
33
|
-
if (typeof values !== "object") {
|
|
34
|
-
return String(values);
|
|
35
|
-
}
|
|
36
|
-
return vals.map((val) => {
|
|
37
|
-
const subAgg = subAggregators[val];
|
|
38
|
-
const v = values[val];
|
|
39
|
-
return subAgg && subAgg.format ? subAgg.format(v) : String(v);
|
|
40
|
-
}).join(" / ");
|
|
41
|
-
},
|
|
42
|
-
// For individual value access
|
|
43
|
-
valueOf(valName) {
|
|
44
|
-
if (subAggregators[valName]) {
|
|
45
|
-
return subAggregators[valName].value();
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
},
|
|
49
|
-
formatOf(valName, value) {
|
|
50
|
-
if (subAggregators[valName] && subAggregators[valName].format) {
|
|
51
|
-
return subAggregators[valName].format(value);
|
|
52
|
-
}
|
|
53
|
-
return String(value);
|
|
54
|
-
},
|
|
55
|
-
numInputs: vals.length
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
function defaultColorScaleGenerator(values) {
|
|
61
|
-
const min = Math.min(...values.filter((v) => typeof v === "number"));
|
|
62
|
-
const max = Math.max(...values.filter((v) => typeof v === "number"));
|
|
63
|
-
return (value) => {
|
|
64
|
-
if (typeof value !== "number" || max === min) {
|
|
65
|
-
return { backgroundColor: "white" };
|
|
66
|
-
}
|
|
67
|
-
const ratio = (value - min) / (max - min);
|
|
68
|
-
const nonRed = 255 - Math.round(255 * ratio);
|
|
69
|
-
return { backgroundColor: `rgb(255,${nonRed},${nonRed})` };
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function validateAggregatorMap(aggregatorMap, aggregators) {
|
|
73
|
-
const errors = [];
|
|
74
|
-
const availableAggregators = Object.keys(aggregators);
|
|
75
|
-
Object.entries(aggregatorMap).forEach(([val, aggName]) => {
|
|
76
|
-
if (!aggregators[aggName]) {
|
|
77
|
-
errors.push(
|
|
78
|
-
`Unknown aggregator '${aggName}' for value '${val}'. Available: ${availableAggregators.join(", ")}`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
return {
|
|
83
|
-
valid: errors.length === 0,
|
|
84
|
-
errors
|
|
85
|
-
};
|
|
86
|
-
}
|
|
3
|
+
const multiAggregator = require("./multiAggregator-t4E8vUde.cjs");
|
|
87
4
|
function createMultiValueAggregator(aggregatorMap, aggregators, vals) {
|
|
88
5
|
return function multiValueAggregatorFactory(data, rowKey, colKey) {
|
|
89
6
|
const subAggregators = {};
|
|
@@ -162,8 +79,9 @@ function extendPivotData(BasePivotData) {
|
|
|
162
79
|
}
|
|
163
80
|
};
|
|
164
81
|
}
|
|
165
|
-
exports.createMultiAggregator = createMultiAggregator;
|
|
82
|
+
exports.createMultiAggregator = multiAggregator.createMultiAggregator;
|
|
83
|
+
exports.defaultColorScaleGenerator = multiAggregator.defaultColorScaleGenerator;
|
|
84
|
+
exports.getAggregatorNumInputs = multiAggregator.getAggregatorNumInputs;
|
|
85
|
+
exports.validateAggregatorMap = multiAggregator.validateAggregatorMap;
|
|
166
86
|
exports.createMultiValueAggregator = createMultiValueAggregator;
|
|
167
|
-
exports.defaultColorScaleGenerator = defaultColorScaleGenerator;
|
|
168
87
|
exports.extendPivotData = extendPivotData;
|
|
169
|
-
exports.validateAggregatorMap = validateAggregatorMap;
|
package/dist/core.mjs
CHANGED
|
@@ -1,87 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const defaultAggregator = "Sum";
|
|
3
|
-
return function multiAggregatorFactory(vals) {
|
|
4
|
-
return function(data, rowKey, colKey) {
|
|
5
|
-
const subAggregators = {};
|
|
6
|
-
const results = {};
|
|
7
|
-
vals.forEach((val) => {
|
|
8
|
-
const aggName = aggregatorMap[val] || defaultAggregator;
|
|
9
|
-
const aggFactory = aggregators[aggName];
|
|
10
|
-
if (aggFactory) {
|
|
11
|
-
subAggregators[val] = aggFactory([val])(data, rowKey, colKey);
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
return {
|
|
15
|
-
push(record) {
|
|
16
|
-
vals.forEach((val) => {
|
|
17
|
-
if (subAggregators[val]) {
|
|
18
|
-
subAggregators[val].push(record);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
},
|
|
22
|
-
value() {
|
|
23
|
-
vals.forEach((val) => {
|
|
24
|
-
if (subAggregators[val]) {
|
|
25
|
-
results[val] = subAggregators[val].value();
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
return results;
|
|
29
|
-
},
|
|
30
|
-
format(values) {
|
|
31
|
-
if (typeof values !== "object") {
|
|
32
|
-
return String(values);
|
|
33
|
-
}
|
|
34
|
-
return vals.map((val) => {
|
|
35
|
-
const subAgg = subAggregators[val];
|
|
36
|
-
const v = values[val];
|
|
37
|
-
return subAgg && subAgg.format ? subAgg.format(v) : String(v);
|
|
38
|
-
}).join(" / ");
|
|
39
|
-
},
|
|
40
|
-
// For individual value access
|
|
41
|
-
valueOf(valName) {
|
|
42
|
-
if (subAggregators[valName]) {
|
|
43
|
-
return subAggregators[valName].value();
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
},
|
|
47
|
-
formatOf(valName, value) {
|
|
48
|
-
if (subAggregators[valName] && subAggregators[valName].format) {
|
|
49
|
-
return subAggregators[valName].format(value);
|
|
50
|
-
}
|
|
51
|
-
return String(value);
|
|
52
|
-
},
|
|
53
|
-
numInputs: vals.length
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function defaultColorScaleGenerator(values) {
|
|
59
|
-
const min = Math.min(...values.filter((v) => typeof v === "number"));
|
|
60
|
-
const max = Math.max(...values.filter((v) => typeof v === "number"));
|
|
61
|
-
return (value) => {
|
|
62
|
-
if (typeof value !== "number" || max === min) {
|
|
63
|
-
return { backgroundColor: "white" };
|
|
64
|
-
}
|
|
65
|
-
const ratio = (value - min) / (max - min);
|
|
66
|
-
const nonRed = 255 - Math.round(255 * ratio);
|
|
67
|
-
return { backgroundColor: `rgb(255,${nonRed},${nonRed})` };
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function validateAggregatorMap(aggregatorMap, aggregators) {
|
|
71
|
-
const errors = [];
|
|
72
|
-
const availableAggregators = Object.keys(aggregators);
|
|
73
|
-
Object.entries(aggregatorMap).forEach(([val, aggName]) => {
|
|
74
|
-
if (!aggregators[aggName]) {
|
|
75
|
-
errors.push(
|
|
76
|
-
`Unknown aggregator '${aggName}' for value '${val}'. Available: ${availableAggregators.join(", ")}`
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return {
|
|
81
|
-
valid: errors.length === 0,
|
|
82
|
-
errors
|
|
83
|
-
};
|
|
84
|
-
}
|
|
1
|
+
import { c, d, g, v } from "./multiAggregator-1pTQ492r.js";
|
|
85
2
|
function createMultiValueAggregator(aggregatorMap, aggregators, vals) {
|
|
86
3
|
return function multiValueAggregatorFactory(data, rowKey, colKey) {
|
|
87
4
|
const subAggregators = {};
|
|
@@ -120,9 +37,9 @@ function createMultiValueAggregator(aggregatorMap, aggregators, vals) {
|
|
|
120
37
|
return String(values ?? "");
|
|
121
38
|
}
|
|
122
39
|
return vals.map((val) => {
|
|
123
|
-
const
|
|
40
|
+
const v2 = values[val];
|
|
124
41
|
const subAgg = subAggregators[val];
|
|
125
|
-
return subAgg && subAgg.format ? subAgg.format(
|
|
42
|
+
return subAgg && subAgg.format ? subAgg.format(v2) : String(v2 ?? "");
|
|
126
43
|
}).join(" / ");
|
|
127
44
|
},
|
|
128
45
|
formatOf(valName, value) {
|
|
@@ -161,9 +78,10 @@ function extendPivotData(BasePivotData) {
|
|
|
161
78
|
};
|
|
162
79
|
}
|
|
163
80
|
export {
|
|
164
|
-
createMultiAggregator,
|
|
81
|
+
c as createMultiAggregator,
|
|
165
82
|
createMultiValueAggregator,
|
|
166
|
-
defaultColorScaleGenerator,
|
|
83
|
+
d as defaultColorScaleGenerator,
|
|
167
84
|
extendPivotData,
|
|
168
|
-
|
|
85
|
+
g as getAggregatorNumInputs,
|
|
86
|
+
v as validateAggregatorMap
|
|
169
87
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const multiAggregator = require("./multiAggregator-t4E8vUde.cjs");
|
|
3
4
|
const core = require("./core.js");
|
|
4
|
-
exports.createMultiAggregator =
|
|
5
|
+
exports.createMultiAggregator = multiAggregator.createMultiAggregator;
|
|
6
|
+
exports.defaultColorScaleGenerator = multiAggregator.defaultColorScaleGenerator;
|
|
7
|
+
exports.getAggregatorNumInputs = multiAggregator.getAggregatorNumInputs;
|
|
8
|
+
exports.validateAggregatorMap = multiAggregator.validateAggregatorMap;
|
|
5
9
|
exports.createMultiValueAggregator = core.createMultiValueAggregator;
|
|
6
|
-
exports.defaultColorScaleGenerator = core.defaultColorScaleGenerator;
|
|
7
10
|
exports.extendPivotData = core.extendPivotData;
|
|
8
|
-
exports.validateAggregatorMap = core.validateAggregatorMap;
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c, d, g, v } from "./multiAggregator-1pTQ492r.js";
|
|
2
|
+
import { createMultiValueAggregator, extendPivotData } from "./core.mjs";
|
|
2
3
|
export {
|
|
3
|
-
createMultiAggregator,
|
|
4
|
+
c as createMultiAggregator,
|
|
4
5
|
createMultiValueAggregator,
|
|
5
|
-
defaultColorScaleGenerator,
|
|
6
|
+
d as defaultColorScaleGenerator,
|
|
6
7
|
extendPivotData,
|
|
7
|
-
|
|
8
|
+
g as getAggregatorNumInputs,
|
|
9
|
+
v as validateAggregatorMap
|
|
8
10
|
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
function getAggregatorNumInputs(aggFactory) {
|
|
2
|
+
try {
|
|
3
|
+
const instance = aggFactory([])();
|
|
4
|
+
return instance.numInputs || 0;
|
|
5
|
+
} catch {
|
|
6
|
+
return 1;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function createMultiAggregator(aggregatorMap, aggregators) {
|
|
10
|
+
const defaultAggregator = "Sum";
|
|
11
|
+
return function multiAggregatorFactory(vals) {
|
|
12
|
+
return function(data, rowKey, colKey) {
|
|
13
|
+
const subAggregators = {};
|
|
14
|
+
const results = {};
|
|
15
|
+
vals.forEach((val) => {
|
|
16
|
+
const aggConfig = aggregatorMap[val];
|
|
17
|
+
let aggName, aggFields;
|
|
18
|
+
if (typeof aggConfig === "object" && aggConfig !== null) {
|
|
19
|
+
aggName = aggConfig.aggregator || defaultAggregator;
|
|
20
|
+
aggFields = aggConfig.fields || [val];
|
|
21
|
+
} else {
|
|
22
|
+
aggName = aggConfig || defaultAggregator;
|
|
23
|
+
aggFields = [val];
|
|
24
|
+
}
|
|
25
|
+
const aggFactory = aggregators[aggName];
|
|
26
|
+
if (aggFactory) {
|
|
27
|
+
subAggregators[val] = aggFactory(aggFields)(data, rowKey, colKey);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
push(record) {
|
|
32
|
+
vals.forEach((val) => {
|
|
33
|
+
if (subAggregators[val]) {
|
|
34
|
+
subAggregators[val].push(record);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
value() {
|
|
39
|
+
vals.forEach((val) => {
|
|
40
|
+
if (subAggregators[val]) {
|
|
41
|
+
results[val] = subAggregators[val].value();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return results;
|
|
45
|
+
},
|
|
46
|
+
format(values) {
|
|
47
|
+
if (typeof values !== "object") {
|
|
48
|
+
return String(values);
|
|
49
|
+
}
|
|
50
|
+
return vals.map((val) => {
|
|
51
|
+
const subAgg = subAggregators[val];
|
|
52
|
+
const v = values[val];
|
|
53
|
+
return subAgg && subAgg.format ? subAgg.format(v) : String(v);
|
|
54
|
+
}).join(" / ");
|
|
55
|
+
},
|
|
56
|
+
// For individual value access
|
|
57
|
+
valueOf(valName) {
|
|
58
|
+
if (subAggregators[valName]) {
|
|
59
|
+
return subAggregators[valName].value();
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
},
|
|
63
|
+
formatOf(valName, value) {
|
|
64
|
+
if (subAggregators[valName] && subAggregators[valName].format) {
|
|
65
|
+
return subAggregators[valName].format(value);
|
|
66
|
+
}
|
|
67
|
+
return String(value);
|
|
68
|
+
},
|
|
69
|
+
numInputs: vals.length
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function defaultColorScaleGenerator(values) {
|
|
75
|
+
const min = Math.min(...values.filter((v) => typeof v === "number"));
|
|
76
|
+
const max = Math.max(...values.filter((v) => typeof v === "number"));
|
|
77
|
+
return (value) => {
|
|
78
|
+
if (typeof value !== "number" || max === min) {
|
|
79
|
+
return { backgroundColor: "white" };
|
|
80
|
+
}
|
|
81
|
+
const ratio = (value - min) / (max - min);
|
|
82
|
+
const nonRed = 255 - Math.round(255 * ratio);
|
|
83
|
+
return { backgroundColor: `rgb(255,${nonRed},${nonRed})` };
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function validateAggregatorMap(aggregatorMap, aggregators) {
|
|
87
|
+
const errors = [];
|
|
88
|
+
const availableAggregators = Object.keys(aggregators);
|
|
89
|
+
Object.entries(aggregatorMap).forEach(([val, aggName]) => {
|
|
90
|
+
if (!aggregators[aggName]) {
|
|
91
|
+
errors.push(
|
|
92
|
+
`Unknown aggregator '${aggName}' for value '${val}'. Available: ${availableAggregators.join(", ")}`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
valid: errors.length === 0,
|
|
98
|
+
errors
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
createMultiAggregator as c,
|
|
103
|
+
defaultColorScaleGenerator as d,
|
|
104
|
+
getAggregatorNumInputs as g,
|
|
105
|
+
validateAggregatorMap as v
|
|
106
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function getAggregatorNumInputs(aggFactory) {
|
|
3
|
+
try {
|
|
4
|
+
const instance = aggFactory([])();
|
|
5
|
+
return instance.numInputs || 0;
|
|
6
|
+
} catch {
|
|
7
|
+
return 1;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function createMultiAggregator(aggregatorMap, aggregators) {
|
|
11
|
+
const defaultAggregator = "Sum";
|
|
12
|
+
return function multiAggregatorFactory(vals) {
|
|
13
|
+
return function(data, rowKey, colKey) {
|
|
14
|
+
const subAggregators = {};
|
|
15
|
+
const results = {};
|
|
16
|
+
vals.forEach((val) => {
|
|
17
|
+
const aggConfig = aggregatorMap[val];
|
|
18
|
+
let aggName, aggFields;
|
|
19
|
+
if (typeof aggConfig === "object" && aggConfig !== null) {
|
|
20
|
+
aggName = aggConfig.aggregator || defaultAggregator;
|
|
21
|
+
aggFields = aggConfig.fields || [val];
|
|
22
|
+
} else {
|
|
23
|
+
aggName = aggConfig || defaultAggregator;
|
|
24
|
+
aggFields = [val];
|
|
25
|
+
}
|
|
26
|
+
const aggFactory = aggregators[aggName];
|
|
27
|
+
if (aggFactory) {
|
|
28
|
+
subAggregators[val] = aggFactory(aggFields)(data, rowKey, colKey);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
push(record) {
|
|
33
|
+
vals.forEach((val) => {
|
|
34
|
+
if (subAggregators[val]) {
|
|
35
|
+
subAggregators[val].push(record);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
value() {
|
|
40
|
+
vals.forEach((val) => {
|
|
41
|
+
if (subAggregators[val]) {
|
|
42
|
+
results[val] = subAggregators[val].value();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return results;
|
|
46
|
+
},
|
|
47
|
+
format(values) {
|
|
48
|
+
if (typeof values !== "object") {
|
|
49
|
+
return String(values);
|
|
50
|
+
}
|
|
51
|
+
return vals.map((val) => {
|
|
52
|
+
const subAgg = subAggregators[val];
|
|
53
|
+
const v = values[val];
|
|
54
|
+
return subAgg && subAgg.format ? subAgg.format(v) : String(v);
|
|
55
|
+
}).join(" / ");
|
|
56
|
+
},
|
|
57
|
+
// For individual value access
|
|
58
|
+
valueOf(valName) {
|
|
59
|
+
if (subAggregators[valName]) {
|
|
60
|
+
return subAggregators[valName].value();
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
},
|
|
64
|
+
formatOf(valName, value) {
|
|
65
|
+
if (subAggregators[valName] && subAggregators[valName].format) {
|
|
66
|
+
return subAggregators[valName].format(value);
|
|
67
|
+
}
|
|
68
|
+
return String(value);
|
|
69
|
+
},
|
|
70
|
+
numInputs: vals.length
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function defaultColorScaleGenerator(values) {
|
|
76
|
+
const min = Math.min(...values.filter((v) => typeof v === "number"));
|
|
77
|
+
const max = Math.max(...values.filter((v) => typeof v === "number"));
|
|
78
|
+
return (value) => {
|
|
79
|
+
if (typeof value !== "number" || max === min) {
|
|
80
|
+
return { backgroundColor: "white" };
|
|
81
|
+
}
|
|
82
|
+
const ratio = (value - min) / (max - min);
|
|
83
|
+
const nonRed = 255 - Math.round(255 * ratio);
|
|
84
|
+
return { backgroundColor: `rgb(255,${nonRed},${nonRed})` };
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function validateAggregatorMap(aggregatorMap, aggregators) {
|
|
88
|
+
const errors = [];
|
|
89
|
+
const availableAggregators = Object.keys(aggregators);
|
|
90
|
+
Object.entries(aggregatorMap).forEach(([val, aggName]) => {
|
|
91
|
+
if (!aggregators[aggName]) {
|
|
92
|
+
errors.push(
|
|
93
|
+
`Unknown aggregator '${aggName}' for value '${val}'. Available: ${availableAggregators.join(", ")}`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
valid: errors.length === 0,
|
|
99
|
+
errors
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
exports.createMultiAggregator = createMultiAggregator;
|
|
103
|
+
exports.defaultColorScaleGenerator = defaultColorScaleGenerator;
|
|
104
|
+
exports.getAggregatorNumInputs = getAggregatorNumInputs;
|
|
105
|
+
exports.validateAggregatorMap = validateAggregatorMap;
|
package/dist/vue2.js
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const vuePivottable = require("vue-pivottable");
|
|
4
|
+
const multiAggregator = require("./multiAggregator-t4E8vUde.cjs");
|
|
4
5
|
const { PivotData } = vuePivottable.PivotUtilities;
|
|
5
6
|
function createMultiValueAggregator(aggregatorMap, aggregators, vals) {
|
|
7
|
+
const defaultAggregator = "Sum";
|
|
6
8
|
return function multiValueAggregatorFactory(data, rowKey, colKey) {
|
|
7
9
|
const subAggregators = {};
|
|
8
10
|
vals.forEach((val) => {
|
|
9
|
-
const
|
|
11
|
+
const aggConfig = aggregatorMap[val];
|
|
12
|
+
let aggName, aggFields;
|
|
13
|
+
if (typeof aggConfig === "object" && aggConfig !== null) {
|
|
14
|
+
aggName = aggConfig.aggregator || defaultAggregator;
|
|
15
|
+
aggFields = aggConfig.fields || [val];
|
|
16
|
+
} else {
|
|
17
|
+
aggName = aggConfig || defaultAggregator;
|
|
18
|
+
aggFields = [val];
|
|
19
|
+
}
|
|
10
20
|
const aggFactory = aggregators[aggName];
|
|
11
21
|
if (aggFactory) {
|
|
12
|
-
subAggregators[val] = aggFactory(
|
|
22
|
+
subAggregators[val] = aggFactory(aggFields)(data, rowKey, colKey);
|
|
13
23
|
}
|
|
14
24
|
});
|
|
15
25
|
return {
|
|
@@ -181,6 +191,14 @@ function makeMultiValueRenderer(opts = {}) {
|
|
|
181
191
|
if (this.valueLabels && this.valueLabels[valName]) {
|
|
182
192
|
return this.valueLabels[valName];
|
|
183
193
|
}
|
|
194
|
+
const aggConfig = this.aggregatorMap[valName];
|
|
195
|
+
if (typeof aggConfig === "object" && aggConfig !== null && aggConfig.fields) {
|
|
196
|
+
const fields = aggConfig.fields;
|
|
197
|
+
if (fields.length >= 2) {
|
|
198
|
+
return `${fields[0]}/${fields[1]}`;
|
|
199
|
+
}
|
|
200
|
+
return fields[0] || valName;
|
|
201
|
+
}
|
|
184
202
|
return valName;
|
|
185
203
|
},
|
|
186
204
|
/**
|
|
@@ -214,11 +232,19 @@ function makeMultiValueRenderer(opts = {}) {
|
|
|
214
232
|
* Format a single value using the appropriate aggregator
|
|
215
233
|
*/
|
|
216
234
|
formatValue(valName, value) {
|
|
217
|
-
const
|
|
235
|
+
const aggConfig = this.aggregatorMap[valName];
|
|
236
|
+
let aggName, aggFields;
|
|
237
|
+
if (typeof aggConfig === "object" && aggConfig !== null) {
|
|
238
|
+
aggName = aggConfig.aggregator || "Sum";
|
|
239
|
+
aggFields = aggConfig.fields || [valName];
|
|
240
|
+
} else {
|
|
241
|
+
aggName = aggConfig || "Sum";
|
|
242
|
+
aggFields = [valName];
|
|
243
|
+
}
|
|
218
244
|
const agg = this.aggregators[aggName];
|
|
219
245
|
if (agg) {
|
|
220
246
|
try {
|
|
221
|
-
const instance = agg(
|
|
247
|
+
const instance = agg(aggFields)();
|
|
222
248
|
if (instance && instance.format) {
|
|
223
249
|
return instance.format(value);
|
|
224
250
|
}
|
|
@@ -450,5 +476,6 @@ function makeMultiValueRenderer(opts = {}) {
|
|
|
450
476
|
const MultiValueTableRenderer = {
|
|
451
477
|
"Multi-Value Table": makeMultiValueRenderer({ name: "vue2-multi-value-table" })
|
|
452
478
|
};
|
|
479
|
+
exports.getAggregatorNumInputs = multiAggregator.getAggregatorNumInputs;
|
|
453
480
|
exports.MultiValueRenderers = MultiValueTableRenderer;
|
|
454
481
|
exports.makeMultiValueRenderer = makeMultiValueRenderer;
|
package/dist/vue2.mjs
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import { PivotUtilities } from "vue-pivottable";
|
|
2
|
+
import { g } from "./multiAggregator-1pTQ492r.js";
|
|
2
3
|
const { PivotData } = PivotUtilities;
|
|
3
4
|
function createMultiValueAggregator(aggregatorMap, aggregators, vals) {
|
|
5
|
+
const defaultAggregator = "Sum";
|
|
4
6
|
return function multiValueAggregatorFactory(data, rowKey, colKey) {
|
|
5
7
|
const subAggregators = {};
|
|
6
8
|
vals.forEach((val) => {
|
|
7
|
-
const
|
|
9
|
+
const aggConfig = aggregatorMap[val];
|
|
10
|
+
let aggName, aggFields;
|
|
11
|
+
if (typeof aggConfig === "object" && aggConfig !== null) {
|
|
12
|
+
aggName = aggConfig.aggregator || defaultAggregator;
|
|
13
|
+
aggFields = aggConfig.fields || [val];
|
|
14
|
+
} else {
|
|
15
|
+
aggName = aggConfig || defaultAggregator;
|
|
16
|
+
aggFields = [val];
|
|
17
|
+
}
|
|
8
18
|
const aggFactory = aggregators[aggName];
|
|
9
19
|
if (aggFactory) {
|
|
10
|
-
subAggregators[val] = aggFactory(
|
|
20
|
+
subAggregators[val] = aggFactory(aggFields)(data, rowKey, colKey);
|
|
11
21
|
}
|
|
12
22
|
});
|
|
13
23
|
return {
|
|
@@ -179,6 +189,14 @@ function makeMultiValueRenderer(opts = {}) {
|
|
|
179
189
|
if (this.valueLabels && this.valueLabels[valName]) {
|
|
180
190
|
return this.valueLabels[valName];
|
|
181
191
|
}
|
|
192
|
+
const aggConfig = this.aggregatorMap[valName];
|
|
193
|
+
if (typeof aggConfig === "object" && aggConfig !== null && aggConfig.fields) {
|
|
194
|
+
const fields = aggConfig.fields;
|
|
195
|
+
if (fields.length >= 2) {
|
|
196
|
+
return `${fields[0]}/${fields[1]}`;
|
|
197
|
+
}
|
|
198
|
+
return fields[0] || valName;
|
|
199
|
+
}
|
|
182
200
|
return valName;
|
|
183
201
|
},
|
|
184
202
|
/**
|
|
@@ -212,11 +230,19 @@ function makeMultiValueRenderer(opts = {}) {
|
|
|
212
230
|
* Format a single value using the appropriate aggregator
|
|
213
231
|
*/
|
|
214
232
|
formatValue(valName, value) {
|
|
215
|
-
const
|
|
233
|
+
const aggConfig = this.aggregatorMap[valName];
|
|
234
|
+
let aggName, aggFields;
|
|
235
|
+
if (typeof aggConfig === "object" && aggConfig !== null) {
|
|
236
|
+
aggName = aggConfig.aggregator || "Sum";
|
|
237
|
+
aggFields = aggConfig.fields || [valName];
|
|
238
|
+
} else {
|
|
239
|
+
aggName = aggConfig || "Sum";
|
|
240
|
+
aggFields = [valName];
|
|
241
|
+
}
|
|
216
242
|
const agg = this.aggregators[aggName];
|
|
217
243
|
if (agg) {
|
|
218
244
|
try {
|
|
219
|
-
const instance = agg(
|
|
245
|
+
const instance = agg(aggFields)();
|
|
220
246
|
if (instance && instance.format) {
|
|
221
247
|
return instance.format(value);
|
|
222
248
|
}
|
|
@@ -450,5 +476,6 @@ const MultiValueTableRenderer = {
|
|
|
450
476
|
};
|
|
451
477
|
export {
|
|
452
478
|
MultiValueTableRenderer as MultiValueRenderers,
|
|
479
|
+
g as getAggregatorNumInputs,
|
|
453
480
|
makeMultiValueRenderer
|
|
454
481
|
};
|
package/dist/vue3.js
CHANGED
|
@@ -2,15 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const vue = require("vue");
|
|
4
4
|
const vuePivottable = require("vue-pivottable");
|
|
5
|
+
const multiAggregator = require("./multiAggregator-t4E8vUde.cjs");
|
|
5
6
|
const { PivotData } = vuePivottable.PivotUtilities;
|
|
6
7
|
function createMultiValueAggregator(aggregatorMap, aggregators, vals) {
|
|
8
|
+
const defaultAggregator = "Sum";
|
|
7
9
|
return function multiValueAggregatorFactory(data, rowKey, colKey) {
|
|
8
10
|
const subAggregators = {};
|
|
9
11
|
vals.forEach((val) => {
|
|
10
|
-
const
|
|
12
|
+
const aggConfig = aggregatorMap[val];
|
|
13
|
+
let aggName, aggFields;
|
|
14
|
+
if (typeof aggConfig === "object" && aggConfig !== null) {
|
|
15
|
+
aggName = aggConfig.aggregator || defaultAggregator;
|
|
16
|
+
aggFields = aggConfig.fields || [val];
|
|
17
|
+
} else {
|
|
18
|
+
aggName = aggConfig || defaultAggregator;
|
|
19
|
+
aggFields = [val];
|
|
20
|
+
}
|
|
11
21
|
const aggFactory = aggregators[aggName];
|
|
12
22
|
if (aggFactory) {
|
|
13
|
-
subAggregators[val] = aggFactory(
|
|
23
|
+
subAggregators[val] = aggFactory(aggFields)(data, rowKey, colKey);
|
|
14
24
|
}
|
|
15
25
|
});
|
|
16
26
|
return {
|
|
@@ -176,6 +186,14 @@ function makeMultiValueRenderer(opts = {}) {
|
|
|
176
186
|
if (props.valueLabels && props.valueLabels[valName]) {
|
|
177
187
|
return props.valueLabels[valName];
|
|
178
188
|
}
|
|
189
|
+
const aggConfig = props.aggregatorMap[valName];
|
|
190
|
+
if (typeof aggConfig === "object" && aggConfig !== null && aggConfig.fields) {
|
|
191
|
+
const fields = aggConfig.fields;
|
|
192
|
+
if (fields.length >= 2) {
|
|
193
|
+
return `${fields[0]}/${fields[1]}`;
|
|
194
|
+
}
|
|
195
|
+
return fields[0] || valName;
|
|
196
|
+
}
|
|
179
197
|
return valName;
|
|
180
198
|
};
|
|
181
199
|
const spanSize = (arr, i, j) => {
|
|
@@ -203,11 +221,19 @@ function makeMultiValueRenderer(opts = {}) {
|
|
|
203
221
|
return len;
|
|
204
222
|
};
|
|
205
223
|
const formatValue = (valName, value) => {
|
|
206
|
-
const
|
|
224
|
+
const aggConfig = props.aggregatorMap[valName];
|
|
225
|
+
let aggName, aggFields;
|
|
226
|
+
if (typeof aggConfig === "object" && aggConfig !== null) {
|
|
227
|
+
aggName = aggConfig.aggregator || "Sum";
|
|
228
|
+
aggFields = aggConfig.fields || [valName];
|
|
229
|
+
} else {
|
|
230
|
+
aggName = aggConfig || "Sum";
|
|
231
|
+
aggFields = [valName];
|
|
232
|
+
}
|
|
207
233
|
const agg = props.aggregators[aggName];
|
|
208
234
|
if (agg) {
|
|
209
235
|
try {
|
|
210
|
-
const instance = agg(
|
|
236
|
+
const instance = agg(aggFields)();
|
|
211
237
|
if (instance && instance.format) {
|
|
212
238
|
return instance.format(value);
|
|
213
239
|
}
|
|
@@ -250,7 +276,6 @@ function makeMultiValueRenderer(opts = {}) {
|
|
|
250
276
|
}, items);
|
|
251
277
|
};
|
|
252
278
|
const pivotData = vue.computed(() => {
|
|
253
|
-
console.log("Computing pivotData with aggregatorMap:", props.aggregatorMap);
|
|
254
279
|
const multiValueAgg = createMultiValueAggregator(
|
|
255
280
|
props.aggregatorMap,
|
|
256
281
|
props.aggregators,
|
|
@@ -417,5 +442,6 @@ function makeMultiValueRenderer(opts = {}) {
|
|
|
417
442
|
const MultiValueTableRenderer = vue.markRaw({
|
|
418
443
|
"Multi-Value Table": makeMultiValueRenderer({ name: "vue3-multi-value-table" })
|
|
419
444
|
});
|
|
445
|
+
exports.getAggregatorNumInputs = multiAggregator.getAggregatorNumInputs;
|
|
420
446
|
exports.MultiValueRenderers = MultiValueTableRenderer;
|
|
421
447
|
exports.makeMultiValueRenderer = makeMultiValueRenderer;
|
package/dist/vue3.mjs
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import { markRaw, defineComponent, h, computed } from "vue";
|
|
2
2
|
import { PivotUtilities } from "vue-pivottable";
|
|
3
|
+
import { g } from "./multiAggregator-1pTQ492r.js";
|
|
3
4
|
const { PivotData } = PivotUtilities;
|
|
4
5
|
function createMultiValueAggregator(aggregatorMap, aggregators, vals) {
|
|
6
|
+
const defaultAggregator = "Sum";
|
|
5
7
|
return function multiValueAggregatorFactory(data, rowKey, colKey) {
|
|
6
8
|
const subAggregators = {};
|
|
7
9
|
vals.forEach((val) => {
|
|
8
|
-
const
|
|
10
|
+
const aggConfig = aggregatorMap[val];
|
|
11
|
+
let aggName, aggFields;
|
|
12
|
+
if (typeof aggConfig === "object" && aggConfig !== null) {
|
|
13
|
+
aggName = aggConfig.aggregator || defaultAggregator;
|
|
14
|
+
aggFields = aggConfig.fields || [val];
|
|
15
|
+
} else {
|
|
16
|
+
aggName = aggConfig || defaultAggregator;
|
|
17
|
+
aggFields = [val];
|
|
18
|
+
}
|
|
9
19
|
const aggFactory = aggregators[aggName];
|
|
10
20
|
if (aggFactory) {
|
|
11
|
-
subAggregators[val] = aggFactory(
|
|
21
|
+
subAggregators[val] = aggFactory(aggFields)(data, rowKey, colKey);
|
|
12
22
|
}
|
|
13
23
|
});
|
|
14
24
|
return {
|
|
@@ -174,6 +184,14 @@ function makeMultiValueRenderer(opts = {}) {
|
|
|
174
184
|
if (props.valueLabels && props.valueLabels[valName]) {
|
|
175
185
|
return props.valueLabels[valName];
|
|
176
186
|
}
|
|
187
|
+
const aggConfig = props.aggregatorMap[valName];
|
|
188
|
+
if (typeof aggConfig === "object" && aggConfig !== null && aggConfig.fields) {
|
|
189
|
+
const fields = aggConfig.fields;
|
|
190
|
+
if (fields.length >= 2) {
|
|
191
|
+
return `${fields[0]}/${fields[1]}`;
|
|
192
|
+
}
|
|
193
|
+
return fields[0] || valName;
|
|
194
|
+
}
|
|
177
195
|
return valName;
|
|
178
196
|
};
|
|
179
197
|
const spanSize = (arr, i, j) => {
|
|
@@ -201,11 +219,19 @@ function makeMultiValueRenderer(opts = {}) {
|
|
|
201
219
|
return len;
|
|
202
220
|
};
|
|
203
221
|
const formatValue = (valName, value) => {
|
|
204
|
-
const
|
|
222
|
+
const aggConfig = props.aggregatorMap[valName];
|
|
223
|
+
let aggName, aggFields;
|
|
224
|
+
if (typeof aggConfig === "object" && aggConfig !== null) {
|
|
225
|
+
aggName = aggConfig.aggregator || "Sum";
|
|
226
|
+
aggFields = aggConfig.fields || [valName];
|
|
227
|
+
} else {
|
|
228
|
+
aggName = aggConfig || "Sum";
|
|
229
|
+
aggFields = [valName];
|
|
230
|
+
}
|
|
205
231
|
const agg = props.aggregators[aggName];
|
|
206
232
|
if (agg) {
|
|
207
233
|
try {
|
|
208
|
-
const instance = agg(
|
|
234
|
+
const instance = agg(aggFields)();
|
|
209
235
|
if (instance && instance.format) {
|
|
210
236
|
return instance.format(value);
|
|
211
237
|
}
|
|
@@ -248,7 +274,6 @@ function makeMultiValueRenderer(opts = {}) {
|
|
|
248
274
|
}, items);
|
|
249
275
|
};
|
|
250
276
|
const pivotData = computed(() => {
|
|
251
|
-
console.log("Computing pivotData with aggregatorMap:", props.aggregatorMap);
|
|
252
277
|
const multiValueAgg = createMultiValueAggregator(
|
|
253
278
|
props.aggregatorMap,
|
|
254
279
|
props.aggregators,
|
|
@@ -417,5 +442,6 @@ const MultiValueTableRenderer = markRaw({
|
|
|
417
442
|
});
|
|
418
443
|
export {
|
|
419
444
|
MultiValueTableRenderer as MultiValueRenderers,
|
|
445
|
+
g as getAggregatorNumInputs,
|
|
420
446
|
makeMultiValueRenderer
|
|
421
447
|
};
|
package/package.json
CHANGED