@vue-pivottable/multi-value-renderer 0.1.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/LICENSE +21 -0
- package/README.md +167 -0
- package/dist/MultiValuePivotData.js +81 -0
- package/dist/MultiValueTableRenderer.js +364 -0
- package/dist/core.js +92 -0
- package/dist/core.mjs +92 -0
- package/dist/index.js +12 -0
- package/dist/index.mjs +12 -0
- package/dist/styles.css +119 -0
- package/dist/vue2.js +399 -0
- package/dist/vue2.mjs +399 -0
- package/dist/vue3.js +5 -0
- package/dist/vue3.mjs +5 -0
- package/package.json +81 -0
- package/types/index.d.ts +170 -0
package/dist/core.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const MultiValuePivotData = require("./MultiValuePivotData.js");
|
|
4
|
+
function createMultiAggregator(aggregatorMap, aggregators) {
|
|
5
|
+
const defaultAggregator = "Sum";
|
|
6
|
+
return function multiAggregatorFactory(vals) {
|
|
7
|
+
return function(data, rowKey, colKey) {
|
|
8
|
+
const subAggregators = {};
|
|
9
|
+
const results = {};
|
|
10
|
+
vals.forEach((val) => {
|
|
11
|
+
const aggName = aggregatorMap[val] || defaultAggregator;
|
|
12
|
+
const aggFactory = aggregators[aggName];
|
|
13
|
+
if (aggFactory) {
|
|
14
|
+
subAggregators[val] = aggFactory([val])(data, rowKey, colKey);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
push(record) {
|
|
19
|
+
vals.forEach((val) => {
|
|
20
|
+
if (subAggregators[val]) {
|
|
21
|
+
subAggregators[val].push(record);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
value() {
|
|
26
|
+
vals.forEach((val) => {
|
|
27
|
+
if (subAggregators[val]) {
|
|
28
|
+
results[val] = subAggregators[val].value();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return results;
|
|
32
|
+
},
|
|
33
|
+
format(values) {
|
|
34
|
+
if (typeof values !== "object") {
|
|
35
|
+
return String(values);
|
|
36
|
+
}
|
|
37
|
+
return vals.map((val) => {
|
|
38
|
+
const subAgg = subAggregators[val];
|
|
39
|
+
const v = values[val];
|
|
40
|
+
return subAgg && subAgg.format ? subAgg.format(v) : String(v);
|
|
41
|
+
}).join(" / ");
|
|
42
|
+
},
|
|
43
|
+
// For individual value access
|
|
44
|
+
valueOf(valName) {
|
|
45
|
+
if (subAggregators[valName]) {
|
|
46
|
+
return subAggregators[valName].value();
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
},
|
|
50
|
+
formatOf(valName, value) {
|
|
51
|
+
if (subAggregators[valName] && subAggregators[valName].format) {
|
|
52
|
+
return subAggregators[valName].format(value);
|
|
53
|
+
}
|
|
54
|
+
return String(value);
|
|
55
|
+
},
|
|
56
|
+
numInputs: vals.length
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function defaultColorScaleGenerator(values) {
|
|
62
|
+
const min = Math.min(...values.filter((v) => typeof v === "number"));
|
|
63
|
+
const max = Math.max(...values.filter((v) => typeof v === "number"));
|
|
64
|
+
return (value) => {
|
|
65
|
+
if (typeof value !== "number" || max === min) {
|
|
66
|
+
return { backgroundColor: "white" };
|
|
67
|
+
}
|
|
68
|
+
const ratio = (value - min) / (max - min);
|
|
69
|
+
const nonRed = 255 - Math.round(255 * ratio);
|
|
70
|
+
return { backgroundColor: `rgb(255,${nonRed},${nonRed})` };
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function validateAggregatorMap(aggregatorMap, aggregators) {
|
|
74
|
+
const errors = [];
|
|
75
|
+
const availableAggregators = Object.keys(aggregators);
|
|
76
|
+
Object.entries(aggregatorMap).forEach(([val, aggName]) => {
|
|
77
|
+
if (!aggregators[aggName]) {
|
|
78
|
+
errors.push(
|
|
79
|
+
`Unknown aggregator '${aggName}' for value '${val}'. Available: ${availableAggregators.join(", ")}`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
valid: errors.length === 0,
|
|
85
|
+
errors
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
exports.createMultiValueAggregator = MultiValuePivotData.createMultiValueAggregator;
|
|
89
|
+
exports.extendPivotData = MultiValuePivotData.extendPivotData;
|
|
90
|
+
exports.createMultiAggregator = createMultiAggregator;
|
|
91
|
+
exports.defaultColorScaleGenerator = defaultColorScaleGenerator;
|
|
92
|
+
exports.validateAggregatorMap = validateAggregatorMap;
|
package/dist/core.mjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { c, e } from "./MultiValuePivotData.js";
|
|
2
|
+
function createMultiAggregator(aggregatorMap, aggregators) {
|
|
3
|
+
const defaultAggregator = "Sum";
|
|
4
|
+
return function multiAggregatorFactory(vals) {
|
|
5
|
+
return function(data, rowKey, colKey) {
|
|
6
|
+
const subAggregators = {};
|
|
7
|
+
const results = {};
|
|
8
|
+
vals.forEach((val) => {
|
|
9
|
+
const aggName = aggregatorMap[val] || defaultAggregator;
|
|
10
|
+
const aggFactory = aggregators[aggName];
|
|
11
|
+
if (aggFactory) {
|
|
12
|
+
subAggregators[val] = aggFactory([val])(data, rowKey, colKey);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
push(record) {
|
|
17
|
+
vals.forEach((val) => {
|
|
18
|
+
if (subAggregators[val]) {
|
|
19
|
+
subAggregators[val].push(record);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
value() {
|
|
24
|
+
vals.forEach((val) => {
|
|
25
|
+
if (subAggregators[val]) {
|
|
26
|
+
results[val] = subAggregators[val].value();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return results;
|
|
30
|
+
},
|
|
31
|
+
format(values) {
|
|
32
|
+
if (typeof values !== "object") {
|
|
33
|
+
return String(values);
|
|
34
|
+
}
|
|
35
|
+
return vals.map((val) => {
|
|
36
|
+
const subAgg = subAggregators[val];
|
|
37
|
+
const v = values[val];
|
|
38
|
+
return subAgg && subAgg.format ? subAgg.format(v) : String(v);
|
|
39
|
+
}).join(" / ");
|
|
40
|
+
},
|
|
41
|
+
// For individual value access
|
|
42
|
+
valueOf(valName) {
|
|
43
|
+
if (subAggregators[valName]) {
|
|
44
|
+
return subAggregators[valName].value();
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
},
|
|
48
|
+
formatOf(valName, value) {
|
|
49
|
+
if (subAggregators[valName] && subAggregators[valName].format) {
|
|
50
|
+
return subAggregators[valName].format(value);
|
|
51
|
+
}
|
|
52
|
+
return String(value);
|
|
53
|
+
},
|
|
54
|
+
numInputs: vals.length
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function defaultColorScaleGenerator(values) {
|
|
60
|
+
const min = Math.min(...values.filter((v) => typeof v === "number"));
|
|
61
|
+
const max = Math.max(...values.filter((v) => typeof v === "number"));
|
|
62
|
+
return (value) => {
|
|
63
|
+
if (typeof value !== "number" || max === min) {
|
|
64
|
+
return { backgroundColor: "white" };
|
|
65
|
+
}
|
|
66
|
+
const ratio = (value - min) / (max - min);
|
|
67
|
+
const nonRed = 255 - Math.round(255 * ratio);
|
|
68
|
+
return { backgroundColor: `rgb(255,${nonRed},${nonRed})` };
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function validateAggregatorMap(aggregatorMap, aggregators) {
|
|
72
|
+
const errors = [];
|
|
73
|
+
const availableAggregators = Object.keys(aggregators);
|
|
74
|
+
Object.entries(aggregatorMap).forEach(([val, aggName]) => {
|
|
75
|
+
if (!aggregators[aggName]) {
|
|
76
|
+
errors.push(
|
|
77
|
+
`Unknown aggregator '${aggName}' for value '${val}'. Available: ${availableAggregators.join(", ")}`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
valid: errors.length === 0,
|
|
83
|
+
errors
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
createMultiAggregator,
|
|
88
|
+
c as createMultiValueAggregator,
|
|
89
|
+
defaultColorScaleGenerator,
|
|
90
|
+
e as extendPivotData,
|
|
91
|
+
validateAggregatorMap
|
|
92
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const core = require("./core.js");
|
|
4
|
+
const MultiValuePivotData = require("./MultiValuePivotData.js");
|
|
5
|
+
const MultiValueTableRenderer = require("./MultiValueTableRenderer.js");
|
|
6
|
+
exports.createMultiAggregator = core.createMultiAggregator;
|
|
7
|
+
exports.defaultColorScaleGenerator = core.defaultColorScaleGenerator;
|
|
8
|
+
exports.validateAggregatorMap = core.validateAggregatorMap;
|
|
9
|
+
exports.createMultiValueAggregator = MultiValuePivotData.createMultiValueAggregator;
|
|
10
|
+
exports.extendPivotData = MultiValuePivotData.extendPivotData;
|
|
11
|
+
exports.MultiValueRenderers = MultiValueTableRenderer.MultiValueTableRenderer;
|
|
12
|
+
exports.makeMultiValueRenderer = MultiValueTableRenderer.makeMultiValueRenderer;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createMultiAggregator, defaultColorScaleGenerator, validateAggregatorMap } from "./core.mjs";
|
|
2
|
+
import { c, e } from "./MultiValuePivotData.js";
|
|
3
|
+
import { M, m } from "./MultiValueTableRenderer.js";
|
|
4
|
+
export {
|
|
5
|
+
M as MultiValueRenderers,
|
|
6
|
+
createMultiAggregator,
|
|
7
|
+
c as createMultiValueAggregator,
|
|
8
|
+
defaultColorScaleGenerator,
|
|
9
|
+
e as extendPivotData,
|
|
10
|
+
m as makeMultiValueRenderer,
|
|
11
|
+
validateAggregatorMap
|
|
12
|
+
};
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-Value Renderer Styles
|
|
3
|
+
*
|
|
4
|
+
* Styles for the multi-value table renderer.
|
|
5
|
+
* Import this CSS alongside your vue-pivottable styles.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/* Multi-value table */
|
|
9
|
+
.pvtMultiValueTable {
|
|
10
|
+
border-collapse: collapse;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/* Multi-value cell container */
|
|
14
|
+
.multi-value-cell {
|
|
15
|
+
display: flex;
|
|
16
|
+
gap: 4px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.multi-value-cell.layout-vertical {
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.multi-value-cell.layout-horizontal {
|
|
24
|
+
flex-direction: row;
|
|
25
|
+
flex-wrap: wrap;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Individual value item */
|
|
29
|
+
.multi-value-item {
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: baseline;
|
|
32
|
+
font-size: 0.9em;
|
|
33
|
+
line-height: 1.4;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.multi-value-item:not(:last-child) {
|
|
37
|
+
padding-bottom: 2px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* Value label (e.g., "Sales:") */
|
|
41
|
+
.multi-value-label {
|
|
42
|
+
color: #666;
|
|
43
|
+
font-size: 0.85em;
|
|
44
|
+
margin-right: 4px;
|
|
45
|
+
white-space: nowrap;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* Value number */
|
|
49
|
+
.multi-value-value {
|
|
50
|
+
font-weight: 500;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Multi-value cells in table */
|
|
54
|
+
.pvtMultiVal {
|
|
55
|
+
padding: 6px 8px !important;
|
|
56
|
+
vertical-align: top;
|
|
57
|
+
min-width: 80px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* Horizontal layout adjustments */
|
|
61
|
+
.layout-horizontal .multi-value-item {
|
|
62
|
+
padding-right: 8px;
|
|
63
|
+
border-right: 1px solid #eee;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.layout-horizontal .multi-value-item:last-child {
|
|
67
|
+
padding-right: 0;
|
|
68
|
+
border-right: none;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/* Compact layout - no special styling needed */
|
|
72
|
+
|
|
73
|
+
/* Hover effects */
|
|
74
|
+
.pvtMultiVal:hover {
|
|
75
|
+
background-color: rgba(0, 0, 0, 0.02);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* Totals styling */
|
|
79
|
+
.pvtTotal.pvtMultiVal,
|
|
80
|
+
.pvtGrandTotal.pvtMultiVal {
|
|
81
|
+
background-color: #f8f8f8;
|
|
82
|
+
font-weight: 600;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.pvtTotal.pvtMultiVal .multi-value-value,
|
|
86
|
+
.pvtGrandTotal.pvtMultiVal .multi-value-value {
|
|
87
|
+
font-weight: 600;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* Dark mode support */
|
|
91
|
+
@media (prefers-color-scheme: dark) {
|
|
92
|
+
.multi-value-label {
|
|
93
|
+
color: #aaa;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.layout-horizontal .multi-value-item {
|
|
97
|
+
border-right-color: #444;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.pvtMultiVal:hover {
|
|
101
|
+
background-color: rgba(255, 255, 255, 0.05);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.pvtTotal.pvtMultiVal,
|
|
105
|
+
.pvtGrandTotal.pvtMultiVal {
|
|
106
|
+
background-color: #2a2a2a;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* Print styles */
|
|
111
|
+
@media print {
|
|
112
|
+
.multi-value-label {
|
|
113
|
+
color: #333;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.pvtMultiVal:hover {
|
|
117
|
+
background-color: transparent;
|
|
118
|
+
}
|
|
119
|
+
}
|