@graphysdk/geom-mekko 0.1.0 → 0.1.1-beta.1792417802336
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/dist/index.cjs +1 -1
- package/dist/index.mjs +104 -102
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let n=require("@graphysdk/react"),x=require("react"),f=require("react/jsx-runtime");var V=(e,t)=>{const a=t==="x"?(0,n.getXMin)(e):(0,n.getYMin)(e),o=t==="x"?(0,n.getXMax)(e):(0,n.getYMax)(e),r=t==="x"?(0,n.getYMin)(e):(0,n.getXMin)(e),s=t==="x"?(0,n.getYMax)(e):(0,n.getXMax)(e);return a===null||o===null||r===null||s===null?null:{observation:e,columnStart:a,columnEnd:o,low:r,high:s}},S=(e,t)=>{const a=[];for(const o of e){const r=V(o,t);r!==null&&a.push(r)}return a},w=e=>e===null||!Number.isFinite(e)||e<=0?null:e,B=(e,t,a,o="data")=>{const r=a.map(w),s=I(t),l=e.map((d,c)=>c).sort((d,c)=>(s.get(t[d])??0)-(s.get(t[c])??0)),u=new Map;for(const d of l){const c=e[d],m=r[d];c===null||m===null||m===void 0||u.set(c,(u.get(c)??0)+m)}const v=new Map;let h=0;for(const[d,c]of
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let n=require("@graphysdk/react"),x=require("react"),f=require("react/jsx-runtime");var V=(e,t)=>{const a=t==="x"?(0,n.getXMin)(e):(0,n.getYMin)(e),o=t==="x"?(0,n.getXMax)(e):(0,n.getYMax)(e),r=t==="x"?(0,n.getYMin)(e):(0,n.getXMin)(e),s=t==="x"?(0,n.getYMax)(e):(0,n.getXMax)(e);return a===null||o===null||r===null||s===null?null:{observation:e,columnStart:a,columnEnd:o,low:r,high:s}},S=(e,t)=>{const a=[];for(const o of e){const r=V(o,t);r!==null&&a.push(r)}return a},w=e=>e===null||!Number.isFinite(e)||e<=0?null:e,B=(e,t,a,o="data")=>{const r=a.map(w),s=I(t),l=e.map((d,c)=>c).sort((d,c)=>(s.get(t[d])??0)-(s.get(t[c])??0)),u=new Map;for(const d of l){const c=e[d],m=r[d];c===null||m===null||m===void 0||u.set(c,(u.get(c)??0)+m)}const v=new Map;let h=0;for(const[d,c]of G([...u],o)){const m=h;h+=c,v.set(d,{start:m,end:h})}const i=h;if(i===0)return r.map(()=>null);const g=r.map(()=>null),p=new Map;for(const d of l){const c=e[d],m=r[d],k=u.get(c),b=v.get(c);if(m==null||k===void 0||k===0||b===void 0)continue;const M=p.get(c)??0;p.set(c,M+m),g[d]={columnStart:b.start/i,columnEnd:b.end/i,cellStart:M/k,cellEnd:(M+m)/k,shareOfColumn:m/k,columnShare:k/i}}return g},I=e=>{const t=new Map;for(const a of e)t.has(a)||t.set(a,t.size);return t},G=(e,t)=>{if(t==="data")return e;if(t==="ascending")return[...e].sort(([,r],[,s])=>r-s);if(t==="descending")return[...e].sort(([,r],[,s])=>s-r);const a=I(t),o=r=>a.get(r)??a.size;return[...e].sort(([r],[s])=>o(r)-o(s))},y={shareOfColumn:"mekkoShareOfColumn",columnShare:"mekkoColumnShare"},j=["data","ascending","descending"],P=e=>j.includes(e)||Array.isArray(e)&&e.every(t=>typeof t=="string"||typeof t=="number"),D=e=>{const t=e?.sort;return P(t)?t:"data"},E=new Set(["value","columnShare"]),O="mekkoAmount",K=class extends n.Stat{constructor(...e){super(...e),this.type="mekko",this.computedVariables=E}computeStat({data:e,mapping:t,params:a}){const o=(0,n.readVariableName)(t.x),r=(0,n.readVariableName)(t.y);if(o===null||r===null||!e.hasVariable(o)||!e.hasVariable(r))return{data:e,mapping:{}};if(e.size()>0&&e.getType(r)!=="numeric"){const u=e.getType(r);throw new n.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'mekko' stat requires a numeric 'y' (got '${u}' for variable '${r}')`,context:{aesthetic:"y",variableName:r,variableType:u},suggestion:"Map each cell's amount to 'y'."})}const s=(0,n.getGroupVariables)(e,t).filter(u=>u!==o),l=H(e,o,r,s);return{data:R(l,o,r,s,D(a)),mapping:{y:y.shareOfColumn,value:r,columnShare:y.columnShare}}}},H=(e,t,a,o)=>{const r=e.getValues(a,{type:"numeric"}).map(w);return e.addVariable(O,"numeric",r,e.getValueFormat(a)).groupBy(t,...o).rollup({[a]:{variableName:O,aggregation:"sum"}})},R=(e,t,a,o,r)=>{const s=o.map(i=>e.getValues(i)),l=Array.from({length:e.size()},(i,g)=>JSON.stringify(s.map(p=>p[g]))),u=B(e.getValues(t).map(X),l,e.getValues(a,{type:"numeric"}),r),v={type:"percentage"},h=i=>u.map(g=>g===null?null:i(g));return e.addVariable(y.shareOfColumn,"numeric",h(i=>i.shareOfColumn),v).addVariable(y.columnShare,"numeric",h(i=>i.columnShare),v).addVariable(n.POSITION_VARIABLES.xMin,"numeric",h(i=>i.columnStart)).addVariable(n.POSITION_VARIABLES.xMax,"numeric",h(i=>i.columnEnd)).addVariable(n.POSITION_VARIABLES.yMin,"numeric",h(i=>i.cellStart)).addVariable(n.POSITION_VARIABLES.yMax,"numeric",h(i=>i.cellEnd))},X=e=>e instanceof Date?e.getTime():e,_=(e,t)=>{const a=(0,n.composePoint)(t,{main:e.columnStart,cross:e.low}),o=(0,n.composePoint)(t,{main:e.columnEnd,cross:e.high}),[r,s]=T((0,n.toViewBoxX)(a.x),(0,n.toViewBoxX)(o.x)),[l,u]=T((0,n.toViewBoxY)(a.y),(0,n.toViewBoxY)(o.y));return{x:r,y:l,width:s-r,height:u-l}},L=(e,t,a)=>{const o=_(e,t);return{x:o.x*a.width,y:o.y*a.height,width:o.width*a.width,height:o.height*a.height}},T=(e,t)=>e<=t?[e,t]:[t,e],$=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return{labels:t,droppedCount:0};const{position:a,justify:o,align:r,offset:s}=e.layer.dataLabels,l=a==="auto",u=l?"inside":a,v=(0,n.readMainAxis)(e.coordSystem),h=(0,n.buildPanelAnchorBox)(e.panelRect);let i=0;for(const g of S(e.layer.data,v)){const p=e.formatLabel(g.observation);if(p==="")continue;const{width:d,height:c}=e.measureDataLabel("observation",u,p),m=(0,n.resolveAnchoredLabelCenter)({box:L(g,v,e.panelRect),panel:h,orientation:v==="x"?{valueAxis:"y",valueDirectionSign:-1}:{valueAxis:"x",valueDirectionSign:1},placement:u,justify:l?"center":o,align:l?"center":r,offset:s,labelWidth:d,labelHeight:c});if(l&&m.position!=="inside"){i+=1;continue}t.push({layerId:e.layer.id,x:m.x,y:m.y,text:p,width:d,height:c,isRotated:!1,role:"observation",position:m.position,backdropColor:m.position==="inside"?(0,n.readBackdropColor)(e.styleReaders,g.observation):void 0})}return{labels:t,droppedCount:i}},W=1,Y={strokeWidth:"pixels"},N=class extends n.Geom{constructor(...e){super(...e),this.type="mekko",this.defaultParams={},this.defaultStat=new K,this.positionRoles=[{axis:"x",role:"min",valueKind:"value"},{axis:"x",role:"max",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"alpha"},{kind:"data",name:"value"},{kind:"data",name:"columnShare"}],this.derivedVariables=[y.shareOfColumn,y.columnShare],this.supportedPositions=["identity"],this.supportedCoordTypes=["cartesian","flip"],this.categorySpanAxes=["x"],this.grid={cartesian:{hideGridX:!0},flip:{hideGridX:!0}},this.legend={suppressWhenSingleItem:!0},this.dataLabelCoordTypes=["cartesian","flip"],this.getDataLabelPlacements=$,this.spatialKind="rects",this.highlightStrategy="observation-rerender",this.styleTarget=(0,n.defineGeomStyleTarget)({observation:{vocabulary:Y,aesthetics:{fill:"color",alpha:"alpha"},rest:{fill:(0,n.token)("geom"),fillAlpha:1,stroke:(0,n.token)("graphBackground"),strokeWidth:W}}}),this.validateMapping=({mapping:t,computedVariables:a})=>a.has("columnShare")?[...E].filter(o=>t[o]!==void 0).map(o=>({code:"CONFLICTING_STAT_MAPPING",message:`mekko stat computes '${o}' from 'x' and 'y'; remove its mapping`})):[{code:"MISSING_STAT_OUTPUT",message:"mekko geom lays its cells out in the 'mekko' stat; remove the layer's stat"}],this.resolveAnchorPosition=(t,{coordSystem:a})=>{const o=(0,n.readMainAxis)(a),r=V(t,o);if(r===null)return null;const s=(r.columnStart+r.columnEnd)/2,l=(r.low+r.high)/2;return o==="x"?{x:s,y:l}:{x:l,y:s}}}resolveParams(e){const{sort:t,...a}=super.resolveParams(e);return t===void 0||P(t)?t===void 0?a:{...a,sort:t}:(e.diagnostics?.addWarning({code:"INVALID_GEOM_PARAM",message:`Mekko sort must be 'data', 'ascending', 'descending' or a list of columns, got ${JSON.stringify(t)}; falling back to 'data'.`,context:{geom:"mekko",param:"sort",expected:"'data' | 'ascending' | 'descending' | columns[]"},suggestion:"Set params.sort to 'descending' to run the columns largest first, or list them in order."}),a)}compile({data:e}){return{data:e,mapping:{}}}},F=({layer:e,coordSystem:t,panelRect:a})=>{const o=(0,n.readMainAxis)(t);return S(e.data,o).map(r=>{const s=L(r,o,a),l=s.x+s.width,u=s.y+s.height;return{kind:"region",pathData:`M${s.x},${s.y}H${l}V${u}H${s.x}Z`}})},C=e=>{const t=(0,n.createStableKeyGenerator)(e.data,e.mapping,e.id);return a=>t(a.observation)},A=({cells:e,mainAxis:t,styleReaders:a,getKey:o,isHovered:r=!1,shouldAnimateTransitions:s=!1})=>{const l=r?"hovered":void 0,u=(0,x.useMemo)(()=>e.map(i=>a.get("fill",i.observation,l)??"transparent"),[e,a,l]),{fillFor:v,defs:h}=(0,n.usePaintDefs)({paints:u});return(0,f.jsxs)(f.Fragment,{children:[h,e.map((i,g)=>{const p=_(i,t),d=u[g],c=a.get("stroke",i.observation,l);return(0,f.jsx)(n.GeomRect,{"data-testid":"mekko-cell",x:(0,n.toPercent)(p.x),y:(0,n.toPercent)(p.y),width:(0,n.toPercent)(p.width),height:(0,n.toPercent)(p.height),fill:d===void 0?void 0:v(d),opacity:a.get("alpha",i.observation,l),fillOpacity:a.get("fillAlpha",i.observation,l),stroke:c===void 0?void 0:(0,n.toPaintColor)(c),strokeWidth:a.get("strokeWidth",i.observation,l),cornerRadius:a.get("cornerRadius",i.observation,l),effects:(0,n.readGeomEffects)(a,i.observation,l),shouldAnimateTransitions:s},o(i))})]})},U=({layer:e,sourceLayer:t,mainAxis:a,styleReaders:o})=>(0,f.jsx)(A,{cells:(0,x.useMemo)(()=>S(e.data,a),[e.data,a]),mainAxis:a,styleReaders:o,getKey:(0,x.useMemo)(()=>C(t),[t])}),q=({layer:e,primary:t,mainAxis:a,styleReaders:o})=>(0,f.jsx)("g",{"data-testid":"hovered-cells",children:(0,f.jsx)(A,{cells:S([t.observation],a),mainAxis:a,styleReaders:o,getKey:(0,x.useMemo)(()=>C(e),[e]),isHovered:!0})}),z=({layer:e,mainAxis:t,styleReaders:a,shouldAnimateTransitions:o,intro:r})=>{const s=(0,f.jsx)(A,{cells:(0,x.useMemo)(()=>S(e.data,t),[e.data,t]),mainAxis:t,styleReaders:a,getKey:(0,x.useMemo)(()=>C(e),[e]),shouldAnimateTransitions:o});return r==null?s:(0,f.jsx)(n.IntroFade,{intro:{type:"fade",layerId:r.layerId,durationSeconds:r.durationSeconds},children:s})},J=(0,n.defineGeomRenderer)(new N,{coord:"cartesian",swatchShape:"square",render:({layer:e,coordSystem:t,styleReaders:a,shouldAnimateTransitions:o,intro:r})=>(0,f.jsx)(z,{layer:e,mainAxis:(0,n.readMainAxis)(t),styleReaders:a,shouldAnimateTransitions:o,intro:r}),renderHighlight:({layer:e,sourceLayer:t,coordSystem:a,styleReaders:o})=>(0,f.jsx)(U,{layer:e,sourceLayer:t,mainAxis:(0,n.readMainAxis)(a),styleReaders:o}),renderHover:({layer:e,primary:t,coordSystem:a,styleReaders:o})=>(0,f.jsx)(q,{layer:e,primary:t,mainAxis:(0,n.readMainAxis)(a),styleReaders:o}),renderHoverCompanions:()=>null,getEditOutlineShapes:F});exports.MekkoGeom=N;exports.mekko=J;
|
package/dist/index.mjs
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { Geom as X, GeomRect as Y, IntroFade as j, POSITION_VARIABLES as
|
|
1
|
+
import { Geom as X, GeomRect as Y, IntroFade as j, POSITION_VARIABLES as x, Stat as z, UserInputError as q, buildPanelAnchorBox as J, composePoint as O, createStableKeyGenerator as Z, defineGeomRenderer as Q, defineGeomStyleTarget as ee, getGroupVariables as te, getXMax as V, getXMin as E, getYMax as P, getYMin as I, readBackdropColor as re, readGeomEffects as oe, readMainAxis as k, readVariableName as L, resolveAnchoredLabelCenter as ae, toPaintColor as ne, toPercent as C, toViewBoxX as _, toViewBoxY as N, token as G, usePaintDefs as se } from "@graphysdk/react";
|
|
2
2
|
import { useMemo as y } from "react";
|
|
3
|
-
import { Fragment as
|
|
3
|
+
import { Fragment as ie, jsx as f, jsxs as le } from "react/jsx-runtime";
|
|
4
4
|
var K = (e, t) => {
|
|
5
|
-
const r = t === "x" ? E(e) : I(e),
|
|
6
|
-
return r === null ||
|
|
5
|
+
const r = t === "x" ? E(e) : I(e), a = t === "x" ? V(e) : P(e), o = t === "x" ? I(e) : E(e), n = t === "x" ? P(e) : V(e);
|
|
6
|
+
return r === null || a === null || o === null || n === null ? null : {
|
|
7
7
|
observation: e,
|
|
8
8
|
columnStart: r,
|
|
9
|
-
columnEnd:
|
|
10
|
-
low:
|
|
9
|
+
columnEnd: a,
|
|
10
|
+
low: o,
|
|
11
11
|
high: n
|
|
12
12
|
};
|
|
13
|
-
},
|
|
13
|
+
}, b = (e, t) => {
|
|
14
14
|
const r = [];
|
|
15
|
-
for (const
|
|
16
|
-
const
|
|
17
|
-
|
|
15
|
+
for (const a of e) {
|
|
16
|
+
const o = K(a, t);
|
|
17
|
+
o !== null && r.push(o);
|
|
18
18
|
}
|
|
19
19
|
return r;
|
|
20
|
-
}, H = (e) => e === null || !Number.isFinite(e) || e <= 0 ? null : e,
|
|
21
|
-
const
|
|
20
|
+
}, H = (e) => e === null || !Number.isFinite(e) || e <= 0 ? null : e, ue = (e, t, r, a = "data") => {
|
|
21
|
+
const o = r.map(H), n = $(t), i = e.map((c, u) => u).sort((c, u) => (n.get(t[c]) ?? 0) - (n.get(t[u]) ?? 0)), l = /* @__PURE__ */ new Map();
|
|
22
22
|
for (const c of i) {
|
|
23
|
-
const u = e[c], d =
|
|
23
|
+
const u = e[c], d = o[c];
|
|
24
24
|
u === null || d === null || d === void 0 || l.set(u, (l.get(u) ?? 0) + d);
|
|
25
25
|
}
|
|
26
26
|
const p = /* @__PURE__ */ new Map();
|
|
27
27
|
let m = 0;
|
|
28
|
-
for (const [c, u] of
|
|
28
|
+
for (const [c, u] of ce([...l], a)) {
|
|
29
29
|
const d = m;
|
|
30
30
|
m += u, p.set(c, {
|
|
31
31
|
start: d,
|
|
@@ -33,10 +33,10 @@ var K = (e, t) => {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
const s = m;
|
|
36
|
-
if (s === 0) return
|
|
37
|
-
const h =
|
|
36
|
+
if (s === 0) return o.map(() => null);
|
|
37
|
+
const h = o.map(() => null), g = /* @__PURE__ */ new Map();
|
|
38
38
|
for (const c of i) {
|
|
39
|
-
const u = e[c], d =
|
|
39
|
+
const u = e[c], d = o[c], v = l.get(u), M = p.get(u);
|
|
40
40
|
if (d == null || v === void 0 || v === 0 || M === void 0) continue;
|
|
41
41
|
const T = g.get(u) ?? 0;
|
|
42
42
|
g.set(u, T + d), h[c] = {
|
|
@@ -53,95 +53,95 @@ var K = (e, t) => {
|
|
|
53
53
|
const t = /* @__PURE__ */ new Map();
|
|
54
54
|
for (const r of e) t.has(r) || t.set(r, t.size);
|
|
55
55
|
return t;
|
|
56
|
-
},
|
|
56
|
+
}, ce = (e, t) => {
|
|
57
57
|
if (t === "data") return e;
|
|
58
|
-
if (t === "ascending") return [...e].sort(([,
|
|
59
|
-
if (t === "descending") return [...e].sort(([,
|
|
60
|
-
const r = $(t),
|
|
61
|
-
return [...e].sort(([
|
|
58
|
+
if (t === "ascending") return [...e].sort(([, o], [, n]) => o - n);
|
|
59
|
+
if (t === "descending") return [...e].sort(([, o], [, n]) => n - o);
|
|
60
|
+
const r = $(t), a = (o) => r.get(o) ?? r.size;
|
|
61
|
+
return [...e].sort(([o], [n]) => a(o) - a(n));
|
|
62
62
|
}, S = {
|
|
63
63
|
shareOfColumn: "mekkoShareOfColumn",
|
|
64
64
|
columnShare: "mekkoColumnShare"
|
|
65
|
-
},
|
|
65
|
+
}, de = [
|
|
66
66
|
"data",
|
|
67
67
|
"ascending",
|
|
68
68
|
"descending"
|
|
69
|
-
], W = (e) =>
|
|
69
|
+
], W = (e) => de.includes(e) || Array.isArray(e) && e.every((t) => typeof t == "string" || typeof t == "number"), me = (e) => {
|
|
70
70
|
const t = e?.sort;
|
|
71
71
|
return W(t) ? t : "data";
|
|
72
|
-
}, F = /* @__PURE__ */ new Set(["value", "columnShare"]),
|
|
72
|
+
}, F = /* @__PURE__ */ new Set(["value", "columnShare"]), B = "mekkoAmount", he = class extends z {
|
|
73
73
|
constructor(...e) {
|
|
74
74
|
super(...e), this.type = "mekko", this.computedVariables = F;
|
|
75
75
|
}
|
|
76
76
|
computeStat({ data: e, mapping: t, params: r }) {
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
77
|
+
const a = L(t.x), o = L(t.y);
|
|
78
|
+
if (a === null || o === null || !e.hasVariable(a) || !e.hasVariable(o)) return {
|
|
79
79
|
data: e,
|
|
80
80
|
mapping: {}
|
|
81
81
|
};
|
|
82
|
-
if (e.size() > 0 && e.getType(
|
|
83
|
-
const l = e.getType(
|
|
82
|
+
if (e.size() > 0 && e.getType(o) !== "numeric") {
|
|
83
|
+
const l = e.getType(o);
|
|
84
84
|
throw new q({
|
|
85
85
|
code: "INCOMPATIBLE_TYPE",
|
|
86
|
-
message: `'mekko' stat requires a numeric 'y' (got '${l}' for variable '${
|
|
86
|
+
message: `'mekko' stat requires a numeric 'y' (got '${l}' for variable '${o}')`,
|
|
87
87
|
context: {
|
|
88
88
|
aesthetic: "y",
|
|
89
|
-
variableName:
|
|
89
|
+
variableName: o,
|
|
90
90
|
variableType: l
|
|
91
91
|
},
|
|
92
92
|
suggestion: "Map each cell's amount to 'y'."
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
const n = te(e, t).filter((l) => l !==
|
|
95
|
+
const n = te(e, t).filter((l) => l !== a), i = ge(e, a, o, n);
|
|
96
96
|
return {
|
|
97
|
-
data:
|
|
97
|
+
data: pe(i, a, o, n, me(r)),
|
|
98
98
|
mapping: {
|
|
99
99
|
y: S.shareOfColumn,
|
|
100
|
-
value:
|
|
100
|
+
value: o,
|
|
101
101
|
columnShare: S.columnShare
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
},
|
|
106
|
-
const
|
|
107
|
-
return e.addVariable(
|
|
108
|
-
variableName:
|
|
105
|
+
}, ge = (e, t, r, a) => {
|
|
106
|
+
const o = e.getValues(r, { type: "numeric" }).map(H);
|
|
107
|
+
return e.addVariable(B, "numeric", o, e.getValueFormat(r)).groupBy(t, ...a).rollup({ [r]: {
|
|
108
|
+
variableName: B,
|
|
109
109
|
aggregation: "sum"
|
|
110
110
|
} });
|
|
111
|
-
},
|
|
112
|
-
const n =
|
|
113
|
-
return e.addVariable(S.shareOfColumn, "numeric", m((s) => s.shareOfColumn), p).addVariable(S.columnShare, "numeric", m((s) => s.columnShare), p).addVariable(
|
|
114
|
-
},
|
|
111
|
+
}, pe = (e, t, r, a, o) => {
|
|
112
|
+
const n = a.map((s) => e.getValues(s)), i = Array.from({ length: e.size() }, (s, h) => JSON.stringify(n.map((g) => g[h]))), l = ue(e.getValues(t).map(fe), i, e.getValues(r, { type: "numeric" }), o), p = { type: "percentage" }, m = (s) => l.map((h) => h === null ? null : s(h));
|
|
113
|
+
return e.addVariable(S.shareOfColumn, "numeric", m((s) => s.shareOfColumn), p).addVariable(S.columnShare, "numeric", m((s) => s.columnShare), p).addVariable(x.xMin, "numeric", m((s) => s.columnStart)).addVariable(x.xMax, "numeric", m((s) => s.columnEnd)).addVariable(x.yMin, "numeric", m((s) => s.cellStart)).addVariable(x.yMax, "numeric", m((s) => s.cellEnd));
|
|
114
|
+
}, fe = (e) => e instanceof Date ? e.getTime() : e, R = (e, t) => {
|
|
115
115
|
const r = O(t, {
|
|
116
116
|
main: e.columnStart,
|
|
117
117
|
cross: e.low
|
|
118
|
-
}),
|
|
118
|
+
}), a = O(t, {
|
|
119
119
|
main: e.columnEnd,
|
|
120
120
|
cross: e.high
|
|
121
|
-
}), [
|
|
121
|
+
}), [o, n] = D(_(r.x), _(a.x)), [i, l] = D(N(r.y), N(a.y));
|
|
122
122
|
return {
|
|
123
|
-
x:
|
|
123
|
+
x: o,
|
|
124
124
|
y: i,
|
|
125
|
-
width: n -
|
|
125
|
+
width: n - o,
|
|
126
126
|
height: l - i
|
|
127
127
|
};
|
|
128
128
|
}, U = (e, t, r) => {
|
|
129
|
-
const
|
|
129
|
+
const a = R(e, t);
|
|
130
130
|
return {
|
|
131
|
-
x:
|
|
132
|
-
y:
|
|
133
|
-
width:
|
|
134
|
-
height:
|
|
131
|
+
x: a.x * r.width,
|
|
132
|
+
y: a.y * r.height,
|
|
133
|
+
width: a.width * r.width,
|
|
134
|
+
height: a.height * r.height
|
|
135
135
|
};
|
|
136
|
-
},
|
|
136
|
+
}, D = (e, t) => e <= t ? [e, t] : [t, e], ve = (e) => {
|
|
137
137
|
const t = [];
|
|
138
138
|
if (!e.layer.dataLabels.showDataLabels) return {
|
|
139
139
|
labels: t,
|
|
140
140
|
droppedCount: 0
|
|
141
141
|
};
|
|
142
|
-
const { position: r, justify:
|
|
142
|
+
const { position: r, justify: a, align: o, offset: n } = e.layer.dataLabels, i = r === "auto", l = i ? "inside" : r, p = k(e.coordSystem), m = J(e.panelRect);
|
|
143
143
|
let s = 0;
|
|
144
|
-
for (const h of
|
|
144
|
+
for (const h of b(e.layer.data, p)) {
|
|
145
145
|
const g = e.formatLabel(h.observation);
|
|
146
146
|
if (g === "") continue;
|
|
147
147
|
const { width: c, height: u } = e.measureDataLabel("observation", l, g), d = ae({
|
|
@@ -155,8 +155,8 @@ var K = (e, t) => {
|
|
|
155
155
|
valueDirectionSign: 1
|
|
156
156
|
},
|
|
157
157
|
placement: l,
|
|
158
|
-
justify: i ? "center" :
|
|
159
|
-
align: i ? "center" :
|
|
158
|
+
justify: i ? "center" : a,
|
|
159
|
+
align: i ? "center" : o,
|
|
160
160
|
offset: n,
|
|
161
161
|
labelWidth: c,
|
|
162
162
|
labelHeight: u
|
|
@@ -182,9 +182,9 @@ var K = (e, t) => {
|
|
|
182
182
|
labels: t,
|
|
183
183
|
droppedCount: s
|
|
184
184
|
};
|
|
185
|
-
},
|
|
185
|
+
}, ke = 1, ye = { strokeWidth: "pixels" }, Se = class extends X {
|
|
186
186
|
constructor(...e) {
|
|
187
|
-
super(...e), this.type = "mekko", this.defaultParams = {}, this.defaultStat = new
|
|
187
|
+
super(...e), this.type = "mekko", this.defaultParams = {}, this.defaultStat = new he(), this.positionRoles = [
|
|
188
188
|
{
|
|
189
189
|
axis: "x",
|
|
190
190
|
role: "min",
|
|
@@ -226,29 +226,29 @@ var K = (e, t) => {
|
|
|
226
226
|
], this.derivedVariables = [S.shareOfColumn, S.columnShare], this.supportedPositions = ["identity"], this.supportedCoordTypes = ["cartesian", "flip"], this.categorySpanAxes = ["x"], this.grid = {
|
|
227
227
|
cartesian: { hideGridX: !0 },
|
|
228
228
|
flip: { hideGridX: !0 }
|
|
229
|
-
}, this.legend = { suppressWhenSingleItem: !0 }, this.dataLabelCoordTypes = ["cartesian", "flip"], this.getDataLabelPlacements =
|
|
230
|
-
vocabulary:
|
|
229
|
+
}, this.legend = { suppressWhenSingleItem: !0 }, this.dataLabelCoordTypes = ["cartesian", "flip"], this.getDataLabelPlacements = ve, this.spatialKind = "rects", this.highlightStrategy = "observation-rerender", this.styleTarget = ee({ observation: {
|
|
230
|
+
vocabulary: ye,
|
|
231
231
|
aesthetics: {
|
|
232
232
|
fill: "color",
|
|
233
233
|
alpha: "alpha"
|
|
234
234
|
},
|
|
235
235
|
rest: {
|
|
236
|
-
fill:
|
|
236
|
+
fill: G("geom"),
|
|
237
237
|
fillAlpha: 1,
|
|
238
|
-
stroke:
|
|
239
|
-
strokeWidth:
|
|
238
|
+
stroke: G("graphBackground"),
|
|
239
|
+
strokeWidth: ke
|
|
240
240
|
}
|
|
241
|
-
} }), this.validateMapping = ({ mapping: t, computedVariables: r }) => r.has("columnShare") ? [...F].filter((
|
|
241
|
+
} }), this.validateMapping = ({ mapping: t, computedVariables: r }) => r.has("columnShare") ? [...F].filter((a) => t[a] !== void 0).map((a) => ({
|
|
242
242
|
code: "CONFLICTING_STAT_MAPPING",
|
|
243
|
-
message: `mekko stat computes '${
|
|
243
|
+
message: `mekko stat computes '${a}' from 'x' and 'y'; remove its mapping`
|
|
244
244
|
})) : [{
|
|
245
245
|
code: "MISSING_STAT_OUTPUT",
|
|
246
246
|
message: "mekko geom lays its cells out in the 'mekko' stat; remove the layer's stat"
|
|
247
247
|
}], this.resolveAnchorPosition = (t, { coordSystem: r }) => {
|
|
248
|
-
const
|
|
249
|
-
if (
|
|
250
|
-
const n = (
|
|
251
|
-
return
|
|
248
|
+
const a = k(r), o = K(t, a);
|
|
249
|
+
if (o === null) return null;
|
|
250
|
+
const n = (o.columnStart + o.columnEnd) / 2, i = (o.low + o.high) / 2;
|
|
251
|
+
return a === "x" ? {
|
|
252
252
|
x: n,
|
|
253
253
|
y: i
|
|
254
254
|
} : {
|
|
@@ -279,10 +279,10 @@ var K = (e, t) => {
|
|
|
279
279
|
mapping: {}
|
|
280
280
|
};
|
|
281
281
|
}
|
|
282
|
-
},
|
|
283
|
-
const
|
|
284
|
-
return
|
|
285
|
-
const n = U(
|
|
282
|
+
}, be = ({ layer: e, coordSystem: t, panelRect: r }) => {
|
|
283
|
+
const a = k(t);
|
|
284
|
+
return b(e.data, a).map((o) => {
|
|
285
|
+
const n = U(o, a, r), i = n.x + n.width, l = n.y + n.height;
|
|
286
286
|
return {
|
|
287
287
|
kind: "region",
|
|
288
288
|
pathData: `M${n.x},${n.y}H${i}V${l}H${n.x}Z`
|
|
@@ -291,13 +291,13 @@ var K = (e, t) => {
|
|
|
291
291
|
}, w = (e) => {
|
|
292
292
|
const t = Z(e.data, e.mapping, e.id);
|
|
293
293
|
return (r) => t(r.observation);
|
|
294
|
-
}, A = ({ cells: e, mainAxis: t, styleReaders: r, getKey:
|
|
295
|
-
const i =
|
|
294
|
+
}, A = ({ cells: e, mainAxis: t, styleReaders: r, getKey: a, isHovered: o = !1, shouldAnimateTransitions: n = !1 }) => {
|
|
295
|
+
const i = o ? "hovered" : void 0, l = y(() => e.map((s) => r.get("fill", s.observation, i) ?? "transparent"), [
|
|
296
296
|
e,
|
|
297
297
|
r,
|
|
298
298
|
i
|
|
299
|
-
]), { fillFor: p, defs: m } =
|
|
300
|
-
return /* @__PURE__ */ ie
|
|
299
|
+
]), { fillFor: p, defs: m } = se({ paints: l });
|
|
300
|
+
return /* @__PURE__ */ le(ie, { children: [m, e.map((s, h) => {
|
|
301
301
|
const g = R(s, t), c = l[h], u = r.get("stroke", s.observation, i);
|
|
302
302
|
return /* @__PURE__ */ f(Y, {
|
|
303
303
|
"data-testid": "mekko-cell",
|
|
@@ -308,67 +308,69 @@ var K = (e, t) => {
|
|
|
308
308
|
fill: c === void 0 ? void 0 : p(c),
|
|
309
309
|
opacity: r.get("alpha", s.observation, i),
|
|
310
310
|
fillOpacity: r.get("fillAlpha", s.observation, i),
|
|
311
|
-
stroke: u === void 0 ? void 0 :
|
|
311
|
+
stroke: u === void 0 ? void 0 : ne(u),
|
|
312
312
|
strokeWidth: r.get("strokeWidth", s.observation, i),
|
|
313
|
+
cornerRadius: r.get("cornerRadius", s.observation, i),
|
|
314
|
+
effects: oe(r, s.observation, i),
|
|
313
315
|
shouldAnimateTransitions: n
|
|
314
|
-
},
|
|
316
|
+
}, a(s));
|
|
315
317
|
})] });
|
|
316
|
-
}, xe = ({ layer: e, sourceLayer: t, mainAxis: r, styleReaders:
|
|
317
|
-
cells: y(() =>
|
|
318
|
+
}, xe = ({ layer: e, sourceLayer: t, mainAxis: r, styleReaders: a }) => /* @__PURE__ */ f(A, {
|
|
319
|
+
cells: y(() => b(e.data, r), [e.data, r]),
|
|
318
320
|
mainAxis: r,
|
|
319
|
-
styleReaders:
|
|
321
|
+
styleReaders: a,
|
|
320
322
|
getKey: y(() => w(t), [t])
|
|
321
|
-
}),
|
|
323
|
+
}), Ce = ({ layer: e, primary: t, mainAxis: r, styleReaders: a }) => /* @__PURE__ */ f("g", {
|
|
322
324
|
"data-testid": "hovered-cells",
|
|
323
325
|
children: /* @__PURE__ */ f(A, {
|
|
324
|
-
cells:
|
|
326
|
+
cells: b([t.observation], r),
|
|
325
327
|
mainAxis: r,
|
|
326
|
-
styleReaders:
|
|
328
|
+
styleReaders: a,
|
|
327
329
|
getKey: y(() => w(e), [e]),
|
|
328
330
|
isHovered: !0
|
|
329
331
|
})
|
|
330
|
-
}),
|
|
332
|
+
}), Me = ({ layer: e, mainAxis: t, styleReaders: r, shouldAnimateTransitions: a, intro: o }) => {
|
|
331
333
|
const n = /* @__PURE__ */ f(A, {
|
|
332
|
-
cells: y(() =>
|
|
334
|
+
cells: y(() => b(e.data, t), [e.data, t]),
|
|
333
335
|
mainAxis: t,
|
|
334
336
|
styleReaders: r,
|
|
335
337
|
getKey: y(() => w(e), [e]),
|
|
336
|
-
shouldAnimateTransitions:
|
|
338
|
+
shouldAnimateTransitions: a
|
|
337
339
|
});
|
|
338
|
-
return
|
|
340
|
+
return o == null ? n : /* @__PURE__ */ f(j, {
|
|
339
341
|
intro: {
|
|
340
342
|
type: "fade",
|
|
341
|
-
layerId:
|
|
342
|
-
durationSeconds:
|
|
343
|
+
layerId: o.layerId,
|
|
344
|
+
durationSeconds: o.durationSeconds
|
|
343
345
|
},
|
|
344
346
|
children: n
|
|
345
347
|
});
|
|
346
|
-
},
|
|
348
|
+
}, Oe = Q(new Se(), {
|
|
347
349
|
coord: "cartesian",
|
|
348
350
|
swatchShape: "square",
|
|
349
|
-
render: ({ layer: e, coordSystem: t, styleReaders: r, shouldAnimateTransitions:
|
|
351
|
+
render: ({ layer: e, coordSystem: t, styleReaders: r, shouldAnimateTransitions: a, intro: o }) => /* @__PURE__ */ f(Me, {
|
|
350
352
|
layer: e,
|
|
351
353
|
mainAxis: k(t),
|
|
352
354
|
styleReaders: r,
|
|
353
|
-
shouldAnimateTransitions:
|
|
354
|
-
intro:
|
|
355
|
+
shouldAnimateTransitions: a,
|
|
356
|
+
intro: o
|
|
355
357
|
}),
|
|
356
|
-
renderHighlight: ({ layer: e, sourceLayer: t, coordSystem: r, styleReaders:
|
|
358
|
+
renderHighlight: ({ layer: e, sourceLayer: t, coordSystem: r, styleReaders: a }) => /* @__PURE__ */ f(xe, {
|
|
357
359
|
layer: e,
|
|
358
360
|
sourceLayer: t,
|
|
359
361
|
mainAxis: k(r),
|
|
360
|
-
styleReaders:
|
|
362
|
+
styleReaders: a
|
|
361
363
|
}),
|
|
362
|
-
renderHover: ({ layer: e, primary: t, coordSystem: r, styleReaders:
|
|
364
|
+
renderHover: ({ layer: e, primary: t, coordSystem: r, styleReaders: a }) => /* @__PURE__ */ f(Ce, {
|
|
363
365
|
layer: e,
|
|
364
366
|
primary: t,
|
|
365
367
|
mainAxis: k(r),
|
|
366
|
-
styleReaders:
|
|
368
|
+
styleReaders: a
|
|
367
369
|
}),
|
|
368
370
|
renderHoverCompanions: () => null,
|
|
369
|
-
getEditOutlineShapes:
|
|
371
|
+
getEditOutlineShapes: be
|
|
370
372
|
});
|
|
371
373
|
export {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
+
Se as MekkoGeom,
|
|
375
|
+
Oe as mekko
|
|
374
376
|
};
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"marimekko",
|
|
15
15
|
"mosaic"
|
|
16
16
|
],
|
|
17
|
-
"version": "0.1.
|
|
17
|
+
"version": "0.1.1-beta.1792417802336",
|
|
18
18
|
"type": "module",
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": "^19.0.0",
|
|
36
|
-
"@graphysdk/react": "^1.9.0-beta.
|
|
36
|
+
"@graphysdk/react": "^1.9.0-beta.1792417802336"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@testing-library/react": "^16.3.1",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"vite": "^8.1.5",
|
|
46
46
|
"vite-plugin-dts": "^4.5.4",
|
|
47
47
|
"vitest": "^4.1.11",
|
|
48
|
-
"@graphysdk/
|
|
49
|
-
"@graphysdk/
|
|
48
|
+
"@graphysdk/viz-engine": "1.9.0-beta.1792417802336",
|
|
49
|
+
"@graphysdk/react": "1.9.0-beta.1792417802336",
|
|
50
50
|
"@graphytools/typescript-config": "0.0.1",
|
|
51
|
-
"@graphytools/
|
|
52
|
-
"@graphytools/
|
|
51
|
+
"@graphytools/vitest-config": "1.0.0",
|
|
52
|
+
"@graphytools/eslint-config": "0.0.1"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|