diff --git a/scalene/scalene-gui/index.html.template b/scalene/scalene-gui/index.html.template index 7ee3e5193..aec731562 100644 --- a/scalene/scalene-gui/index.html.template +++ b/scalene/scalene-gui/index.html.template @@ -126,7 +126,7 @@ size="22" placeholder="(OpenAI API key)" id="api-key" - oninput="checkApiKey(event.target.value)" + oninput="checkApiKey(event.target.value, document.getElementById('openai-compatibility-api-url').value)" /> @@ -147,6 +147,32 @@ +
`,a=`${n}`,o=window.open("");o.document.write(i+e+a),o.document.title=`${qe[r]} JSON Source`}function Ye(e,t){if(e.$schema){const n=(0,l.default)(e.$schema);t&&t!==n.library&&console.warn(`The given visualization spec is written in ${qe[n.library]}, but mode argument sets ${qe[t]??t}.`);const r=n.library;return Oe(je[r],`^${n.version.slice(1)}`)||console.warn(`The input spec uses ${qe[r]} ${n.version}, but the current version of ${qe[r]} is v${je[r]}.`),r}return"mark"in e||"encoding"in e||"layer"in e||"hconcat"in e||"vconcat"in e||"facet"in e||"repeat"in e?"vega-lite":"marks"in e||"signals"in e||"scales"in e||"axes"in e?"vega":t??"vega"}function Xe(e){return!(!e||!("load"in e))}function Ke(e){return Xe(e)?e:$e.loader(e)}async function Je(e,t,n={}){let r,s;(0,a.isString)(t)?(s=Ke(n.loader),r=JSON.parse(await s.load(t))):r=t;const d=function(e){const t=e.usermeta?.embedOptions??{};return(0,a.isString)(t.defaultStyle)&&(t.defaultStyle=!1),t}(r),f=d.loader;s&&!f||(s=Ke(n.loader??f));const p=await Qe(d,s),h=await Qe(n,s),g={...Pe(h,p),config:(0,a.mergeConfig)(h.config??{},p.config??{})};return await async function(e,t,n={},r){const s=n.theme?(0,a.mergeConfig)(u[n.theme],n.config??{}):n.config,d=(0,a.isBoolean)(n.actions)?n.actions:Pe({},Ue,n.actions??{}),f={...ze,...n.i18n},p=n.renderer??"canvas",h=n.logLevel??$e.Warn,g=n.downloadFileName??"visualization",m="string"==typeof e?document.querySelector(e):e;if(!m)throw new Error(`${e} does not exist`);if(!1!==n.defaultStyle){const e="vega-embed-style",{root:t,rootContainer:r}=function(e){const t=e.getRootNode?e.getRootNode():document;return t instanceof ShadowRoot?{root:t,rootContainer:t}:{root:document,rootContainer:document.head??document.body}}(m);if(!t.getElementById(e)){const t=document.createElement("style");t.id=e,t.innerHTML=void 0===n.defaultStyle||!0===n.defaultStyle?Fe.toString():n.defaultStyle,r.appendChild(t)}}const y=Ye(t,n.mode);let v=He[y](t,s);if("vega-lite"===y&&v.$schema){const e=(0,l.default)(v.$schema);Oe(je.vega,`^${e.version.slice(1)}`)||console.warn(`The compiled spec uses Vega ${e.version}, but current version is v${je.vega}.`)}m.classList.add("vega-embed"),d&&m.classList.add("has-actions");m.innerHTML="";let b=m;if(d){const e=document.createElement("div");e.classList.add(Ve),m.appendChild(e),b=e}const x=n.patch;x&&(v=x instanceof Function?x(v):R(v,x,!0,!1).newDocument);n.formatLocale&&$e.formatLocale(n.formatLocale);n.timeFormatLocale&&$e.timeFormatLocale(n.timeFormatLocale);if(n.expressionFunctions)for(const e in n.expressionFunctions){const t=n.expressionFunctions[e];"fn"in t?$e.expressionFunction(e,t.fn,t.visitor):t instanceof Function&&$e.expressionFunction(e,t)}const{ast:E}=n,S=$e.parse(v,"vega-lite"===y?{}:s,{ast:E}),w=new(n.viewClass||$e.View)(S,{loader:r,logLevel:h,renderer:p,...E?{expr:$e.expressionInterpreter??n.expr??o.expressionInterpreter}:{}});if(w.addSignalListener("autosize",((e,t)=>{const{type:n}=t;"fit-x"==n?(b.classList.add("fit-x"),b.classList.remove("fit-y")):"fit-y"==n?(b.classList.remove("fit-x"),b.classList.add("fit-y")):"fit"==n?b.classList.add("fit-x","fit-y"):b.classList.remove("fit-x","fit-y")})),!1!==n.tooltip){const{loader:e,tooltip:t}=n,r=e&&!Xe(e)?e?.baseURL:void 0,i="function"==typeof t?t:new c.Handler({baseURL:r,...!0===t?{}:t}).call;w.tooltip(i)}let _,{hover:A}=n;void 0===A&&(A="vega"===y);if(A){const{hoverSet:e,updateSet:t}="boolean"==typeof A?{}:A;w.hover(e,t)}n&&(null!=n.width&&w.width(n.width),null!=n.height&&w.height(n.height),null!=n.padding&&w.padding(n.padding));if(await w.initialize(b,n.bind).runAsync(),!1!==d){let e=m;if(!1!==n.defaultStyle||n.forceActionsMenu){const t=document.createElement("details");t.title=f.CLICK_TO_VIEW_ACTIONS,m.append(t),e=t;const n=document.createElement("summary");n.innerHTML=Ge,t.append(n),_=e=>{t.contains(e.target)||t.removeAttribute("open")},document.addEventListener("click",_)}const r=document.createElement("div");if(e.append(r),r.classList.add("vega-actions"),!0===d||!1!==d.export)for(const e of["svg","png"])if(!0===d||!0===d.export||d.export[e]){const t=f[`${e.toUpperCase()}_ACTION`],i=document.createElement("a"),o=(0,a.isObject)(n.scaleFactor)?n.scaleFactor[e]:n.scaleFactor;i.text=t,i.href="#",i.target="_blank",i.download=`${g}.${e}`,i.addEventListener("mousedown",(async function(t){t.preventDefault();const n=await w.toImageURL(e,o);this.href=n})),r.append(i)}if(!0===d||!1!==d.source){const e=document.createElement("a");e.text=f.SOURCE_ACTION,e.href="#",e.addEventListener("click",(function(e){We((0,i.default)(t),n.sourceHeader??"",n.sourceFooter??"",y),e.preventDefault()})),r.append(e)}if("vega-lite"===y&&(!0===d||!1!==d.compiled)){const e=document.createElement("a");e.text=f.COMPILED_ACTION,e.href="#",e.addEventListener("click",(function(e){We((0,i.default)(v),n.sourceHeader??"",n.sourceFooter??"","vega"),e.preventDefault()})),r.append(e)}if(!0===d||!1!==d.editor){const e=n.editorUrl??"https://vega.github.io/editor/",a=document.createElement("a");a.text=f.EDITOR_ACTION,a.href="#",a.addEventListener("click",(function(n){!function(e,t,n){const r=e.open(t),{origin:i}=new URL(t);let a=40;e.addEventListener("message",(function t(n){n.source===r&&(a=0,e.removeEventListener("message",t,!1))}),!1),setTimeout((function e(){a<=0||(r.postMessage(n,i),setTimeout(e,250),a-=1)}),250)}(window,e,{config:s,mode:x?"vega":y,renderer:p,spec:(0,i.default)(x?v:t)}),n.preventDefault()})),r.append(a)}}function C(){_&&document.removeEventListener("click",_),w.finalize()}return{view:w,spec:t,vgSpec:v,finalize:C,embedOptions:n}}(e,r,g,s)}async function Qe(e,t){const n=(0,a.isString)(e.config)?JSON.parse(await t.load(e.config)):e.config??{},r=(0,a.isString)(e.patch)?JSON.parse(await t.load(e.patch)):e.patch;return{...e,...r?{patch:r}:{},...n?{config:n}:{}}}},73784:(e,t,n)=>{"use strict";n.r(t),n.d(t,{axisticks:()=>l,datajoin:()=>u,encode:()=>d,legendentries:()=>f,linkpath:()=>y,pie:()=>S,scale:()=>A,sortitems:()=>R,stack:()=>P});var r=n(24988),i=n(14588),a=n(26372),o=n(61388),s=n(82226);function l(e){r.Transform.call(this,null,e)}function u(e){r.Transform.call(this,null,e)}function c(){return(0,r.ingest)({})}function d(e){r.Transform.call(this,null,e)}function f(e){r.Transform.call(this,[],e)}(0,a.inherits)(l,r.Transform,{transform(e,t){if(this.value&&!e.modified())return t.StopPropagation;var n=t.dataflow.locale(),a=t.fork(t.NO_SOURCE|t.NO_FIELDS),o=this.value,s=e.scale,l=null==e.count?e.values?e.values.length:10:e.count,u=(0,i.tickCount)(s,l,e.minstep),c=e.format||(0,i.tickFormat)(n,s,u,e.formatSpecifier,e.formatType,!!e.values),d=e.values?(0,i.validTicks)(s,e.values,u):(0,i.tickValues)(s,u);return o&&(a.rem=o),o=d.map(((e,t)=>(0,r.ingest)({index:t/(d.length-1||1),value:e,label:c(e)}))),e.extra&&o.length&&o.push((0,r.ingest)({index:-1,extra:{value:o[0].value},label:""})),a.source=o,a.add=o,this.value=o,a}}),(0,a.inherits)(u,r.Transform,{transform(e,t){var n=t.dataflow,i=t.fork(t.NO_SOURCE|t.NO_FIELDS),o=e.item||c,s=e.key||r.tupleid,l=this.value;return(0,a.isArray)(i.encode)&&(i.encode=null),l&&(e.modified("key")||t.modified(s))&&(0,a.error)("DataJoin does not support modified key function or fields."),l||(t=t.addAll(),this.value=l=function(e){const t=(0,a.fastmap)().test((e=>e.exit));return t.lookup=n=>t.get(e(n)),t}(s)),t.visit(t.ADD,(e=>{const t=s(e);let n=l.get(t);n?n.exit?(l.empty--,i.add.push(n)):i.mod.push(n):(n=o(e),l.set(t,n),i.add.push(n)),n.datum=e,n.exit=!1})),t.visit(t.MOD,(e=>{const t=s(e),n=l.get(t);n&&(n.datum=e,i.mod.push(n))})),t.visit(t.REM,(e=>{const t=s(e),n=l.get(t);e!==n.datum||n.exit||(i.rem.push(n),n.exit=!0,++l.empty)})),t.changed(t.ADD_MOD)&&i.modifies("datum"),(t.clean()||e.clean&&l.empty>n.cleanThreshold)&&n.runAfter(l.clean),i}}),(0,a.inherits)(d,r.Transform,{transform(e,t){var n=t.fork(t.ADD_REM),r=e.mod||!1,i=e.encoders,o=t.encode;if((0,a.isArray)(o)){if(!n.changed()&&!o.every((e=>i[e])))return t.StopPropagation;o=o[0],n.encode=null}var s="enter"===o,l=i.update||a.falsy,u=i.enter||a.falsy,c=i.exit||a.falsy,d=(o&&!s?i[o]:l)||a.falsy;if(t.changed(t.ADD)&&(t.visit(t.ADD,(t=>{u(t,e),l(t,e)})),n.modifies(u.output),n.modifies(l.output),d!==a.falsy&&d!==l&&(t.visit(t.ADD,(t=>{d(t,e)})),n.modifies(d.output))),t.changed(t.REM)&&c!==a.falsy&&(t.visit(t.REM,(t=>{c(t,e)})),n.modifies(c.output)),s||d!==a.falsy){const i=t.MOD|(e.modified()?t.REFLOW:0);s?(t.visit(i,(t=>{const i=u(t,e)||r;(d(t,e)||i)&&n.mod.push(t)})),n.mod.length&&n.modifies(u.output)):t.visit(i,(t=>{(d(t,e)||r)&&n.mod.push(t)})),n.mod.length&&n.modifies(d.output)}return n.changed()?n:t.StopPropagation}}),(0,a.inherits)(f,r.Transform,{transform(e,t){if(null!=this.value&&!e.modified())return t.StopPropagation;var n,o,s,l,u,c=t.dataflow.locale(),d=t.fork(t.NO_SOURCE|t.NO_FIELDS),f=this.value,p=e.type||i.SymbolLegend,h=e.scale,g=+e.limit,m=(0,i.tickCount)(h,null==e.count?5:e.count,e.minstep),y=!!e.values||p===i.SymbolLegend,v=e.format||(0,i.labelFormat)(c,h,m,p,e.formatSpecifier,e.formatType,y),b=e.values||(0,i.labelValues)(h,m);return f&&(d.rem=f),p===i.SymbolLegend?(g&&b.length>g?(t.dataflow.warn("Symbol legend count exceeds limit, filtering items."),f=b.slice(0,g-1),u=!0):f=b,(0,a.isFunction)(s=e.size)?(e.values||0!==h(f[0])||(f=f.slice(1)),l=f.reduce(((t,n)=>Math.max(t,s(n,e))),0)):s=(0,a.constant)(l=s||8),f=f.map(((t,n)=>(0,r.ingest)({index:n,label:v(t,n,f),value:t,offset:l,size:s(t,e)}))),u&&(u=b[f.length],f.push((0,r.ingest)({index:f.length,label:`\u2026${b.length-f.length} entries`,value:u,offset:l,size:s(u,e)})))):p===i.GradientLegend?(n=h.domain(),o=(0,i.scaleFraction)(h,n[0],(0,a.peek)(n)),b.length<3&&!e.values&&n[0]!==(0,a.peek)(n)&&(b=[n[0],(0,a.peek)(n)]),f=b.map(((e,t)=>(0,r.ingest)({index:t,label:v(e,t,b),value:e,perc:o(e)})))):(s=b.length-1,o=(0,i.labelFraction)(h),f=b.map(((e,t)=>(0,r.ingest)({index:t,label:v(e,t,b),value:e,perc:t?o(e):0,perc2:t===s?1:o(b[t+1])})))),d.source=f,d.add=f,this.value=f,d}});const p=e=>e.source.x,h=e=>e.source.y,g=e=>e.target.x,m=e=>e.target.y;function y(e){r.Transform.call(this,{},e)}y.Definition={type:"LinkPath",metadata:{modifies:!0},params:[{name:"sourceX",type:"field",default:"source.x"},{name:"sourceY",type:"field",default:"source.y"},{name:"targetX",type:"field",default:"target.x"},{name:"targetY",type:"field",default:"target.y"},{name:"orient",type:"enum",default:"vertical",values:["horizontal","vertical","radial"]},{name:"shape",type:"enum",default:"line",values:["line","arc","curve","diagonal","orthogonal"]},{name:"require",type:"signal"},{name:"as",type:"string",default:"path"}]},(0,a.inherits)(y,r.Transform,{transform(e,t){var n=e.sourceX||p,r=e.sourceY||h,i=e.targetX||g,o=e.targetY||m,s=e.as||"path",l=e.orient||"vertical",u=e.shape||"line",c=E.get(u+"-"+l)||E.get(u);return c||(0,a.error)("LinkPath unsupported type: "+e.shape+(e.orient?"-"+e.orient:"")),t.visit(t.SOURCE,(e=>{e[s]=c(n(e),r(e),i(e),o(e))})),t.reflow(e.modified()).modifies(s)}});const v=(e,t,n,r)=>"M"+e+","+t+"L"+n+","+r,b=(e,t,n,r)=>{var i=n-e,a=r-t,o=Math.hypot(i,a)/2;return"M"+e+","+t+"A"+o+","+o+" "+180*Math.atan2(a,i)/Math.PI+" 0 1 "+n+","+r},x=(e,t,n,r)=>{const i=n-e,a=r-t,o=.2*(i+a),s=.2*(a-i);return"M"+e+","+t+"C"+(e+o)+","+(t+s)+" "+(n+s)+","+(r-o)+" "+n+","+r},E=(0,a.fastmap)({line:v,"line-radial":(e,t,n,r)=>v(t*Math.cos(e),t*Math.sin(e),r*Math.cos(n),r*Math.sin(n)),arc:b,"arc-radial":(e,t,n,r)=>b(t*Math.cos(e),t*Math.sin(e),r*Math.cos(n),r*Math.sin(n)),curve:x,"curve-radial":(e,t,n,r)=>x(t*Math.cos(e),t*Math.sin(e),r*Math.cos(n),r*Math.sin(n)),"orthogonal-horizontal":(e,t,n,r)=>"M"+e+","+t+"V"+r+"H"+n,"orthogonal-vertical":(e,t,n,r)=>"M"+e+","+t+"H"+n+"V"+r,"orthogonal-radial":(e,t,n,r)=>{const i=Math.cos(e),a=Math.sin(e),o=Math.cos(n),s=Math.sin(n);return"M"+t*i+","+t*a+"A"+t+","+t+" 0 0,"+((Math.abs(n-e)>Math.PI?n<=e:n>e)?1:0)+" "+t*o+","+t*s+"L"+r*o+","+r*s},"diagonal-horizontal":(e,t,n,r)=>{const i=(e+n)/2;return"M"+e+","+t+"C"+i+","+t+" "+i+","+r+" "+n+","+r},"diagonal-vertical":(e,t,n,r)=>{const i=(t+r)/2;return"M"+e+","+t+"C"+e+","+i+" "+n+","+i+" "+n+","+r},"diagonal-radial":(e,t,n,r)=>{const i=Math.cos(e),a=Math.sin(e),o=Math.cos(n),s=Math.sin(n),l=(t+r)/2;return"M"+t*i+","+t*a+"C"+l*i+","+l*a+" "+l*o+","+l*s+" "+r*o+","+r*s}});function S(e){r.Transform.call(this,null,e)}S.Definition={type:"Pie",metadata:{modifies:!0},params:[{name:"field",type:"field"},{name:"startAngle",type:"number",default:0},{name:"endAngle",type:"number",default:6.283185307179586},{name:"sort",type:"boolean",default:!1},{name:"as",type:"string",array:!0,length:2,default:["startAngle","endAngle"]}]},(0,a.inherits)(S,r.Transform,{transform(e,t){var n,r,i,s=e.as||["startAngle","endAngle"],l=s[0],u=s[1],c=e.field||a.one,d=e.startAngle||0,f=null!=e.endAngle?e.endAngle:2*Math.PI,p=t.source,h=p.map(c),g=h.length,m=d,y=(f-d)/(0,o.sum)(h),v=(0,o.range)(g);for(e.sort&&v.sort(((e,t)=>h[e]-h[t])),n=0;n