@candleview/core 3.0.3 → 3.0.5
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.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var bt=(M=>(M.Top="Top",M.Bottom="Bottom",M))(bt||{}),Z=(M=>(M.Text="Text",M.Arrow="Arrow",M))(Z||{}),x=(M=>(M.ONE_SECOND="1s",M.FIVE_SECONDS="5s",M.FIFTEEN_SECONDS="15s",M.THIRTY_SECONDS="30s",M.ONE_MINUTE="1m",M.THREE_MINUTES="3m",M.FIVE_MINUTES="5m",M.FIFTEEN_MINUTES="15m",M.THIRTY_MINUTES="30m",M.FORTY_FIVE_MINUTES="45m",M.ONE_HOUR="1H",M.TWO_HOURS="2H",M.THREE_HOURS="3H",M.FOUR_HOURS="4H",M.SIX_HOURS="6H",M.EIGHT_HOURS="8H",M.TWELVE_HOURS="12H",M.ONE_DAY="1D",M.THREE_DAYS="3D",M.ONE_WEEK="1W",M.TWO_WEEKS="2W",M.ONE_MONTH="1M",M.THREE_MONTHS="3M",M.SIX_MONTHS="6M",M))(x||{}),Y=(M=>(M.NEW_YORK="America/New_York",M.CHICAGO="America/Chicago",M.DENVER="America/Denver",M.LOS_ANGELES="America/Los_Angeles",M.TORONTO="America/Toronto",M.LONDON="Europe/London",M.PARIS="Europe/Paris",M.FRANKFURT="Europe/Frankfurt",M.ZURICH="Europe/Zurich",M.MOSCOW="Europe/Moscow",M.DUBAI="Asia/Dubai",M.KARACHI="Asia/Karachi",M.KOLKATA="Asia/Kolkata",M.SHANGHAI="Asia/Shanghai",M.HONG_KONG="Asia/Hong_Kong",M.SINGAPORE="Asia/Singapore",M.TOKYO="Asia/Tokyo",M.SEOUL="Asia/Seoul",M.SYDNEY="Australia/Sydney",M.AUCKLAND="Pacific/Auckland",M.UTC="UTC",M))(Y||{}),j=(M=>(M.Default="default",M.Crosshair="crosshair",M.None="none",M.Circle="circle",M.Dot="dot",M))(j||{}),ms=(M=>(M.MainChart="MainChart",M.SubChart="SubChart",M))(ms||{}),R=(M=>(M.Candle="Candle",M.HollowCandle="HollowCandle",M.Bar="Bar",M.BaseLine="BaseLine",M.Line="Line",M.Area="Area",M.StepLine="StepLine",M.Histogram="Histogram",M.HeikinAshi="HeikinAshi",M.LineBreak="LineBreak",M.Mountain="Mountain",M.BaselineArea="BaselineArea",M.HighLow="HighLow",M.HLCArea="HLCArea",M))(R||{}),w=(M=>(M.MA="MA",M.EMA="EMA",M.BOLLINGER="BOLLINGER",M.ICHIMOKU="ICHIMOKU",M.DONCHIAN="DONCHIAN",M.ENVELOPE="ENVELOPE",M.VWAP="VWAP",M.HEATMAP="HEATMAP",M.MARKETPROFILE="MARKETPROFILE",M))(w||{}),B=(M=>(M.RSI="RSI",M.MACD="MACD",M.VOLUME="VOLUME",M.SAR="SAR",M.KDJ="KDJ",M.ATR="ATR",M.STOCHASTIC="STOCHASTIC",M.CCI="CCI",M.BBWIDTH="BBWIDTH",M.ADX="ADX",M.OBV="OBV",M))(B||{}),C=(M=>(M[M.Text=0]="Text",M[M.Emoji=1]="Emoji",M[M.LineSegment=2]="LineSegment",M[M.ArrowLine=3]="ArrowLine",M[M.ThickArrowLine=4]="ThickArrowLine",M[M.HorizontalLine=5]="HorizontalLine",M[M.VerticalLine=6]="VerticalLine",M[M.ParallelChannel=7]="ParallelChannel",M[M.LinearRegressionChannel=8]="LinearRegressionChannel",M[M.EquidistantChannel=9]="EquidistantChannel",M[M.DisjointChannel=10]="DisjointChannel",M[M.Pitchfork=11]="Pitchfork",M[M.AndrewPitchfork=12]="AndrewPitchfork",M[M.EnhancedAndrewPitchfork=13]="EnhancedAndrewPitchfork",M[M.SchiffPitchfork=14]="SchiffPitchfork",M[M.Rectangle=15]="Rectangle",M[M.Circle=16]="Circle",M[M.Ellipse=17]="Ellipse",M[M.Sector=18]="Sector",M[M.Curve=19]="Curve",M[M.DoubleCurve=20]="DoubleCurve",M[M.Triangle=21]="Triangle",M[M.GannFan=22]="GannFan",M[M.GannBox=23]="GannBox",M[M.GannRectangle=24]="GannRectangle",M[M.FibonacciTimeZoon=25]="FibonacciTimeZoon",M[M.FibonacciRetracement=26]="FibonacciRetracement",M[M.FibonacciArc=27]="FibonacciArc",M[M.FibonacciCircle=28]="FibonacciCircle",M[M.FibonacciSpiral=29]="FibonacciSpiral",M[M.FibonacciWedge=30]="FibonacciWedge",M[M.FibonacciFan=31]="FibonacciFan",M[M.FibonacciChannel=32]="FibonacciChannel",M[M.FibonacciExtensionBasePrice=33]="FibonacciExtensionBasePrice",M[M.FibonacciExtensionBaseTime=34]="FibonacciExtensionBaseTime",M[M.XABCD=35]="XABCD",M[M.HeadAndShoulders=36]="HeadAndShoulders",M[M.ABCD=37]="ABCD",M[M.TriangleABCD=38]="TriangleABCD",M[M.Elliott_Impulse=39]="Elliott_Impulse",M[M.Elliott_Corrective=40]="Elliott_Corrective",M[M.Elliott_Triangle=41]="Elliott_Triangle",M[M.Elliott_Double_Combination=42]="Elliott_Double_Combination",M[M.Elliott_Triple_Combination=43]="Elliott_Triple_Combination",M[M.TimeRange=44]="TimeRange",M[M.PriceRange=45]="PriceRange",M[M.TimePriceRange=46]="TimePriceRange",M[M.Pencil=47]="Pencil",M[M.Pen=48]="Pen",M[M.Brush=49]="Brush",M[M.MarkerPen=50]="MarkerPen",M[M.Eraser=51]="Eraser",M[M.Image=52]="Image",M[M.Table=53]="Table",M[M.LongPosition=54]="LongPosition",M[M.ShortPosition=55]="ShortPosition",M[M.PriceLabel=56]="PriceLabel",M[M.Flag=57]="Flag",M[M.PriceNote=58]="PriceNote",M[M.SignPost=59]="SignPost",M[M.Pin=60]="Pin",M[M.BubbleBox=61]="BubbleBox",M[M.TextEdit=62]="TextEdit",M[M.MockKLine=63]="MockKLine",M[M.HeatMap=64]="HeatMap",M[M.TimeEvent=65]="TimeEvent",M[M.PriceEvent=66]="PriceEvent",M))(C||{});function se(M){switch(M){case 0:return"text";case 0:return"emoji";case 0:return"line-segment";case 0:return"horizontal-line";case 0:return"vertical-line";case 3:return"arrow-line";case 4:return"thick-arrow-line";case 7:return"parallel-channel";case 8:return"linear-regression-channel";case 9:return"equidistant-channel";case 10:return"disjoint-channel";case 11:return"pitch-pitch-fork";case 12:return"andrew-pitch-fork";case 14:return"schiff-pitch-fork";case 13:return"enhanced-andrew-pitch-fork";case 15:return"rectangle";case 16:return"circle";case 17:return"ellipse";case 21:return"triangle";case 22:return"gann-fan";case 23:return"gann-box";case 24:return"gann-rectangle";case 25:return"fibonacci-time-zoon";case 26:return"fibonacci-retracement";case 27:return"fibonacci-fibonacci-arc";case 28:return"fibonacci-circle";case 29:return"fibonacci-spiral";case 30:return"fibonacci-wedge";case 31:return"fibonacci-fan";case 32:return"fibonacci-channel";case 33:return"fibonacci-extension-base-price";case 34:return"fibonacci-extension-base-time";case 18:return"sector";case 19:return"curve";case 20:return"double-curve";case 35:return"xabcd";case 36:return"head-and-shoulders";case 37:return"abcd";case 38:return"triangle-abcd";case 39:return"elliott-impulse";case 40:return"elliott-corrective";case 41:return"elliott-triangle";case 42:return"elliott-double-combination";case 43:return"elliott-triple-combination";case 44:return"time-range";case 45:return"price-range";case 46:return"time-price-range";case 47:return"pencil";case 48:return"pen";case 49:return"brush";case 50:return"marker-pen";case 51:return"eraser";case 52:return"image";case 53:return"table";case 54:return"long-position";case 55:return"short-position";case 56:return"price-label";case 57:return"flag";case 58:return"price-note";case 59:return"signpost";case 60:return"pin";case 61:return"bubble-box";case 62:return"text-edit";case 63:return"mock-line";case 64:return"heat-map";default:return""}}var ks=(M=>(M.Time="time",M.Price="price",M.None="none",M))(ks||{});const Ps={"America/New_York":{name:"America/New_York",offset:"-05:00",displayName:"New York"},"America/Chicago":{name:"America/Chicago",offset:"-06:00",displayName:"Chicago"},"America/Denver":{name:"America/Denver",offset:"-07:00",displayName:"Denver"},"America/Los_Angeles":{name:"America/Los_Angeles",offset:"-08:00",displayName:"Los Angeles"},"America/Toronto":{name:"America/Toronto",offset:"-05:00",displayName:"Toronto"},"Europe/London":{name:"Europe/London",offset:"+00:00",displayName:"London"},"Europe/Paris":{name:"Europe/Paris",offset:"+01:00",displayName:"Paris"},"Europe/Frankfurt":{name:"Europe/Frankfurt",offset:"+01:00",displayName:"Frankfurt"},"Europe/Zurich":{name:"Europe/Zurich",offset:"+01:00",displayName:"Zurich"},"Europe/Moscow":{name:"Europe/Moscow",offset:"+03:00",displayName:"Moscow"},"Asia/Dubai":{name:"Asia/Dubai",offset:"+04:00",displayName:"Dubai"},"Asia/Karachi":{name:"Asia/Karachi",offset:"+05:00",displayName:"Karachi"},"Asia/Kolkata":{name:"Asia/Kolkata",offset:"+05:30",displayName:"Kolkata"},"Asia/Shanghai":{name:"Asia/Shanghai",offset:"+08:00",displayName:"Shanghai"},"Asia/Hong_Kong":{name:"Asia/Hong_Kong",offset:"+08:00",displayName:"Hong Kong"},"Asia/Singapore":{name:"Asia/Singapore",offset:"+08:00",displayName:"Singapore"},"Asia/Tokyo":{name:"Asia/Tokyo",offset:"+09:00",displayName:"Tokyo"},"Asia/Seoul":{name:"Asia/Seoul",offset:"+09:00",displayName:"Seoul"},"Australia/Sydney":{name:"Australia/Sydney",offset:"+10:00",displayName:"Sydney"},"Pacific/Auckland":{name:"Pacific/Auckland",offset:"+12:00",displayName:"Auckland"},UTC:{name:"UTC",offset:"+00:00",displayName:"UTC"}},Ss={"1s":{seconds:1,groupBy:"second"},"5s":{seconds:5,groupBy:"second"},"15s":{seconds:15,groupBy:"second"},"30s":{seconds:30,groupBy:"second"},"1m":{seconds:60,groupBy:"minute"},"3m":{seconds:180,groupBy:"minute"},"5m":{seconds:300,groupBy:"minute"},"15m":{seconds:900,groupBy:"minute"},"30m":{seconds:1800,groupBy:"minute"},"45m":{seconds:2700,groupBy:"minute"},"1H":{seconds:3600,groupBy:"hour"},"2H":{seconds:7200,groupBy:"hour"},"3H":{seconds:10800,groupBy:"hour"},"4H":{seconds:14400,groupBy:"hour"},"6H":{seconds:21600,groupBy:"hour"},"8H":{seconds:28800,groupBy:"hour"},"12H":{seconds:43200,groupBy:"hour"},"1D":{seconds:86400,groupBy:"day"},"3D":{seconds:259200,groupBy:"day"},"1W":{seconds:604800,groupBy:"week"},"2W":{seconds:1209600,groupBy:"week"},"1M":{seconds:2592e3,groupBy:"month"},"3M":{seconds:7776e3,groupBy:"month"},"6M":{seconds:15552e3,groupBy:"month"}};class ca{constructor(t,e=1){this._time=t,this._count=e}attached(t){this._chart=t.chart,this._series=t.series,t.requestUpdate()}updateAllViews(){}paneViews(){return this._renderer||(this._renderer={draw:t=>{const e=t.context??t._context;if(!e||!this._chart||!this._series)return;const i=this._chart.timeScale().timeToCoordinate(this._time);if(i==null)return;const r=this._series.data().find(n=>n.time===this._time);if(!r)return;const s=r.low;let a=this._series.priceToCoordinate(s);if(a!=null){a+=20,e.save();for(let n=0;n<this._count;n++){const o=a+n*25;if(e.beginPath(),e.moveTo(i,o-12),e.lineTo(i-6,o),e.lineTo(i+6,o),e.closePath(),this._count===1)e.fillStyle="green";else if(this._count===2)e.fillStyle=n===0?"green":"lightgreen";else{const h=["green","lightgreen","lime","teal"];e.fillStyle=h[n]||"green"}e.fill(),e.beginPath(),e.moveTo(i,o),e.lineTo(i,o+8),e.strokeStyle=e.fillStyle,e.lineWidth=2,e.stroke(),this._count>=3&&(e.fillStyle="black",e.font="10px Arial",e.textAlign="center",e.textBaseline="middle",e.fillText((n+1).toString(),i,o+20))}e.restore()}}}),[{renderer:()=>this._renderer}]}}class da{constructor(t,e=[]){this._defaultIsCircular=!0,this._defaultFontSize=11,this._defaultPadding=2,this._defaultTextColor="white",this._defaultBackgroundColor="green",this._time=t,this._textItems=e}attached(t){this._chart=t.chart,this._series=t.series,t.requestUpdate()}updateAllViews(){}paneViews(){return this._renderer||(this._renderer={draw:t=>{const e=t.context??t._context;if(!e||!this._chart||!this._series)return;const i=this._chart.timeScale().timeToCoordinate(this._time);if(i==null)return;const r=this._series.data().find(n=>n.time===this._time);if(!r)return;const s=r.low;let a=this._series.priceToCoordinate(s);if(a!=null){a+=20,e.save();for(let n=0;n<this._textItems.length;n++){const o=this._textItems[n],h=a+n*40,l=o.fontSize??this._defaultFontSize,c="Arial";e.font=`${l}px ${c}`;const u=e.measureText(o.text).width,g=l,p=o.padding??this._defaultPadding,f=u+p*2,m=g+p*2,k=i-f/2,P=h-m/2;if(e.fillStyle=o.backgroundColor??this._defaultBackgroundColor,o.isCircular??this._defaultIsCircular){const S=Math.max(f,m)/2;e.beginPath(),e.arc(i,h,S,0,Math.PI*2),e.fill()}else e.fillRect(k,P,f,m);e.fillStyle=o.textColor??this._defaultTextColor,e.textAlign="center",e.textBaseline="middle",e.fillText(o.text,i,h)}e.restore()}}}),[{renderer:()=>this._renderer}]}addTextItem(t,e="white",i="blue",r=!1,s=this._defaultFontSize,a=this._defaultPadding){this._textItems.push({text:t,textColor:e,backgroundColor:i,isCircular:r,fontSize:s,padding:a}),this._chart&&this._chart.requestUpdate()}setTextItems(t){this._textItems=t,this._chart&&this._chart.requestUpdate()}updateText(t,e){this._textItems[t]&&(this._textItems[t].text=e,this._chart&&this._chart.requestUpdate())}updateColors(t,e,i){this._textItems[t]&&(this._textItems[t].textColor=e,this._textItems[t].backgroundColor=i,this._chart&&this._chart.requestUpdate())}updateCircular(t,e){this._textItems[t]&&(this._textItems[t].isCircular=e,this._chart&&this._chart.requestUpdate())}removeTextItem(t){this._textItems[t]&&(this._textItems.splice(t,1),this._chart&&this._chart.requestUpdate())}clearTextItems(){this._textItems=[],this._chart&&this._chart.requestUpdate()}getTextItemCount(){return this._textItems.length}}class ua{constructor(t,e=1){this._time=t,this._count=e}attached(t){this._chart=t.chart,this._series=t.series,t.requestUpdate()}updateAllViews(){}paneViews(){return this._renderer||(this._renderer={draw:t=>{const e=t.context??t._context;if(!e||!this._chart||!this._series)return;const i=this._chart.timeScale().timeToCoordinate(this._time);if(i==null)return;const r=this._series.data().find(n=>n.time===this._time);if(!r)return;const s=r.high;let a=this._series.priceToCoordinate(s);if(a!=null){a-=20,e.save();for(let n=0;n<this._count;n++){const o=a-n*25;if(e.beginPath(),e.moveTo(i,o+12),e.lineTo(i-6,o),e.lineTo(i+6,o),e.closePath(),this._count===1)e.fillStyle="red";else if(this._count===2)e.fillStyle=n===0?"red":"orange";else{const h=["red","orange","#1237dbff","purple"];e.fillStyle=h[n]||"red"}e.fill(),e.beginPath(),e.moveTo(i,o),e.lineTo(i,o-8),e.strokeStyle=e.fillStyle,e.lineWidth=2,e.stroke(),this._count>=3&&(e.fillStyle="black",e.font="10px Arial",e.textAlign="center",e.textBaseline="middle",e.fillText((n+1).toString(),i,o-20))}e.restore()}}}),[{renderer:()=>this._renderer}]}}class ga{constructor(t,e=[]){this._defaultIsCircular=!0,this._defaultFontSize=11,this._defaultPadding=2,this._defaultTextColor="white",this._defaultBackgroundColor="red",this._time=t,this._textItems=e}attached(t){this._chart=t.chart,this._series=t.series,t.requestUpdate()}updateAllViews(){}paneViews(){return this._renderer||(this._renderer={draw:t=>{const e=t.context??t._context;if(!e||!this._chart||!this._series)return;const i=this._chart.timeScale().timeToCoordinate(this._time);if(i==null)return;const r=this._series.data().find(n=>n.time===this._time);if(!r)return;const s=r.high;let a=this._series.priceToCoordinate(s);if(a!=null){a-=20,e.save();for(let n=0;n<this._textItems.length;n++){const o=this._textItems[n],h=a-n*40,l=o.fontSize??this._defaultFontSize,c="Arial";e.font=`${l}px ${c}`;const u=e.measureText(o.text).width,g=l,p=o.padding??this._defaultPadding,f=u+p*2,m=g+p*2,k=i-f/2,P=h-m/2;if(e.fillStyle=o.backgroundColor??this._defaultBackgroundColor,o.isCircular??this._defaultIsCircular){const S=Math.max(f,m)/2;e.beginPath(),e.arc(i,h,S,0,Math.PI*2),e.fill()}else e.fillRect(k,P,f,m);e.fillStyle=o.textColor??this._defaultTextColor,e.textAlign="center",e.textBaseline="middle",e.fillText(o.text,i,h)}e.restore()}}}),[{renderer:()=>this._renderer}]}addTextItem(t,e="white",i="blue",r=!1,s=this._defaultFontSize,a=this._defaultPadding){this._textItems.push({text:t,textColor:e,backgroundColor:i,isCircular:r,fontSize:s,padding:a}),this._chart&&this._chart.requestUpdate()}setTextItems(t){this._textItems=t,this._chart&&this._chart.requestUpdate()}updateText(t,e){this._textItems[t]&&(this._textItems[t].text=e,this._chart&&this._chart.requestUpdate())}updateColors(t,e,i){this._textItems[t]&&(this._textItems[t].textColor=e,this._textItems[t].backgroundColor=i,this._chart&&this._chart.requestUpdate())}updateCircular(t,e){this._textItems[t]&&(this._textItems[t].isCircular=e,this._chart&&this._chart.requestUpdate())}removeTextItem(t){this._textItems[t]&&(this._textItems.splice(t,1),this._chart&&this._chart.requestUpdate())}clearTextItems(){this._textItems=[],this._chart&&this._chart.requestUpdate()}getTextItemCount(){return this._textItems.length}}class pa{constructor(){this._marks=[],this._tolerance=1440*60*1e3,this._timeframe="1d",this._chartSeries=null}autoDetectTimeframe(t){if(!t||t.length<2)return"1d";const e=[];for(let r=1;r<Math.min(t.length,10);r++){const s=t[r].time-t[r-1].time;e.push(s)}const i=this.median(e);return i<=60*1e3?"1m":i<=300*1e3?"5m":i<=900*1e3?"15m":i<=3600*1e3?"1h":i<=14400*1e3?"4h":i<=1440*60*1e3?"1d":i<=10080*60*1e3?"1w":"1M"}median(t){if(t.length===0)return 0;t.sort((i,r)=>i-r);const e=Math.floor(t.length/2);return t.length%2?t[e]:(t[e-1]+t[e])/2}calculateTolerance(t){const e=t.slice(-1).toLowerCase(),i=parseInt(t.slice(0,-1))||1;switch(e){case"m":return Math.max(i*60*1e3,300*1e3);case"h":return i*60*60*1e3;case"d":return i*24*60*60*1e3;case"w":return i*7*24*60*60*1e3;case"M":return i*30*24*60*60*1e3;default:return 1440*60*1e3}}findClosestBarTime(t,e){const i=this.autoDetectTimeframe(t);i!==this._timeframe&&(this._timeframe=i,this._tolerance=this.calculateTolerance(i));let r=null,s=1/0;for(const a of t){const n=Math.abs(a.time-e);n<=this._tolerance&&n<s&&(s=n,r=a.time)}return r}isInSameTimeUnit(t,e,i){const r=new Date(t),s=new Date(e);if(i.endsWith("w")){const a=this.getWeekNumber(r),n=this.getWeekNumber(s);return a.year===n.year&&a.week===n.week}else if(i.endsWith("M"))return r.getFullYear()===s.getFullYear()&&r.getMonth()===s.getMonth();return!1}getWeekNumber(t){const e=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate())),i=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-i);const r=new Date(Date.UTC(e.getUTCFullYear(),0,1));return{year:e.getUTCFullYear(),week:Math.ceil(((e.getTime()-r.getTime())/864e5+1)/7)}}addMark(t,e){if(!e||!e.series)return;this._chartSeries=e;const i=e.series.data();if(!i||i.length===0)return;const r=new Map;t.forEach(a=>{r.has(a.time)||r.set(a.time,[]),r.get(a.time).push(a)});const s=new Map;r.forEach((a,n)=>{const o=this.findClosestBarTime(i,n);o!==null&&(s.has(o)||s.set(o,[]),a.forEach(h=>{s.get(o).push({...h,time:o})}))}),s.forEach((a,n)=>{const o=new Map;a.forEach(h=>{const l=Object.values(Z).find(c=>c===h.type);l&&(o.has(l)||o.set(l,[]),o.get(l).push(h))}),o.forEach((h,l)=>{const c=h.flatMap(g=>g.data),d=c.filter(g=>Object.values(bt).find(p=>p===g.direction)===bt.Top),u=c.filter(g=>Object.values(bt).find(p=>p===g.direction)===bt.Bottom);d.length>0&&this.addTopMark([{time:n,type:l,data:d}],l,e),u.length>0&&this.addBottomMark([{time:n,type:l,data:u}],l,e)})})}recalculateMarks(){this._chartSeries&&([...this._marks],this.clearAllMarks())}refreshTimeframe(){if(!this._chartSeries)return;const t=this._chartSeries.series.data();if(!t||t.length<2)return;const e=this.autoDetectTimeframe(t);e!==this._timeframe&&(this._timeframe=e,this._tolerance=this.calculateTolerance(e),this.recalculateMarks())}addTopMark(t,e,i){switch(e){case Z.Text:t.forEach(r=>{const s=r.data.map(n=>{const o={text:n.text};return n.textColor!==void 0&&(o.textColor=n.textColor),n.backgroundColor!==void 0&&(o.backgroundColor=n.backgroundColor),n.isCircular!==void 0&&(o.isCircular=n.isCircular),n.fontSize!==void 0&&(o.fontSize=n.fontSize),n.padding!==void 0&&(o.padding=n.padding),o}),a=new ga(r.time,s);i.series.attachPrimitive(a),this._marks.push(a)});break;case Z.Arrow:t.forEach(r=>{const s=r.data.length,a=new ua(r.time,s);i.series.attachPrimitive(a),this._marks.push(a)});break;default:return}}addBottomMark(t,e,i){switch(e){case Z.Text:t.forEach(r=>{const s=r.data.map(n=>{const o={text:n.text};return n.textColor!==void 0&&(o.textColor=n.textColor),n.backgroundColor!==void 0&&(o.backgroundColor=n.backgroundColor),n.isCircular!==void 0&&(o.isCircular=n.isCircular),n.fontSize!==void 0&&(o.fontSize=n.fontSize),n.padding!==void 0&&(o.padding=n.padding),o}),a=new da(r.time,s);i.series.attachPrimitive(a),this._marks.push(a)});break;case Z.Arrow:t.forEach(r=>{const s=r.data.length,a=new ca(r.time,s);i.series.attachPrimitive(a),this._marks.push(a)});break;default:return}}removeAllMark(){this._marks=[]}getTolerance(){return this._tolerance}getTimeframe(){return this._timeframe}getMarkCount(){return this._marks.length}clearAllMarks(t){const e=t||this._chartSeries;e&&this._marks.forEach(i=>{e.series.detachPrimitive(i)}),this._marks=[]}destroy(){this.clearAllMarks(),this._chartSeries=null}}class fa{constructor(t){this.staticMarkManager=null,this.storedMarks=[],this.timezone=Y.NEW_YORK,this.chartManager=t}setTimezone(t){this.timezone=t}initStaticMarkManager(){const t=this.chartManager.getChart();if(!t||!t.chartSeries){console.warn("[CandleView] Chart not ready for static marks");return}this.staticMarkManager=new pa}ensureManager(){const t=this.chartManager.getChart();return!t||!t.chartSeries?(console.warn("[CandleView] Chart not ready for static marks"),!1):(this.staticMarkManager||this.initStaticMarkManager(),!!this.staticMarkManager)}reapplyMarks(){this.storedMarks.length!==0&&(this.staticMarkManager&&this.staticMarkManager.clearAllMarks(),this.addStaticMarks(this.storedMarks,!1))}getStoredMarks(){return[...this.storedMarks]}convertToChartTime(t){const i={[Y.NEW_YORK]:-18e3,[Y.CHICAGO]:-21600,[Y.DENVER]:-25200,[Y.LOS_ANGELES]:-28800,[Y.TORONTO]:-18e3,[Y.LONDON]:0,[Y.PARIS]:3600,[Y.FRANKFURT]:3600,[Y.ZURICH]:3600,[Y.MOSCOW]:10800,[Y.DUBAI]:14400,[Y.KARACHI]:18e3,[Y.KOLKATA]:19800,[Y.SHANGHAI]:28800,[Y.HONG_KONG]:28800,[Y.SINGAPORE]:28800,[Y.TOKYO]:32400,[Y.SEOUL]:32400,[Y.SYDNEY]:39600,[Y.AUCKLAND]:43200,[Y.UTC]:0}[this.timezone]||0,r=-new Date().getTimezoneOffset()*60;return t+(i-r)}addStaticMark(t,e,i,r,s){if(!this.ensureManager())return;const a=this.chartManager.getChart();if(!a||!a.chartSeries)return;const n={time:t,text:e,direction:i,type:r,options:s};this.storedMarks.push(n);const o={time:this.convertToChartTime(t),type:r,data:[{direction:i,text:e,textColor:s?.textColor,backgroundColor:s?.backgroundColor,isCircular:s?.isCircular,fontSize:s?.fontSize,padding:s?.padding}]};this.staticMarkManager.addMark([o],a.chartSeries)}addStaticMarks(t,e=!0){if(!this.ensureManager())return;const i=this.chartManager.getChart();if(!i||!i.chartSeries)return;e&&this.storedMarks.push(...t);const r=t.map(s=>({time:this.convertToChartTime(s.time),type:s.type,data:[{direction:s.direction,text:s.text,textColor:s.options?.textColor,backgroundColor:s.options?.backgroundColor,isCircular:s.options?.isCircular,fontSize:s.options?.fontSize,padding:s.options?.padding}]}));this.staticMarkManager.addMark(r,i.chartSeries)}addTextMark(t,e,i,r){this.addStaticMark(t,e,i,Z.Text,r)}addArrowMark(t,e,i){const r=i?.label||"";this.addStaticMark(t,r,e,Z.Arrow,i)}addTextMarks(t){this.addStaticMarks(t.map(e=>({time:e.time,text:e.text,direction:e.direction,type:Z.Text,options:e.options})))}addArrowMarks(t){this.addStaticMarks(t.map(e=>({time:e.time,text:e.options?.label||"",direction:e.direction,type:Z.Arrow,options:e.options})))}clearAllStaticMarks(){this.staticMarkManager&&this.staticMarkManager.clearAllMarks(),this.storedMarks=[]}getStaticMarkCount(){return this.staticMarkManager?.getMarkCount()||0}refreshMarks(){this.staticMarkManager?.recalculateMarks()}destroy(){this.staticMarkManager&&(this.staticMarkManager.destroy(),this.staticMarkManager=null),this.storedMarks=[]}}class Ma{constructor(){this.rootEl=null,this.chartContainerEl=null,this.technologyPanelContainer=null,this.drawingPanelContainer=null}create(t,e){t.innerHTML="",t.style.cssText="position:relative;width:100%;height:100%;overflow:hidden;";const i=document.createElement("style");i.id="candleview-no-select",i.textContent=`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var bt=(M=>(M.Top="Top",M.Bottom="Bottom",M))(bt||{}),Z=(M=>(M.Text="Text",M.Arrow="Arrow",M))(Z||{}),x=(M=>(M.ONE_SECOND="1s",M.FIVE_SECONDS="5s",M.FIFTEEN_SECONDS="15s",M.THIRTY_SECONDS="30s",M.ONE_MINUTE="1m",M.THREE_MINUTES="3m",M.FIVE_MINUTES="5m",M.FIFTEEN_MINUTES="15m",M.THIRTY_MINUTES="30m",M.FORTY_FIVE_MINUTES="45m",M.ONE_HOUR="1H",M.TWO_HOURS="2H",M.THREE_HOURS="3H",M.FOUR_HOURS="4H",M.SIX_HOURS="6H",M.EIGHT_HOURS="8H",M.TWELVE_HOURS="12H",M.ONE_DAY="1D",M.THREE_DAYS="3D",M.ONE_WEEK="1W",M.TWO_WEEKS="2W",M.ONE_MONTH="1M",M.THREE_MONTHS="3M",M.SIX_MONTHS="6M",M))(x||{}),Y=(M=>(M.NEW_YORK="America/New_York",M.CHICAGO="America/Chicago",M.DENVER="America/Denver",M.LOS_ANGELES="America/Los_Angeles",M.TORONTO="America/Toronto",M.LONDON="Europe/London",M.PARIS="Europe/Paris",M.FRANKFURT="Europe/Frankfurt",M.ZURICH="Europe/Zurich",M.MOSCOW="Europe/Moscow",M.DUBAI="Asia/Dubai",M.KARACHI="Asia/Karachi",M.KOLKATA="Asia/Kolkata",M.SHANGHAI="Asia/Shanghai",M.HONG_KONG="Asia/Hong_Kong",M.SINGAPORE="Asia/Singapore",M.TOKYO="Asia/Tokyo",M.SEOUL="Asia/Seoul",M.SYDNEY="Australia/Sydney",M.AUCKLAND="Pacific/Auckland",M.UTC="UTC",M))(Y||{}),j=(M=>(M.Default="default",M.Crosshair="crosshair",M.None="none",M.Circle="circle",M.Dot="dot",M))(j||{}),ms=(M=>(M.MainChart="MainChart",M.SubChart="SubChart",M))(ms||{}),R=(M=>(M.Candle="Candle",M.HollowCandle="HollowCandle",M.Bar="Bar",M.BaseLine="BaseLine",M.Line="Line",M.Area="Area",M.StepLine="StepLine",M.Histogram="Histogram",M.HeikinAshi="HeikinAshi",M.LineBreak="LineBreak",M.Mountain="Mountain",M.BaselineArea="BaselineArea",M.HighLow="HighLow",M.HLCArea="HLCArea",M))(R||{}),w=(M=>(M.MA="MA",M.EMA="EMA",M.BOLLINGER="BOLLINGER",M.ICHIMOKU="ICHIMOKU",M.DONCHIAN="DONCHIAN",M.ENVELOPE="ENVELOPE",M.VWAP="VWAP",M.HEATMAP="HEATMAP",M.MARKETPROFILE="MARKETPROFILE",M))(w||{}),B=(M=>(M.RSI="RSI",M.MACD="MACD",M.VOLUME="VOLUME",M.SAR="SAR",M.KDJ="KDJ",M.ATR="ATR",M.STOCHASTIC="STOCHASTIC",M.CCI="CCI",M.BBWIDTH="BBWIDTH",M.ADX="ADX",M.OBV="OBV",M))(B||{}),C=(M=>(M[M.Text=0]="Text",M[M.Emoji=1]="Emoji",M[M.LineSegment=2]="LineSegment",M[M.ArrowLine=3]="ArrowLine",M[M.ThickArrowLine=4]="ThickArrowLine",M[M.HorizontalLine=5]="HorizontalLine",M[M.VerticalLine=6]="VerticalLine",M[M.ParallelChannel=7]="ParallelChannel",M[M.LinearRegressionChannel=8]="LinearRegressionChannel",M[M.EquidistantChannel=9]="EquidistantChannel",M[M.DisjointChannel=10]="DisjointChannel",M[M.Pitchfork=11]="Pitchfork",M[M.AndrewPitchfork=12]="AndrewPitchfork",M[M.EnhancedAndrewPitchfork=13]="EnhancedAndrewPitchfork",M[M.SchiffPitchfork=14]="SchiffPitchfork",M[M.Rectangle=15]="Rectangle",M[M.Circle=16]="Circle",M[M.Ellipse=17]="Ellipse",M[M.Sector=18]="Sector",M[M.Curve=19]="Curve",M[M.DoubleCurve=20]="DoubleCurve",M[M.Triangle=21]="Triangle",M[M.GannFan=22]="GannFan",M[M.GannBox=23]="GannBox",M[M.GannRectangle=24]="GannRectangle",M[M.FibonacciTimeZoon=25]="FibonacciTimeZoon",M[M.FibonacciRetracement=26]="FibonacciRetracement",M[M.FibonacciArc=27]="FibonacciArc",M[M.FibonacciCircle=28]="FibonacciCircle",M[M.FibonacciSpiral=29]="FibonacciSpiral",M[M.FibonacciWedge=30]="FibonacciWedge",M[M.FibonacciFan=31]="FibonacciFan",M[M.FibonacciChannel=32]="FibonacciChannel",M[M.FibonacciExtensionBasePrice=33]="FibonacciExtensionBasePrice",M[M.FibonacciExtensionBaseTime=34]="FibonacciExtensionBaseTime",M[M.XABCD=35]="XABCD",M[M.HeadAndShoulders=36]="HeadAndShoulders",M[M.ABCD=37]="ABCD",M[M.TriangleABCD=38]="TriangleABCD",M[M.Elliott_Impulse=39]="Elliott_Impulse",M[M.Elliott_Corrective=40]="Elliott_Corrective",M[M.Elliott_Triangle=41]="Elliott_Triangle",M[M.Elliott_Double_Combination=42]="Elliott_Double_Combination",M[M.Elliott_Triple_Combination=43]="Elliott_Triple_Combination",M[M.TimeRange=44]="TimeRange",M[M.PriceRange=45]="PriceRange",M[M.TimePriceRange=46]="TimePriceRange",M[M.Pencil=47]="Pencil",M[M.Pen=48]="Pen",M[M.Brush=49]="Brush",M[M.MarkerPen=50]="MarkerPen",M[M.Eraser=51]="Eraser",M[M.Image=52]="Image",M[M.Table=53]="Table",M[M.LongPosition=54]="LongPosition",M[M.ShortPosition=55]="ShortPosition",M[M.PriceLabel=56]="PriceLabel",M[M.Flag=57]="Flag",M[M.PriceNote=58]="PriceNote",M[M.SignPost=59]="SignPost",M[M.Pin=60]="Pin",M[M.BubbleBox=61]="BubbleBox",M[M.TextEdit=62]="TextEdit",M[M.MockKLine=63]="MockKLine",M[M.HeatMap=64]="HeatMap",M[M.TimeEvent=65]="TimeEvent",M[M.PriceEvent=66]="PriceEvent",M))(C||{});function se(M){switch(M){case 0:return"text";case 0:return"emoji";case 0:return"line-segment";case 0:return"horizontal-line";case 0:return"vertical-line";case 3:return"arrow-line";case 4:return"thick-arrow-line";case 7:return"parallel-channel";case 8:return"linear-regression-channel";case 9:return"equidistant-channel";case 10:return"disjoint-channel";case 11:return"pitch-pitch-fork";case 12:return"andrew-pitch-fork";case 14:return"schiff-pitch-fork";case 13:return"enhanced-andrew-pitch-fork";case 15:return"rectangle";case 16:return"circle";case 17:return"ellipse";case 21:return"triangle";case 22:return"gann-fan";case 23:return"gann-box";case 24:return"gann-rectangle";case 25:return"fibonacci-time-zoon";case 26:return"fibonacci-retracement";case 27:return"fibonacci-fibonacci-arc";case 28:return"fibonacci-circle";case 29:return"fibonacci-spiral";case 30:return"fibonacci-wedge";case 31:return"fibonacci-fan";case 32:return"fibonacci-channel";case 33:return"fibonacci-extension-base-price";case 34:return"fibonacci-extension-base-time";case 18:return"sector";case 19:return"curve";case 20:return"double-curve";case 35:return"xabcd";case 36:return"head-and-shoulders";case 37:return"abcd";case 38:return"triangle-abcd";case 39:return"elliott-impulse";case 40:return"elliott-corrective";case 41:return"elliott-triangle";case 42:return"elliott-double-combination";case 43:return"elliott-triple-combination";case 44:return"time-range";case 45:return"price-range";case 46:return"time-price-range";case 47:return"pencil";case 48:return"pen";case 49:return"brush";case 50:return"marker-pen";case 51:return"eraser";case 52:return"image";case 53:return"table";case 54:return"long-position";case 55:return"short-position";case 56:return"price-label";case 57:return"flag";case 58:return"price-note";case 59:return"signpost";case 60:return"pin";case 61:return"bubble-box";case 62:return"text-edit";case 63:return"mock-line";case 64:return"heat-map";default:return""}}var ks=(M=>(M.Time="time",M.Price="price",M.None="none",M))(ks||{});const Ps={"America/New_York":{name:"America/New_York",offset:"-05:00",displayName:"New York"},"America/Chicago":{name:"America/Chicago",offset:"-06:00",displayName:"Chicago"},"America/Denver":{name:"America/Denver",offset:"-07:00",displayName:"Denver"},"America/Los_Angeles":{name:"America/Los_Angeles",offset:"-08:00",displayName:"Los Angeles"},"America/Toronto":{name:"America/Toronto",offset:"-05:00",displayName:"Toronto"},"Europe/London":{name:"Europe/London",offset:"+00:00",displayName:"London"},"Europe/Paris":{name:"Europe/Paris",offset:"+01:00",displayName:"Paris"},"Europe/Frankfurt":{name:"Europe/Frankfurt",offset:"+01:00",displayName:"Frankfurt"},"Europe/Zurich":{name:"Europe/Zurich",offset:"+01:00",displayName:"Zurich"},"Europe/Moscow":{name:"Europe/Moscow",offset:"+03:00",displayName:"Moscow"},"Asia/Dubai":{name:"Asia/Dubai",offset:"+04:00",displayName:"Dubai"},"Asia/Karachi":{name:"Asia/Karachi",offset:"+05:00",displayName:"Karachi"},"Asia/Kolkata":{name:"Asia/Kolkata",offset:"+05:30",displayName:"Kolkata"},"Asia/Shanghai":{name:"Asia/Shanghai",offset:"+08:00",displayName:"Shanghai"},"Asia/Hong_Kong":{name:"Asia/Hong_Kong",offset:"+08:00",displayName:"Hong Kong"},"Asia/Singapore":{name:"Asia/Singapore",offset:"+08:00",displayName:"Singapore"},"Asia/Tokyo":{name:"Asia/Tokyo",offset:"+09:00",displayName:"Tokyo"},"Asia/Seoul":{name:"Asia/Seoul",offset:"+09:00",displayName:"Seoul"},"Australia/Sydney":{name:"Australia/Sydney",offset:"+10:00",displayName:"Sydney"},"Pacific/Auckland":{name:"Pacific/Auckland",offset:"+12:00",displayName:"Auckland"},UTC:{name:"UTC",offset:"+00:00",displayName:"UTC"}},Ss={"1s":{seconds:1,groupBy:"second"},"5s":{seconds:5,groupBy:"second"},"15s":{seconds:15,groupBy:"second"},"30s":{seconds:30,groupBy:"second"},"1m":{seconds:60,groupBy:"minute"},"3m":{seconds:180,groupBy:"minute"},"5m":{seconds:300,groupBy:"minute"},"15m":{seconds:900,groupBy:"minute"},"30m":{seconds:1800,groupBy:"minute"},"45m":{seconds:2700,groupBy:"minute"},"1H":{seconds:3600,groupBy:"hour"},"2H":{seconds:7200,groupBy:"hour"},"3H":{seconds:10800,groupBy:"hour"},"4H":{seconds:14400,groupBy:"hour"},"6H":{seconds:21600,groupBy:"hour"},"8H":{seconds:28800,groupBy:"hour"},"12H":{seconds:43200,groupBy:"hour"},"1D":{seconds:86400,groupBy:"day"},"3D":{seconds:259200,groupBy:"day"},"1W":{seconds:604800,groupBy:"week"},"2W":{seconds:1209600,groupBy:"week"},"1M":{seconds:2592e3,groupBy:"month"},"3M":{seconds:7776e3,groupBy:"month"},"6M":{seconds:15552e3,groupBy:"month"}};class ca{constructor(t,e=1){this._time=t,this._count=e}attached(t){this._chart=t.chart,this._series=t.series,t.requestUpdate()}updateAllViews(){}paneViews(){return this._renderer||(this._renderer={draw:t=>{const e=t.context??t._context;if(!e||!this._chart||!this._series)return;const i=this._chart.timeScale().timeToCoordinate(this._time);if(i==null)return;const r=this._series.data().find(n=>n.time===this._time);if(!r)return;const s=r.low;let a=this._series.priceToCoordinate(s);if(a!=null){a+=20,e.save();for(let n=0;n<this._count;n++){const o=a+n*25;if(e.beginPath(),e.moveTo(i,o-12),e.lineTo(i-6,o),e.lineTo(i+6,o),e.closePath(),this._count===1)e.fillStyle="green";else if(this._count===2)e.fillStyle=n===0?"green":"lightgreen";else{const h=["green","lightgreen","lime","teal"];e.fillStyle=h[n]||"green"}e.fill(),e.beginPath(),e.moveTo(i,o),e.lineTo(i,o+8),e.strokeStyle=e.fillStyle,e.lineWidth=2,e.stroke(),this._count>=3&&(e.fillStyle="black",e.font="10px Arial",e.textAlign="center",e.textBaseline="middle",e.fillText((n+1).toString(),i,o+20))}e.restore()}}}),[{renderer:()=>this._renderer}]}}class da{constructor(t,e=[]){this._defaultIsCircular=!0,this._defaultFontSize=11,this._defaultPadding=2,this._defaultTextColor="white",this._defaultBackgroundColor="green",this._time=t,this._textItems=e}attached(t){this._chart=t.chart,this._series=t.series,t.requestUpdate()}updateAllViews(){}paneViews(){return this._renderer||(this._renderer={draw:t=>{const e=t.context??t._context;if(!e||!this._chart||!this._series)return;const i=this._chart.timeScale().timeToCoordinate(this._time);if(i==null)return;const r=this._series.data().find(n=>n.time===this._time);if(!r)return;const s=r.low;let a=this._series.priceToCoordinate(s);if(a!=null){a+=20,e.save();for(let n=0;n<this._textItems.length;n++){const o=this._textItems[n],h=a+n*40,l=o.fontSize??this._defaultFontSize,c="Arial";e.font=`${l}px ${c}`;const u=e.measureText(o.text).width,g=l,p=o.padding??this._defaultPadding,f=u+p*2,m=g+p*2,k=i-f/2,P=h-m/2;if(e.fillStyle=o.backgroundColor??this._defaultBackgroundColor,o.isCircular??this._defaultIsCircular){const S=Math.max(f,m)/2;e.beginPath(),e.arc(i,h,S,0,Math.PI*2),e.fill()}else e.fillRect(k,P,f,m);e.fillStyle=o.textColor??this._defaultTextColor,e.textAlign="center",e.textBaseline="middle",e.fillText(o.text,i,h)}e.restore()}}}),[{renderer:()=>this._renderer}]}addTextItem(t,e="white",i="blue",r=!1,s=this._defaultFontSize,a=this._defaultPadding){this._textItems.push({text:t,textColor:e,backgroundColor:i,isCircular:r,fontSize:s,padding:a}),this._chart&&this._chart.requestUpdate()}setTextItems(t){this._textItems=t,this._chart&&this._chart.requestUpdate()}updateText(t,e){this._textItems[t]&&(this._textItems[t].text=e,this._chart&&this._chart.requestUpdate())}updateColors(t,e,i){this._textItems[t]&&(this._textItems[t].textColor=e,this._textItems[t].backgroundColor=i,this._chart&&this._chart.requestUpdate())}updateCircular(t,e){this._textItems[t]&&(this._textItems[t].isCircular=e,this._chart&&this._chart.requestUpdate())}removeTextItem(t){this._textItems[t]&&(this._textItems.splice(t,1),this._chart&&this._chart.requestUpdate())}clearTextItems(){this._textItems=[],this._chart&&this._chart.requestUpdate()}getTextItemCount(){return this._textItems.length}}class ua{constructor(t,e=1){this._time=t,this._count=e}attached(t){this._chart=t.chart,this._series=t.series,t.requestUpdate()}updateAllViews(){}paneViews(){return this._renderer||(this._renderer={draw:t=>{const e=t.context??t._context;if(!e||!this._chart||!this._series)return;const i=this._chart.timeScale().timeToCoordinate(this._time);if(i==null)return;const r=this._series.data().find(n=>n.time===this._time);if(!r)return;const s=r.high;let a=this._series.priceToCoordinate(s);if(a!=null){a-=20,e.save();for(let n=0;n<this._count;n++){const o=a-n*25;if(e.beginPath(),e.moveTo(i,o+12),e.lineTo(i-6,o),e.lineTo(i+6,o),e.closePath(),this._count===1)e.fillStyle="red";else if(this._count===2)e.fillStyle=n===0?"red":"orange";else{const h=["red","orange","#1237dbff","purple"];e.fillStyle=h[n]||"red"}e.fill(),e.beginPath(),e.moveTo(i,o),e.lineTo(i,o-8),e.strokeStyle=e.fillStyle,e.lineWidth=2,e.stroke(),this._count>=3&&(e.fillStyle="black",e.font="10px Arial",e.textAlign="center",e.textBaseline="middle",e.fillText((n+1).toString(),i,o-20))}e.restore()}}}),[{renderer:()=>this._renderer}]}}class ga{constructor(t,e=[]){this._defaultIsCircular=!0,this._defaultFontSize=11,this._defaultPadding=2,this._defaultTextColor="white",this._defaultBackgroundColor="red",this._time=t,this._textItems=e}attached(t){this._chart=t.chart,this._series=t.series,t.requestUpdate()}updateAllViews(){}paneViews(){return this._renderer||(this._renderer={draw:t=>{const e=t.context??t._context;if(!e||!this._chart||!this._series)return;const i=this._chart.timeScale().timeToCoordinate(this._time);if(i==null)return;const r=this._series.data().find(n=>n.time===this._time);if(!r)return;const s=r.high;let a=this._series.priceToCoordinate(s);if(a!=null){a-=20,e.save();for(let n=0;n<this._textItems.length;n++){const o=this._textItems[n],h=a-n*40,l=o.fontSize??this._defaultFontSize,c="Arial";e.font=`${l}px ${c}`;const u=e.measureText(o.text).width,g=l,p=o.padding??this._defaultPadding,f=u+p*2,m=g+p*2,k=i-f/2,P=h-m/2;if(e.fillStyle=o.backgroundColor??this._defaultBackgroundColor,o.isCircular??this._defaultIsCircular){const S=Math.max(f,m)/2;e.beginPath(),e.arc(i,h,S,0,Math.PI*2),e.fill()}else e.fillRect(k,P,f,m);e.fillStyle=o.textColor??this._defaultTextColor,e.textAlign="center",e.textBaseline="middle",e.fillText(o.text,i,h)}e.restore()}}}),[{renderer:()=>this._renderer}]}addTextItem(t,e="white",i="blue",r=!1,s=this._defaultFontSize,a=this._defaultPadding){this._textItems.push({text:t,textColor:e,backgroundColor:i,isCircular:r,fontSize:s,padding:a}),this._chart&&this._chart.requestUpdate()}setTextItems(t){this._textItems=t,this._chart&&this._chart.requestUpdate()}updateText(t,e){this._textItems[t]&&(this._textItems[t].text=e,this._chart&&this._chart.requestUpdate())}updateColors(t,e,i){this._textItems[t]&&(this._textItems[t].textColor=e,this._textItems[t].backgroundColor=i,this._chart&&this._chart.requestUpdate())}updateCircular(t,e){this._textItems[t]&&(this._textItems[t].isCircular=e,this._chart&&this._chart.requestUpdate())}removeTextItem(t){this._textItems[t]&&(this._textItems.splice(t,1),this._chart&&this._chart.requestUpdate())}clearTextItems(){this._textItems=[],this._chart&&this._chart.requestUpdate()}getTextItemCount(){return this._textItems.length}}class pa{constructor(){this._marks=[],this._tolerance=1440*60*1e3,this._timeframe="1d",this._chartSeries=null}autoDetectTimeframe(t){if(!t||t.length<2)return"1d";const e=[];for(let r=1;r<Math.min(t.length,10);r++){const s=t[r].time-t[r-1].time;e.push(s)}const i=this.median(e);return i<=60*1e3?"1m":i<=300*1e3?"5m":i<=900*1e3?"15m":i<=3600*1e3?"1h":i<=14400*1e3?"4h":i<=1440*60*1e3?"1d":i<=10080*60*1e3?"1w":"1M"}median(t){if(t.length===0)return 0;t.sort((i,r)=>i-r);const e=Math.floor(t.length/2);return t.length%2?t[e]:(t[e-1]+t[e])/2}calculateTolerance(t){const e=t.slice(-1).toLowerCase(),i=parseInt(t.slice(0,-1))||1;switch(e){case"m":return Math.max(i*60*1e3,300*1e3);case"h":return i*60*60*1e3;case"d":return i*24*60*60*1e3;case"w":return i*7*24*60*60*1e3;case"M":return i*30*24*60*60*1e3;default:return 1440*60*1e3}}findClosestBarTime(t,e){const i=this.autoDetectTimeframe(t);i!==this._timeframe&&(this._timeframe=i,this._tolerance=this.calculateTolerance(i));let r=null,s=1/0;for(const a of t){const n=Math.abs(a.time-e);n<=this._tolerance&&n<s&&(s=n,r=a.time)}return r}isInSameTimeUnit(t,e,i){const r=new Date(t),s=new Date(e);if(i.endsWith("w")){const a=this.getWeekNumber(r),n=this.getWeekNumber(s);return a.year===n.year&&a.week===n.week}else if(i.endsWith("M"))return r.getFullYear()===s.getFullYear()&&r.getMonth()===s.getMonth();return!1}getWeekNumber(t){const e=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate())),i=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-i);const r=new Date(Date.UTC(e.getUTCFullYear(),0,1));return{year:e.getUTCFullYear(),week:Math.ceil(((e.getTime()-r.getTime())/864e5+1)/7)}}addMark(t,e){if(!e||!e.series)return;this._chartSeries=e;const i=e.series.data();if(!i||i.length===0)return;const r=new Map;t.forEach(a=>{r.has(a.time)||r.set(a.time,[]),r.get(a.time).push(a)});const s=new Map;r.forEach((a,n)=>{const o=this.findClosestBarTime(i,n);o!==null&&(s.has(o)||s.set(o,[]),a.forEach(h=>{s.get(o).push({...h,time:o})}))}),s.forEach((a,n)=>{const o=new Map;a.forEach(h=>{const l=Object.values(Z).find(c=>c===h.type);l&&(o.has(l)||o.set(l,[]),o.get(l).push(h))}),o.forEach((h,l)=>{const c=h.flatMap(g=>g.data),d=c.filter(g=>Object.values(bt).find(p=>p===g.direction)===bt.Top),u=c.filter(g=>Object.values(bt).find(p=>p===g.direction)===bt.Bottom);d.length>0&&this.addTopMark([{time:n,type:l,data:d}],l,e),u.length>0&&this.addBottomMark([{time:n,type:l,data:u}],l,e)})})}recalculateMarks(){this._chartSeries&&([...this._marks],this.clearAllMarks())}refreshTimeframe(){if(!this._chartSeries)return;const t=this._chartSeries.series.data();if(!t||t.length<2)return;const e=this.autoDetectTimeframe(t);e!==this._timeframe&&(this._timeframe=e,this._tolerance=this.calculateTolerance(e),this.recalculateMarks())}addTopMark(t,e,i){switch(e){case Z.Text:t.forEach(r=>{const s=r.data.map(n=>{const o={text:n.text};return n.textColor!==void 0&&(o.textColor=n.textColor),n.backgroundColor!==void 0&&(o.backgroundColor=n.backgroundColor),n.isCircular!==void 0&&(o.isCircular=n.isCircular),n.fontSize!==void 0&&(o.fontSize=n.fontSize),n.padding!==void 0&&(o.padding=n.padding),o}),a=new ga(r.time,s);i.series.attachPrimitive(a),this._marks.push(a)});break;case Z.Arrow:t.forEach(r=>{const s=r.data.length,a=new ua(r.time,s);i.series.attachPrimitive(a),this._marks.push(a)});break;default:return}}addBottomMark(t,e,i){switch(e){case Z.Text:t.forEach(r=>{const s=r.data.map(n=>{const o={text:n.text};return n.textColor!==void 0&&(o.textColor=n.textColor),n.backgroundColor!==void 0&&(o.backgroundColor=n.backgroundColor),n.isCircular!==void 0&&(o.isCircular=n.isCircular),n.fontSize!==void 0&&(o.fontSize=n.fontSize),n.padding!==void 0&&(o.padding=n.padding),o}),a=new da(r.time,s);i.series.attachPrimitive(a),this._marks.push(a)});break;case Z.Arrow:t.forEach(r=>{const s=r.data.length,a=new ca(r.time,s);i.series.attachPrimitive(a),this._marks.push(a)});break;default:return}}removeAllMark(){this._marks=[]}getTolerance(){return this._tolerance}getTimeframe(){return this._timeframe}getMarkCount(){return this._marks.length}clearAllMarks(t){const e=t||this._chartSeries;e&&this._marks.forEach(i=>{e.series.detachPrimitive(i)}),this._marks=[]}destroy(){this.clearAllMarks(),this._chartSeries=null}}class fa{constructor(t){this.staticMarkManager=null,this.storedMarks=[],this.timezone=Y.NEW_YORK,this.chartManager=t}setTimezone(t){this.timezone=t}initStaticMarkManager(){const t=this.chartManager.getChart();if(!t||!t.chartSeries){console.warn("[CandleView] Chart not ready for static marks");return}this.staticMarkManager=new pa}ensureManager(){const t=this.chartManager.getChart();return!t||!t.chartSeries?(console.warn("[CandleView] Chart not ready for static marks"),!1):(this.staticMarkManager||this.initStaticMarkManager(),!!this.staticMarkManager)}reapplyMarks(){this.storedMarks.length!==0&&(this.staticMarkManager&&this.staticMarkManager.clearAllMarks(),this.addStaticMarks(this.storedMarks,!1))}getStoredMarks(){return[...this.storedMarks]}convertToChartTime(t){const i={[Y.NEW_YORK]:-18e3,[Y.CHICAGO]:-21600,[Y.DENVER]:-25200,[Y.LOS_ANGELES]:-28800,[Y.TORONTO]:-18e3,[Y.LONDON]:0,[Y.PARIS]:3600,[Y.FRANKFURT]:3600,[Y.ZURICH]:3600,[Y.MOSCOW]:10800,[Y.DUBAI]:14400,[Y.KARACHI]:18e3,[Y.KOLKATA]:19800,[Y.SHANGHAI]:28800,[Y.HONG_KONG]:28800,[Y.SINGAPORE]:28800,[Y.TOKYO]:32400,[Y.SEOUL]:32400,[Y.SYDNEY]:39600,[Y.AUCKLAND]:43200,[Y.UTC]:0}[this.timezone]||0,r=-new Date().getTimezoneOffset()*60;return t+(i-r)}addStaticMark(t,e,i,r,s){if(!this.ensureManager())return;const a=this.chartManager.getChart();if(!a||!a.chartSeries)return;const n={time:t,text:e,direction:i,type:r,options:s};this.storedMarks.push(n);const o={time:this.convertToChartTime(t),type:r,data:[{direction:i,text:e,textColor:s?.textColor,backgroundColor:s?.backgroundColor,isCircular:s?.isCircular,fontSize:s?.fontSize,padding:s?.padding}]};this.staticMarkManager.addMark([o],a.chartSeries)}addStaticMarks(t,e=!0){if(!this.ensureManager())return;const i=this.chartManager.getChart();if(!i||!i.chartSeries)return;e&&this.storedMarks.push(...t);const r=t.map(s=>({time:this.convertToChartTime(s.time),type:s.type,data:[{direction:s.direction,text:s.text,textColor:s.options?.textColor,backgroundColor:s.options?.backgroundColor,isCircular:s.options?.isCircular,fontSize:s.options?.fontSize,padding:s.options?.padding}]}));this.staticMarkManager.addMark(r,i.chartSeries)}addTextMark(t,e,i,r){this.addStaticMark(t,e,i,Z.Text,r)}addArrowMark(t,e,i){const r=i?.label||"";this.addStaticMark(t,r,e,Z.Arrow,i)}addTextMarks(t){this.addStaticMarks(t.map(e=>({time:e.time,text:e.text,direction:e.direction,type:Z.Text,options:e.options})))}addArrowMarks(t){this.addStaticMarks(t.map(e=>({time:e.time,text:e.options?.label||"",direction:e.direction,type:Z.Arrow,options:e.options})))}clearAllStaticMarks(){this.staticMarkManager&&this.staticMarkManager.clearAllMarks(),this.storedMarks=[]}getStaticMarkCount(){return this.staticMarkManager?.getMarkCount()||0}refreshMarks(){this.staticMarkManager?.recalculateMarks()}destroy(){this.staticMarkManager&&(this.staticMarkManager.destroy(),this.staticMarkManager=null),this.storedMarks=[]}}class Ma{constructor(){this.rootEl=null,this.chartContainerEl=null,this.technologyPanelContainer=null,this.drawingPanelContainer=null}create(t,e){t.innerHTML="";const i=document.createElement("style");i.id="candleview-no-select",i.textContent=`
|
|
2
2
|
.candleview-root,
|
|
3
3
|
.candleview-root * {
|
|
4
4
|
user-select: none !important;
|
|
@@ -1781,4 +1781,4 @@
|
|
|
1781
1781
|
<span class="brush-pulse" style="display:inline-block;width:8px;height:8px;border-radius:50%;animation:brush-pulse 1.5s infinite;"></span>
|
|
1782
1782
|
<span class="brush-text">${this.i18n.t("brushActive")||"Brush Mode"}</span>
|
|
1783
1783
|
<span class="brush-hint" style="margin-left:4px;font-size:10px;opacity:0.7;">ESC</span>
|
|
1784
|
-
`,this.updateTheme(),t.style.position="relative",t.appendChild(this.indicator)}hide(){this.indicator&&(this.indicator.style.display="none")}updateTheme(){if(!this.indicator)return;const t=this.theme.getColors();Object.assign(this.indicator.style,{background:t.panelBg,border:`1px solid ${t.panelBorder}`,color:t.textColor});const e=this.indicator.querySelector(".brush-pulse");e&&(e.style.background=this.theme.isDark()?"#FF6B35":"#E64A19")}updateI18n(t){this.i18n=t;const e=this.indicator?.querySelector(".brush-text");e&&(e.textContent=this.i18n.t("brushActive")||"Brush Mode")}}class Jc{constructor(t){this.panels=null,this.priceEvents=null,this.marks=null,this.brushHint=null,this.topPanelState={...la},this.leftPanelState={...ha},this.onTimeframeChangeCallback=null,this.isDataLoaded=!1,this.pendingData=null,this.config=t;const{container:e,isOwn:i}=this.resolveContainer(t);this.container=e,this.isOwnContainer=i,this.chartType=t.chartType||R.Candle,this.currentTimeframe=t.timeframe||x.FIFTEEN_MINUTES,this.currentTimezone=t.timezone||Y.NEW_YORK,this.topPanelState.activeTimeframe=this.currentTimeframe,this.topPanelState.currentTimezone=this.currentTimezone,this.topPanelState.currentMainChartType=this.chartType,this.theme=new zs(t.theme||"dark"),this.currentTheme=this.theme.isDark()?nt:ht,Ht(t.locale||"zh-cn"),this.i18n=ge(),this.dom=new Ma,this.initDOM(),this.candleViewChart=new Oc(this.dom.getChartContainerEl(),this.theme,this.i18n,this.chartType,t.title),this.candleViewChart.showLoader(),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(5,"Creating DOM...")},1),this.dataManager=new _a(t.data||[],this.currentTimeframe,this.currentTimezone),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(20,"Data Manager Initialized")},2),this.candleViewChart.init(this.dataManager.getPreprocessedData()),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(35,"Chart Initialized")},3),this.initPanels(),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(50,"Panels Initialized")},4),this.marks=new fa(this.candleViewChart),this.marks.setTimezone(this.currentTimezone),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(65,"Marks Initialized")},5),this.brushHint=new Gc(this.theme,this.i18n),this.brushHint.injectStyles(),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(80,"Brush Hint Initialized")},6),this.priceEvents=new Qc(this.candleViewChart,this.dataManager,this.currentTheme),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(95,"Price Events Initialized")},7),this.isDataLoaded=!0,this.candleViewChart.updateLoaderProgress(100,"Ready"),setTimeout(()=>{this.candleViewChart.hideLoader()},200),window.addEventListener("resize",()=>this.handleResize())}resolveContainer(t){if(t.container)return{container:t.container,isOwn:!1};if(t.containerSelector){const e=document.querySelector(t.containerSelector);if(!e)throw new Error(`[CandleView] Container not found: ${t.containerSelector}`);return{container:e,isOwn:!1}}if(t.id){const e=document.getElementById(t.id);if(!e)throw new Error(`[CandleView] Container not found: #${t.id}`);return{container:e,isOwn:!1}}if(t.parent){const e=this.createAutoContainer();return t.parent.appendChild(e),{container:e,isOwn:!0}}if(t.parentSelector){const e=document.querySelector(t.parentSelector);if(!e)throw new Error(`[CandleView] Parent not found: ${t.parentSelector}`);const i=this.createAutoContainer();return e.appendChild(i),{container:i,isOwn:!0}}throw new Error("[CandleView] Must provide container, containerSelector, id, parent, or parentSelector")}createAutoContainer(){const t=document.createElement("div");return t.style.cssText="width:100%;height:100%;position:relative;overflow:hidden;",t}initDOM(){this.dom.create(this.container,this.theme.getColors())}initPanels(){this.panels=new $c({technologyPanelContainer:this.config.technologyPanel!==!1?this.dom.getTechnologyPanelContainer():null,drawingPanelContainer:this.config.drawingPanel!==!1?this.dom.getDrawingPanelContainer():null,rootContainer:this.dom.getRootEl(),theme:this.theme,i18n:this.i18n,chartManager:this.candleViewChart,dataManager:this.dataManager,brushHint:this.brushHint,marks:this.marks,candleView:this,topPanelState:this.topPanelState,leftPanelState:this.leftPanelState,onTimeframeChange:t=>this.handleTimeframeChange(t),onChartTypeChange:t=>this.handleChartTypeChange(t),onThemeToggle:()=>this.handleThemeToggle(),onToolSelect:t=>this.config.onToolSelect?.(t),onFullscreenClick:()=>this.config.onFullscreenClick?.(),onTimezoneSelect:t=>this.handleTimezoneSelect(t),onMainChartIndicatorSelect:t=>{this.candleViewChart.getChart()?.addOrUpdateMainChartIndicator(t),this.config.onMainChartIndicatorSelect?.(t)},onSubChartIndicatorSelect:t=>{const e=this.candleViewChart.getChart();if(!e)return;const i=this.getEnabledSubChartIndicators(),r=t.filter(a=>!i.includes(a));i.filter(a=>!t.includes(a)).forEach(a=>{e.removeSubChart(a)}),r.forEach(a=>{e.addSubChart(a,n=>{if(e){const o=e.chartPanesManager?.getParamsByIndicatorType(n)||[];e.openSubChartIndicatorsModal(o,n)}},n=>{e.removeSubChart(n),this.syncSubChartIndicatorState()})}),this.config.onSubChartIndicatorSelect?.(t)}}),this.panels.init()}handleTimeframeChange(t){this.onTimeframeChangeCallback?this.onTimeframeChangeCallback(this,t):(this.currentTimeframe=t,this.isDataLoaded&&(this.candleViewChart.showLoader(),this.candleViewChart.updateLoaderProgress(100,"changingTimeframe")),this.dataManager.setTimeframe(t),this.dataManager.refresh(),this.candleViewChart.setData(this.dataManager.getPreprocessedData()),setTimeout(()=>this.marks?.reapplyMarks(),100),this.isDataLoaded&&setTimeout(()=>{this.candleViewChart.hideLoader()},300),this.config.onTimeframeChange?.(t))}handleTimezoneSelect(t){this.currentTimezone=t,this.isDataLoaded&&(this.candleViewChart.showLoader(),this.candleViewChart.updateLoaderProgress(100,"changingTimezone")),this.dataManager.setTimezone(t),this.dataManager.refresh(),this.candleViewChart.setData(this.dataManager.getPreprocessedData()),this.marks?.setTimezone(t),setTimeout(()=>this.marks?.reapplyMarks(),100),this.isDataLoaded&&setTimeout(()=>{this.candleViewChart.hideLoader()},300),this.config.onTimezoneSelect?.(t)}handleChartTypeChange(t){this.chartType=t,this.isDataLoaded&&this.candleViewChart.updateChartType(t),this.config.onChartTypeChange?.(t)}handleThemeToggle(){const t=this.theme.isDark()?"light":"dark";this.theme.setTheme(t),this.currentTheme=this.theme.isDark()?nt:ht,this.dom.getRootEl()?.style.setProperty("background",this.theme.getColors().background),this.isDataLoaded&&this.candleViewChart.updateTheme(this.theme),this.brushHint?.updateTheme(),this.panels?.updateTheme(this.theme),this.config.onThemeToggle?.(t)}handleResize(){this.candleViewChart.getChart()?.handleResize()}setData(t,e=!1){if(!this.isDataLoaded){this.pendingData=t,this.dataManager.setData(t);return}e?(this.candleViewChart.showLoader(),this.candleViewChart.updateLoaderProgress(100,"loadingData"),this.dataManager.setData(t),this.candleViewChart.setData(this.dataManager.getPreprocessedData()),setTimeout(()=>{this.candleViewChart.hideLoader()},300)):(this.dataManager.setData(t),this.candleViewChart.setData(this.dataManager.getPreprocessedData()))}updateData(t){if(!this.isDataLoaded){this.pendingData=[...this.pendingData||[],...t],this.dataManager.appendData(t);return}const e=this.candleViewChart.getChart(),i=e?.getChart()?.timeScale().getVisibleLogicalRange();this.dataManager.appendData(t),this.candleViewChart.setData(this.dataManager.getPreprocessedData()),i&&e?.getChart()&&setTimeout(()=>e.getChart()?.timeScale().setVisibleLogicalRange(i),0)}setTheme(t){this.theme.setTheme(t),this.currentTheme=this.theme.isDark()?nt:ht,this.dom.getRootEl()?.style.setProperty("background",this.theme.getColors().background),this.isDataLoaded&&this.candleViewChart.updateTheme(this.theme),this.brushHint?.updateTheme(),this.panels?.updateTheme(this.theme)}setLocale(t){Ht(t),this.i18n=ge(),this.panels?.updateI18n(this.i18n),this.isDataLoaded&&this.candleViewChart.updateI18n(this.i18n),this.brushHint?.updateI18n(this.i18n)}setOnTimeframeChangeCallback(t){this.onTimeframeChangeCallback=t}getOnTimeframeChangeCallback(){return this.onTimeframeChangeCallback}setChartType(t){this.isDataLoaded&&this.candleViewChart.updateChartType(t)}getCurrentTheme(){return this.currentTheme}getTopPanelState(){return{...this.topPanelState}}getLeftPanelState(){return{...this.leftPanelState}}getDrawingState(){return this.candleViewChart.getChart()?.getDrawingState()||null}setCursorType(t){this.candleViewChart.getChart()?.setCursorType(t)}showAllMarks(){this.candleViewChart.getChart()?.showAllMark()}hideAllMarks(){this.candleViewChart.getChart()?.hideAllMark()}clearAllMarks(){this.candleViewChart.getChart()?.clearAllMark()}clearCurrentTool(){}getCurrentTool(){return null}registerPriceEvents(t){this.isDataLoaded&&this.priceEvents?.register(t)}removePriceEventMarker(t){this.priceEvents?.remove(t)}clearAllPriceEventMarkers(){this.priceEvents?.clearAll()}getPriceEvents(){return this.priceEvents?.getAll()||[]}addStaticMark(t,e,i,r,s){this.marks?.addStaticMark(t,e,i,r,s)}addStaticMarks(t){this.marks?.addStaticMarks(t)}addTextMark(t,e,i,r){this.marks?.addTextMark(t,e,i,r)}addArrowMark(t,e,i){this.marks?.addArrowMark(t,e,i)}addTextMarks(t){this.marks?.addTextMarks(t)}addArrowMarks(t){this.marks?.addArrowMarks(t)}clearAllStaticMarks(){this.marks?.clearAllStaticMarks()}getStaticMarkCount(){return this.marks?.getStaticMarkCount()||0}getChart(){return this.candleViewChart.getChart()}setTitle(t){this.getChart()?.setTitle(t)}openMainChartIndicator(t,e){const i=this.candleViewChart.getChart();if(!i||!this.isDataLoaded)return;let r=null;switch(t){case w.MA:r={...$s,nonce:Date.now()};break;case w.EMA:r={...Qs,nonce:Date.now()};break;case w.BOLLINGER:r={...Gs,nonce:Date.now()};break;case w.ICHIMOKU:r={...Js,nonce:Date.now()};break;case w.DONCHIAN:r={...Zs,nonce:Date.now()};break;case w.ENVELOPE:r={...ta,nonce:Date.now()};break;case w.VWAP:r={...ea,nonce:Date.now()};break;case w.HEATMAP:r={...ia,nonce:Date.now()};break;case w.MARKETPROFILE:r={...ra,nonce:Date.now()};break;default:return}e&&r&&(r.parameters={...r.parameters,...e}),r&&i.addOrUpdateMainChartIndicator(r)}closeMainChartIndicator(t){const e=this.candleViewChart.getChart();if(!(!e||!this.isDataLoaded)){if(t===w.HEATMAP){e.hideHeatMap(),e.removeMainChartIndicator(t);return}if(t===w.MARKETPROFILE){e.hideMarketProfile(),e.removeMainChartIndicator(t);return}e.removeMainChartIndicator(t)}}closeAllMainChartIndicators(){const t=this.candleViewChart.getChart();if(!t||!this.isDataLoaded)return;t.hideHeatMap(),t.removeMainChartIndicator(w.HEATMAP),t.hideMarketProfile(),t.removeMainChartIndicator(w.MARKETPROFILE),[w.MA,w.EMA,w.BOLLINGER,w.ICHIMOKU,w.DONCHIAN,w.ENVELOPE,w.VWAP].forEach(i=>{t.removeMainChartIndicator(i)})}openSubChartIndicator(t,e,i){const r=this.candleViewChart.getChart();!r||!this.isDataLoaded||(r.addSubChart(t,s=>{if(r){const a=r.chartPanesManager?.getParamsByIndicatorType(s)||[];r.openSubChartIndicatorsModal(a,s)}e?.(s)},s=>{r.removeSubChart(s),i?.(s)}),this.syncSubChartIndicatorState())}closeSubChartIndicator(t){const e=this.candleViewChart.getChart();!e||!this.isDataLoaded||(e.removeSubChart(t),this.syncSubChartIndicatorState())}closeAllSubChartIndicators(){const t=this.candleViewChart.getChart();if(!t||!this.isDataLoaded)return;[B.RSI,B.MACD,B.VOLUME,B.SAR,B.KDJ,B.ATR,B.STOCHASTIC,B.CCI,B.BBWIDTH,B.ADX,B.OBV].forEach(i=>{t.removeSubChart(i)}),this.syncSubChartIndicatorState()}syncSubChartIndicatorState(){const t=this.getEnabledSubChartIndicators();if(this.panels&&this.panels.topPanel){const e=this.panels.topPanel;e&&typeof e.setSelectedSubChartIndicators=="function"&&e.setSelectedSubChartIndicators(t)}}isMainChartIndicatorEnabled(t){const e=this.candleViewChart.getChart();return e?e.isMainChartIndicatorEnabled?.(t)??!1:!1}isSubChartIndicatorEnabled(t){const e=this.candleViewChart.getChart();return e?e.isSubChartIndicatorEnabled?.(t)??!1:!1}getEnabledMainChartIndicators(){const t=this.candleViewChart.getChart();return t?t.getEnabledMainChartIndicators?.()??[]:[]}getEnabledSubChartIndicators(){const t=this.candleViewChart.getChart();return t?t.getEnabledSubChartIndicators?.()??[]:[]}async captureScreenshot(t="CandleView",e=.15){const i=this.dom.getChartContainerEl();if(!i)throw new Error("[CandleView] Chart container not found");await new Promise(l=>setTimeout(l,100));const r=i.getBoundingClientRect(),s=document.createElement("canvas");s.width=r.width*devicePixelRatio,s.height=r.height*devicePixelRatio;const a=s.getContext("2d");a.scale(devicePixelRatio,devicePixelRatio),a.fillStyle=this.theme.getColors().background,a.fillRect(0,0,r.width,r.height);const n=i.querySelectorAll("canvas");for(let l=0;l<n.length;l++){const c=n[l],d=c.getBoundingClientRect();a.drawImage(c,d.left-r.left,d.top-r.top,d.width,d.height)}const o=Math.max(40,Math.min(r.width/8,80));a.font=`${o}px Arial, sans-serif`,a.textAlign="center",a.textBaseline="middle";const h=this.theme.isDark();return a.fillStyle=h?`rgba(255, 255, 255, ${e})`:`rgba(0, 0, 0, ${e})`,a.fillText(t,r.width/2,r.height/2),s.toDataURL("image/png")}destroy(){this.panels?.destroy(),this.candleViewChart.destroy(),this.marks?.destroy(),this.dom.destroy(),this.isOwnContainer&&this.container.parentNode&&this.container.remove(),window.removeEventListener("resize",()=>this.handleResize())}}exports.CandleView=Jc;exports.ChartType=ms;exports.CursorType=j;exports.Dark=nt;exports.DataPreprocessor=Ce;exports.DrawingType=C;exports.EN=sa;exports.Light=ht;exports.MainChartIndicatorType=w;exports.MainChartType=R;exports.ScriptType=ks;exports.StaticMarkDirection=bt;exports.StaticMarkType=Z;exports.SubChartIndicatorType=B;exports.TIMEFRAME_CONFIGS=Ss;exports.TIMEZONE_CONFIGS=Ps;exports.Theme=zs;exports.TimeframeEnum=x;exports.TimezoneEnum=Y;exports.drawingTypeName=se;exports.getI18n=ge;exports.setLocale=Ht;exports.zhCN=Kt;
|
|
1784
|
+
`,this.updateTheme(),t.style.position="relative",t.appendChild(this.indicator)}hide(){this.indicator&&(this.indicator.style.display="none")}updateTheme(){if(!this.indicator)return;const t=this.theme.getColors();Object.assign(this.indicator.style,{background:t.panelBg,border:`1px solid ${t.panelBorder}`,color:t.textColor});const e=this.indicator.querySelector(".brush-pulse");e&&(e.style.background=this.theme.isDark()?"#FF6B35":"#E64A19")}updateI18n(t){this.i18n=t;const e=this.indicator?.querySelector(".brush-text");e&&(e.textContent=this.i18n.t("brushActive")||"Brush Mode")}}class Jc{constructor(t){this.panels=null,this.priceEvents=null,this.marks=null,this.brushHint=null,this.topPanelState={...la},this.leftPanelState={...ha},this.onTimeframeChangeCallback=null,this.isDataLoaded=!1,this.pendingData=null,this.config=t;const{container:e,isOwn:i}=this.resolveContainer(t);this.container=e,this.isOwnContainer=i,this.chartType=t.chartType||R.Candle,this.currentTimeframe=t.timeframe||x.FIFTEEN_MINUTES,this.currentTimezone=t.timezone||Y.NEW_YORK,this.topPanelState.activeTimeframe=this.currentTimeframe,this.topPanelState.currentTimezone=this.currentTimezone,this.topPanelState.currentMainChartType=this.chartType,this.theme=new zs(t.theme||"dark"),this.currentTheme=this.theme.isDark()?nt:ht,Ht(t.locale||"zh-cn"),this.i18n=ge(),this.dom=new Ma,this.initDOM(),this.candleViewChart=new Oc(this.dom.getChartContainerEl(),this.theme,this.i18n,this.chartType,t.title),this.candleViewChart.showLoader(),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(5,"Creating DOM...")},1),this.dataManager=new _a(t.data||[],this.currentTimeframe,this.currentTimezone),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(20,"Data Manager Initialized")},2),this.candleViewChart.init(this.dataManager.getPreprocessedData()),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(35,"Chart Initialized")},3),this.initPanels(),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(50,"Panels Initialized")},4),this.marks=new fa(this.candleViewChart),this.marks.setTimezone(this.currentTimezone),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(65,"Marks Initialized")},5),this.brushHint=new Gc(this.theme,this.i18n),this.brushHint.injectStyles(),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(80,"Brush Hint Initialized")},6),this.priceEvents=new Qc(this.candleViewChart,this.dataManager,this.currentTheme),setTimeout(()=>{this.candleViewChart.updateLoaderProgress(95,"Price Events Initialized")},7),this.isDataLoaded=!0,this.candleViewChart.updateLoaderProgress(100,"Ready"),setTimeout(()=>{this.candleViewChart.hideLoader()},200),window.addEventListener("resize",()=>this.handleResize())}resolveContainer(t){if(t.container)return{container:t.container,isOwn:!1};if(t.containerSelector){const e=document.querySelector(t.containerSelector);if(!e)throw new Error(`[CandleView] Container not found: ${t.containerSelector}`);return{container:e,isOwn:!1}}if(t.id){const e=document.getElementById(t.id);if(!e)throw new Error(`[CandleView] Container not found: #${t.id}`);return{container:e,isOwn:!1}}if(t.parent){const e=this.createAutoContainer();return t.parent.appendChild(e),{container:e,isOwn:!0}}if(t.parentSelector){const e=document.querySelector(t.parentSelector);if(!e)throw new Error(`[CandleView] Parent not found: ${t.parentSelector}`);const i=this.createAutoContainer();return e.appendChild(i),{container:i,isOwn:!0}}throw new Error("[CandleView] Must provide container, containerSelector, id, parent, or parentSelector")}createAutoContainer(){const t=document.createElement("div");return t.style.cssText="width:100%;height:100%;overflow:hidden;",t}initDOM(){this.dom.create(this.container,this.theme.getColors())}initPanels(){this.panels=new $c({technologyPanelContainer:this.config.technologyPanel!==!1?this.dom.getTechnologyPanelContainer():null,drawingPanelContainer:this.config.drawingPanel!==!1?this.dom.getDrawingPanelContainer():null,rootContainer:this.dom.getRootEl(),theme:this.theme,i18n:this.i18n,chartManager:this.candleViewChart,dataManager:this.dataManager,brushHint:this.brushHint,marks:this.marks,candleView:this,topPanelState:this.topPanelState,leftPanelState:this.leftPanelState,onTimeframeChange:t=>this.handleTimeframeChange(t),onChartTypeChange:t=>this.handleChartTypeChange(t),onThemeToggle:()=>this.handleThemeToggle(),onToolSelect:t=>this.config.onToolSelect?.(t),onFullscreenClick:()=>this.config.onFullscreenClick?.(),onTimezoneSelect:t=>this.handleTimezoneSelect(t),onMainChartIndicatorSelect:t=>{this.candleViewChart.getChart()?.addOrUpdateMainChartIndicator(t),this.config.onMainChartIndicatorSelect?.(t)},onSubChartIndicatorSelect:t=>{const e=this.candleViewChart.getChart();if(!e)return;const i=this.getEnabledSubChartIndicators(),r=t.filter(a=>!i.includes(a));i.filter(a=>!t.includes(a)).forEach(a=>{e.removeSubChart(a)}),r.forEach(a=>{e.addSubChart(a,n=>{if(e){const o=e.chartPanesManager?.getParamsByIndicatorType(n)||[];e.openSubChartIndicatorsModal(o,n)}},n=>{e.removeSubChart(n),this.syncSubChartIndicatorState()})}),this.config.onSubChartIndicatorSelect?.(t)}}),this.panels.init()}handleTimeframeChange(t){this.onTimeframeChangeCallback?this.onTimeframeChangeCallback(this,t):(this.currentTimeframe=t,this.isDataLoaded&&(this.candleViewChart.showLoader(),this.candleViewChart.updateLoaderProgress(100,"changingTimeframe")),this.dataManager.setTimeframe(t),this.dataManager.refresh(),this.candleViewChart.setData(this.dataManager.getPreprocessedData()),setTimeout(()=>this.marks?.reapplyMarks(),100),this.isDataLoaded&&setTimeout(()=>{this.candleViewChart.hideLoader()},300),this.config.onTimeframeChange?.(t))}handleTimezoneSelect(t){this.currentTimezone=t,this.isDataLoaded&&(this.candleViewChart.showLoader(),this.candleViewChart.updateLoaderProgress(100,"changingTimezone")),this.dataManager.setTimezone(t),this.dataManager.refresh(),this.candleViewChart.setData(this.dataManager.getPreprocessedData()),this.marks?.setTimezone(t),setTimeout(()=>this.marks?.reapplyMarks(),100),this.isDataLoaded&&setTimeout(()=>{this.candleViewChart.hideLoader()},300),this.config.onTimezoneSelect?.(t)}handleChartTypeChange(t){this.chartType=t,this.isDataLoaded&&this.candleViewChart.updateChartType(t),this.config.onChartTypeChange?.(t)}handleThemeToggle(){const t=this.theme.isDark()?"light":"dark";this.theme.setTheme(t),this.currentTheme=this.theme.isDark()?nt:ht,this.dom.getRootEl()?.style.setProperty("background",this.theme.getColors().background),this.isDataLoaded&&this.candleViewChart.updateTheme(this.theme),this.brushHint?.updateTheme(),this.panels?.updateTheme(this.theme),this.config.onThemeToggle?.(t)}handleResize(){this.candleViewChart.getChart()?.handleResize()}setData(t,e=!1){if(!this.isDataLoaded){this.pendingData=t,this.dataManager.setData(t);return}e?(this.candleViewChart.showLoader(),this.candleViewChart.updateLoaderProgress(100,"loadingData"),this.dataManager.setData(t),this.candleViewChart.setData(this.dataManager.getPreprocessedData()),setTimeout(()=>{this.candleViewChart.hideLoader()},300)):(this.dataManager.setData(t),this.candleViewChart.setData(this.dataManager.getPreprocessedData()))}updateData(t){if(!this.isDataLoaded){this.pendingData=[...this.pendingData||[],...t],this.dataManager.appendData(t);return}const e=this.candleViewChart.getChart(),i=e?.getChart()?.timeScale().getVisibleLogicalRange();this.dataManager.appendData(t),this.candleViewChart.setData(this.dataManager.getPreprocessedData()),i&&e?.getChart()&&setTimeout(()=>e.getChart()?.timeScale().setVisibleLogicalRange(i),0)}setTheme(t){this.theme.setTheme(t),this.currentTheme=this.theme.isDark()?nt:ht,this.dom.getRootEl()?.style.setProperty("background",this.theme.getColors().background),this.isDataLoaded&&this.candleViewChart.updateTheme(this.theme),this.brushHint?.updateTheme(),this.panels?.updateTheme(this.theme)}setLocale(t){Ht(t),this.i18n=ge(),this.panels?.updateI18n(this.i18n),this.isDataLoaded&&this.candleViewChart.updateI18n(this.i18n),this.brushHint?.updateI18n(this.i18n)}setOnTimeframeChangeCallback(t){this.onTimeframeChangeCallback=t}getOnTimeframeChangeCallback(){return this.onTimeframeChangeCallback}setChartType(t){this.isDataLoaded&&this.candleViewChart.updateChartType(t)}getCurrentTheme(){return this.currentTheme}getTopPanelState(){return{...this.topPanelState}}getLeftPanelState(){return{...this.leftPanelState}}getDrawingState(){return this.candleViewChart.getChart()?.getDrawingState()||null}setCursorType(t){this.candleViewChart.getChart()?.setCursorType(t)}showAllMarks(){this.candleViewChart.getChart()?.showAllMark()}hideAllMarks(){this.candleViewChart.getChart()?.hideAllMark()}clearAllMarks(){this.candleViewChart.getChart()?.clearAllMark()}clearCurrentTool(){}getCurrentTool(){return null}registerPriceEvents(t){this.isDataLoaded&&this.priceEvents?.register(t)}removePriceEventMarker(t){this.priceEvents?.remove(t)}clearAllPriceEventMarkers(){this.priceEvents?.clearAll()}getPriceEvents(){return this.priceEvents?.getAll()||[]}addStaticMark(t,e,i,r,s){this.marks?.addStaticMark(t,e,i,r,s)}addStaticMarks(t){this.marks?.addStaticMarks(t)}addTextMark(t,e,i,r){this.marks?.addTextMark(t,e,i,r)}addArrowMark(t,e,i){this.marks?.addArrowMark(t,e,i)}addTextMarks(t){this.marks?.addTextMarks(t)}addArrowMarks(t){this.marks?.addArrowMarks(t)}clearAllStaticMarks(){this.marks?.clearAllStaticMarks()}getStaticMarkCount(){return this.marks?.getStaticMarkCount()||0}getChart(){return this.candleViewChart.getChart()}setTitle(t){this.getChart()?.setTitle(t)}openMainChartIndicator(t,e){const i=this.candleViewChart.getChart();if(!i||!this.isDataLoaded)return;let r=null;switch(t){case w.MA:r={...$s,nonce:Date.now()};break;case w.EMA:r={...Qs,nonce:Date.now()};break;case w.BOLLINGER:r={...Gs,nonce:Date.now()};break;case w.ICHIMOKU:r={...Js,nonce:Date.now()};break;case w.DONCHIAN:r={...Zs,nonce:Date.now()};break;case w.ENVELOPE:r={...ta,nonce:Date.now()};break;case w.VWAP:r={...ea,nonce:Date.now()};break;case w.HEATMAP:r={...ia,nonce:Date.now()};break;case w.MARKETPROFILE:r={...ra,nonce:Date.now()};break;default:return}e&&r&&(r.parameters={...r.parameters,...e}),r&&i.addOrUpdateMainChartIndicator(r)}closeMainChartIndicator(t){const e=this.candleViewChart.getChart();if(!(!e||!this.isDataLoaded)){if(t===w.HEATMAP){e.hideHeatMap(),e.removeMainChartIndicator(t);return}if(t===w.MARKETPROFILE){e.hideMarketProfile(),e.removeMainChartIndicator(t);return}e.removeMainChartIndicator(t)}}closeAllMainChartIndicators(){const t=this.candleViewChart.getChart();if(!t||!this.isDataLoaded)return;t.hideHeatMap(),t.removeMainChartIndicator(w.HEATMAP),t.hideMarketProfile(),t.removeMainChartIndicator(w.MARKETPROFILE),[w.MA,w.EMA,w.BOLLINGER,w.ICHIMOKU,w.DONCHIAN,w.ENVELOPE,w.VWAP].forEach(i=>{t.removeMainChartIndicator(i)})}openSubChartIndicator(t,e,i){const r=this.candleViewChart.getChart();!r||!this.isDataLoaded||(r.addSubChart(t,s=>{if(r){const a=r.chartPanesManager?.getParamsByIndicatorType(s)||[];r.openSubChartIndicatorsModal(a,s)}e?.(s)},s=>{r.removeSubChart(s),i?.(s)}),this.syncSubChartIndicatorState())}closeSubChartIndicator(t){const e=this.candleViewChart.getChart();!e||!this.isDataLoaded||(e.removeSubChart(t),this.syncSubChartIndicatorState())}closeAllSubChartIndicators(){const t=this.candleViewChart.getChart();if(!t||!this.isDataLoaded)return;[B.RSI,B.MACD,B.VOLUME,B.SAR,B.KDJ,B.ATR,B.STOCHASTIC,B.CCI,B.BBWIDTH,B.ADX,B.OBV].forEach(i=>{t.removeSubChart(i)}),this.syncSubChartIndicatorState()}syncSubChartIndicatorState(){const t=this.getEnabledSubChartIndicators();if(this.panels&&this.panels.topPanel){const e=this.panels.topPanel;e&&typeof e.setSelectedSubChartIndicators=="function"&&e.setSelectedSubChartIndicators(t)}}isMainChartIndicatorEnabled(t){const e=this.candleViewChart.getChart();return e?e.isMainChartIndicatorEnabled?.(t)??!1:!1}isSubChartIndicatorEnabled(t){const e=this.candleViewChart.getChart();return e?e.isSubChartIndicatorEnabled?.(t)??!1:!1}getEnabledMainChartIndicators(){const t=this.candleViewChart.getChart();return t?t.getEnabledMainChartIndicators?.()??[]:[]}getEnabledSubChartIndicators(){const t=this.candleViewChart.getChart();return t?t.getEnabledSubChartIndicators?.()??[]:[]}async captureScreenshot(t="CandleView",e=.15){const i=this.dom.getChartContainerEl();if(!i)throw new Error("[CandleView] Chart container not found");await new Promise(l=>setTimeout(l,100));const r=i.getBoundingClientRect(),s=document.createElement("canvas");s.width=r.width*devicePixelRatio,s.height=r.height*devicePixelRatio;const a=s.getContext("2d");a.scale(devicePixelRatio,devicePixelRatio),a.fillStyle=this.theme.getColors().background,a.fillRect(0,0,r.width,r.height);const n=i.querySelectorAll("canvas");for(let l=0;l<n.length;l++){const c=n[l],d=c.getBoundingClientRect();a.drawImage(c,d.left-r.left,d.top-r.top,d.width,d.height)}const o=Math.max(40,Math.min(r.width/8,80));a.font=`${o}px Arial, sans-serif`,a.textAlign="center",a.textBaseline="middle";const h=this.theme.isDark();return a.fillStyle=h?`rgba(255, 255, 255, ${e})`:`rgba(0, 0, 0, ${e})`,a.fillText(t,r.width/2,r.height/2),s.toDataURL("image/png")}destroy(){this.panels?.destroy(),this.candleViewChart.destroy(),this.marks?.destroy(),this.dom.destroy(),this.isOwnContainer&&this.container.parentNode&&this.container.remove(),window.removeEventListener("resize",()=>this.handleResize())}}exports.CandleView=Jc;exports.ChartType=ms;exports.CursorType=j;exports.Dark=nt;exports.DataPreprocessor=Ce;exports.DrawingType=C;exports.EN=sa;exports.Light=ht;exports.MainChartIndicatorType=w;exports.MainChartType=R;exports.ScriptType=ks;exports.StaticMarkDirection=bt;exports.StaticMarkType=Z;exports.SubChartIndicatorType=B;exports.TIMEFRAME_CONFIGS=Ss;exports.TIMEZONE_CONFIGS=Ps;exports.Theme=zs;exports.TimeframeEnum=x;exports.TimezoneEnum=Y;exports.drawingTypeName=se;exports.getI18n=ge;exports.setLocale=Ht;exports.zhCN=Kt;
|
package/dist/index.mjs
CHANGED
|
@@ -726,7 +726,7 @@ class pa {
|
|
|
726
726
|
this.rootEl = null, this.chartContainerEl = null, this.technologyPanelContainer = null, this.drawingPanelContainer = null;
|
|
727
727
|
}
|
|
728
728
|
create(t, e) {
|
|
729
|
-
t.innerHTML = ""
|
|
729
|
+
t.innerHTML = "";
|
|
730
730
|
const i = document.createElement("style");
|
|
731
731
|
i.id = "candleview-no-select", i.textContent = `
|
|
732
732
|
.candleview-root,
|
|
@@ -57727,7 +57727,7 @@ class Zc {
|
|
|
57727
57727
|
}
|
|
57728
57728
|
createAutoContainer() {
|
|
57729
57729
|
const t = document.createElement("div");
|
|
57730
|
-
return t.style.cssText = "width:100%;height:100%;
|
|
57730
|
+
return t.style.cssText = "width:100%;height:100%;overflow:hidden;", t;
|
|
57731
57731
|
}
|
|
57732
57732
|
initDOM() {
|
|
57733
57733
|
this.dom.create(this.container, this.theme.getColors());
|