fejn-kline
Version:
kline chart
90 lines (72 loc) • 35.4 kB
JavaScript
import{lt as A,minus as z,times as M,div as j,toFixed as _,gt as L}from"fejn-number";import{LineType as d,PolygonType as u,YAxisType as H,YAxisPosition as J,TooltipShowType as x,TooltipShowRule as k,CandleType as G,init as q}from"klinecharts";export{dispose as simpleDispose}from"klinecharts";import{s as w,L as h,t as g,l as R,g as E,i as K,a as Y,_ as Z,T as D}from"./shared/fejn-kline.qKrv9-tA.mjs";const T=t=>{const e=w[t]||w.dark;return{grid:{show:!0,horizontal:{show:!0,size:1,color:e.grid,style:d.Dashed,dashedValue:[2,2]},vertical:{show:!0,size:1,color:e.grid,style:d.Dashed,dashedValue:[2,2]}},candle:{type:G.CandleSolid,bar:{upColor:e.up,downColor:e.down,noChangeColor:e.up,upBorderColor:e.up,downBorderColor:e.down,noChangeBorderColor:e.up,upWickColor:e.up,downWickColor:e.down,noChangeWickColor:e.up},area:{lineSize:2,lineColor:"#2196F3",value:"close",smooth:!0,backgroundColor:[{offset:0,color:"rgba(33, 150, 243, 0.01)"},{offset:1,color:"rgba(33, 150, 243, 0.2)"}],point:{show:!0,color:"blue",radius:4,rippleColor:"0.3",rippleRadius:8,animation:!0,animationDuration:1e3}},priceMark:{show:!0,high:{show:!0,color:e.price_mark,textOffset:4,textSize:e.text_size,textFamily:e.family,textWeight:"normal"},low:{show:!0,color:e.price_mark,textOffset:4,textSize:e.text_size,textFamily:e.family,textWeight:"normal"},last:{show:!0,upColor:e.up,downColor:e.down,noChangeColor:e.up,line:{show:!0,style:d.Dashed,dashedValue:[4,4],size:.4},text:{show:!0,style:u.Fill,size:e.text_size,paddingLeft:7,paddingTop:3,paddingRight:5,paddingBottom:2,borderStyle:d.Solid,borderSize:1,borderColor:"transparent",borderDashedValue:[2,2],color:"#FFFFFF",family:e.family,weight:"normal",borderRadius:2}}},tooltip:{offsetLeft:4,offsetTop:6,offsetRight:4,offsetBottom:6,showRule:k.Always,showType:x.Standard,custom:[],defaultValue:"n/a",rect:{position:"fixed",paddingLeft:4,paddingRight:4,paddingTop:4,paddingBottom:4,offsetLeft:4,offsetTop:4,offsetRight:4,offsetBottom:4,borderRadius:4,borderSize:1,borderColor:"#f2f3f5",color:"#FEFEFE"},text:{size:11,family:e.family,weight:"normal",color:e.tooltip_color,marginLeft:12,marginTop:12,marginRight:-6,marginBottom:0},icons:[]}},indicator:{ohlc:{upColor:e.up_opacity,downColor:e.down_opacity,noChangeColor:e.up_opacity},bars:[{style:u.Fill,borderStyle:d.Solid,borderSize:1,borderDashedValue:[2,2],upColor:e.up_opacity,downColor:e.down_opacity,noChangeColor:e.up_opacity}],lines:[{style:d.Solid,smooth:!1,size:.4,dashedValue:[2,2],color:"#FF9600"},{style:d.Solid,smooth:!1,size:.4,dashedValue:[2,2],color:"#935EBD"},{style:d.Solid,smooth:!1,size:.4,dashedValue:[2,2],color:"#2196F3"},{style:d.Solid,smooth:!1,size:.4,dashedValue:[2,2],color:"#E11D74"},{style:d.Solid,smooth:!1,size:.4,dashedValue:[2,2],color:"#01C5C4"}],circles:[{style:u.Fill,borderStyle:d.Solid,borderSize:1,borderDashedValue:[2,2],upColor:e.up_opacity,downColor:e.down_opacity,noChangeColor:e.up_opacity}],lastValueMark:{show:!1,text:{show:!1,style:u.Fill,color:"#FFFFFF",size:e.text_size,family:e.family,weight:"normal",borderStyle:d.Solid,borderSize:1,borderDashedValue:[2,2],paddingLeft:7,paddingTop:3,paddingRight:5,paddingBottom:2,borderRadius:2}},tooltip:{offsetLeft:4,offsetTop:6,offsetRight:4,offsetBottom:6,showRule:k.Always,showType:x.Standard,showName:!0,showParams:!0,defaultValue:"n/a",text:{size:12,family:e.family,weight:"normal",color:e.tooltip_color,marginTop:12,marginRight:-6,marginBottom:0,marginLeft:12},icons:[]}},xAxis:{show:!0,size:"auto",axisLine:{show:!0,color:e.scales_line,size:1},tickText:{show:!0,color:e.scales_text,family:e.family,weight:"normal",size:e.text_size,marginStart:3,marginEnd:6},tickLine:{show:!0,size:1,length:3,color:e.scales_line}},yAxis:{show:!0,size:"auto",position:J.Right,type:H.Normal,inside:!1,reverse:!1,axisLine:{show:!0,color:e.scales_line,size:1},tickText:{show:!0,color:e.scales_text,family:e.family,weight:"normal",size:e.text_size,marginStart:3,marginEnd:6},tickLine:{show:!0,size:1,length:3,color:e.scales_line}},separator:{size:1,color:e.scales_line,fill:!0,activeBackgroundColor:"rgba(230, 230, 230, .15)"},crosshair:{show:!0,horizontal:{show:!0,line:{show:!0,style:d.Dashed,dashedValue:[6,6],size:1,color:e.cross_line},text:{show:!0,style:u.Fill,color:e.crosshair,size:e.text_size,family:e.family,weight:"normal",borderStyle:d.Solid,borderDashedValue:[2,2],borderSize:1,borderColor:e.crosshair_bg,borderRadius:2,paddingLeft:7,paddingRight:5,paddingTop:3,paddingBottom:2,backgroundColor:e.crosshair_bg}},vertical:{show:!0,line:{show:!0,style:d.Dashed,dashedValue:[6,6],size:1,color:"#888888"},text:{show:!0,style:u.Fill,color:"#FFFFFF",size:e.text_size,family:e.family,weight:"normal",borderStyle:d.Solid,borderDashedValue:[2,2],borderSize:1,borderColor:e.crosshair_bg,borderRadius:2,paddingLeft:2,paddingRight:2,paddingTop:3,paddingBottom:2,backgroundColor:e.crosshair_bg}}},overlay:{point:{color:"#1677FF",borderColor:"rgba(22, 119, 255, 0.35)",borderSize:1,radius:5,activeColor:"#1677FF",activeBorderColor:"rgba(22, 119, 255, 0.35)",activeBorderSize:3,activeRadius:5},line:{style:d.Solid,smooth:!1,color:"#1677FF",size:1,dashedValue:[2,2]},rect:{style:u.Fill,color:"rgba(22, 119, 255, 0.25)",borderColor:"#1677FF",borderSize:1,borderRadius:0,borderStyle:d.Solid,borderDashedValue:[2,2]},polygon:{style:u.Fill,color:"#1677FF",borderColor:"#1677FF",borderSize:1,borderStyle:d.Solid,borderDashedValue:[2,2]},circle:{style:u.Fill,color:"rgba(22, 119, 255, 0.25)",borderColor:"#1677FF",borderSize:1,borderStyle:d.Solid,borderDashedValue:[2,2]},arc:{style:d.Solid,color:"#1677FF",size:1,dashedValue:[2,2]},text:{color:"#1677FF",size:12,family:e.family,weight:"normal",borderStyle:d.Solid,borderDashedValue:[2,2],borderSize:0,borderRadius:2,borderColor:"#1677FF",paddingLeft:0,paddingRight:0,paddingTop:0,paddingBottom:0,backgroundColor:"transparent"},rectText:{style:u.Fill,color:"#FFFFFF",size:12,family:e.family,weight:"normal",borderStyle:d.Solid,borderDashedValue:[2,2],borderSize:1,borderRadius:2,borderColor:"#1677FF",paddingLeft:4,paddingRight:4,paddingTop:4,paddingBottom:4,backgroundColor:"#1677FF"}}}},f={o:"O",h:"H",l:"L",c:"C"},Q={[h["en-US"]]:f,[h["vi-VN"]]:f,[h["es-ES"]]:f,[h["id-ID"]]:f,[h["zh-CN"]]:{o:"\u5F00=",h:"\u9AD8=",l:"\u4F4E=",c:"\u6536="},[h["zh-TW"]]:{o:"\u958B=",h:"\u9AD8=",l:"\u4F4E=",c:"\u6536="},[h["ja-JP"]]:{o:"\u59CB\u5024",h:"\u9AD8\u5024",l:"\u5B89\u5024",c:"\u7D42\u5024"},[h["ru-RU"]]:{o:"\u041E\u0422\u041A\u0420",h:"\u041C\u0410\u041A\u0421",l:"\u041C\u0418\u041D",c:"\u0417\u0410\u041A\u0420"},[h["tr-TR"]]:{o:"A",h:"Y",l:"D",c:"K"},[h["pt-BR"]]:{o:"Abr",h:"M\xE1x.",l:"M\xEDn.",c:"Fch"},[h["fr-FR"]]:{o:"O",h:"H",l:"B",c:"C"},[h["th-TH"]]:{o:"\u0E40\u0E1B\u0E34\u0E14",h:"\u0E2A\u0E39\u0E07",l:"\u0E15\u0E48\u0E33",c:"\u0E1B\u0E34\u0E14"},[h["ko-KR"]]:{o:"\uC2DC",h:"\uACE0",l:"\uC800",c:"\uC885"}};function X(t){const{data:e,pricePrecision:o,locale:a}=t,s=Q[h[a]],i=z(e.close,e.open),l=M(j(i,e.open),100),r=A(i,0)?t.downColor:t.upColor,n=`${L(i,0)?"+":""}${_(i,o,7)}`,c=`(${L(l,0)?"+":""}${_(l,2,7)}%)`;return[{title:s.o,value:{text:_(e.open,o),color:r}},{title:s.h,value:{text:_(e.high,o),color:r}},{title:s.l,value:{text:_(e.low,o),color:r}},{title:s.c,value:{text:_(e.close,o),color:r}},{title:"",value:{text:`${n} ${c}`,color:r}}]}function ee(t,e){if(typeof t=="string"&&!t.length)throw new Error("Dom id \u4E0D\u80FD\u4E3A\u7A7A");e.styles||(e.styles=T(e?.theme||g)),e.locale=h[e.locale]||R;const o=q(t,e);if(!o)return null;o.$updateTooltip=()=>{const{candle:s}=o.getStyles();s.tooltip.custom=({current:i},{bar:l})=>{const r={data:i,pricePrecision:o.getPriceVolumePrecision().price,locale:o.getLocale(),upColor:l.upColor,downColor:l.downColor};return X(r)},o.setStyles({candle:s})},o.$setTheme=s=>{const i=T(s);i&&o.setStyles(i)};const a=()=>{const s=new ResizeObserver(()=>{setTimeout(()=>{o.resize()},0)});o.getDom()&&s.observe(o.getDom())};return o.$addDefaultMa=()=>{o.getIndicatorByPaneId("candle_pane","MA")&&o.removeIndicator("candle_pane","MA"),o.createIndicator({name:"MA",calcParams:[10,30,60]},!1,{id:"candle_pane",dragEnabled:!0})},o.$addVol=()=>{o.getIndicatorByPaneId("default_vol","VOL")&&o.removeIndicator("default_vol","VOL"),o.createIndicator({name:"VOL",calcParams:[20],precision:o.getPriceVolumePrecision().volume,figures:[{key:"ma1",title:"",type:"line"},{key:"volume",title:"",type:"bar",baseValue:0,styles({current:s},i,{bars:l}){const{close:r,open:n}=s.kLineData||{close:0,open:0},{upColor:c,downColor:p}=l[0];return{color:A(z(r,n),0)?p:c}}}]},!1,{id:"default_vol"})},o.$screenshot=()=>{const s=o.getConvertPictureUrl(!0),i=new Image,l=window.open("","_blank");i.src=s,l?.document.write(i.outerHTML),l?.document.close()},o.$setGraph=s=>{const i=o.getStyles();i.candle.type=E.simple_map[s]||E.simple_map[1],o.setStyles(i)},a(),o.$updateTooltip(),o.setLeftMinVisibleBarCount(2),o.setRightMinVisibleBarCount(2),o.setOffsetRightDistance(42),o.setBarSpace(6.2),o.setPaneOptions({id:"candle_pane",gap:{top:.3}}),e.showMa&&o.$addDefaultMa(),e.showVol&&o.$addVol(),o}function C(t,e){const o={...t};for(const a in e)typeof t[a]!="object"||t[a]===null||Array.isArray(t[a])?e[a]!==void 0&&(o[a]=e[a]):o[a]=C(t[a],e[a]);return o}const te={width:800,height:500,interval:"1D",timezone:"Etc/UTC",container:"",library_path:"",locale:"en",widgetbar:{details:!1,watchlist:!1,news:!1,datawindow:!1,watchlist_settings:{default_symbols:[]}},overrides:{"mainSeriesProperties.showCountdown":!1},studies_overrides:{},trading_customization:{position:{},order:{}},brokerConfig:{configFlags:{}},fullscreen:!1,autosize:!1,disabled_features:[],enabled_features:[],debug:!1,logo:{},time_frames:[{text:"5y",resolution:"1W"},{text:"1y",resolution:"1W"},{text:"6m",resolution:"120"},{text:"3m",resolution:"60"},{text:"1m",resolution:"30"},{text:"5d",resolution:"5"},{text:"1d",resolution:"1"}],client_id:"0",user_id:"0",charts_storage_api_version:"1.0",favorites:{intervals:[],chartTypes:[],indicators:[],drawingTools:[]}},W=JSON.parse('[{"iso":"ar","dir":"rtl","language":"ar"},{"iso":"pt","dir":"ltr","language":"pt"},{"iso":"ca","dir":"ltr","language":"ca_ES"},{"iso":"cs","dir":"ltr","language":"cs"},{"iso":"de","dir":"ltr","language":"de"},{"iso":"en","dir":"ltr","language":"en"},{"iso":"es","dir":"ltr","language":"es"},{"iso":"fa","dir":"rtl","language":"fa"},{"iso":"fr","dir":"ltr","language":"fr"},{"iso":"he","dir":"rtl","language":"he_IL"},{"iso":"hu","dir":"ltr","language":"hu_HU"},{"iso":"id","dir":"ltr","language":"id_ID"},{"iso":"en","dir":"ltr","language":"en"},{"iso":"it","dir":"ltr","language":"it"},{"iso":"ja","dir":"ltr","language":"ja"},{"iso":"ko","dir":"ltr","language":"ko"},{"iso":"ms","dir":"ltr","language":"ms_MY"},{"iso":"pl","dir":"ltr","language":"pl"},{"iso":"ru","dir":"ltr","language":"ru"},{"iso":"sv","dir":"ltr","language":"sv"},{"iso":"th","dir":"ltr","language":"th"},{"iso":"tr","dir":"ltr","language":"tr"},{"iso":"vi","dir":"ltr","language":"vi"},{"iso":"zh-Hans","dir":"ltr","language":"zh"},{"iso":"zh-Hant","dir":"ltr","language":"zh_TW"},{"iso":"el","dir":"ltr","language":"el"},{"iso":"nl","dir":"ltr","language":"nl_NL"},{"iso":"ro","dir":"ltr","language":"ro"}]');let U=!1;function oe(){return"CL v26.003 (internal id e793d706 @ 2023-10-05T20:27:44.510Z)"}const ie=class{constructor(t){var e,o;if(this._id=`tradingview_${(1048576*(1+Math.random())|0).toString(16).substring(1)}`,this._ready=!1,this._readyHandlers=[],this._onWindowResize=this._autoResizeChart.bind(this),!t.datafeed)throw new Error("Datafeed is not defined");!((e=t.overrides)===null||e===void 0)&&e["mainSeriesProperties.priceAxisProperties.lockScale"]&&(console.warn("mainSeriesProperties.priceAxisProperties.lockScale can not be set to true within the widget constructor"),delete t.overrides["mainSeriesProperties.priceAxisProperties.lockScale"]),this._options=C(te,t),((o=this._options.theme)!==null&&o!==void 0?o:"light").toLowerCase()==="dark"&&this._options.loading_screen===void 0&&(this._options.loading_screen={backgroundColor:"#131722"}),this._options.debug&&(U||(U=!0,console.log("Using CL v26.003 (internal id e793d706 @ 2023-10-05T20:27:44.510Z)"))),this._create()}setDebugMode(t){this._innerAPI().setDebugMode(t)}onChartReady(t){this._ready?t.call(this):this._readyHandlers.push(t)}headerReady(){return this._innerWindowLoaded.then(()=>this._innerWindow().headerReady())}onGrayedObjectClicked(t){this._doWhenInnerApiLoaded(e=>{e.onGrayedObjectClicked(t)})}onShortcut(t,e){this._doWhenInnerWindowLoaded(o=>{o.createShortcutAction(t,e)})}subscribe(t,e){this._doWhenInnerApiLoaded(o=>{o.subscribe(t,e)})}unsubscribe(t,e){this._doWhenInnerApiLoaded(o=>{o.unsubscribe(t,e)})}chart(t){return this._innerAPI().chart(t)}getLanguage(){return this._options.locale}setSymbol(t,e,o){this._innerAPI().changeSymbol(t,e,o)}remove(){window.removeEventListener("resize",this._onWindowResize),this._readyHandlers.splice(0,this._readyHandlers.length),delete window[this._id],this._iFrame.parentNode&&this._iFrame.parentNode.removeChild(this._iFrame)}closePopupsAndDialogs(){this._doWhenInnerApiLoaded(t=>{t.closePopupsAndDialogs()})}selectLineTool(t,e){this._innerAPI().selectLineTool(t,e)}selectedLineTool(){return this._innerAPI().selectedLineTool()}save(t){this._innerAPI().saveChart(t)}load(t,e){this._innerAPI().loadChart({json:t,extendedData:e})}getSavedCharts(t){this._innerAPI().getSavedCharts(t)}loadChartFromServer(t){this._innerAPI().loadChartFromServer(t)}saveChartToServer(t,e,o){this._innerAPI().saveChartToServer(t,e,o)}removeChartFromServer(t,e){this._innerAPI().removeChartFromServer(t,e)}onContextMenu(t){this._doWhenInnerApiLoaded(e=>{e.onContextMenu(t)})}createButton(t){return this._innerWindow().createButton(t)}createDropdown(t){return this._innerWindow().createDropdown(t)}showNoticeDialog(t){this._doWhenInnerApiLoaded(e=>{e.showNoticeDialog(t)})}showConfirmDialog(t){this._doWhenInnerApiLoaded(e=>{e.showConfirmDialog(t)})}showLoadChartDialog(){this._innerAPI().showLoadChartDialog()}showSaveAsChartDialog(){this._innerAPI().showSaveAsChartDialog()}symbolInterval(){return this._innerAPI().getSymbolInterval()}mainSeriesPriceFormatter(){return this._innerAPI().mainSeriesPriceFormatter()}getIntervals(){return this._innerAPI().getIntervals()}getStudiesList(){return this._innerAPI().getStudiesList()}getStudyInputs(t){return this._innerAPI().getStudyInputs(t)}getStudyStyles(t){return this._innerAPI().getStudyStyles(t)}addCustomCSSFile(t){this._innerWindow().addCustomCSSFile(t)}applyOverrides(t){this._options=C(this._options,{overrides:t}),this._doWhenInnerWindowLoaded(e=>{e.applyOverrides(t)})}applyStudiesOverrides(t){this._doWhenInnerWindowLoaded(e=>{e.applyStudiesOverrides(t)})}watchList(){return this._innerAPI().watchlist()}news(){return this._innerAPI().news()}widgetbar(){return this._innerAPI().widgetbar()}activeChart(){return this._innerAPI().activeChart()}activeChartIndex(){return this._innerAPI().activeChartIndex()}setActiveChart(t){return this._innerAPI().setActiveChart(t)}chartsCount(){return this._innerAPI().chartsCount()}layout(){return this._innerAPI().layout()}setLayout(t){this._innerAPI().setLayout(t)}layoutName(){return this._innerAPI().layoutName()}changeTheme(t,e){return this._innerWindow().changeTheme(t,e)}getTheme(){return this._innerWindow().getTheme()}takeScreenshot(){this._doWhenInnerApiLoaded(t=>{t.takeScreenshot()})}lockAllDrawingTools(){return this._innerAPI().lockAllDrawingTools()}hideAllDrawingTools(){return this._innerAPI().hideAllDrawingTools()}drawOnAllCharts(t){this._innerAPI().drawOnAllCharts(t)}magnetEnabled(){return this._innerAPI().magnetEnabled()}magnetMode(){return this._innerAPI().magnetMode()}undoRedoState(){return this._innerAPI().undoRedoState()}setIntervalLinkingEnabled(t){this._innerAPI().setIntervalLinkingEnabled(t)}setDateRangeLinkingEnabled(t){this._innerAPI().setDateRangeLinkingEnabled(t)}setTimeFrame(t){this._innerAPI().setTimeFrame(t)}symbolSync(){return this._innerAPI().symbolSync()}intervalSync(){return this._innerAPI().intervalSync()}crosshairSync(){return this._innerAPI().crosshairSync()}timeSync(){return this._innerAPI().timeSync()}dateRangeSync(){return this._innerAPI().dateRangeSync()}setFeatureEnabled(t,e){this._innerAPI().setFeatureEnabled(t,e)}getAllFeatures(){return this._innerWindow().getAllFeatures()}clearUndoHistory(){return this._innerAPI().clearUndoHistory()}undo(){return this._innerAPI().undo()}redo(){return this._innerAPI().redo()}startFullscreen(){this._innerAPI().startFullscreen()}exitFullscreen(){this._innerAPI().exitFullscreen()}takeClientScreenshot(t){return this._innerAPI().takeClientScreenshot(t)}navigationButtonsVisibility(){return this._innerWindow().getNavigationButtonsVisibility()}paneButtonsVisibility(){return this._innerWindow().getPaneButtonsVisibility()}dateFormat(){return this._innerWindow().getDateFormat()}timeHoursFormat(){return this._innerWindow().getTimeHoursFormat()}currencyAndUnitVisibility(){return this._innerWindow().getCurrencyAndUnitVisibility()}supportedChartTypes(){return this._innerAPI().supportedChartTypes()}watermark(){return this._innerAPI().watermark()}customSymbolStatus(){return this._innerWindow().customSymbolStatus()}setCSSCustomProperty(t,e){if(t.startsWith("--")===!1)throw new Error("customPropertyName should begin with a double hyphen");this._innerWindow().document.body.style.setProperty(t,e)}getCSSCustomPropertyValue(t){if(t.startsWith("--")===!1)throw new Error("customPropertyName should begin with a double hyphen");const e=this._innerWindow().document.body;return e.style.getPropertyValue(t)||getComputedStyle(e).getPropertyValue(t)}linking(){return this._innerAPI().linking}_innerAPI(){return this._innerWindow().tradingViewApi}_innerWindow(){return this._iFrame.contentWindow}_doWhenInnerWindowLoaded(t){this._ready?t(this._innerWindow()):this._innerWindowLoaded.then(()=>{t(this._innerWindow())})}_doWhenInnerApiLoaded(t){this._doWhenInnerWindowLoaded(e=>{e.doWhenApiIsReady(()=>t(this._innerAPI()))})}_autoResizeChart(){this._options.fullscreen&&(this._iFrame.style.height=window.innerHeight+"px",re&&setTimeout(()=>{this._iFrame.style.height=window.innerHeight+"px"},30))}_create(){var t,e;const o=(e=(t=this._options.enabled_features)===null||t===void 0?void 0:t.includes("iframe_loading_compatibility_mode"))!==null&&e!==void 0&&e,[a,s]=this._render(!o),i=this._options.container,l=typeof i=="string"?document.getElementById(i):i;if(l===null)throw new Error(`There is no such element - #${this._options.container}`);l.innerHTML=a,this._iFrame=l.querySelector(`#${this._id}`);const r=this._iFrame;o&&(r.contentWindow?(r.contentWindow.document.open(),r.contentWindow.document.write(s),r.contentWindow.document.close()):console.warn("Unable to locate contentWindow for the created iframe. Please try disabling the `iframe_loading_compatibility_mode` featureset.")),(this._options.autosize||this._options.fullscreen)&&(r.style.width="100%",this._options.fullscreen||(r.style.height="100%")),window.addEventListener("resize",this._onWindowResize),this._onWindowResize(),this._innerWindowLoaded=new Promise(n=>{const c=()=>{r.removeEventListener("load",c,!1),n()};r.addEventListener("load",c,!1)}),this._innerWindowLoaded.then(()=>{try{this._innerWindow().widgetReady(()=>{this._ready=!0;for(const n of this._readyHandlers)try{n.call(this)}catch(c){console.error(c)}this._innerWindow().initializationFinished()})}catch(n){if(n instanceof Error&&/widgetReady is not a function/.test(n.message))throw new Error(`There was an error when loading the library. Usually this error means the library failed to load its static files. Check that the library files are available at ${window.location.host}/${this._options.library_path||""} or correct the library_path option.`)}})}_render(t){const e=window;if(e[this._id]={datafeed:this._options.datafeed,customFormatters:this._options.custom_formatters||this._options.customFormatters,brokerFactory:this._options.broker_factory||this._options.brokerFactory,overrides:this._options.overrides,studiesOverrides:this._options.studies_overrides,tradingCustomization:this._options.trading_customization,disabledFeatures:this._options.disabled_features,enabledFeatures:this._options.enabled_features,brokerConfig:this._options.broker_config||this._options.brokerConfig,restConfig:this._options.restConfig,favorites:this._options.favorites,logo:this._options.logo,numeric_formatting:this._options.numeric_formatting,rss_news_feed:this._options.rss_news_feed,rss_news_title:this._options.rss_news_title,newsProvider:this._options.news_provider,loadLastChart:this._options.load_last_chart,saveLoadAdapter:this._options.save_load_adapter,loading_screen:this._options.loading_screen,settingsAdapter:this._options.settings_adapter,getCustomIndicators:this._options.custom_indicators_getter,additionalSymbolInfoFields:this._options.additional_symbol_info_fields,headerWidgetButtonsMode:this._options.header_widget_buttons_mode,customTranslateFunction:this._options.custom_translate_function,symbolSearchComplete:this._options.symbol_search_complete,contextMenu:this._options.context_menu,settingsOverrides:this._options.settings_overrides,timeframe:this._options.timeframe,customTimezones:this._options.custom_timezones},this._options.saved_data)e[this._id].chartContent={json:this._options.saved_data},this._options.saved_data_meta_info&&(e[this._id].chartContentExtendedData=this._options.saved_data_meta_info);else if(!this._options.load_last_chart&&!this._options.symbol)throw new Error("Symbol is not defined: either 'symbol' or 'load_last_chart' option must be set");if(this._options.library_path&&!this._options.library_path.endsWith("/")&&console.warn("library_path option should contain a trailing forward slash"),this._options.locale){const i=encodeURIComponent(this._options.locale);W.findIndex(l=>l.language===i)>=0||(console.warn("locale isn't supported. Using default of `en`."),this._options.locale="en")}const o=function(i,l){var r;const n=new URL(`${i||""}`,location.href).href,c=JSON.parse('["bundles/runtime.0809a655c13b333b6a76.js","bundles/__LANG__.5008.e5d7d914577969582fa4.js","bundles/3515.2f722d33cebe31a154b1.css","bundles/9401.4792ed983286dcafa79b.js","bundles/library.847f247511d3f9997d72.js"]'),p=encodeURIComponent(l),b=(r=W.find(y=>y.language===p))!==null&&r!==void 0?r:{iso:"en",dir:"ltr"},B=`lang="${b.iso}" dir="${b.dir}"`;return`<!DOCTYPE html><html ${(S={bundles:`
${function(y,$,N){if(y===void 0)return"";const I=[],F=[];for(const m of y)m.endsWith(".js")?I.push(`<script defer crossorigin="anonymous" src="${m.replace("__LANG__",N)}"><\/script>`):m.endsWith(".css")&&F.push(`<link type="text/css" href="${$?m.replace(/\.css$/i,".rtl.css"):m}" rel="stylesheet"/>`);return[...I,...F].join(`
`)}(c,b.dir==="rtl",p)}
`,localeLanguage:p,htmlAttrs:B,libraryPath:n}).htmlAttrs}><head><base href="${S.libraryPath}"><meta charset="utf-8"><script>window===window.parent&&(location.href="about:blank")<\/script> ${S.bundles} </head><body class="chart-page unselectable on-widget"><div class="loading-indicator" id="loading-indicator"></div><script>var JSServer={},__initialEnabledFeaturesets=["charting_library"]<\/script><script>(function() {
window.urlParams = (function () {
var match,
pl = /\\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, ' ')).replace(/<\\/?[^>]+(>|$)/g, ''); },
query = function() {
// We don't use hash on the url because: safari 13 throws an error if you attempt this
// on a blob, and safari 14 will strip hash from blob urls.
if (frameElement && frameElement.dataset.widgetOptions) {
return frameElement.dataset.widgetOptions;
} else {
throw "Unexpected use of this page";
}
}(),
result = {};
while (match = search.exec(query)) {
result[decode(match[1])] = decode(match[2]);
}
var additionalSettingsObject = window.parent[result.uid];
var customObjectNames = ['datafeed', 'customFormatters', 'brokerFactory', 'save_load_adapter', 'customTranslateFunction', 'contextMenu'];
for (var p in additionalSettingsObject) {
if (customObjectNames.indexOf(p) === -1) {
result[p] = JSON.stringify(additionalSettingsObject[p]);
}
}
return result;
})();
window.locale = urlParams.locale;
window.language = urlParams.locale; // a very big attention needed here
window.customTranslateFunction = window.parent[urlParams.uid].customTranslateFunction;
window.addCustomCSSFile = function(href) {
var link = document.createElement('link');
link.setAttribute('type', 'text/css');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('href', href);
link.setAttribute('cross-origin', 'anonymous');
window.loadedCustomCss = new Promise((resolve) => {
link.onload = resolve;
link.onerror = resolve;
});
document.body.appendChild(link);
};
window.loadedCustomCss = Promise.resolve();
if (!!urlParams.customCSS) {
window.addCustomCSSFile(urlParams.customCSS);
}
var loadingScreenParams = {};
if (typeof urlParams.loading_screen === 'string') {
try {
loadingScreenParams = JSON.parse(urlParams.loading_screen);
} catch(e) {}
}
var loadingIndicatorElement = document.getElementById('loading-indicator');
if (loadingScreenParams.backgroundColor) {
loadingIndicatorElement.style = 'background-color: ' + loadingScreenParams.backgroundColor;
}
!function(){"use strict";var t,e=new WeakMap;!function(t){t[t.Element=1]="Element",t[t.Document=9]="Document"}(t||(t={}));var n={mini:"xsmall",xsmall:"xsmall",small:"small",medium:"medium",large:"large"};var i,s,o,r,l,c=(void 0===l&&(l=""),i='<div class="tv-spinner '.concat(l,'" role="progressbar"></div>'),o=function(n,i){var s,o;return s=null==i?document.documentElement:i.nodeType===t.Document?i.documentElement:i,e&&(o=e.get(s)),o||((o=s.ownerDocument.createRange()).selectNodeContents(s),e&&e.set(s,o)),o.createContextualFragment(n)}(i,s),null!==(r=o.firstElementChild)&&o.removeChild(r),r),a=function(){function t(t){this._shown=!1,this._el=c.cloneNode(!0),this.setSize(n[t||"large"])}return t.prototype.spin=function(t){return this._el.classList.add("tv-spinner--shown"),void 0===this._container&&(this._container=t,void 0!==t&&t.appendChild(this._el)),this._shown=!0,this},t.prototype.stop=function(t){return t&&void 0!==this._container&&this._container.removeChild(this._el),this._el&&this._el.classList.remove("tv-spinner--shown"),this._shown=!1,this},t.prototype.setStyle=function(t){var e=this;return Object.keys(t).forEach((function(n){var i=t[n];void 0!==i&&e._el.style.setProperty(n,i)})),this},t.prototype.style=function(){return this._el.style},t.prototype.setSize=function(t){var e=void 0!==t?"tv-spinner--size_".concat(t):"";return this._el.className="tv-spinner ".concat(e," ").concat(this._shown?"tv-spinner--shown":""),this},t.prototype.getEl=function(){return this._el},t.prototype.destroy=function(){this.stop(),delete this._el,delete this._container},t}();window.Spinner=a}();
var spinnerColor = (loadingScreenParams.foregroundColor) ? loadingScreenParams.foregroundColor : undefined;
var loadingSpinner = new Spinner('large').setStyle({
'--tv-spinner-color': spinnerColor,
zIndex: String(2e9),
});
loadingSpinner.getEl().classList.add('spinner');
loadingSpinner.spin(loadingIndicatorElement);
})();<\/script></body></html>`;var S}(this._options.library_path||"",this._options.locale);let a=new URL("about:blank");if(t){const i=new Blob([o],{type:"text/html"}),l=URL.createObjectURL(i);a=new URL(l)}const s="symbol="+encodeURIComponent(this._options.symbol||"")+"&interval="+encodeURIComponent(this._options.interval)+(this._options.toolbar_bg?"&toolbarbg="+encodeURIComponent(this._options.toolbar_bg.replace("#","")):"")+(this._options.studies_access?"&studiesAccess="+encodeURIComponent(JSON.stringify(this._options.studies_access)):"")+"&widgetbar="+encodeURIComponent(JSON.stringify(this._options.widgetbar))+(this._options.drawings_access?"&drawingsAccess="+encodeURIComponent(JSON.stringify(this._options.drawings_access)):"")+"&timeFrames="+encodeURIComponent(JSON.stringify(this._options.time_frames))+"&locale="+encodeURIComponent(this._options.locale)+"&uid="+encodeURIComponent(this._id)+"&clientId="+encodeURIComponent(String(this._options.client_id))+"&userId="+encodeURIComponent(String(this._options.user_id))+(this._options.charts_storage_url?"&chartsStorageUrl="+encodeURIComponent(this._options.charts_storage_url):"")+(this._options.charts_storage_api_version?"&chartsStorageVer="+encodeURIComponent(this._options.charts_storage_api_version):"")+(this._options.custom_css_url?"&customCSS="+encodeURIComponent(this._options.custom_css_url):"")+(this._options.custom_font_family?"&customFontFamily="+encodeURIComponent(this._options.custom_font_family):"")+(this._options.auto_save_delay?"&autoSaveDelay="+encodeURIComponent(String(this._options.auto_save_delay)):"")+"&debug="+encodeURIComponent(String(this._options.debug))+(this._options.snapshot_url?"&snapshotUrl="+encodeURIComponent(this._options.snapshot_url):"")+(this._options.timezone?"&timezone="+encodeURIComponent(this._options.timezone):"")+(this._options.study_count_limit?"&studyCountLimit="+encodeURIComponent(String(this._options.study_count_limit)):"")+(this._options.symbol_search_request_delay?"&ssreqdelay="+encodeURIComponent(String(this._options.symbol_search_request_delay)):"")+(this._options.compare_symbols?"&compareSymbols="+encodeURIComponent(JSON.stringify(this._options.compare_symbols)):"")+(this._options.theme?"&theme="+encodeURIComponent(String(this._options.theme)):"")+(this._options.header_widget_buttons_mode?"&header_widget_buttons_mode="+encodeURIComponent(String(this._options.header_widget_buttons_mode)):"")+(this._options.time_scale?"&time_scale="+encodeURIComponent(JSON.stringify(this._options.time_scale)):"");return[`<iframe
id="${this._id}" name="${this._id}" src="${a.href}" data-widget-options="${s}"
${this._options.autosize||this._options.fullscreen?"":`width="${this._options.width}" height="${this._options.height}"`} title="Financial Chart" frameborder="0" allowTransparency="true" scrolling="no" allowfullscreen style="display:block;opacity:0">
</iframe>`,o]}};typeof window<"u"&&(window.TradingView=window.TradingView||{},window.TradingView.version=oe);const re=!(typeof window>"u"||!window.navigator||!window.navigator.userAgent)&&window.navigator.userAgent.includes("CriOS"),ne={supported_resolutions:K,supports_marks:!0,supports_time:!0,supports_timescale_marks:!0,supports_search:!0,reset_cache_timeout:.001},se={onReady:t=>{setTimeout(()=>t(ne))},searchSymbols:()=>{},resolveSymbol:(t,e)=>{const o={name:t,full_name:`${t}:Example Exchange`,ticker:t,description:t,exchange:"Example Exchange",listed_exchange:"Example Exchange",type:"crypto",session:"24x7",timezone:"Etc/UTC",format:"price",minmov:1,minmove2:0,pricescale:1e8,has_seconds:!0,has_intraday:!0,has_daily:!0,has_weekly_and_monthly:!0,volume_precision:4,visible_plots_set:"ohlcv"};setTimeout(()=>{e(o)})},getBars:()=>{},subscribeBars:()=>{},unsubscribeBars:()=>{}},V=(t=g)=>{const e=w[t];return{volumePaneSize:"medium","scalesProperties.fontSize":10,"scalesProperties.lineColor":e.scales_line,"scalesProperties.textColor":e.scales_text,"scalesProperties.crosshairLabelBgColorLight":e.crosshair_bg,"scalesProperties.crosshairLabelBgColorDark":e.crosshair_bg,"paneProperties.background":e.background,"paneProperties.backgroundType":"solid","paneProperties.vertGridProperties.style":1,"paneProperties.horzGridProperties.style":1,"paneProperties.vertGridProperties.color":e.grid,"paneProperties.horzGridProperties.color":e.grid,"paneProperties.crossHairProperties.color":e.cross_line,"mainSeriesProperties.candleStyle.upColor":e.up,"mainSeriesProperties.candleStyle.downColor":e.down,"mainSeriesProperties.candleStyle.borderUpColor":e.up,"mainSeriesProperties.candleStyle.borderDownColor":e.down,"mainSeriesProperties.candleStyle.wickUpColor":e.up,"mainSeriesProperties.candleStyle.wickDownColor":e.down,"mainSeriesProperties.hollowCandleStyle.upColor":e.up,"mainSeriesProperties.hollowCandleStyle.downColor":e.down,"mainSeriesProperties.hollowCandleStyle.borderUpColor":e.up,"mainSeriesProperties.hollowCandleStyle.borderDownColor":e.down,"mainSeriesProperties.hollowCandleStyle.wickUpColor":e.up,"mainSeriesProperties.hollowCandleStyle.wickDownColor":e.down,"mainSeriesProperties.haStyle.upColor":e.up,"mainSeriesProperties.haStyle.downColor":e.down,"mainSeriesProperties.haStyle.borderUpColor":e.up,"mainSeriesProperties.haStyle.borderDownColor":e.down,"mainSeriesProperties.haStyle.wickUpColor":e.up,"mainSeriesProperties.haStyle.wickDownColor":e.down,"mainSeriesProperties.barStyle.upColor":e.up,"mainSeriesProperties.barStyle.downColor":e.down,"mainSeriesProperties.baselineStyle.topFillColor1":"rgba(21, 187, 122, 0.1)","mainSeriesProperties.baselineStyle.topFillColor2":"rgba(21, 187, 122, 0.1)","mainSeriesProperties.baselineStyle.bottomFillColor1":"rgba(210, 51, 77, 0.1)","mainSeriesProperties.baselineStyle.bottomFillColor2":"rgba(210, 51, 77, 0.1)","mainSeriesProperties.baselineStyle.topLineColor":e.up,"mainSeriesProperties.baselineStyle.bottomLineColor":e.down,"mainSeriesProperties.columnStyle.upColor":e.up,"mainSeriesProperties.columnStyle.downColor":e.down,"mainSeriesProperties.lineStyle.color":e.up,"mainSeriesProperties.lineWithMarkersStyle.color":e.up,"mainSeriesProperties.highLowAvgPrice.highLowPriceLabelsVisible":!0}},{getStore:v,removeStore:O,setStore:P}=Z;function ae(t,e){if(typeof t=="string"&&!t.length)throw new Error("Dom id \u4E0D\u80FD\u4E3A\u7A7A");const o={...e},a=e.storeKey||Y;["locale","datafeed","storeKey"].forEach(n=>{delete o[n]});const s=w[e.theme||g],i=v(a);if(i&&i.charts?.length){const n=i.charts[0].panes?.[0]?.sources?.[0].state;n&&(n.symbol=e.symbol,n.interval=e.interval)}const l={container:t,locale:D[e.locale]||D[R],datafeed:Object.assign(se,e.datafeed||{}),autosize:!0,time_frames:[],timezone:"Etc/UTC",theme:g,custom_css_url:e.custom_css_url||"theme.css",custom_font_family:s.family,overrides:V(e.theme||g),header_widget_buttons_mode:"compact",enabled_features:["hide_left_toolbar_by_default","move_logo_to_main_pane","chart_crosshair_menu"],disabled_features:["header_symbol_search","header_compare","symbol_search_hot_key","volume_force_overlay","display_market_status","header_widget"],studies_overrides:{"volume.volume.color.0":s.down,"volume.volume.color.1":s.up,"volume.volume ma.color":s.ma},auto_save_delay:.05,settings_adapter:{initialSettings:{...i},setValue(n,c){const p=v(a)||{};["chartproperties","chartproperties.mainSeriesProperties"].includes(n)||(p[n]=c),P(a,p)},removeValue(n){const c=v(a)||{};Object.hasOwn(c,n)&&delete c[n],P(a,c)}},...o};i||(O("tradingview.chartproperties.mainSeriesProperties"),O("tradingview.chartproperties")),i?.layout&&i.charts?.length&&(l.saved_data=i);const r=new ie(l);return r.$addDefaultMa=()=>{const n=r.activeChart();[10,30,60].forEach(c=>{n.createStudy("Moving Average",!1,!1,{length:c},{showLabelsOnPriceScale:!1})})},r.onChartReady(()=>{e.showMa&&!i&&r.$addDefaultMa(),r.subscribe("onAutoSaveNeeded",()=>{r.save(n=>{P(a,n)})}),r.subscribe("onScreenshotReady",n=>{window.open(`https://www.tradingview.com/x/${n}/`,"_blank")}),r.subscribe("onPlusClick",n=>{typeof e.onPlusClick=="function"&&e?.onPlusClick(n)})}),r}export{V as getOverrides,ee as simpleInit,ae as tvInit};