@prefecthq/prefab-ui 0.17.0 → 0.18.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.
|
@@ -179,6 +179,10 @@ class PrefabApp(BaseModel):
|
|
|
179
179
|
default=None,
|
|
180
180
|
description="Custom JS action handlers: name → function expression",
|
|
181
181
|
)
|
|
182
|
+
on_mount: Any | None = Field(
|
|
183
|
+
default=None,
|
|
184
|
+
description="Action(s) to execute when the app mounts",
|
|
185
|
+
)
|
|
182
186
|
|
|
183
187
|
_context_root: Any = PrivateAttr(default=None)
|
|
184
188
|
|
|
@@ -259,7 +263,7 @@ class PrefabApp(BaseModel):
|
|
|
259
263
|
|
|
260
264
|
if isinstance(self.view, dict):
|
|
261
265
|
# Pre-serialized dict — wrap in a serialized Div
|
|
262
|
-
wrapper = Div(css_class=cls)
|
|
266
|
+
wrapper = Div(css_class=cls, on_mount=self.on_mount)
|
|
263
267
|
wrapper_json = wrapper.to_json()
|
|
264
268
|
wrapper_json["children"] = [self.view]
|
|
265
269
|
return wrapper_json
|
|
@@ -271,10 +275,14 @@ class PrefabApp(BaseModel):
|
|
|
271
275
|
):
|
|
272
276
|
# Bare Div from context manager — stamp the class directly
|
|
273
277
|
self.view.css_class = cls
|
|
278
|
+
if self.on_mount is not None:
|
|
279
|
+
self.view.on_mount = self.on_mount
|
|
274
280
|
return self.view.to_json()
|
|
275
281
|
|
|
276
282
|
# Wrap the user's view in a new Div
|
|
277
|
-
return Div(
|
|
283
|
+
return Div(
|
|
284
|
+
children=[self.view], css_class=cls, on_mount=self.on_mount
|
|
285
|
+
).to_json()
|
|
278
286
|
|
|
279
287
|
def to_json(
|
|
280
288
|
self,
|
|
@@ -2005,6 +2013,12 @@ class Component(BaseModel):
|
|
|
2005
2013
|
description="CSS/Tailwind classes for styling. Accepts a Responsive() for breakpoint-aware classes.",
|
|
2006
2014
|
)
|
|
2007
2015
|
|
|
2016
|
+
on_mount: Any | None = Field(
|
|
2017
|
+
default=None,
|
|
2018
|
+
alias="onMount",
|
|
2019
|
+
description="Action(s) to execute when this component mounts.",
|
|
2020
|
+
)
|
|
2021
|
+
|
|
2008
2022
|
def __init__(self, /, **kwargs: Any) -> None:
|
|
2009
2023
|
parent = kwargs.pop("parent", None)
|
|
2010
2024
|
if parent is not None:
|
|
@@ -2749,6 +2763,9 @@ class BarChart(Component):
|
|
|
2749
2763
|
show_tooltip: bool = Field(
|
|
2750
2764
|
default=True, alias="showTooltip", description="Show tooltip on hover"
|
|
2751
2765
|
)
|
|
2766
|
+
animate: bool = Field(
|
|
2767
|
+
default=True, description="Animate transitions when data changes"
|
|
2768
|
+
)
|
|
2752
2769
|
show_grid: bool = Field(
|
|
2753
2770
|
default=True, alias="showGrid", description="Show cartesian grid"
|
|
2754
2771
|
)
|
|
@@ -2815,6 +2832,9 @@ class LineChart(Component):
|
|
|
2815
2832
|
show_tooltip: bool = Field(
|
|
2816
2833
|
default=True, alias="showTooltip", description="Show tooltip on hover"
|
|
2817
2834
|
)
|
|
2835
|
+
animate: bool = Field(
|
|
2836
|
+
default=True, description="Animate transitions when data changes"
|
|
2837
|
+
)
|
|
2818
2838
|
show_grid: bool = Field(
|
|
2819
2839
|
default=True, alias="showGrid", description="Show cartesian grid"
|
|
2820
2840
|
)
|
|
@@ -2884,6 +2904,9 @@ class AreaChart(Component):
|
|
|
2884
2904
|
show_tooltip: bool = Field(
|
|
2885
2905
|
default=True, alias="showTooltip", description="Show tooltip on hover"
|
|
2886
2906
|
)
|
|
2907
|
+
animate: bool = Field(
|
|
2908
|
+
default=True, description="Animate transitions when data changes"
|
|
2909
|
+
)
|
|
2887
2910
|
show_grid: bool = Field(
|
|
2888
2911
|
default=True, alias="showGrid", description="Show cartesian grid"
|
|
2889
2912
|
)
|
|
@@ -2948,6 +2971,9 @@ class PieChart(Component):
|
|
|
2948
2971
|
show_tooltip: bool = Field(
|
|
2949
2972
|
default=True, alias="showTooltip", description="Show tooltip on hover"
|
|
2950
2973
|
)
|
|
2974
|
+
animate: bool = Field(
|
|
2975
|
+
default=True, description="Animate transitions when data changes"
|
|
2976
|
+
)
|
|
2951
2977
|
|
|
2952
2978
|
|
|
2953
2979
|
class ScatterChart(Component):
|
|
@@ -3002,6 +3028,9 @@ class ScatterChart(Component):
|
|
|
3002
3028
|
show_tooltip: bool = Field(
|
|
3003
3029
|
default=True, alias="showTooltip", description="Show tooltip on hover"
|
|
3004
3030
|
)
|
|
3031
|
+
animate: bool = Field(
|
|
3032
|
+
default=True, description="Animate transitions when data changes"
|
|
3033
|
+
)
|
|
3005
3034
|
show_grid: bool = Field(
|
|
3006
3035
|
default=True, alias="showGrid", description="Show cartesian grid"
|
|
3007
3036
|
)
|
|
@@ -3056,6 +3085,9 @@ class RadarChart(Component):
|
|
|
3056
3085
|
show_tooltip: bool = Field(
|
|
3057
3086
|
default=True, alias="showTooltip", description="Show tooltip on hover"
|
|
3058
3087
|
)
|
|
3088
|
+
animate: bool = Field(
|
|
3089
|
+
default=True, description="Animate transitions when data changes"
|
|
3090
|
+
)
|
|
3059
3091
|
show_grid: bool = Field(
|
|
3060
3092
|
default=True, alias="showGrid", description="Show polar grid"
|
|
3061
3093
|
)
|
|
@@ -3111,6 +3143,9 @@ class RadialChart(Component):
|
|
|
3111
3143
|
show_tooltip: bool = Field(
|
|
3112
3144
|
default=True, alias="showTooltip", description="Show tooltip on hover"
|
|
3113
3145
|
)
|
|
3146
|
+
animate: bool = Field(
|
|
3147
|
+
default=True, description="Animate transitions when data changes"
|
|
3148
|
+
)
|
|
3114
3149
|
|
|
3115
3150
|
|
|
3116
3151
|
SparklineVariant = (
|
|
@@ -5642,6 +5677,9 @@ class Histogram(Component):
|
|
|
5642
5677
|
show_tooltip: bool = Field(
|
|
5643
5678
|
default=True, alias="showTooltip", description="Show tooltip on hover"
|
|
5644
5679
|
)
|
|
5680
|
+
animate: bool = Field(
|
|
5681
|
+
default=True, description="Animate transitions when data changes"
|
|
5682
|
+
)
|
|
5645
5683
|
show_legend: bool = Field(
|
|
5646
5684
|
default=True, alias="showLegend", description="Show legend"
|
|
5647
5685
|
)
|
|
@@ -8873,7 +8911,9 @@ class SetInterval(Action):
|
|
|
8873
8911
|
"""
|
|
8874
8912
|
|
|
8875
8913
|
action: Literal["setInterval"] = "setInterval"
|
|
8876
|
-
duration: int = Field(
|
|
8914
|
+
duration: int | RxStr = Field(
|
|
8915
|
+
description="Interval between ticks, in milliseconds. Accepts Rx for reactive values.",
|
|
8916
|
+
)
|
|
8877
8917
|
while_: RxStr | None = Field(
|
|
8878
8918
|
default=None,
|
|
8879
8919
|
alias="while",
|
|
@@ -9310,6 +9350,10 @@ def _format_scalar(value: object) -> str:
|
|
|
9310
9350
|
"""Format a non-Rx Python value as an expression token.
|
|
9311
9351
|
|
|
9312
9352
|
Strings → single-quoted, numbers → bare, bools → true/false, None → null.
|
|
9353
|
+
|
|
9354
|
+
Strings containing \`\`{{ expr }}\`\` templates (e.g. from f-strings like
|
|
9355
|
+
\`\`f"{STATE.x}%"\`\`) are expanded into concatenation expressions so
|
|
9356
|
+
\`\`"{{ stats.cpu }}%"\`\` becomes \`\`stats.cpu + '%'\`\`.
|
|
9313
9357
|
"""
|
|
9314
9358
|
if isinstance(value, bool):
|
|
9315
9359
|
return "true" if value else "false"
|
|
@@ -9318,10 +9362,39 @@ def _format_scalar(value: object) -> str:
|
|
|
9318
9362
|
if value is None:
|
|
9319
9363
|
return "null"
|
|
9320
9364
|
if isinstance(value, str):
|
|
9365
|
+
if "{{" in value:
|
|
9366
|
+
return _expand_template_string(value)
|
|
9321
9367
|
return f"'{value}'"
|
|
9322
9368
|
return str(value)
|
|
9323
9369
|
|
|
9324
9370
|
|
|
9371
|
+
def _expand_template_string(s: str) -> str:
|
|
9372
|
+
"""Convert a string with \`\`{{ }}\`\` markers into a concatenation expression.
|
|
9373
|
+
|
|
9374
|
+
\`\`"{{ x }}%"\`\` → \`\`x + '%'\`\`
|
|
9375
|
+
\`\`"Hello {{ name }}, you have {{ count }} items"\`\`
|
|
9376
|
+
→ \`\`'Hello ' + name + ', you have ' + count + ' items'\`\`
|
|
9377
|
+
"""
|
|
9378
|
+
import re
|
|
9379
|
+
|
|
9380
|
+
parts: list[str] = []
|
|
9381
|
+
last_end = 0
|
|
9382
|
+
for m in re.finditer(r"\\{\\{\\s*(.*?)\\s*\\}\\}", s):
|
|
9383
|
+
# Text before this template
|
|
9384
|
+
before = s[last_end : m.start()]
|
|
9385
|
+
if before:
|
|
9386
|
+
parts.append(f"'{before}'")
|
|
9387
|
+
# The expression inside {{ }}
|
|
9388
|
+
parts.append(m.group(1))
|
|
9389
|
+
last_end = m.end()
|
|
9390
|
+
# Text after the last template
|
|
9391
|
+
after = s[last_end:]
|
|
9392
|
+
if after:
|
|
9393
|
+
parts.append(f"'{after}'")
|
|
9394
|
+
|
|
9395
|
+
return " + ".join(parts) if parts else "''"
|
|
9396
|
+
|
|
9397
|
+
|
|
9325
9398
|
def _resolve_operand(value: object, min_prec: int, *, strict: bool = False) -> str:
|
|
9326
9399
|
"""Resolve a child operand (Rx or scalar) for use in an expression.
|
|
9327
9400
|
|
|
@@ -9606,7 +9679,7 @@ class Rx:
|
|
|
9606
9679
|
# ── Ternary ──────────────────────────────────────────────────────
|
|
9607
9680
|
|
|
9608
9681
|
def then(self, if_true: object, if_false: object) -> Rx:
|
|
9609
|
-
"""Ternary conditional:
|
|
9682
|
+
"""Ternary conditional: \`\`condition ? if_true : if_false\`\`."""
|
|
9610
9683
|
return Rx(_Ternary(self, if_true, if_false), _PREC_TERNARY)
|
|
9611
9684
|
|
|
9612
9685
|
# ── Pipes ────────────────────────────────────────────────────────
|
|
@@ -77,4 +77,4 @@ ${r.map(([a,o])=>{var c;const u=((c=o.theme)==null?void 0:c[n])||o.color;return
|
|
|
77
77
|
`)}
|
|
78
78
|
}
|
|
79
79
|
`).join(`
|
|
80
|
-
`)}}):null},cr=Qe,Mt=M.forwardRef(({active:t,payload:e,className:r,indicator:n="dot",hideLabel:i=!1,hideIndicator:a=!1,label:o,labelFormatter:u,labelClassName:c,formatter:s,color:f,nameKey:l,labelKey:p},d)=>{const{config:y}=f0(),h=M.useMemo(()=>{var m;if(i||!(e!=null&&e.length))return null;const[g]=e,b=`${p||(g==null?void 0:g.dataKey)||(g==null?void 0:g.name)||"value"}`,x=jf(y,g,b),A=!p&&typeof o=="string"?((m=y[o])==null?void 0:m.label)||o:x==null?void 0:x.label;return u?D.jsx("div",{className:Fe("font-medium",c),children:u(A,e)}):A?D.jsx("div",{className:Fe("font-medium",c),children:A}):null},[o,u,e,i,c,y,p]);if(!t||!(e!=null&&e.length))return null;const v=e.length===1&&n!=="dot";return D.jsxs("div",{ref:d,className:Fe("grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",r),children:[v?null:h,D.jsx("div",{className:"grid gap-1.5",children:e.filter(g=>g.type!=="none").map((g,b)=>{const x=`${l||g.name||g.dataKey||"value"}`,A=jf(y,g,x),m=f||g.payload.fill||g.color;return D.jsx("div",{className:Fe("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",n==="dot"&&"items-center"),children:s&&(g==null?void 0:g.value)!==void 0&&g.name?s(g.value,g.name,g,b,g.payload):D.jsxs(D.Fragment,{children:[A!=null&&A.icon?D.jsx(A.icon,{}):!a&&D.jsx("div",{className:Fe("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":n==="dot","w-1":n==="line","w-0 border-[1.5px] border-dashed bg-transparent":n==="dashed","my-0.5":v&&n==="dashed"}),style:{"--color-bg":m,"--color-border":m}}),D.jsxs("div",{className:Fe("flex flex-1 justify-between leading-none",v?"items-end":"items-center"),children:[D.jsxs("div",{className:"grid gap-1.5",children:[v?h:null,D.jsx("span",{className:"text-muted-foreground",children:(A==null?void 0:A.label)||g.name})]}),g.value&&D.jsx("span",{className:"font-mono font-medium tabular-nums text-foreground",children:g.value.toLocaleString()})]})]})},g.dataKey)})})]})});Mt.displayName="ChartTooltip";const sn=Vt,sr=M.forwardRef(({className:t,hideIcon:e=!1,payload:r,verticalAlign:n="bottom",nameKey:i},a)=>{const{config:o}=f0();return r!=null&&r.length?D.jsx("div",{ref:a,className:Fe("flex flex-wrap items-center justify-center gap-4",n==="top"?"pb-3":"pt-3",t),children:r.filter(u=>u.type!=="none").map(u=>{const c=`${i||u.dataKey||"value"}`,s=jf(o,u,c);return D.jsxs("div",{className:Fe("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[s!=null&&s.icon&&!e?D.jsx(s.icon,{}):D.jsx("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:u.color}}),s==null?void 0:s.label]},u.value)})}):null});sr.displayName="ChartLegend";function jf(t,e,r){if(typeof e!="object"||e===null)return;const n="payload"in e&&typeof e.payload=="object"&&e.payload!==null?e.payload:void 0;let i=r;return r in e&&typeof e[r]=="string"?i=e[r]:n&&r in n&&typeof n[r]=="string"&&(i=n[r]),i in t?t[i]:t[r]}const Jg={default:"pf-sparkline-variant-default",success:"pf-sparkline-variant-success",warning:"pf-sparkline-variant-warning",destructive:"pf-sparkline-variant-destructive",info:"pf-sparkline-variant-info",muted:"pf-sparkline-variant-muted"};function PN(t,e,r,n){const i=Math.min(...t),o=Math.max(...t)-i||1,u=n/2,c=r*.7-u,s=u;return t.map((f,l)=>{const p=t.length===1?e/2:l/(t.length-1)*e,d=s+c*(1-(f-i)/o);return`${p},${d}`}).join(" ")}function SN(t,e,r,n){const i=Math.min(...t),o=Math.max(...t)-i||1,u=n/2,c=r*.7-u,s=u,f=[];for(let l=0;l<t.length;l++){const p=t.length===1?e/2:l/(t.length-1)*e,d=s+c*(1-(t[l]-i)/o);if(l>0){const y=s+c*(1-(t[l-1]-i)/o);f.push(`${p},${y}`)}f.push(`${p},${d}`)}return f.join(" ")}function _N(t,e,r,n){if(t.length<2){const d=e/2,y=t[0],v=t[0]-y||1,g=n/2,b=r*.7-g,A=g+b*(1-(t[0]-y)/v);return`M ${d},${A}`}const i=Math.min(...t),o=Math.max(...t)-i||1,u=n/2,c=r*.7-u,s=u,f=t.map((d,y)=>y/(t.length-1)*e),l=t.map(d=>s+c*(1-(d-i)/o));let p=`M ${f[0]},${l[0]}`;for(let d=0;d<t.length-1;d++){const y=f[Math.max(0,d-1)],h=l[Math.max(0,d-1)],v=f[d],g=l[d],b=f[d+1],x=l[d+1],A=f[Math.min(t.length-1,d+2)],m=l[Math.min(t.length-1,d+2)],O=v+(b-y)/6,w=g+(x-h)/6,S=b-(A-v)/6,_=x-(m-g)/6;p+=` C ${O},${w} ${S},${_} ${b},${x}`}return p}let jN=0;function DN({data:t=[],height:e,variant:r="default",indicatorClass:n,fill:i=!1,curve:a="linear",strokeWidth:o=1.5,mode:u="line",className:c,cssClass:s}){if(typeof t=="string"||t.length===0)return null;const f=Jg[r??"default"]??Jg.default,l=`spark-${++jN}`,p=100,d=40;if(u==="bar"){const m=Math.min(0,...t),w=Math.max(...t)-m||1,S=1,_=(p-S*(t.length-1))/t.length;return D.jsx("svg",{className:Fe("pf-sparkline w-full",e==null&&"h-6",f,c,s),viewBox:`0 0 ${p} ${d}`,preserveAspectRatio:"none",style:e!=null?{height:e}:void 0,children:t.map((T,j)=>{const E=(T-m)/w*(d-1);return D.jsx("rect",{x:j*(_+S),y:d-E,width:_,height:E,fill:"currentColor",opacity:.7,rx:.5,className:n},j)})})}const y=a==="smooth",h=a==="step",v=y?_N(t,p,d,o):"",g=y?"":h?SN(t,p,d,o):PN(t,p,d,o),b=y?`${v} L ${p},${d} L 0,${d} Z`:"",x=i&&!y?`${g} ${p},${d} 0,${d}`:"",A={fill:"none",stroke:"currentColor",strokeWidth:o,strokeLinejoin:"round",strokeLinecap:"round",vectorEffect:"non-scaling-stroke",className:Fe("pf-sparkline-line",n)};return D.jsxs("svg",{className:Fe("pf-sparkline w-full",f,c,s),viewBox:`0 0 ${p} ${d}`,preserveAspectRatio:"none",style:{height:e},children:[i&&D.jsxs(D.Fragment,{children:[D.jsx("defs",{children:D.jsxs("linearGradient",{id:l,x1:"0",y1:"0",x2:"0",y2:"1",children:[D.jsx("stop",{offset:"0%",className:"pf-sparkline-fill-stop-start"}),D.jsx("stop",{offset:"100%",className:"pf-sparkline-fill-stop-end"})]})}),y?D.jsx("path",{d:b,fill:`url(#${l})`,stroke:"none"}):D.jsx("polygon",{points:x,fill:`url(#${l})`})]}),y?D.jsx("path",{d:v,...A}):D.jsx("polyline",{points:g,...A})]})}const gp=t=>new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}).format(t),jt=["var(--color-chart-1)","var(--color-chart-2)","var(--color-chart-3)","var(--color-chart-4)","var(--color-chart-5)"];function Ai(t){const e={};for(let r=0;r<t.length;r++){const n=t[r];e[n.dataKey]={label:n.label??n.dataKey,color:n.color??jt[r%jt.length]}}return e}function p0(t,e){const r={};for(let n=0;n<t.length;n++){const i=String(t[n][e]??`item-${n}`);r[i]={label:i,color:jt[n%jt.length]}}return r}function NN({data:t=[],series:e,xAxis:r,height:n=300,stacked:i=!1,horizontal:a=!1,barRadius:o=4,showLegend:u=!1,showTooltip:c=!0,showGrid:s=!0,showYAxis:f=!0,yAxisFormat:l="auto",className:p}){if(typeof t=="string")return null;const d=Ai(e);return D.jsx(kt,{config:d,className:p,style:{height:n,aspectRatio:"auto"},children:D.jsxs(vN,{data:t,layout:a?"vertical":"horizontal",children:[s&&D.jsx(gi,{vertical:a,horizontal:!a}),a&&r&&D.jsx(Ye,{dataKey:r,type:"category",tickLine:!1,axisLine:!1,tickMargin:8}),a&&D.jsx(Xe,{type:"number",hide:!0}),!a&&r&&D.jsx(Xe,{dataKey:r,tickLine:!1,axisLine:!1,tickMargin:8}),!a&&f&&D.jsx(Ye,{tickLine:!1,axisLine:!1,tickMargin:8,tickFormatter:l==="compact"?gp:void 0}),c&&D.jsx(cr,{content:D.jsx(Mt,{})}),u&&D.jsx(sn,{content:D.jsx(sr,{})}),e.map(y=>D.jsx(or,{dataKey:y.dataKey,fill:`var(--color-${y.dataKey})`,radius:o,stackId:i?"stack":void 0},y.dataKey))]})})}const d0={linear:"linear",smooth:"monotone",step:"step"};function LN({data:t=[],series:e,xAxis:r,height:n=300,curve:i="linear",showDots:a=!1,showLegend:o=!1,showTooltip:u=!0,showGrid:c=!0,showYAxis:s=!0,yAxisFormat:f="auto",className:l}){if(typeof t=="string")return null;const p=Ai(e);return D.jsx(kt,{config:p,className:l,style:{height:n,aspectRatio:"auto"},children:D.jsxs(dN,{data:t,children:[c&&D.jsx(gi,{vertical:!1}),r&&D.jsx(Xe,{dataKey:r,tickLine:!1,axisLine:!1,tickMargin:8}),s&&D.jsx(Ye,{tickLine:!1,axisLine:!1,tickMargin:8,tickFormatter:f==="compact"?gp:void 0}),u&&D.jsx(cr,{content:D.jsx(Mt,{})}),o&&D.jsx(sn,{content:D.jsx(sr,{})}),e.map(d=>D.jsx(bi,{dataKey:d.dataKey,type:d0[i]??i,stroke:`var(--color-${d.dataKey})`,strokeWidth:2,dot:a},d.dataKey))]})})}function qN({data:t=[],series:e,xAxis:r,height:n=300,stacked:i=!1,curve:a="linear",showDots:o=!1,showLegend:u=!1,showTooltip:c=!0,showGrid:s=!0,showYAxis:f=!0,yAxisFormat:l="auto",className:p}){if(typeof t=="string")return null;const d=Ai(e);return D.jsx(kt,{config:d,className:p,style:{height:n,aspectRatio:"auto"},children:D.jsxs(gN,{data:t,children:[s&&D.jsx(gi,{vertical:!1}),r&&D.jsx(Xe,{dataKey:r,tickLine:!1,axisLine:!1,tickMargin:8}),f&&D.jsx(Ye,{tickLine:!1,axisLine:!1,tickMargin:8,tickFormatter:l==="compact"?gp:void 0}),c&&D.jsx(cr,{content:D.jsx(Mt,{})}),u&&D.jsx(sn,{content:D.jsx(sr,{})}),e.map(y=>D.jsx(Rt,{dataKey:y.dataKey,type:d0[a]??a,fill:`var(--color-${y.dataKey})`,stroke:`var(--color-${y.dataKey})`,fillOpacity:.4,dot:o,stackId:i?"stack":void 0},y.dataKey))]})})}function BN({data:t=[],dataKey:e,nameKey:r,height:n=300,innerRadius:i=0,showLabel:a=!1,paddingAngle:o=0,showLegend:u=!1,showTooltip:c=!0,className:s}){if(typeof t=="string")return null;const f=p0(t,r),l=t.map((h,v)=>({...h,fill:jt[v%jt.length]})),p=a?"60%":"80%",d=i>0?`${Math.round(i/100*(a?60:80))}%`:0,y=u?n-36:n;return D.jsxs("div",{className:s,children:[D.jsx(kt,{config:f,style:{height:y,aspectRatio:"auto"},children:D.jsxs(hN,{children:[c&&D.jsx(cr,{content:D.jsx(Mt,{nameKey:r})}),D.jsx(bt,{data:l,dataKey:e,nameKey:r,innerRadius:d,outerRadius:p,label:a,paddingAngle:o})]})}),u&&D.jsx("div",{style:{display:"flex",flexWrap:"wrap",justifyContent:"center",gap:"12px",paddingTop:"8px",fontSize:"12px"},children:l.map((h,v)=>D.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[D.jsx("div",{style:{width:"8px",height:"8px",borderRadius:"2px",backgroundColor:h.fill,flexShrink:0}}),String(h[r]??"")]},v))})]})}function FN({data:t=[],series:e,axisKey:r,height:n=300,filled:i=!0,showDots:a=!1,showLegend:o=!1,showTooltip:u=!0,showGrid:c=!0,className:s}){if(typeof t=="string")return null;const f=Ai(e);return D.jsx(kt,{config:f,className:s,style:{height:n,aspectRatio:"auto"},children:D.jsxs(yN,{data:t,children:[c&&D.jsx(tO,{}),r&&D.jsx(ar,{dataKey:r}),u&&D.jsx(cr,{content:D.jsx(Mt,{})}),o&&D.jsx(sn,{content:D.jsx(sr,{})}),e.map(l=>D.jsx(yi,{dataKey:l.dataKey,fill:`var(--color-${l.dataKey})`,fillOpacity:i?.3:0,stroke:`var(--color-${l.dataKey})`,strokeWidth:2,dot:a},l.dataKey))]})})}function zN({data:t=[],dataKey:e,nameKey:r,height:n=300,innerRadius:i=30,startAngle:a=180,endAngle:o=0,showLegend:u=!1,showTooltip:c=!0,className:s}){if(typeof t=="string")return null;const f=p0(t,r),l=t.map((p,d)=>({...p,fill:jt[d%jt.length]}));return D.jsx(kt,{config:f,className:s,style:{height:n,aspectRatio:"auto"},children:D.jsxs(bN,{data:l,innerRadius:i,startAngle:a,endAngle:o,children:[c&&D.jsx(cr,{content:D.jsx(Mt,{nameKey:r})}),u&&D.jsx(sn,{content:D.jsx(sr,{nameKey:r})}),D.jsx(mi,{dataKey:e})]})})}function KN({data:t=[],series:e,xAxis:r,yAxis:n,zAxis:i,height:a=300,showLegend:o=!1,showTooltip:u=!0,showGrid:c=!0,className:s}){if(typeof t=="string")return null;const f=M.useMemo(()=>t,[JSON.stringify(t)]),l=Ai(e);return D.jsx(kt,{config:l,className:s,style:{height:a,aspectRatio:"auto"},children:D.jsxs(mN,{data:f,children:[c&&D.jsx(gi,{}),D.jsx(Xe,{dataKey:r,type:"number",name:r,tickLine:!1,axisLine:!1,tickMargin:8}),D.jsx(Ye,{dataKey:n,type:"number",name:n,tickLine:!1,axisLine:!1,tickMargin:8}),i&&D.jsx(xi,{dataKey:i,type:"number",name:i,range:[40,400]}),u&&D.jsx(cr,{content:D.jsx(Mt,{})}),o&&D.jsx(sn,{content:D.jsx(sr,{})}),e.map(p=>D.jsx(Oi,{name:p.label??p.dataKey,data:e.length===1?f:f.filter(d=>d._series===p.dataKey),fill:`var(--color-${p.dataKey})`},p.dataKey))]})})}export{qN as PrefabAreaChart,NN as PrefabBarChart,LN as PrefabLineChart,BN as PrefabPieChart,FN as PrefabRadarChart,zN as PrefabRadialChart,KN as PrefabScatterChart,DN as PrefabSparkline};
|
|
80
|
+
`)}}):null},cr=Qe,Mt=M.forwardRef(({active:t,payload:e,className:r,indicator:n="dot",hideLabel:i=!1,hideIndicator:a=!1,label:o,labelFormatter:u,labelClassName:c,formatter:s,color:f,nameKey:l,labelKey:p},d)=>{const{config:y}=f0(),h=M.useMemo(()=>{var m;if(i||!(e!=null&&e.length))return null;const[g]=e,b=`${p||(g==null?void 0:g.dataKey)||(g==null?void 0:g.name)||"value"}`,x=jf(y,g,b),A=!p&&typeof o=="string"?((m=y[o])==null?void 0:m.label)||o:x==null?void 0:x.label;return u?D.jsx("div",{className:Fe("font-medium",c),children:u(A,e)}):A?D.jsx("div",{className:Fe("font-medium",c),children:A}):null},[o,u,e,i,c,y,p]);if(!t||!(e!=null&&e.length))return null;const v=e.length===1&&n!=="dot";return D.jsxs("div",{ref:d,className:Fe("grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",r),children:[v?null:h,D.jsx("div",{className:"grid gap-1.5",children:e.filter(g=>g.type!=="none").map((g,b)=>{const x=`${l||g.name||g.dataKey||"value"}`,A=jf(y,g,x),m=f||g.payload.fill||g.color;return D.jsx("div",{className:Fe("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",n==="dot"&&"items-center"),children:s&&(g==null?void 0:g.value)!==void 0&&g.name?s(g.value,g.name,g,b,g.payload):D.jsxs(D.Fragment,{children:[A!=null&&A.icon?D.jsx(A.icon,{}):!a&&D.jsx("div",{className:Fe("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":n==="dot","w-1":n==="line","w-0 border-[1.5px] border-dashed bg-transparent":n==="dashed","my-0.5":v&&n==="dashed"}),style:{"--color-bg":m,"--color-border":m}}),D.jsxs("div",{className:Fe("flex flex-1 justify-between leading-none",v?"items-end":"items-center"),children:[D.jsxs("div",{className:"grid gap-1.5",children:[v?h:null,D.jsx("span",{className:"text-muted-foreground",children:(A==null?void 0:A.label)||g.name})]}),g.value&&D.jsx("span",{className:"font-mono font-medium tabular-nums text-foreground",children:g.value.toLocaleString()})]})]})},g.dataKey)})})]})});Mt.displayName="ChartTooltip";const sn=Vt,sr=M.forwardRef(({className:t,hideIcon:e=!1,payload:r,verticalAlign:n="bottom",nameKey:i},a)=>{const{config:o}=f0();return r!=null&&r.length?D.jsx("div",{ref:a,className:Fe("flex flex-wrap items-center justify-center gap-4",n==="top"?"pb-3":"pt-3",t),children:r.filter(u=>u.type!=="none").map(u=>{const c=`${i||u.dataKey||"value"}`,s=jf(o,u,c);return D.jsxs("div",{className:Fe("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[s!=null&&s.icon&&!e?D.jsx(s.icon,{}):D.jsx("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:u.color}}),s==null?void 0:s.label]},u.value)})}):null});sr.displayName="ChartLegend";function jf(t,e,r){if(typeof e!="object"||e===null)return;const n="payload"in e&&typeof e.payload=="object"&&e.payload!==null?e.payload:void 0;let i=r;return r in e&&typeof e[r]=="string"?i=e[r]:n&&r in n&&typeof n[r]=="string"&&(i=n[r]),i in t?t[i]:t[r]}const Jg={default:"pf-sparkline-variant-default",success:"pf-sparkline-variant-success",warning:"pf-sparkline-variant-warning",destructive:"pf-sparkline-variant-destructive",info:"pf-sparkline-variant-info",muted:"pf-sparkline-variant-muted"};function PN(t,e,r,n){const i=Math.min(...t),o=Math.max(...t)-i||1,u=n/2,c=r*.7-u,s=u;return t.map((f,l)=>{const p=t.length===1?e/2:l/(t.length-1)*e,d=s+c*(1-(f-i)/o);return`${p},${d}`}).join(" ")}function SN(t,e,r,n){const i=Math.min(...t),o=Math.max(...t)-i||1,u=n/2,c=r*.7-u,s=u,f=[];for(let l=0;l<t.length;l++){const p=t.length===1?e/2:l/(t.length-1)*e,d=s+c*(1-(t[l]-i)/o);if(l>0){const y=s+c*(1-(t[l-1]-i)/o);f.push(`${p},${y}`)}f.push(`${p},${d}`)}return f.join(" ")}function _N(t,e,r,n){if(t.length<2){const d=e/2,y=t[0],v=t[0]-y||1,g=n/2,b=r*.7-g,A=g+b*(1-(t[0]-y)/v);return`M ${d},${A}`}const i=Math.min(...t),o=Math.max(...t)-i||1,u=n/2,c=r*.7-u,s=u,f=t.map((d,y)=>y/(t.length-1)*e),l=t.map(d=>s+c*(1-(d-i)/o));let p=`M ${f[0]},${l[0]}`;for(let d=0;d<t.length-1;d++){const y=f[Math.max(0,d-1)],h=l[Math.max(0,d-1)],v=f[d],g=l[d],b=f[d+1],x=l[d+1],A=f[Math.min(t.length-1,d+2)],m=l[Math.min(t.length-1,d+2)],O=v+(b-y)/6,w=g+(x-h)/6,S=b-(A-v)/6,_=x-(m-g)/6;p+=` C ${O},${w} ${S},${_} ${b},${x}`}return p}let jN=0;function DN({data:t=[],height:e,variant:r="default",indicatorClass:n,fill:i=!1,curve:a="linear",strokeWidth:o=1.5,mode:u="line",className:c,cssClass:s}){if(typeof t=="string"||t.length===0)return null;const f=Jg[r??"default"]??Jg.default,l=`spark-${++jN}`,p=100,d=40;if(u==="bar"){const m=Math.min(0,...t),w=Math.max(...t)-m||1,S=1,_=(p-S*(t.length-1))/t.length;return D.jsx("svg",{className:Fe("pf-sparkline w-full",e==null&&"h-6",f,c,s),viewBox:`0 0 ${p} ${d}`,preserveAspectRatio:"none",style:e!=null?{height:e}:void 0,children:t.map((T,j)=>{const E=(T-m)/w*(d-1);return D.jsx("rect",{x:j*(_+S),y:d-E,width:_,height:E,fill:"currentColor",opacity:.7,rx:.5,className:n},j)})})}const y=a==="smooth",h=a==="step",v=y?_N(t,p,d,o):"",g=y?"":h?SN(t,p,d,o):PN(t,p,d,o),b=y?`${v} L ${p},${d} L 0,${d} Z`:"",x=i&&!y?`${g} ${p},${d} 0,${d}`:"",A={fill:"none",stroke:"currentColor",strokeWidth:o,strokeLinejoin:"round",strokeLinecap:"round",vectorEffect:"non-scaling-stroke",className:Fe("pf-sparkline-line",n)};return D.jsxs("svg",{className:Fe("pf-sparkline w-full",f,c,s),viewBox:`0 0 ${p} ${d}`,preserveAspectRatio:"none",style:{height:e},children:[i&&D.jsxs(D.Fragment,{children:[D.jsx("defs",{children:D.jsxs("linearGradient",{id:l,x1:"0",y1:"0",x2:"0",y2:"1",children:[D.jsx("stop",{offset:"0%",className:"pf-sparkline-fill-stop-start"}),D.jsx("stop",{offset:"100%",className:"pf-sparkline-fill-stop-end"})]})}),y?D.jsx("path",{d:b,fill:`url(#${l})`,stroke:"none"}):D.jsx("polygon",{points:x,fill:`url(#${l})`})]}),y?D.jsx("path",{d:v,...A}):D.jsx("polyline",{points:g,...A})]})}const gp=t=>new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}).format(t),jt=["var(--color-chart-1)","var(--color-chart-2)","var(--color-chart-3)","var(--color-chart-4)","var(--color-chart-5)"];function Ai(t){const e={};for(let r=0;r<t.length;r++){const n=t[r];e[n.dataKey]={label:n.label??n.dataKey,color:n.color??jt[r%jt.length]}}return e}function p0(t,e){const r={};for(let n=0;n<t.length;n++){const i=String(t[n][e]??`item-${n}`);r[i]={label:i,color:jt[n%jt.length]}}return r}function NN({data:t=[],series:e,xAxis:r,height:n=300,stacked:i=!1,horizontal:a=!1,barRadius:o=4,showLegend:u=!1,showTooltip:c=!0,animate:s=!0,showGrid:f=!0,showYAxis:l=!0,yAxisFormat:p="auto",className:d}){if(typeof t=="string")return null;const y=Ai(e);return D.jsx(kt,{config:y,className:d,style:{height:n,aspectRatio:"auto"},children:D.jsxs(vN,{data:t,layout:a?"vertical":"horizontal",children:[f&&D.jsx(gi,{vertical:a,horizontal:!a}),a&&r&&D.jsx(Ye,{dataKey:r,type:"category",tickLine:!1,axisLine:!1,tickMargin:8}),a&&D.jsx(Xe,{type:"number",hide:!0}),!a&&r&&D.jsx(Xe,{dataKey:r,tickLine:!1,axisLine:!1,tickMargin:8}),!a&&l&&D.jsx(Ye,{tickLine:!1,axisLine:!1,tickMargin:8,tickFormatter:p==="compact"?gp:void 0}),c&&D.jsx(cr,{content:D.jsx(Mt,{})}),u&&D.jsx(sn,{content:D.jsx(sr,{})}),e.map(h=>D.jsx(or,{isAnimationActive:s,dataKey:h.dataKey,fill:`var(--color-${h.dataKey})`,radius:o,stackId:i?"stack":void 0},h.dataKey))]})})}const d0={linear:"linear",smooth:"monotone",step:"step"};function LN({data:t=[],series:e,xAxis:r,height:n=300,curve:i="linear",showDots:a=!1,showLegend:o=!1,showTooltip:u=!0,animate:c=!0,showGrid:s=!0,showYAxis:f=!0,yAxisFormat:l="auto",className:p}){if(typeof t=="string")return null;const d=Ai(e);return D.jsx(kt,{config:d,className:p,style:{height:n,aspectRatio:"auto"},children:D.jsxs(dN,{data:t,children:[s&&D.jsx(gi,{vertical:!1}),r&&D.jsx(Xe,{dataKey:r,tickLine:!1,axisLine:!1,tickMargin:8}),f&&D.jsx(Ye,{tickLine:!1,axisLine:!1,tickMargin:8,tickFormatter:l==="compact"?gp:void 0}),u&&D.jsx(cr,{content:D.jsx(Mt,{})}),o&&D.jsx(sn,{content:D.jsx(sr,{})}),e.map(y=>D.jsx(bi,{isAnimationActive:c,dataKey:y.dataKey,type:d0[i]??i,stroke:`var(--color-${y.dataKey})`,strokeWidth:2,dot:a},y.dataKey))]})})}function qN({data:t=[],series:e,xAxis:r,height:n=300,stacked:i=!1,curve:a="linear",showDots:o=!1,showLegend:u=!1,showTooltip:c=!0,animate:s=!0,showGrid:f=!0,showYAxis:l=!0,yAxisFormat:p="auto",className:d}){if(typeof t=="string")return null;const y=Ai(e);return D.jsx(kt,{config:y,className:d,style:{height:n,aspectRatio:"auto"},children:D.jsxs(gN,{data:t,children:[f&&D.jsx(gi,{vertical:!1}),r&&D.jsx(Xe,{dataKey:r,tickLine:!1,axisLine:!1,tickMargin:8}),l&&D.jsx(Ye,{tickLine:!1,axisLine:!1,tickMargin:8,tickFormatter:p==="compact"?gp:void 0}),c&&D.jsx(cr,{content:D.jsx(Mt,{})}),u&&D.jsx(sn,{content:D.jsx(sr,{})}),e.map(h=>D.jsx(Rt,{isAnimationActive:s,dataKey:h.dataKey,type:d0[a]??a,fill:`var(--color-${h.dataKey})`,stroke:`var(--color-${h.dataKey})`,fillOpacity:.4,dot:o,stackId:i?"stack":void 0},h.dataKey))]})})}function BN({data:t=[],dataKey:e,nameKey:r,height:n=300,innerRadius:i=0,showLabel:a=!1,paddingAngle:o=0,showLegend:u=!1,showTooltip:c=!0,animate:s=!0,className:f}){if(typeof t=="string")return null;const l=p0(t,r),p=t.map((v,g)=>({...v,fill:jt[g%jt.length]})),d=a?"60%":"80%",y=i>0?`${Math.round(i/100*(a?60:80))}%`:0,h=u?n-36:n;return D.jsxs("div",{className:f,children:[D.jsx(kt,{config:l,style:{height:h,aspectRatio:"auto"},children:D.jsxs(hN,{children:[c&&D.jsx(cr,{content:D.jsx(Mt,{nameKey:r})}),D.jsx(bt,{isAnimationActive:s,data:p,dataKey:e,nameKey:r,innerRadius:y,outerRadius:d,label:a,paddingAngle:o})]})}),u&&D.jsx("div",{style:{display:"flex",flexWrap:"wrap",justifyContent:"center",gap:"12px",paddingTop:"8px",fontSize:"12px"},children:p.map((v,g)=>D.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[D.jsx("div",{style:{width:"8px",height:"8px",borderRadius:"2px",backgroundColor:v.fill,flexShrink:0}}),String(v[r]??"")]},g))})]})}function FN({data:t=[],series:e,axisKey:r,height:n=300,filled:i=!0,showDots:a=!1,showLegend:o=!1,showTooltip:u=!0,animate:c=!0,showGrid:s=!0,className:f}){if(typeof t=="string")return null;const l=Ai(e);return D.jsx(kt,{config:l,className:f,style:{height:n,aspectRatio:"auto"},children:D.jsxs(yN,{data:t,children:[s&&D.jsx(tO,{}),r&&D.jsx(ar,{dataKey:r}),u&&D.jsx(cr,{content:D.jsx(Mt,{})}),o&&D.jsx(sn,{content:D.jsx(sr,{})}),e.map(p=>D.jsx(yi,{isAnimationActive:c,dataKey:p.dataKey,fill:`var(--color-${p.dataKey})`,fillOpacity:i?.3:0,stroke:`var(--color-${p.dataKey})`,strokeWidth:2,dot:a},p.dataKey))]})})}function zN({data:t=[],dataKey:e,nameKey:r,height:n=300,innerRadius:i=30,startAngle:a=180,endAngle:o=0,showLegend:u=!1,showTooltip:c=!0,animate:s=!0,className:f}){if(typeof t=="string")return null;const l=p0(t,r),p=t.map((d,y)=>({...d,fill:jt[y%jt.length]}));return D.jsx(kt,{config:l,className:f,style:{height:n,aspectRatio:"auto"},children:D.jsxs(bN,{data:p,innerRadius:i,startAngle:a,endAngle:o,children:[c&&D.jsx(cr,{content:D.jsx(Mt,{nameKey:r})}),u&&D.jsx(sn,{content:D.jsx(sr,{nameKey:r})}),D.jsx(mi,{isAnimationActive:s,dataKey:e})]})})}function KN({data:t=[],series:e,xAxis:r,yAxis:n,zAxis:i,height:a=300,showLegend:o=!1,showTooltip:u=!0,animate:c=!0,showGrid:s=!0,className:f}){if(typeof t=="string")return null;const l=M.useMemo(()=>t,[JSON.stringify(t)]),p=Ai(e);return D.jsx(kt,{config:p,className:f,style:{height:a,aspectRatio:"auto"},children:D.jsxs(mN,{data:l,children:[s&&D.jsx(gi,{}),D.jsx(Xe,{dataKey:r,type:"number",name:r,tickLine:!1,axisLine:!1,tickMargin:8}),D.jsx(Ye,{dataKey:n,type:"number",name:n,tickLine:!1,axisLine:!1,tickMargin:8}),i&&D.jsx(xi,{dataKey:i,type:"number",name:i,range:[40,400]}),u&&D.jsx(cr,{content:D.jsx(Mt,{})}),o&&D.jsx(sn,{content:D.jsx(sr,{})}),e.map(d=>D.jsx(Oi,{isAnimationActive:c,name:d.label??d.dataKey,data:e.length===1?l:l.filter(y=>y._series===d.dataKey),fill:`var(--color-${d.dataKey})`},d.dataKey))]})})}export{qN as PrefabAreaChart,NN as PrefabBarChart,LN as PrefabLineChart,BN as PrefabPieChart,FN as PrefabRadarChart,zN as PrefabRadialChart,KN as PrefabScatterChart,DN as PrefabSparkline};
|