@graphysdk/geom-candlestick 0.1.0 → 0.1.1-beta.1790855561349

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.
@@ -81,10 +81,10 @@ export declare class CandlestickGeom extends Geom<CandlestickGeomParams> {
81
81
  discreteMainAxis: boolean;
82
82
  };
83
83
  /**
84
- * A hovered session is one unit. The wick runs from its low to its high inside the band, so the whole of it
85
- * takes a press for the session, and no stroke runs on to the next one.
84
+ * A hovered session is one unit: the rectangle as wide as its body and as tall as its wick, so a press anywhere
85
+ * across the candle is on the session.
86
86
  */
87
- readonly spatialKind = "spanned-buckets";
87
+ readonly spatialKind = "rects";
88
88
  readonly highlightStrategy: "observation-rerender";
89
89
  /**
90
90
  * The tooltip shows the session's four prices, as written in the data and formatted like the price axis, each
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let i=require("@graphysdk/react"),v=require("react"),d=require("react/jsx-runtime");var x={direction:"candlestickDirection"},M=(t,e)=>{const o=e==="x"?(0,i.getX)(t):(0,i.getY)(t),r=e==="x"?(0,i.getXMin)(t):(0,i.getYMin)(t),s=e==="x"?(0,i.getXMax)(t):(0,i.getYMax)(t),n=e==="x"?(0,i.getYMin)(t):(0,i.getXMin)(t),l=e==="x"?(0,i.getYMax)(t):(0,i.getXMax)(t),c=(0,i.getScaledAesthetic)(t,"open"),a=(0,i.getScaledAesthetic)(t,"close");return o===null||r===null||s===null||n===null||l===null||c===null||a===null?null:{observation:t,band:o,bodyStart:r,bodyEnd:s,low:n,high:l,open:c,close:a,direction:t[x.direction]==="falling"?"falling":"rising"}},p=(t,e)=>{const o=[];for(const r of t){const s=M(r,e);s!==null&&o.push(s)}return o},A=1,B=1,_=.6,O=["open","high","low","close"],V={alpha:"unitInterval",fillAlpha:"unitInterval",strokeWidth:"pixels"},y={fill:"color",stroke:"color"},E={stroke:"color",alpha:"unitInterval",strokeWidth:"pixels",dashArray:"dashArray"},C=class extends i.Geom{constructor(...t){super(...t),this.type="candlestick",this.defaultParams={},this.derivedVariables=[x.direction],this.aesthetics=[{kind:"visual",name:"color"}],this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value",aes:"low"},{axis:"y",role:"max",valueKind:"value",aes:"high"},{axis:"y",role:"scalar",valueKind:"value",aes:"open"},{axis:"y",role:"scalar",valueKind:"value",aes:"close"}],this.supportedPositions=["identity"],this.supportedCoordTypes=["cartesian","flip"],this.scaleConstraints={discreteMainAxis:!0},this.spatialKind="spanned-buckets",this.highlightStrategy="observation-rerender",this.tooltip=O.map(e=>({aes:e})),this.styleTarget=(0,i.defineGeomStyleTarget)({observation:{vocabulary:V,sharedPaint:!1,aesthetics:{},rest:{alpha:1,fillAlpha:1,strokeWidth:A}},parts:{rising:{vocabulary:y,aesthetics:{fill:"color",stroke:"color"},rest:{fill:(0,i.token)("trendPositive"),stroke:(0,i.token)("trendPositive")}},falling:{vocabulary:y,aesthetics:{fill:"color",stroke:"color"},rest:{fill:(0,i.token)("trendNegative"),stroke:(0,i.token)("trendNegative")}},wick:{vocabulary:E,rest:{alpha:1,strokeWidth:B,dashArray:[]}}}}),this.resolveBandFraction=e=>f(e),this.validateMapping=({mapping:e})=>["open","close"].filter(o=>e[o]===void 0).map(o=>({code:"MISSING_AESTHETIC",message:`candlestick geom requires '${o}' to be mapped`})),this.resolveAnchorPosition=(e,{coordSystem:o})=>{const r=(0,i.readMainAxis)(o),s=M(e,r);return s===null?null:r==="x"?{x:s.band,y:s.close}:{x:s.close,y:s.band}}}resolveParams(t){const{width:e,...o}=super.resolveParams(t);if(e===void 0)return o;const r=typeof e=="number"&&Number.isFinite(e)?e:null;if(r!==null&&r>0&&r<=1)return{...o,width:r};const s=r!==null&&r>1?1:void 0;return t.diagnostics?.addWarning({code:"INVALID_GEOM_PARAM",message:`Candlestick width must be a fraction in (0, 1], got ${String(e)}; falling back to ${s??"the default band"}.`,context:{geom:this.type,param:"width",expected:"0 < width <= 1",actual:r??String(e)},suggestion:"Set params.width to a fraction of the session band in (0, 1]."}),{...o,...s!==void 0&&{width:s}}}compile({data:t,mapping:e,params:o}){const r=f(o)/2;return{data:T(t,b(e.open),b(e.close)).addConstantVariable(i.POSITION_VARIABLES.xMin,"numeric",-r).addConstantVariable(i.POSITION_VARIABLES.xMax,"numeric",r),mapping:{y:e.close}}}},f=({width:t})=>t??_,b=t=>t===void 0?null:typeof t=="string"?t:"variable"in t?t.variable:null,T=(t,e,o)=>{if(e===null||o===null||!t.hasVariable(e)||!t.hasVariable(o))return t;const r=t.getValues(e,{type:"numeric"}),s=t.getValues(o,{type:"numeric"}),n=r.map((l,c)=>{const a=s[c];return l===null||a===null||a===void 0?null:a>=l?"rising":"falling"});return t.addVariable(x.direction,"categorical",n)},D=5e-4,S=(t,e)=>{const o=(t.open+t.close)/2,r=Math.max(Math.abs(t.close-t.open),D)/2,s=(0,i.composePoint)(e,{main:t.bodyStart,cross:o-r}),n=(0,i.composePoint)(e,{main:t.bodyEnd,cross:o+r}),[l,c]=w((0,i.toViewBoxX)(s.x),(0,i.toViewBoxX)(n.x)),[a,h]=w((0,i.toViewBoxY)(s.y),(0,i.toViewBoxY)(n.y));return{x:l,y:a,width:c-l,height:h-a}},w=(t,e)=>t<=e?[t,e]:[e,t],W=({layer:t,coordSystem:e,panelRect:o,styleReaders:r})=>{const s=(0,i.readMainAxis)(e),n=p(t.data,s),l=r.part("wick"),c=l===void 0?[]:n.map(h=>{const u=P(h.band,h.low,s,o),g=P(h.band,h.high,s,o),I=l.get("strokeWidth",h.observation)??0;return{kind:"stroke",pathData:`M${u.x},${u.y}L${g.x},${g.y}`,width:I}}),a=n.map(h=>{const u=S(h,s),g=u.x*o.width;return{kind:"region",pathData:`M${g},${u.y*o.height}H${(u.x+u.width)*o.width}V${(u.y+u.height)*o.height}H${g}Z`}});return[...c,...a]},P=(t,e,o,r)=>{const s=(0,i.composePoint)(o,{main:t,cross:e});return(0,i.scalePointToPanel)((0,i.projectPointCartesian)(s.x,s.y),r)},k=t=>{const e=(0,i.createStableKeyGenerator)(t.data,t.mapping,t.id);return o=>e(o.observation)},m=({candles:t,mainAxis:e,styleReaders:o,getKey:r,isHovered:s=!1,shouldAnimateTransitions:n=!1})=>{const l=s?"hovered":void 0,c=o.part("wick");return(0,d.jsxs)(d.Fragment,{children:[c&&t.map(a=>(0,d.jsx)(j,{candle:a,mainAxis:e,readers:c,directionReaders:o.part(a.direction),state:l,shouldAnimateTransitions:n},r(a))),t.map(a=>(0,d.jsx)(Y,{candle:a,mainAxis:e,styleReaders:o,state:l,shouldAnimateTransitions:n},r(a)))]})},j=({candle:t,mainAxis:e,readers:o,directionReaders:r,state:s,shouldAnimateTransitions:n})=>{const l=(0,i.composePoint)(e,{main:t.band,cross:t.low}),c=(0,i.composePoint)(e,{main:t.band,cross:t.high}),a=o.get("strokeWidth",t.observation,s)??0,h=o.get("stroke",t.observation,s)??r?.get("stroke",t.observation,s);return(0,d.jsx)(i.GeomLine,{"data-testid":"candlestick-wick",x1:(0,i.toPercent)((0,i.toViewBoxX)(l.x)),y1:(0,i.toPercent)((0,i.toViewBoxY)(l.y)),x2:(0,i.toPercent)((0,i.toViewBoxX)(c.x)),y2:(0,i.toPercent)((0,i.toViewBoxY)(c.y)),stroke:h===void 0?void 0:(0,i.toPaintColor)(h),strokeOpacity:o.get("alpha",t.observation,s),strokeWidth:a,strokeDasharray:(0,i.toStrokeDasharray)(o.get("dashArray",t.observation,s),a),shouldAnimateTransitions:n})},Y=({candle:t,mainAxis:e,styleReaders:o,state:r,shouldAnimateTransitions:s})=>{const n=S(t,e),l=o.part(t.direction),c=l?.get("fill",t.observation,r),a=l?.get("stroke",t.observation,r);return(0,d.jsx)(i.GeomRect,{"data-testid":"candlestick-body",x:(0,i.toPercent)(n.x),y:(0,i.toPercent)(n.y),width:(0,i.toPercent)(n.width),height:(0,i.toPercent)(n.height),fill:c===void 0?void 0:(0,i.toPaintColor)(c),opacity:o.get("alpha",t.observation,r),fillOpacity:o.get("fillAlpha",t.observation,r),stroke:a===void 0?void 0:(0,i.toPaintColor)(a),strokeWidth:o.get("strokeWidth",t.observation,r),shouldAnimateTransitions:s})},K=({layer:t,sourceLayer:e,mainAxis:o,styleReaders:r})=>(0,d.jsx)(m,{candles:(0,v.useMemo)(()=>p(t.data,o),[t.data,o]),mainAxis:o,styleReaders:r,getKey:(0,v.useMemo)(()=>k(e),[e])}),H=({layer:t,primary:e,siblings:o,mainAxis:r,styleReaders:s})=>(0,d.jsx)("g",{"data-testid":"hovered-candles",children:(0,d.jsx)(m,{candles:p([e,...o].map(n=>n.observation),r),mainAxis:r,styleReaders:s,getKey:(0,v.useMemo)(()=>k(t),[t]),isHovered:!0})}),N=({layer:t,mainAxis:e,styleReaders:o,shouldAnimateTransitions:r,intro:s})=>{const n=(0,d.jsx)(m,{candles:(0,v.useMemo)(()=>p(t.data,e),[t.data,e]),mainAxis:e,styleReaders:o,getKey:(0,v.useMemo)(()=>k(t),[t]),shouldAnimateTransitions:r});return s?.type==="fade"?(0,d.jsx)(i.IntroFade,{intro:s,children:n}):n},X=(0,i.defineGeomRenderer)(new C,{coord:"cartesian",swatchShape:"square",guideMode:"band",render:({layer:t,coordSystem:e,styleReaders:o,shouldAnimateTransitions:r,intro:s})=>(0,d.jsx)(N,{layer:t,mainAxis:(0,i.readMainAxis)(e),styleReaders:o,shouldAnimateTransitions:r,intro:s}),renderHighlight:({layer:t,sourceLayer:e,coordSystem:o,styleReaders:r})=>(0,d.jsx)(K,{layer:t,sourceLayer:e,mainAxis:(0,i.readMainAxis)(o),styleReaders:r}),renderHover:({layer:t,primary:e,group:o,related:r,coordSystem:s,styleReaders:n})=>(0,d.jsx)(H,{layer:t,primary:e,siblings:[...o,...r],mainAxis:(0,i.readMainAxis)(s),styleReaders:n}),renderHoverCompanions:()=>null,getEditOutlineShapes:W});exports.CandlestickGeom=C;exports.candlestick=X;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let r=require("@graphysdk/react"),v=require("react"),c=require("react/jsx-runtime");var x={direction:"candlestickDirection"},M=(t,e)=>{const o=e==="x"?(0,r.getX)(t):(0,r.getY)(t),i=e==="x"?(0,r.getXMin)(t):(0,r.getYMin)(t),n=e==="x"?(0,r.getXMax)(t):(0,r.getYMax)(t),s=e==="x"?(0,r.getYMin)(t):(0,r.getXMin)(t),l=e==="x"?(0,r.getYMax)(t):(0,r.getXMax)(t),d=(0,r.getScaledAesthetic)(t,"open"),a=(0,r.getScaledAesthetic)(t,"close");return o===null||i===null||n===null||s===null||l===null||d===null||a===null?null:{observation:t,band:o,bodyStart:i,bodyEnd:n,low:s,high:l,open:d,close:a,direction:t[x.direction]==="falling"?"falling":"rising"}},p=(t,e)=>{const o=[];for(const i of t){const n=M(i,e);n!==null&&o.push(n)}return o},A=1,B=1,_=.6,O=["open","high","low","close"],V={alpha:"unitInterval",fillAlpha:"unitInterval",strokeWidth:"pixels"},f={fill:"color",stroke:"color"},E={stroke:"color",alpha:"unitInterval",strokeWidth:"pixels",dashArray:"dashArray"},C=class extends r.Geom{constructor(...t){super(...t),this.type="candlestick",this.defaultParams={},this.derivedVariables=[x.direction],this.aesthetics=[{kind:"visual",name:"color"}],this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value",aes:"low"},{axis:"y",role:"max",valueKind:"value",aes:"high"},{axis:"y",role:"scalar",valueKind:"value",aes:"open"},{axis:"y",role:"scalar",valueKind:"value",aes:"close"}],this.supportedPositions=["identity"],this.supportedCoordTypes=["cartesian","flip"],this.scaleConstraints={discreteMainAxis:!0},this.spatialKind="rects",this.highlightStrategy="observation-rerender",this.tooltip=O.map(e=>({aes:e})),this.styleTarget=(0,r.defineGeomStyleTarget)({observation:{vocabulary:V,sharedPaint:!1,aesthetics:{},rest:{alpha:1,fillAlpha:1,strokeWidth:A}},parts:{rising:{vocabulary:f,aesthetics:{fill:"color",stroke:"color"},rest:{fill:(0,r.token)("trendPositive"),stroke:(0,r.token)("trendPositive")}},falling:{vocabulary:f,aesthetics:{fill:"color",stroke:"color"},rest:{fill:(0,r.token)("trendNegative"),stroke:(0,r.token)("trendNegative")}},wick:{vocabulary:E,rest:{alpha:1,strokeWidth:B,dashArray:[]}}}}),this.resolveBandFraction=e=>m(e),this.validateMapping=({mapping:e})=>["open","close"].filter(o=>e[o]===void 0).map(o=>({code:"MISSING_AESTHETIC",message:`candlestick geom requires '${o}' to be mapped`})),this.resolveAnchorPosition=(e,{coordSystem:o})=>{const i=(0,r.readMainAxis)(o),n=M(e,i);return n===null?null:i==="x"?{x:n.band,y:n.close}:{x:n.close,y:n.band}}}resolveParams(t){const{width:e,...o}=super.resolveParams(t);if(e===void 0)return o;const i=typeof e=="number"&&Number.isFinite(e)?e:null;if(i!==null&&i>0&&i<=1)return{...o,width:i};const n=i!==null&&i>1?1:void 0;return t.diagnostics?.addWarning({code:"INVALID_GEOM_PARAM",message:`Candlestick width must be a fraction in (0, 1], got ${String(e)}; falling back to ${n??"the default band"}.`,context:{geom:this.type,param:"width",expected:"0 < width <= 1",actual:i??String(e)},suggestion:"Set params.width to a fraction of the session band in (0, 1]."}),{...o,...n!==void 0&&{width:n}}}compile({data:t,mapping:e,params:o}){const i=m(o)/2;return{data:T(t,b(e.open),b(e.close)).addConstantVariable(r.POSITION_VARIABLES.xMin,"numeric",-i).addConstantVariable(r.POSITION_VARIABLES.xMax,"numeric",i),mapping:{y:e.close}}}},m=({width:t})=>t??_,b=t=>t===void 0?null:typeof t=="string"?t:"variable"in t?t.variable:null,T=(t,e,o)=>{if(e===null||o===null||!t.hasVariable(e)||!t.hasVariable(o))return t;const i=t.getValues(e,{type:"numeric"}),n=t.getValues(o,{type:"numeric"}),s=i.map((l,d)=>{const a=n[d];return l===null||a===null||a===void 0?null:a>=l?"rising":"falling"});return t.addVariable(x.direction,"categorical",s)},D=5e-4,S=(t,e)=>{const o=(t.open+t.close)/2,i=Math.max(Math.abs(t.close-t.open),D)/2,n=(0,r.composePoint)(e,{main:t.bodyStart,cross:o-i}),s=(0,r.composePoint)(e,{main:t.bodyEnd,cross:o+i}),[l,d]=w((0,r.toViewBoxX)(n.x),(0,r.toViewBoxX)(s.x)),[a,h]=w((0,r.toViewBoxY)(n.y),(0,r.toViewBoxY)(s.y));return{x:l,y:a,width:d-l,height:h-a}},w=(t,e)=>t<=e?[t,e]:[e,t],W=({layer:t,coordSystem:e,panelRect:o,styleReaders:i})=>{const n=(0,r.readMainAxis)(e),s=p(t.data,n),l=i.part("wick"),d=l===void 0?[]:s.map(h=>{const u=P(h.band,h.low,n,o),g=P(h.band,h.high,n,o),I=l.get("strokeWidth",h.observation)??0;return{kind:"stroke",pathData:`M${u.x},${u.y}L${g.x},${g.y}`,width:I}}),a=s.map(h=>{const u=S(h,n),g=u.x*o.width;return{kind:"region",pathData:`M${g},${u.y*o.height}H${(u.x+u.width)*o.width}V${(u.y+u.height)*o.height}H${g}Z`}});return[...d,...a]},P=(t,e,o,i)=>{const n=(0,r.composePoint)(o,{main:t,cross:e});return(0,r.scalePointToPanel)((0,r.projectPointCartesian)(n.x,n.y),i)},k=t=>{const e=(0,r.createStableKeyGenerator)(t.data,t.mapping,t.id);return o=>e(o.observation)},y=({candles:t,mainAxis:e,styleReaders:o,getKey:i,isHovered:n=!1,shouldAnimateTransitions:s=!1})=>{const l=n?"hovered":void 0,d=o.part("wick");return(0,c.jsxs)(c.Fragment,{children:[d&&t.map(a=>(0,c.jsx)(j,{candle:a,mainAxis:e,readers:d,directionReaders:o.part(a.direction),state:l,shouldAnimateTransitions:s},i(a))),t.map(a=>(0,c.jsx)(Y,{candle:a,mainAxis:e,styleReaders:o,state:l,shouldAnimateTransitions:s},i(a)))]})},j=({candle:t,mainAxis:e,readers:o,directionReaders:i,state:n,shouldAnimateTransitions:s})=>{const l=(0,r.composePoint)(e,{main:t.band,cross:t.low}),d=(0,r.composePoint)(e,{main:t.band,cross:t.high}),a=o.get("strokeWidth",t.observation,n)??0,h=o.get("stroke",t.observation,n)??i?.get("stroke",t.observation,n);return(0,c.jsx)(r.GeomLine,{"data-testid":"candlestick-wick",x1:(0,r.toPercent)((0,r.toViewBoxX)(l.x)),y1:(0,r.toPercent)((0,r.toViewBoxY)(l.y)),x2:(0,r.toPercent)((0,r.toViewBoxX)(d.x)),y2:(0,r.toPercent)((0,r.toViewBoxY)(d.y)),stroke:h===void 0?void 0:(0,r.toPaintColor)(h),strokeOpacity:o.get("alpha",t.observation,n),strokeWidth:a,strokeDasharray:(0,r.toStrokeDasharray)(o.get("dashArray",t.observation,n),a),shouldAnimateTransitions:s})},Y=({candle:t,mainAxis:e,styleReaders:o,state:i,shouldAnimateTransitions:n})=>{const s=S(t,e),l=o.part(t.direction),d=l?.get("fill",t.observation,i),a=l?.get("stroke",t.observation,i);return(0,c.jsx)(r.GeomRect,{"data-testid":"candlestick-body",x:(0,r.toPercent)(s.x),y:(0,r.toPercent)(s.y),width:(0,r.toPercent)(s.width),height:(0,r.toPercent)(s.height),fill:d===void 0?void 0:(0,r.toPaintColor)(d),opacity:o.get("alpha",t.observation,i),fillOpacity:o.get("fillAlpha",t.observation,i),stroke:a===void 0?void 0:(0,r.toPaintColor)(a),strokeWidth:o.get("strokeWidth",t.observation,i),shouldAnimateTransitions:n})},K=({layer:t,sourceLayer:e,mainAxis:o,styleReaders:i})=>(0,c.jsx)(y,{candles:(0,v.useMemo)(()=>p(t.data,o),[t.data,o]),mainAxis:o,styleReaders:i,getKey:(0,v.useMemo)(()=>k(e),[e])}),H=({layer:t,primary:e,siblings:o,mainAxis:i,styleReaders:n})=>(0,c.jsx)("g",{"data-testid":"hovered-candles",children:(0,c.jsx)(y,{candles:p([e,...o].map(s=>s.observation),i),mainAxis:i,styleReaders:n,getKey:(0,v.useMemo)(()=>k(t),[t]),isHovered:!0})}),N=({layer:t,mainAxis:e,styleReaders:o,shouldAnimateTransitions:i,intro:n})=>{const s=(0,c.jsx)(y,{candles:(0,v.useMemo)(()=>p(t.data,e),[t.data,e]),mainAxis:e,styleReaders:o,getKey:(0,v.useMemo)(()=>k(t),[t]),shouldAnimateTransitions:i}),l=X(n);return l===null?s:(0,c.jsx)(r.IntroFade,{intro:l,children:s})},X=t=>t==null?null:{type:"fade",layerId:t.layerId,durationSeconds:t.durationSeconds},$=(0,r.defineGeomRenderer)(new C,{coord:"cartesian",swatchShape:"square",guideMode:"band",render:({layer:t,coordSystem:e,styleReaders:o,shouldAnimateTransitions:i,intro:n})=>(0,c.jsx)(N,{layer:t,mainAxis:(0,r.readMainAxis)(e),styleReaders:o,shouldAnimateTransitions:i,intro:n}),renderHighlight:({layer:t,sourceLayer:e,coordSystem:o,styleReaders:i})=>(0,c.jsx)(K,{layer:t,sourceLayer:e,mainAxis:(0,r.readMainAxis)(o),styleReaders:i}),renderHover:({layer:t,primary:e,group:o,related:i,coordSystem:n,styleReaders:s})=>(0,c.jsx)(H,{layer:t,primary:e,siblings:[...o,...i],mainAxis:(0,r.readMainAxis)(n),styleReaders:s}),renderHoverCompanions:()=>null,getEditOutlineShapes:W});exports.CandlestickGeom=C;exports.candlestick=$;
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
- import { Geom as $, GeomLine as N, GeomRect as Y, IntroFade as L, POSITION_VARIABLES as P, composePoint as p, createStableKeyGenerator as G, defineGeomRenderer as X, defineGeomStyleTarget as R, getScaledAesthetic as S, getX as F, getXMax as M, getXMin as A, getY as U, getYMax as D, getYMin as E, projectPointCartesian as j, readMainAxis as v, scalePointToPanel as q, toPaintColor as b, toPercent as u, toStrokeDasharray as Z, toViewBoxX as y, toViewBoxY as m, token as f } from "@graphysdk/react";
2
- import { useMemo as k } from "react";
1
+ import { Geom as $, GeomLine as N, GeomRect as Y, IntroFade as L, POSITION_VARIABLES as S, composePoint as p, createStableKeyGenerator as G, defineGeomRenderer as X, defineGeomStyleTarget as F, getScaledAesthetic as P, getX as R, getXMax as M, getXMin as A, getY as U, getYMax as D, getYMin as E, projectPointCartesian as j, readMainAxis as g, scalePointToPanel as q, toPaintColor as b, toPercent as u, toStrokeDasharray as Z, toViewBoxX as y, toViewBoxY as m, token as k } from "@graphysdk/react";
2
+ import { useMemo as f } from "react";
3
3
  import { Fragment as z, jsx as c, jsxs as J } from "react/jsx-runtime";
4
4
  var w = { direction: "candlestickDirection" }, K = (t, e) => {
5
- const r = e === "x" ? F(t) : U(t), i = e === "x" ? A(t) : E(t), o = e === "x" ? M(t) : D(t), a = e === "x" ? E(t) : A(t), s = e === "x" ? D(t) : M(t), l = S(t, "open"), n = S(t, "close");
6
- return r === null || i === null || o === null || a === null || s === null || l === null || n === null ? null : {
5
+ const r = e === "x" ? R(t) : U(t), o = e === "x" ? A(t) : E(t), i = e === "x" ? M(t) : D(t), a = e === "x" ? E(t) : A(t), s = e === "x" ? D(t) : M(t), l = P(t, "open"), n = P(t, "close");
6
+ return r === null || o === null || i === null || a === null || s === null || l === null || n === null ? null : {
7
7
  observation: t,
8
8
  band: r,
9
- bodyStart: i,
10
- bodyEnd: o,
9
+ bodyStart: o,
10
+ bodyEnd: i,
11
11
  low: a,
12
12
  high: s,
13
13
  open: l,
@@ -16,9 +16,9 @@ var w = { direction: "candlestickDirection" }, K = (t, e) => {
16
16
  };
17
17
  }, x = (t, e) => {
18
18
  const r = [];
19
- for (const i of t) {
20
- const o = K(i, e);
21
- o !== null && r.push(o);
19
+ for (const o of t) {
20
+ const i = K(o, e);
21
+ i !== null && r.push(i);
22
22
  }
23
23
  return r;
24
24
  }, Q = 1, tt = 1, et = 0.6, rt = [
@@ -26,14 +26,14 @@ var w = { direction: "candlestickDirection" }, K = (t, e) => {
26
26
  "high",
27
27
  "low",
28
28
  "close"
29
- ], it = {
29
+ ], ot = {
30
30
  alpha: "unitInterval",
31
31
  fillAlpha: "unitInterval",
32
32
  strokeWidth: "pixels"
33
33
  }, _ = {
34
34
  fill: "color",
35
35
  stroke: "color"
36
- }, ot = {
36
+ }, it = {
37
37
  stroke: "color",
38
38
  alpha: "unitInterval",
39
39
  strokeWidth: "pixels",
@@ -73,9 +73,9 @@ var w = { direction: "candlestickDirection" }, K = (t, e) => {
73
73
  valueKind: "value",
74
74
  aes: "close"
75
75
  }
76
- ], this.supportedPositions = ["identity"], this.supportedCoordTypes = ["cartesian", "flip"], this.scaleConstraints = { discreteMainAxis: !0 }, this.spatialKind = "spanned-buckets", this.highlightStrategy = "observation-rerender", this.tooltip = rt.map((e) => ({ aes: e })), this.styleTarget = R({
76
+ ], this.supportedPositions = ["identity"], this.supportedCoordTypes = ["cartesian", "flip"], this.scaleConstraints = { discreteMainAxis: !0 }, this.spatialKind = "rects", this.highlightStrategy = "observation-rerender", this.tooltip = rt.map((e) => ({ aes: e })), this.styleTarget = F({
77
77
  observation: {
78
- vocabulary: it,
78
+ vocabulary: ot,
79
79
  sharedPaint: !1,
80
80
  aesthetics: {},
81
81
  rest: {
@@ -92,8 +92,8 @@ var w = { direction: "candlestickDirection" }, K = (t, e) => {
92
92
  stroke: "color"
93
93
  },
94
94
  rest: {
95
- fill: f("trendPositive"),
96
- stroke: f("trendPositive")
95
+ fill: k("trendPositive"),
96
+ stroke: k("trendPositive")
97
97
  }
98
98
  },
99
99
  falling: {
@@ -103,12 +103,12 @@ var w = { direction: "candlestickDirection" }, K = (t, e) => {
103
103
  stroke: "color"
104
104
  },
105
105
  rest: {
106
- fill: f("trendNegative"),
107
- stroke: f("trendNegative")
106
+ fill: k("trendNegative"),
107
+ stroke: k("trendNegative")
108
108
  }
109
109
  },
110
110
  wick: {
111
- vocabulary: ot,
111
+ vocabulary: it,
112
112
  rest: {
113
113
  alpha: 1,
114
114
  strokeWidth: tt,
@@ -120,95 +120,95 @@ var w = { direction: "candlestickDirection" }, K = (t, e) => {
120
120
  code: "MISSING_AESTHETIC",
121
121
  message: `candlestick geom requires '${r}' to be mapped`
122
122
  })), this.resolveAnchorPosition = (e, { coordSystem: r }) => {
123
- const i = v(r), o = K(e, i);
124
- return o === null ? null : i === "x" ? {
125
- x: o.band,
126
- y: o.close
123
+ const o = g(r), i = K(e, o);
124
+ return i === null ? null : o === "x" ? {
125
+ x: i.band,
126
+ y: i.close
127
127
  } : {
128
- x: o.close,
129
- y: o.band
128
+ x: i.close,
129
+ y: i.band
130
130
  };
131
131
  };
132
132
  }
133
133
  resolveParams(t) {
134
134
  const { width: e, ...r } = super.resolveParams(t);
135
135
  if (e === void 0) return r;
136
- const i = typeof e == "number" && Number.isFinite(e) ? e : null;
137
- if (i !== null && i > 0 && i <= 1) return {
136
+ const o = typeof e == "number" && Number.isFinite(e) ? e : null;
137
+ if (o !== null && o > 0 && o <= 1) return {
138
138
  ...r,
139
- width: i
139
+ width: o
140
140
  };
141
- const o = i !== null && i > 1 ? 1 : void 0;
141
+ const i = o !== null && o > 1 ? 1 : void 0;
142
142
  return t.diagnostics?.addWarning({
143
143
  code: "INVALID_GEOM_PARAM",
144
- message: `Candlestick width must be a fraction in (0, 1], got ${String(e)}; falling back to ${o ?? "the default band"}.`,
144
+ message: `Candlestick width must be a fraction in (0, 1], got ${String(e)}; falling back to ${i ?? "the default band"}.`,
145
145
  context: {
146
146
  geom: this.type,
147
147
  param: "width",
148
148
  expected: "0 < width <= 1",
149
- actual: i ?? String(e)
149
+ actual: o ?? String(e)
150
150
  },
151
151
  suggestion: "Set params.width to a fraction of the session band in (0, 1]."
152
152
  }), {
153
153
  ...r,
154
- ...o !== void 0 && { width: o }
154
+ ...i !== void 0 && { width: i }
155
155
  };
156
156
  }
157
157
  compile({ data: t, mapping: e, params: r }) {
158
- const i = B(r) / 2;
158
+ const o = B(r) / 2;
159
159
  return {
160
- data: nt(t, O(e.open), O(e.close)).addConstantVariable(P.xMin, "numeric", -i).addConstantVariable(P.xMax, "numeric", i),
160
+ data: nt(t, O(e.open), O(e.close)).addConstantVariable(S.xMin, "numeric", -o).addConstantVariable(S.xMax, "numeric", o),
161
161
  mapping: { y: e.close }
162
162
  };
163
163
  }
164
164
  }, B = ({ width: t }) => t ?? et, O = (t) => t === void 0 ? null : typeof t == "string" ? t : "variable" in t ? t.variable : null, nt = (t, e, r) => {
165
165
  if (e === null || r === null || !t.hasVariable(e) || !t.hasVariable(r)) return t;
166
- const i = t.getValues(e, { type: "numeric" }), o = t.getValues(r, { type: "numeric" }), a = i.map((s, l) => {
167
- const n = o[l];
166
+ const o = t.getValues(e, { type: "numeric" }), i = t.getValues(r, { type: "numeric" }), a = o.map((s, l) => {
167
+ const n = i[l];
168
168
  return s === null || n === null || n === void 0 ? null : n >= s ? "rising" : "falling";
169
169
  });
170
170
  return t.addVariable(w.direction, "categorical", a);
171
171
  }, st = 5e-4, H = (t, e) => {
172
- const r = (t.open + t.close) / 2, i = Math.max(Math.abs(t.close - t.open), st) / 2, o = p(e, {
172
+ const r = (t.open + t.close) / 2, o = Math.max(Math.abs(t.close - t.open), st) / 2, i = p(e, {
173
173
  main: t.bodyStart,
174
- cross: r - i
174
+ cross: r - o
175
175
  }), a = p(e, {
176
176
  main: t.bodyEnd,
177
- cross: r + i
178
- }), [s, l] = T(y(o.x), y(a.x)), [n, d] = T(m(o.y), m(a.y));
177
+ cross: r + o
178
+ }), [s, l] = T(y(i.x), y(a.x)), [n, d] = T(m(i.y), m(a.y));
179
179
  return {
180
180
  x: s,
181
181
  y: n,
182
182
  width: l - s,
183
183
  height: d - n
184
184
  };
185
- }, T = (t, e) => t <= e ? [t, e] : [e, t], lt = ({ layer: t, coordSystem: e, panelRect: r, styleReaders: i }) => {
186
- const o = v(e), a = x(t.data, o), s = i.part("wick"), l = s === void 0 ? [] : a.map((d) => {
187
- const h = W(d.band, d.low, o, r), g = W(d.band, d.high, o, r), V = s.get("strokeWidth", d.observation) ?? 0;
185
+ }, T = (t, e) => t <= e ? [t, e] : [e, t], lt = ({ layer: t, coordSystem: e, panelRect: r, styleReaders: o }) => {
186
+ const i = g(e), a = x(t.data, i), s = o.part("wick"), l = s === void 0 ? [] : a.map((d) => {
187
+ const h = W(d.band, d.low, i, r), v = W(d.band, d.high, i, r), V = s.get("strokeWidth", d.observation) ?? 0;
188
188
  return {
189
189
  kind: "stroke",
190
- pathData: `M${h.x},${h.y}L${g.x},${g.y}`,
190
+ pathData: `M${h.x},${h.y}L${v.x},${v.y}`,
191
191
  width: V
192
192
  };
193
193
  }), n = a.map((d) => {
194
- const h = H(d, o), g = h.x * r.width;
194
+ const h = H(d, i), v = h.x * r.width;
195
195
  return {
196
196
  kind: "region",
197
- pathData: `M${g},${h.y * r.height}H${(h.x + h.width) * r.width}V${(h.y + h.height) * r.height}H${g}Z`
197
+ pathData: `M${v},${h.y * r.height}H${(h.x + h.width) * r.width}V${(h.y + h.height) * r.height}H${v}Z`
198
198
  };
199
199
  });
200
200
  return [...l, ...n];
201
- }, W = (t, e, r, i) => {
202
- const o = p(r, {
201
+ }, W = (t, e, r, o) => {
202
+ const i = p(r, {
203
203
  main: t,
204
204
  cross: e
205
205
  });
206
- return q(j(o.x, o.y), i);
206
+ return q(j(i.x, i.y), o);
207
207
  }, C = (t) => {
208
208
  const e = G(t.data, t.mapping, t.id);
209
209
  return (r) => e(r.observation);
210
- }, I = ({ candles: t, mainAxis: e, styleReaders: r, getKey: i, isHovered: o = !1, shouldAnimateTransitions: a = !1 }) => {
211
- const s = o ? "hovered" : void 0, l = r.part("wick");
210
+ }, I = ({ candles: t, mainAxis: e, styleReaders: r, getKey: o, isHovered: i = !1, shouldAnimateTransitions: a = !1 }) => {
211
+ const s = i ? "hovered" : void 0, l = r.part("wick");
212
212
  return /* @__PURE__ */ J(z, { children: [l && t.map((n) => /* @__PURE__ */ c(dt, {
213
213
  candle: n,
214
214
  mainAxis: e,
@@ -216,21 +216,21 @@ var w = { direction: "candlestickDirection" }, K = (t, e) => {
216
216
  directionReaders: r.part(n.direction),
217
217
  state: s,
218
218
  shouldAnimateTransitions: a
219
- }, i(n))), t.map((n) => /* @__PURE__ */ c(ct, {
219
+ }, o(n))), t.map((n) => /* @__PURE__ */ c(ct, {
220
220
  candle: n,
221
221
  mainAxis: e,
222
222
  styleReaders: r,
223
223
  state: s,
224
224
  shouldAnimateTransitions: a
225
- }, i(n)))] });
226
- }, dt = ({ candle: t, mainAxis: e, readers: r, directionReaders: i, state: o, shouldAnimateTransitions: a }) => {
225
+ }, o(n)))] });
226
+ }, dt = ({ candle: t, mainAxis: e, readers: r, directionReaders: o, state: i, shouldAnimateTransitions: a }) => {
227
227
  const s = p(e, {
228
228
  main: t.band,
229
229
  cross: t.low
230
230
  }), l = p(e, {
231
231
  main: t.band,
232
232
  cross: t.high
233
- }), n = r.get("strokeWidth", t.observation, o) ?? 0, d = r.get("stroke", t.observation, o) ?? i?.get("stroke", t.observation, o);
233
+ }), n = r.get("strokeWidth", t.observation, i) ?? 0, d = r.get("stroke", t.observation, i) ?? o?.get("stroke", t.observation, i);
234
234
  return /* @__PURE__ */ c(N, {
235
235
  "data-testid": "candlestick-wick",
236
236
  x1: u(y(s.x)),
@@ -238,13 +238,13 @@ var w = { direction: "candlestickDirection" }, K = (t, e) => {
238
238
  x2: u(y(l.x)),
239
239
  y2: u(m(l.y)),
240
240
  stroke: d === void 0 ? void 0 : b(d),
241
- strokeOpacity: r.get("alpha", t.observation, o),
241
+ strokeOpacity: r.get("alpha", t.observation, i),
242
242
  strokeWidth: n,
243
- strokeDasharray: Z(r.get("dashArray", t.observation, o), n),
243
+ strokeDasharray: Z(r.get("dashArray", t.observation, i), n),
244
244
  shouldAnimateTransitions: a
245
245
  });
246
- }, ct = ({ candle: t, mainAxis: e, styleReaders: r, state: i, shouldAnimateTransitions: o }) => {
247
- const a = H(t, e), s = r.part(t.direction), l = s?.get("fill", t.observation, i), n = s?.get("stroke", t.observation, i);
246
+ }, ct = ({ candle: t, mainAxis: e, styleReaders: r, state: o, shouldAnimateTransitions: i }) => {
247
+ const a = H(t, e), s = r.part(t.direction), l = s?.get("fill", t.observation, o), n = s?.get("stroke", t.observation, o);
248
248
  return /* @__PURE__ */ c(Y, {
249
249
  "data-testid": "candlestick-body",
250
250
  x: u(a.x),
@@ -252,60 +252,64 @@ var w = { direction: "candlestickDirection" }, K = (t, e) => {
252
252
  width: u(a.width),
253
253
  height: u(a.height),
254
254
  fill: l === void 0 ? void 0 : b(l),
255
- opacity: r.get("alpha", t.observation, i),
256
- fillOpacity: r.get("fillAlpha", t.observation, i),
255
+ opacity: r.get("alpha", t.observation, o),
256
+ fillOpacity: r.get("fillAlpha", t.observation, o),
257
257
  stroke: n === void 0 ? void 0 : b(n),
258
- strokeWidth: r.get("strokeWidth", t.observation, i),
259
- shouldAnimateTransitions: o
258
+ strokeWidth: r.get("strokeWidth", t.observation, o),
259
+ shouldAnimateTransitions: i
260
260
  });
261
- }, ht = ({ layer: t, sourceLayer: e, mainAxis: r, styleReaders: i }) => /* @__PURE__ */ c(I, {
262
- candles: k(() => x(t.data, r), [t.data, r]),
261
+ }, ht = ({ layer: t, sourceLayer: e, mainAxis: r, styleReaders: o }) => /* @__PURE__ */ c(I, {
262
+ candles: f(() => x(t.data, r), [t.data, r]),
263
263
  mainAxis: r,
264
- styleReaders: i,
265
- getKey: k(() => C(e), [e])
266
- }), ut = ({ layer: t, primary: e, siblings: r, mainAxis: i, styleReaders: o }) => /* @__PURE__ */ c("g", {
264
+ styleReaders: o,
265
+ getKey: f(() => C(e), [e])
266
+ }), ut = ({ layer: t, primary: e, siblings: r, mainAxis: o, styleReaders: i }) => /* @__PURE__ */ c("g", {
267
267
  "data-testid": "hovered-candles",
268
268
  children: /* @__PURE__ */ c(I, {
269
- candles: x([e, ...r].map((a) => a.observation), i),
270
- mainAxis: i,
271
- styleReaders: o,
272
- getKey: k(() => C(t), [t]),
269
+ candles: x([e, ...r].map((a) => a.observation), o),
270
+ mainAxis: o,
271
+ styleReaders: i,
272
+ getKey: f(() => C(t), [t]),
273
273
  isHovered: !0
274
274
  })
275
- }), gt = ({ layer: t, mainAxis: e, styleReaders: r, shouldAnimateTransitions: i, intro: o }) => {
275
+ }), vt = ({ layer: t, mainAxis: e, styleReaders: r, shouldAnimateTransitions: o, intro: i }) => {
276
276
  const a = /* @__PURE__ */ c(I, {
277
- candles: k(() => x(t.data, e), [t.data, e]),
277
+ candles: f(() => x(t.data, e), [t.data, e]),
278
278
  mainAxis: e,
279
279
  styleReaders: r,
280
- getKey: k(() => C(t), [t]),
281
- shouldAnimateTransitions: i
282
- });
283
- return o?.type === "fade" ? /* @__PURE__ */ c(L, {
284
- intro: o,
280
+ getKey: f(() => C(t), [t]),
281
+ shouldAnimateTransitions: o
282
+ }), s = gt(i);
283
+ return s === null ? a : /* @__PURE__ */ c(L, {
284
+ intro: s,
285
285
  children: a
286
- }) : a;
287
- }, ft = X(new at(), {
286
+ });
287
+ }, gt = (t) => t == null ? null : {
288
+ type: "fade",
289
+ layerId: t.layerId,
290
+ durationSeconds: t.durationSeconds
291
+ }, yt = X(new at(), {
288
292
  coord: "cartesian",
289
293
  swatchShape: "square",
290
294
  guideMode: "band",
291
- render: ({ layer: t, coordSystem: e, styleReaders: r, shouldAnimateTransitions: i, intro: o }) => /* @__PURE__ */ c(gt, {
295
+ render: ({ layer: t, coordSystem: e, styleReaders: r, shouldAnimateTransitions: o, intro: i }) => /* @__PURE__ */ c(vt, {
292
296
  layer: t,
293
- mainAxis: v(e),
297
+ mainAxis: g(e),
294
298
  styleReaders: r,
295
- shouldAnimateTransitions: i,
296
- intro: o
299
+ shouldAnimateTransitions: o,
300
+ intro: i
297
301
  }),
298
- renderHighlight: ({ layer: t, sourceLayer: e, coordSystem: r, styleReaders: i }) => /* @__PURE__ */ c(ht, {
302
+ renderHighlight: ({ layer: t, sourceLayer: e, coordSystem: r, styleReaders: o }) => /* @__PURE__ */ c(ht, {
299
303
  layer: t,
300
304
  sourceLayer: e,
301
- mainAxis: v(r),
302
- styleReaders: i
305
+ mainAxis: g(r),
306
+ styleReaders: o
303
307
  }),
304
- renderHover: ({ layer: t, primary: e, group: r, related: i, coordSystem: o, styleReaders: a }) => /* @__PURE__ */ c(ut, {
308
+ renderHover: ({ layer: t, primary: e, group: r, related: o, coordSystem: i, styleReaders: a }) => /* @__PURE__ */ c(ut, {
305
309
  layer: t,
306
310
  primary: e,
307
- siblings: [...r, ...i],
308
- mainAxis: v(o),
311
+ siblings: [...r, ...o],
312
+ mainAxis: g(i),
309
313
  styleReaders: a
310
314
  }),
311
315
  renderHoverCompanions: () => null,
@@ -313,5 +317,5 @@ var w = { direction: "candlestickDirection" }, K = (t, e) => {
313
317
  });
314
318
  export {
315
319
  at as CandlestickGeom,
316
- ft as candlestick
320
+ yt as candlestick
317
321
  };
@@ -7,9 +7,10 @@ interface CandlestickLayerProps {
7
7
  intro: LayerIntroPlan | null | undefined;
8
8
  }
9
9
  /**
10
- * The layer's own paint. The engine plans a plugin geom's entrance as a fade, so the whole layer comes up on
11
- * one clock. The fade is independent of `shouldAnimateTransitions`: it rides the group rather than moving the
12
- * candles, so it plays even when data changes snap.
10
+ * The layer's own paint. The whole layer fades up on one clock, whatever entrance the engine plans: a candle is a
11
+ * rect to the engine, which plans a bar's grow, but a price has no baseline to grow from. The fade is independent
12
+ * of `shouldAnimateTransitions`: it rides the group rather than moving the candles, so it plays even when data
13
+ * changes snap.
13
14
  */
14
15
  export declare const CandlestickLayer: ({ layer, mainAxis, styleReaders, shouldAnimateTransitions, intro, }: CandlestickLayerProps) => import("react/jsx-runtime").JSX.Element;
15
16
  export {};
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "grammar-of-graphics",
13
13
  "candlestick"
14
14
  ],
15
- "version": "0.1.0",
15
+ "version": "0.1.1-beta.1790855561349",
16
16
  "type": "module",
17
17
  "sideEffects": false,
18
18
  "types": "./dist/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "peerDependencies": {
33
33
  "react": "^19.0.0",
34
- "@graphysdk/react": "^1.9.0-beta.1790720825915"
34
+ "@graphysdk/react": "^1.9.0-beta.1790855561349"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@testing-library/react": "^16.3.1",
@@ -43,11 +43,11 @@
43
43
  "vite": "^8.1.5",
44
44
  "vite-plugin-dts": "^4.5.4",
45
45
  "vitest": "^4.1.11",
46
- "@graphysdk/react": "1.9.0-beta.1790720825915",
46
+ "@graphysdk/react": "1.9.0-beta.1790855561349",
47
+ "@graphysdk/viz-engine": "1.9.0-beta.1790855561349",
48
+ "@graphytools/eslint-config": "0.0.1",
47
49
  "@graphytools/typescript-config": "0.0.1",
48
- "@graphysdk/viz-engine": "1.8.0",
49
- "@graphytools/vitest-config": "1.0.0",
50
- "@graphytools/eslint-config": "0.0.1"
50
+ "@graphytools/vitest-config": "1.0.0"
51
51
  },
52
52
  "publishConfig": {
53
53
  "access": "public"