Files
ai/charting_library/bundles/compare-model.fe4212df34b2149285c2.js

4 lines
12 KiB
JavaScript

"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[7336],{38470:(e,t,o)=>{o.d(t,{SEPARATOR_PREFIX:()=>s,isSeparatorItem:()=>r});const s="###";function r(e){return e.startsWith(s)}},20833:(e,t,o)=>{function s(e){const t=e.logo??null;if(!t){if("logoid"in e&&e.logoid)return{style:"single",logoid:e.logoid};const t="currency-logoid"in e?e["currency-logoid"]:null,o="base-currency-logoid"in e?e["base-currency-logoid"]:null;if(t&&o)return{style:"pair",logoid:o,logoid2:t};if(t||o)return{style:"single",logoid:t??o}}return t}o.d(t,{logoDataFromQuotes:()=>s})},95416:(e,t,o)=>{function s(){return window.configurationData?.exchanges?.map((e=>({...e,country:"",providerId:"",flag:""})))??[]}o.d(t,{getExchanges:()=>s})},965:(e,t,o)=>{o.d(t,{QualifiedSources:()=>s,qualifyProName:()=>i});var s,r=o(85842),n=o(16905);o(756);function i(e){return e}!function(e){function t(e){return e.pro_name}function o(e){{const t=(0,n.isFeaturesetEnabled)("pay_attention_to_ticker_not_symbol")?e.ticker:e.name;return(0,r.ensureDefined)(t)}}e.fromQuotesSnapshot=function(e){return"error"===e.status?e.symbolname:e.values.pro_name},e.fromQuotesResponse=function(e){const{values:o,symbolname:s,status:r}=e;return"error"===r&&s?s:t(o)},e.fromQuotes=t,e.fromSymbolSearchResult=function(e,t){{const{ticker:o,symbol:s}=t??e;return(0,n.isFeaturesetEnabled)("pay_attention_to_ticker_not_symbol")?(0,r.ensureDefined)(o??s):(0,r.ensureDefined)(s)}},e.fromSymbolInfo=o,e.fromSymbolMessage=function(e,t){return"symbol_resolved"===t.method?o(t.params[1]):e}}(s||(s={}))},27889:(e,t,o)=>{o.d(t,{createSearchSources:()=>a,filterSearchSources:()=>n,isAllSearchSourcesSelected:()=>r,splitSearchSourcesByGroup:()=>i});const s=[];function r(e){return""===e.value()}function n(e,t){return e.filter((e=>e.includes(t)))}function i(e){const t=new Map;e.forEach((e=>{t.has(e.group())?t.get(e.group()).push(e):t.set(e.group(),[e])}));for(const e of t.values()){e[0].group()!==ExchangeGroup.NorthAmerica&&e.sort(((e,t)=>e.name().toLowerCase()>t.name().toLowerCase()?1:-1))}return new Map([...t.entries()].sort((([e],[t])=>s.indexOf(e)-s.indexOf(t))))}function a(e,t){return t.map((t=>new e(t)))}},756:(e,t,o)=>{o.d(t,{createGroupColumns:()=>y,exchangeSelectDisabled:()=>h,getAllSymbolTypesValue:()=>u,getAvailableSearchSources:()=>l,getAvailableSymbolTypes:()=>d,getDefaultSearchSource:()=>c,getFeaturedSymbolName:()=>m,getSymbolFullName:()=>a,isOptionDefaultValue:()=>_,isSeparateSymbolSearchTabs:()=>S});var s=o(91599),r=o(27889);class n{constructor(e){this._exchange=e}value(){return this._exchange.value}name(){return(0,r.isAllSearchSourcesSelected)(this)?s.t(null,void 0,o(84020)):this._exchange.name}description(){return this._exchange.desc}country(){return this._exchange.country}providerId(){return this._exchange.providerId}group(){return this._exchange.group}includes(e){return function(e,t){const o=t.toLowerCase(),{name:s,desc:r,searchTerms:n}=e;return s.toLowerCase().includes(o)||r.toLowerCase().includes(o)||void 0!==n&&n.some((e=>e.toLowerCase().includes(o)))
}(this._exchange,e)}getRequestExchangeValue(){return this._exchange.value}getRequestCountryValue(){}}var i=o(95416);function a(e){if(e.fullName)return e.fullName;let t;return t=e.prefix||e.exchange?(e.prefix||e.exchange)+":"+e.name:e.name,t.replace(/<\/?[^>]+(>|$)/g,"")}function c(){const e=l();return e.find(r.isAllSearchSourcesSelected)||e[0]||null}function l(){return(0,r.createSearchSources)(n,(0,i.getExchanges)())}function d(){return window.ChartApiInstance.supportedSymbolsTypes()}function u(){return""}function h(e){return!!S&&!TAB_SOURCE_FILTER_MAP[e]}function m(e){return e.querySelector('[data-ss-item="featured"]')?.getAttribute("data-symbol-name")??null}function y(e,t=2){if(0===e.length)return[];if(1===t)return[e];const o=Math.floor(e.length/2)+e.length%2;return[e.slice(0,o),e.slice(o)].filter((e=>e.length>0))}const S=!1;function _(e){return"string"!=typeof e}},93419:(e,t,o)=>{o.r(t),o.d(t,{CompareModel:()=>w});var s=o(85842),r=o(16905),n=o(95847),i=o(66085),a=o(89659),c=o(5260),l=o(62352),d=o(95416),u=o(965);new Set((0,r.isFeaturesetEnabled)("widget")?["pro_name","short_name","description","exchange","type","country_code","provider_id","typespecs"]:["pro_name","short_name","description","exchange","type","country_code","provider_id","typespecs","logoid","currency-logoid","base-currency-logoid"]);const h=(0,d.getExchanges)(),m={};for(const e of h)m[e.value]={country:e.country,providerId:e.providerId};var y=o(95397),S=o(20833);function _(e){return(0,l.isCompareOrOverlayStudy)(e)}function g(e,t,o){const s=u.QualifiedSources.fromSymbolInfo(e),r=function(e){if(!e)return;const[t,o]=e.split(":");return o&&t&&m[t]?m[t]:void 0}(s),n={id:o?.id()||s,symbol:s,checked:t,title:e.name,description:e.description,exchangeName:e.exchange,country:r?.country,providerId:r?.providerId,marketType:e.type,study:o,isYield:(0,y.isYield)(e)};{const t=e;if(t.logo_urls&&t.logo_urls.length)if(t.logo_urls.length>1){const e=(0,S.logoDataFromQuotes)({"base-currency-logoid":t.logo_urls[0],"currency-logoid":t.logo_urls[1]});n.logoData=e??void 0}else{const e=(0,S.logoDataFromQuotes)({logoid:t.logo_urls[0]});n.logoData=e??void 0}t.exchange_logo&&(n.providerId=t.exchange_logo)}return n}function p(e,t,o,s){return{id:void 0!==o?o.id():e,symbol:e,checked:t,title:e,study:o,description:s}}var f=o(82287),b=o(96375),v=o(38470);var I=o(37636);class w{constructor(e){this._contentItemList=new a.WatchedValue([]),this._checkedSymbols=new Map,this._recentLength=10,this._isDataReady=new a.WatchedValue(!1),this._highlightedSymbol=new a.WatchedValue(null),this._defaultSymbolsDescriptions=new Map,this._idToStudyMap=new Map,this._chartSession=null,this._recentSymbolsEnabled=(0,r.isFeaturesetEnabled)("compare_recent_symbols_enabled"),this._preventHandleSourcesChange=!0,this.removeStudy=e=>{const{symbol:t,study:o}=e;if(!o)return;this._chartWidget.model().removeSource(o,!1);const s=this._checkedSymbols.get(t);s&&s.length>1?this._removeStudyIdFromCheckedSymbols(t,o.id()):this._checkedSymbols.delete(t),this._updateContentItemList(this._contentItemList.value(),!0)},
this._getResolveSymbolPromise=(e,t)=>new Promise((o=>{const r=(0,s.ensureNotNull)(this._chartSession).resolveSymbol((0,n.makeNextSymbolId)(),(0,i.encodeExtendedSymbolOrGetSimpleSymbolString)({symbol:e}),o);t&&t.set(e,r)})),this._chartWidget=e.activeChartWidget.value(),this._chartSession=this._chartWidget.model().model().chartApi();const t=new Set(this._loadRecent().reverse()),o=new Set,c=new Set,l=this._chartWidget.model().model().dataSources().filter(_),d=l.map((e=>{const t=e.symbolInfo();if(t)return Promise.resolve(u.QualifiedSources.fromSymbolInfo(t));const o=e.symbol();return(0,u.qualifyProName)(o)}));Promise.all(d).then((e=>{const s=e.map(((e,t)=>l[t]));e.forEach(((e,r)=>{const n=s[r],i=n.id();this._addStudyIdToCheckedSymbols(e,i),this._idToStudyMap.set(i,n),t.has(e)?o.add(e):c.add(e)}));const r=Array.from(t).filter((e=>this._checkedSymbols.has(e))).reduce(((e,t)=>(o.has(t)&&e.push(t),e)),[]).concat(Array.from(c)),n=Array.from(t);if(this._recentSymbolsEnabled&&n.length<this._recentLength){let e;e=[],this._chartWidget.compareSymbols()&&this._chartWidget.compareSymbols().forEach((t=>{e.push((0,u.qualifyProName)(t.symbol)),this._defaultSymbolsDescriptions.set(t.symbol,t.title)}));const t=[...n,...e];r.push(...t)}else r.push(...n);const i=Array.from(new Set(r));{const e=new Map,t=i.map((t=>this._getResolveSymbolPromise(t,e)));Promise.all(t).then((t=>this._handleInitProcess(r,(o=>{const s=e.get(o);return t.find((e=>e.params[0]===s))}),((e,t)=>u.QualifiedSources.fromSymbolMessage(t,e)),((e,t,o,s)=>"symbol_resolved"===e.method?g(e.params[1],o,s):p(t,o,s,this._getSymbolDescription(t))))))}}))}chartModel(){return this._chartWidget.model().model()}comparableOnSameScale(e){return this._chartWidget.model().model().mainSeries().isYield()&&Boolean(e.isYield)}handleSourcesChange(){if(this._preventHandleSourcesChange)return;const e=this.chartModel().dataSources().filter(_),t=new Set(e.map((e=>e.id())));Array.from(t).forEach((e=>{if(!this._checkedStudiesIds().has(e)){const t=this.chartModel().dataSourceForId(e)||null;if(null!==t&&_(t)){const t=this._getContentItemByStudyId(e);if(!t)return;this._addStudyIdToCheckedSymbols(t.symbol,e),this._saveRecent(t.symbol),this._updateContentItemList(this._contentItemList.value(),!0)}}}));Array.from(this._checkedStudiesIds()).forEach((e=>{if(!t.has(e)){const t=this._getContentItemByStudyId(e);if(!t)return;const o=this._checkedSymbols.get(t.symbol);o&&o.length>1?this._removeStudyIdFromCheckedSymbols(t.symbol,e):this._checkedSymbols.delete(t.symbol),this._updateContentItemList(this._contentItemList.value(),!0)}}))}studies(){return this._contentItemList.readonly()}isDataReady(){return this._isDataReady.readonly()}highlightedSymbol(){return this._highlightedSymbol.readonly()}applyStudy(e,t,o){(0,I.runOrSignInWithPromo)("compareSymbolsTool",{source:"Compare apply study"},(()=>{const s=this._chartWidget;if(!s)return;if(r=e,(0,v.isSeparatorItem)(r))return;var r;let n;switch(t){case c.CompareOption.SamePctScale:n=s.addCompareAsOverlay(e,o);break;case c.CompareOption.SameScale:
n=s.addCompareAsOverlay(e,o,!0);break;case c.CompareOption.NewPriceScale:n=s.addOverlayStudy(e,!0,o);break;case c.CompareOption.NewPane:n=s.addOverlayStudy(e,!1,o)}Promise.all([this._getResolveSymbolPromise(e),n]).then((t=>this._handleApplyProcess(t,(t=>u.QualifiedSources.fromSymbolMessage(e,t)),((e,t,o)=>"symbol_resolved"===e.method?g(e.params[1],!0,o):p(t,!0,o))))),b.emit("add_compare")}))}_snapshoter(){throw new Error("not implemented")}_handleApplyProcess(e,t,o){const[s,r]=e;if(!s||null===r)return;const n=r.id(),i=t(s),a=o(s,i,r);this._saveRecent(i),this._addStudyIdToCheckedSymbols(i,n),this._showNewItem(a,i,n)}_handleInitProcess(e,t,o,s){const r=[];for(const n of e){const e=t(n);if(!e)continue;const i=o(e,n),a=this._checkedSymbols.get(i),c=-1!==r.findIndex((e=>e.symbol===i));if(void 0===a||c)this._recentSymbolsEnabled&&r.push(s(e,i,!1));else for(const t of a)r.push(s(e,i,!0,this._idToStudyMap.get(t)))}this._updateContentItemList(r),this._isDataReady.setValue(!0)}_showNewItem(e,t,o){const s=this._contentItemList.value().map(this._updateChecked,this);s.unshift(e),this._recentSymbolsEnabled&&s.unshift({...e,id:t,study:void 0,checked:!1}),this._updateContentItemList(s),this._highlightedSymbol.setValue(o),setTimeout((()=>this._highlightedSymbol.setValue(null)),500)}_addStudyIdToCheckedSymbols(e,t){const o=this._checkedSymbols.get(e)||[];this._checkedSymbols.set(e,[...o,t])}_removeStudyIdFromCheckedSymbols(e,t){const o=this._checkedSymbols.get(e);if(o){const s=o.indexOf(t);o.splice(s,1),this._checkedSymbols.set(e,o)}}_updateChecked(e){const t=this._checkedSymbols.get(e.symbol),o=e.study?.id();return o?{...e,checked:Boolean(t&&t.includes(o))}:e}_updateContentItemList(e,t){const o=t?e.map(this._updateChecked,this):e,s=o.filter((e=>e.checked));if(this._recentSymbolsEnabled){const e=new Set,t=o.reduce(((t,o)=>(o.checked||e.has(o.symbol)||(t.push(o),e.add(o.symbol)),t)),[]).slice(0,this._recentLength);this._contentItemList.setValue(s.concat(t))}else this._contentItemList.setValue(s)}_checkedStudiesIds(){const e=[].concat(...Array.from(this._checkedSymbols.values()));return new Set(e)}_getContentItemByStudyId(e){const t=this._contentItemList.value(),o=t.findIndex((t=>t.study&&t.study.id()===e));return t[o]}_loadRecent(){if(!this._recentSymbolsEnabled)return[];return f.getJSON("CompareDialog.recent",[]).filter((e=>"string"==typeof e))}_saveRecent(e){if(!this._recentSymbolsEnabled)return;const t=new Set(this._loadRecent());t.has(e)&&t.delete(e),t.add(e),f.setJSON("CompareDialog.recent",Array.from(t).slice(-this._recentLength))}_getSymbolDescription(e){return this._defaultSymbolsDescriptions.size?this._defaultSymbolsDescriptions.get(e)??"":""}}w._snapshoter=null},5260:(e,t,o)=>{var s;o.d(t,{CompareOption:()=>s}),function(e){e[e.SamePctScale=0]="SamePctScale",e[e.NewPriceScale=1]="NewPriceScale",e[e.NewPane=2]="NewPane",e[e.SameScale=3]="SameScale"}(s||(s={}))}}]);