@devgateway/dvz-ui-react 1.9.8 → 1.9.9
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const K=require("react"),ee=x=>{var P,j;const{data:l,measures:D,customMeasureLabels:h,children:W,source:B,extraDimension:A,allDimensions:C}=x;console.log("MapDataFrame props:",x);const T=(B||"").split("/").filter(Boolean),y=T.length>0?T[0]:null,i={locationsData:[],nationalData:{},measureLabelMap:{}};l.metadata&&l.metadata.measures&&Array.isArray(l.metadata.measures),l.children&&l.children[0]&&l.children[0].children;const L=l.metadata||{},q=["value","count","type","children","label","measure"],O=C&&C.length>0?C:L.types||[],b={};O.forEach(e=>{const n=e.category||e.type;n&&(b[n]=e.items||[])});const w=(e,n)=>{const a=b[e];if(!a)return null;const t=n!=null?String(n):n;return a.find(r=>{const o=r.value!=null?String(r.value):r.value,c=r.id!=null?String(r.id):r.id,s=r.code!=null?String(r.code):r.code;return o===t||c===t||s===t})||null},f=(e,n)=>{const a=w(e,n);return a?a.value??a.label??a.id??a.code??n:n},J=(e={})=>{const n={};return Object.keys(e).forEach(a=>{const t=e[a];t!=null&&(Array.isArray(t)?n[a]=t.map(r=>f(a,r)).join(" ,"):n[a]=f(a,t))}),n},$=e=>{const n=b[e]||[];return n.length===1?f(e,n[0].value??n[0].id??n[0].code):null},d=e=>e!=null&&e!=="",R=e=>{if(e)return d(e.value)?e.value:d(e.id)?e.id:e.code},V=e=>e==null?"":String(e).trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),v=(e,n)=>{if(!e)return;const a=V(n),t=e[n];if(t!=null&&t!=="")return t;const r=Object.keys(e);for(let o=0;o<r.length;o++){const c=r[o];if(V(c)===a){const s=e[c];if(s!=null&&s!=="")return s}}},G=(e,n)=>{const a=[y,"country",e.type].filter(Boolean),t=[v(n,"country"),v(e,"country"),y?v(n,y):void 0,y?v(e,y):void 0,e.label,e.value].filter(r=>d(r));for(let r=0;r<a.length;r++){const o=a[r],c=b[o]||[];if(c.length)for(let s=0;s<t.length;s++){const g=t[s],U=V(g),N=c.findIndex(k=>{const m=R(k);return V(m)===U});if(N>=0)return N}}return-1},H=(e,n,a)=>{const t=G(n,a);if(t<0)return;const r=b[e]||[];if(!r.length||t>=r.length)return;const o=R(r[t]);if(d(o))return f(e,o)},Q=(e,n,a)=>{const t=v(a,e);if(d(t))return t;if(d(S[e]))return S[e];const r=v(n,e);if(d(r))return r;const o=H(e,n,a);if(d(o))return o;const c=$(e);if(d(c))return c;const s=n.value;return w(e,s)?f(e,s):""},E=l.appliedFilters||{};if(A){const e=E[A]?E[A][0]:void 0;f(A,e)}const S=J(E),X=e=>{const n={};return Object.keys(e).forEach(a=>{q.includes(a)||(n[a]=e[a])}),e.type&&e.value!==void 0&&(n[e.type]=f(e.type,e.value)),n},F=e=>{let n=X(e);return e.children&&Array.isArray(e.children)&&e.children.forEach(a=>{n={...n,...F(a)}}),n},_=(e,n)=>{if(!(!e.children||!Array.isArray(e.children)))return e.children.map(a=>({...a,label:a.value,value:a[n],variables:F(a),children:_(a,n)}))};L.measures&&L.measures.forEach(e=>{h&&h[e.value]&&h[e.value].hasCustomLabel&&h[e.value].customLabel?i.measureLabelMap[e.value]=h[e.value].customLabel:i.measureLabelMap[e.value]=e.label});const z=(((P=l==null?void 0:l.metadata)==null?void 0:P.measures)||[]).map(e=>e==null?void 0:e.value).filter(Boolean),u=(()=>{if(Array.isArray(D))return D.map(e=>(""+e).trim()).filter(Boolean);if(typeof D=="string"){const e=D.trim();if(!e||e==="[]")return z;if(e.startsWith("[")&&e.endsWith("]"))try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(a=>(""+a).trim()).filter(Boolean)}catch{}return e.split(",").map(n=>n.trim()).filter(Boolean)}return z})(),M=((j=l==null?void 0:l.metadata)==null?void 0:j.types)||[],Y=(B||"").split("/")[0],Z=M.find(e=>e.dimension===Y)||M[0],I=(e,n)=>{var o;if(typeof(e==null?void 0:e.value)=="string")return e.value;const t=M.find(c=>c.dimension===(e==null?void 0:e.type))||Z,r=(o=t==null?void 0:t.items)==null?void 0:o[n];return(r==null?void 0:r.value)||(r==null?void 0:r.code)||(e==null?void 0:e.label)||(e==null?void 0:e.value)},p=(e,n)=>{if(e&&Object.prototype.hasOwnProperty.call(e,n))return e[n];if(n==="value")return e==null?void 0:e.value};if(l&&l.children){l.children.forEach((n,a)=>{const t=I(n,a);u.forEach(r=>{const o={...F(n),...S};O.forEach(s=>{const g=s.category||s.type;g&&(o[g]=Q(g,n,o))});const c={...n,label:t,value:p(n,r),measure:r,variables:o};c.variables.selectedDataFrameTooltipValue=p(n,r),n.children&&(c.children=[],n.children.forEach(s=>{c.children.push({...s,label:s.value,value:p(s,r)})})),c.children=_(n,r),i.locationsData.push(c)})}),i.measures=u.length>1?u:null;const e=u.length>0?u[0]:null;i.nationalData.value=e?p(l,e):null}else if(l&&u.length>0){const e=typeof l.value=="string"&&l.value||l.label||l.type||"total";u.forEach(n=>{const a=p(l,n);a!==void 0&&i.locationsData.push({label:e,value:a,measure:n})}),i.measures=u.length>1?u:null,i.nationalData.value=p(l,u[0])}return K.Children.map(W,e=>K.cloneElement(e,{transformedData:{...i,types:M}}))};exports.default=ee;
|
|
@@ -1,165 +1,211 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import K from "react";
|
|
2
|
+
const ae = (S) => {
|
|
3
|
+
var P, _;
|
|
4
|
+
const { data: l, measures: D, customMeasureLabels: h, children: W, source: B, extraDimension: A, allDimensions: C } = S;
|
|
5
|
+
console.log("MapDataFrame props:", S);
|
|
6
|
+
const T = (B || "").split("/").filter(Boolean), y = T.length > 0 ? T[0] : null, u = {
|
|
6
7
|
locationsData: [],
|
|
7
8
|
nationalData: {},
|
|
8
9
|
measureLabelMap: {}
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
l.metadata && l.metadata.measures && Array.isArray(l.metadata.measures), l.children && l.children[0] && l.children[0].children;
|
|
12
|
+
const L = l.metadata || {}, J = ["value", "count", "type", "children", "label", "measure"], O = C && C.length > 0 ? C : L.types || [], b = {};
|
|
13
|
+
O.forEach((e) => {
|
|
13
14
|
const n = e.category || e.type;
|
|
14
|
-
n && (
|
|
15
|
+
n && (b[n] = e.items || []);
|
|
15
16
|
});
|
|
16
|
-
const
|
|
17
|
-
const a =
|
|
17
|
+
const w = (e, n) => {
|
|
18
|
+
const a = b[e];
|
|
18
19
|
if (!a)
|
|
19
20
|
return null;
|
|
20
|
-
const
|
|
21
|
-
return a.find((
|
|
22
|
-
const
|
|
23
|
-
return
|
|
21
|
+
const t = n != null ? String(n) : n;
|
|
22
|
+
return a.find((r) => {
|
|
23
|
+
const o = r.value != null ? String(r.value) : r.value, c = r.id != null ? String(r.id) : r.id, s = r.code != null ? String(r.code) : r.code;
|
|
24
|
+
return o === t || c === t || s === t;
|
|
24
25
|
}) || null;
|
|
25
|
-
},
|
|
26
|
-
const a =
|
|
26
|
+
}, f = (e, n) => {
|
|
27
|
+
const a = w(e, n);
|
|
27
28
|
return a ? a.value ?? a.label ?? a.id ?? a.code ?? n : n;
|
|
28
|
-
},
|
|
29
|
+
}, $ = (e = {}) => {
|
|
29
30
|
const n = {};
|
|
30
31
|
return Object.keys(e).forEach((a) => {
|
|
31
|
-
const
|
|
32
|
-
|
|
32
|
+
const t = e[a];
|
|
33
|
+
t != null && (Array.isArray(t) ? n[a] = t.map((r) => f(a, r)).join(" ,") : n[a] = f(a, t));
|
|
33
34
|
}), n;
|
|
34
|
-
},
|
|
35
|
-
const n =
|
|
36
|
-
return n.length === 1 ?
|
|
37
|
-
},
|
|
35
|
+
}, q = (e) => {
|
|
36
|
+
const n = b[e] || [];
|
|
37
|
+
return n.length === 1 ? f(e, n[0].value ?? n[0].id ?? n[0].code) : null;
|
|
38
|
+
}, d = (e) => e != null && e !== "", R = (e) => {
|
|
38
39
|
if (e)
|
|
39
|
-
return
|
|
40
|
-
},
|
|
40
|
+
return d(e.value) ? e.value : d(e.id) ? e.id : e.code;
|
|
41
|
+
}, V = (e) => e == null ? "" : String(e).trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, ""), p = (e, n) => {
|
|
41
42
|
if (!e)
|
|
42
43
|
return;
|
|
43
|
-
const a =
|
|
44
|
-
if (
|
|
45
|
-
return
|
|
46
|
-
const
|
|
47
|
-
for (let
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
const s = e[
|
|
44
|
+
const a = V(n), t = e[n];
|
|
45
|
+
if (t != null && t !== "")
|
|
46
|
+
return t;
|
|
47
|
+
const r = Object.keys(e);
|
|
48
|
+
for (let o = 0; o < r.length; o++) {
|
|
49
|
+
const c = r[o];
|
|
50
|
+
if (V(c) === a) {
|
|
51
|
+
const s = e[c];
|
|
51
52
|
if (s != null && s !== "")
|
|
52
53
|
return s;
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
},
|
|
56
|
+
}, G = (e, n) => {
|
|
56
57
|
const a = [
|
|
57
|
-
|
|
58
|
+
y,
|
|
58
59
|
"country",
|
|
59
60
|
e.type
|
|
60
|
-
].filter(Boolean),
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
].filter(Boolean), t = [
|
|
62
|
+
p(n, "country"),
|
|
63
|
+
p(e, "country"),
|
|
64
|
+
y ? p(n, y) : void 0,
|
|
65
|
+
y ? p(e, y) : void 0,
|
|
65
66
|
e.label,
|
|
66
67
|
e.value
|
|
67
|
-
].filter((
|
|
68
|
-
for (let
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
for (let s = 0; s <
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
return
|
|
68
|
+
].filter((r) => d(r));
|
|
69
|
+
for (let r = 0; r < a.length; r++) {
|
|
70
|
+
const o = a[r], c = b[o] || [];
|
|
71
|
+
if (c.length)
|
|
72
|
+
for (let s = 0; s < t.length; s++) {
|
|
73
|
+
const g = t[s], U = V(g), j = c.findIndex((k) => {
|
|
74
|
+
const m = R(k);
|
|
75
|
+
return V(m) === U;
|
|
75
76
|
});
|
|
76
|
-
if (
|
|
77
|
-
return
|
|
77
|
+
if (j >= 0)
|
|
78
|
+
return j;
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
return -1;
|
|
81
|
-
},
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
82
|
+
}, H = (e, n, a) => {
|
|
83
|
+
const t = G(n, a);
|
|
84
|
+
if (t < 0)
|
|
84
85
|
return;
|
|
85
|
-
const
|
|
86
|
-
if (!
|
|
86
|
+
const r = b[e] || [];
|
|
87
|
+
if (!r.length || t >= r.length)
|
|
87
88
|
return;
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
90
|
-
return
|
|
91
|
-
},
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
94
|
-
return r;
|
|
95
|
-
if (c(A[e]))
|
|
96
|
-
return A[e];
|
|
97
|
-
const t = v(n, e);
|
|
98
|
-
if (c(t))
|
|
89
|
+
const o = R(r[t]);
|
|
90
|
+
if (d(o))
|
|
91
|
+
return f(e, o);
|
|
92
|
+
}, Q = (e, n, a) => {
|
|
93
|
+
const t = p(a, e);
|
|
94
|
+
if (d(t))
|
|
99
95
|
return t;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
96
|
+
if (d(x[e]))
|
|
97
|
+
return x[e];
|
|
98
|
+
const r = p(n, e);
|
|
99
|
+
if (d(r))
|
|
100
|
+
return r;
|
|
101
|
+
const o = H(e, n, a);
|
|
102
|
+
if (d(o))
|
|
103
|
+
return o;
|
|
104
|
+
const c = q(e);
|
|
105
|
+
if (d(c))
|
|
106
|
+
return c;
|
|
106
107
|
const s = n.value;
|
|
107
|
-
return
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
R = u(d, e);
|
|
108
|
+
return w(e, s) ? f(e, s) : "";
|
|
109
|
+
}, E = l.appliedFilters || {};
|
|
110
|
+
if (A) {
|
|
111
|
+
const e = E[A] ? E[A][0] : void 0;
|
|
112
|
+
f(A, e);
|
|
113
113
|
}
|
|
114
|
-
const
|
|
114
|
+
const x = $(E), X = (e) => {
|
|
115
115
|
const n = {};
|
|
116
116
|
return Object.keys(e).forEach((a) => {
|
|
117
|
-
|
|
118
|
-
}), e.type && e.value !== void 0 && (n[e.type] =
|
|
119
|
-
},
|
|
120
|
-
let n =
|
|
117
|
+
J.includes(a) || (n[a] = e[a]);
|
|
118
|
+
}), e.type && e.value !== void 0 && (n[e.type] = f(e.type, e.value)), n;
|
|
119
|
+
}, F = (e) => {
|
|
120
|
+
let n = X(e);
|
|
121
121
|
return e.children && Array.isArray(e.children) && e.children.forEach((a) => {
|
|
122
|
-
n = { ...n, ...
|
|
122
|
+
n = { ...n, ...F(a) };
|
|
123
123
|
}), n;
|
|
124
|
-
},
|
|
124
|
+
}, z = (e, n) => {
|
|
125
125
|
if (!(!e.children || !Array.isArray(e.children)))
|
|
126
126
|
return e.children.map((a) => ({
|
|
127
127
|
...a,
|
|
128
128
|
label: a.value,
|
|
129
129
|
value: a[n],
|
|
130
|
-
variables:
|
|
131
|
-
children:
|
|
130
|
+
variables: F(a),
|
|
131
|
+
children: z(a, n)
|
|
132
132
|
}));
|
|
133
133
|
};
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
L.measures && L.measures.forEach((e) => {
|
|
135
|
+
h && h[e.value] && h[e.value].hasCustomLabel && h[e.value].customLabel ? u.measureLabelMap[e.value] = h[e.value].customLabel : u.measureLabelMap[e.value] = e.label;
|
|
136
136
|
});
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
137
|
+
const N = (((P = l == null ? void 0 : l.metadata) == null ? void 0 : P.measures) || []).map((e) => e == null ? void 0 : e.value).filter(Boolean), i = (() => {
|
|
138
|
+
if (Array.isArray(D))
|
|
139
|
+
return D.map((e) => ("" + e).trim()).filter(Boolean);
|
|
140
|
+
if (typeof D == "string") {
|
|
141
|
+
const e = D.trim();
|
|
142
|
+
if (!e || e === "[]")
|
|
143
|
+
return N;
|
|
144
|
+
if (e.startsWith("[") && e.endsWith("]"))
|
|
145
|
+
try {
|
|
146
|
+
const n = JSON.parse(e);
|
|
147
|
+
if (Array.isArray(n))
|
|
148
|
+
return n.map((a) => ("" + a).trim()).filter(Boolean);
|
|
149
|
+
} catch {
|
|
150
|
+
}
|
|
151
|
+
return e.split(",").map((n) => n.trim()).filter(Boolean);
|
|
152
|
+
}
|
|
153
|
+
return N;
|
|
154
|
+
})(), M = ((_ = l == null ? void 0 : l.metadata) == null ? void 0 : _.types) || [], Y = (B || "").split("/")[0], Z = M.find((e) => e.dimension === Y) || M[0], I = (e, n) => {
|
|
155
|
+
var o;
|
|
156
|
+
if (typeof (e == null ? void 0 : e.value) == "string")
|
|
157
|
+
return e.value;
|
|
158
|
+
const t = M.find((c) => c.dimension === (e == null ? void 0 : e.type)) || Z, r = (o = t == null ? void 0 : t.items) == null ? void 0 : o[n];
|
|
159
|
+
return (r == null ? void 0 : r.value) || (r == null ? void 0 : r.code) || (e == null ? void 0 : e.label) || (e == null ? void 0 : e.value);
|
|
160
|
+
}, v = (e, n) => {
|
|
161
|
+
if (e && Object.prototype.hasOwnProperty.call(e, n))
|
|
162
|
+
return e[n];
|
|
163
|
+
if (n === "value")
|
|
164
|
+
return e == null ? void 0 : e.value;
|
|
165
|
+
};
|
|
166
|
+
if (l && l.children) {
|
|
167
|
+
l.children.forEach((n, a) => {
|
|
168
|
+
const t = I(n, a);
|
|
169
|
+
i.forEach((r) => {
|
|
170
|
+
const o = {
|
|
171
|
+
...F(n),
|
|
172
|
+
// Dynamic fields for both formats, including nested dimensions
|
|
173
|
+
...x
|
|
174
|
+
};
|
|
175
|
+
O.forEach((s) => {
|
|
176
|
+
const g = s.category || s.type;
|
|
177
|
+
g && (o[g] = Q(g, n, o));
|
|
178
|
+
});
|
|
179
|
+
const c = {
|
|
180
|
+
...n,
|
|
181
|
+
label: t,
|
|
182
|
+
value: v(n, r),
|
|
183
|
+
measure: r,
|
|
184
|
+
variables: o
|
|
185
|
+
};
|
|
186
|
+
c.variables.selectedDataFrameTooltipValue = v(n, r), n.children && (c.children = [], n.children.forEach((s) => {
|
|
187
|
+
c.children.push({ ...s, label: s.value, value: v(s, r) });
|
|
188
|
+
})), c.children = z(n, r), u.locationsData.push(c);
|
|
148
189
|
});
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
190
|
+
}), u.measures = i.length > 1 ? i : null;
|
|
191
|
+
const e = i.length > 0 ? i[0] : null;
|
|
192
|
+
u.nationalData.value = e ? v(l, e) : null;
|
|
193
|
+
} else if (l && i.length > 0) {
|
|
194
|
+
const e = typeof l.value == "string" && l.value || l.label || l.type || "total";
|
|
195
|
+
i.forEach((n) => {
|
|
196
|
+
const a = v(l, n);
|
|
197
|
+
a !== void 0 && u.locationsData.push({
|
|
198
|
+
label: e,
|
|
199
|
+
value: a,
|
|
200
|
+
measure: n
|
|
201
|
+
});
|
|
202
|
+
}), u.measures = i.length > 1 ? i : null, u.nationalData.value = v(l, i[0]);
|
|
203
|
+
}
|
|
204
|
+
return K.Children.map(W, (e) => K.cloneElement(e, { transformedData: {
|
|
205
|
+
...u,
|
|
206
|
+
types: M
|
|
161
207
|
} }));
|
|
162
208
|
};
|
|
163
209
|
export {
|
|
164
|
-
|
|
210
|
+
ae as default
|
|
165
211
|
};
|