blockcharts 0.0.2 → 0.0.3
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/README.md +118 -17
- package/package.json +43 -6
- package/release/bc.d.ts +35 -2
- package/release/blocks/guide.axis.js +1 -1
- package/release/blocks/guide.grid.js +1 -1
- package/release/blocks/guide.kpi.js +1 -1
- package/release/blocks/guide.legend.js +1 -1
- package/release/blocks/interaction.animate.js +1 -1
- package/release/blocks/interaction.brush.js +1 -1
- package/release/blocks/interaction.click.js +3 -0
- package/release/blocks/interaction.crosshair.js +1 -1
- package/release/blocks/interaction.legend-filter.js +1 -1
- package/release/blocks/interaction.tooltip.js +2 -2
- package/release/blocks/interaction.zoom-controls.js +1 -1
- package/release/blocks/interaction.zoom.js +1 -1
- package/release/blocks/lib.columns.js +1 -1
- package/release/blocks/lib.curve.js +1 -1
- package/release/blocks/lib.pointer.js +2 -2
- package/release/blocks/lib.stats.js +1 -1
- package/release/blocks/lib.ticks.js +1 -1
- package/release/blocks/lib.view.js +1 -1
- package/release/blocks/mark.arc.js +1 -1
- package/release/blocks/mark.area.js +1 -1
- package/release/blocks/mark.boxplot.js +1 -1
- package/release/blocks/mark.candlestick.js +1 -1
- package/release/blocks/mark.line.js +1 -1
- package/release/blocks/mark.point.js +1 -1
- package/release/blocks/mark.polygon.js +1 -1
- package/release/blocks/mark.rect.js +1 -1
- package/release/blocks/mark.rule.js +1 -1
- package/release/blocks/mark.sankey.js +1 -1
- package/release/blocks/mark.text.js +1 -1
- package/release/blocks/mark.violin.js +1 -1
- package/release/blocks/renderer.canvas.js +1 -1
- package/release/blocks/renderer.svg.js +1 -1
- package/release/blocks/scale.band.js +1 -1
- package/release/blocks/scale.color.js +1 -1
- package/release/blocks/scale.linear.js +1 -1
- package/release/blocks/scale.log.js +1 -1
- package/release/blocks/scale.sequential.js +1 -1
- package/release/blocks/scale.size.js +1 -1
- package/release/blocks/scale.time.js +1 -1
- package/release/blocks/transform.aggregate.js +1 -1
- package/release/blocks/transform.bin.js +1 -1
- package/release/blocks/transform.calculate.js +1 -1
- package/release/blocks/transform.calendar.js +1 -1
- package/release/blocks/transform.contour.js +1 -1
- package/release/blocks/transform.decimate.js +1 -1
- package/release/blocks/transform.density.js +1 -1
- package/release/blocks/transform.filter.js +1 -1
- package/release/blocks/transform.fold.js +1 -1
- package/release/blocks/transform.funnel.js +1 -1
- package/release/blocks/transform.hexbin.js +1 -1
- package/release/blocks/transform.highlight.js +1 -1
- package/release/blocks/transform.marimekko.js +1 -1
- package/release/blocks/transform.quartiles.js +1 -1
- package/release/blocks/transform.sankey.js +1 -1
- package/release/blocks/transform.sort.js +1 -1
- package/release/blocks/transform.stack.js +1 -1
- package/release/blocks/transform.treemap.js +1 -1
- package/release/blocks/transform.waterfall.js +1 -1
- package/release/blocks/transform.window.js +1 -1
- package/release/core.js +3 -3
- package/release/frameworks/controller.d.mts +51 -0
- package/release/frameworks/controller.mjs +181 -0
- package/release/frameworks/element.d.mts +32 -0
- package/release/frameworks/element.mjs +95 -0
- package/release/frameworks/react.d.mts +10 -0
- package/release/frameworks/react.mjs +30 -0
- package/release/frameworks/svelte.d.mts +9 -0
- package/release/frameworks/svelte.mjs +17 -0
- package/release/frameworks/vue.d.mts +40 -0
- package/release/frameworks/vue.mjs +44 -0
- package/release/kits/basic.js +8 -5
- package/release/kits/basic.mjs +8 -5
- package/release/kits/composition.js +8 -5
- package/release/kits/composition.mjs +8 -5
- package/release/kits/dashboard.js +8 -5
- package/release/kits/dashboard.mjs +8 -5
- package/release/kits/full.js +8 -5
- package/release/kits/full.mjs +8 -5
- package/release/kits/timeseries.js +8 -5
- package/release/kits/timeseries.mjs +8 -5
- package/release/loader.js +1 -1
- package/release/manifest.json +227 -122
- package/release/schema/chart.schema.json +4155 -0
- package/release/schema/page.schema.json +4547 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/*! blockcharts 0.0.
|
|
2
|
-
"use strict";(function(){const ve="0.0.2",Ee=globalThis,ue=Ee.BC;if(ue&&typeof ue.define=="function"&&typeof ue.version=="string"){ue.version!==ve&&console.warn(`blockcharts core ${ve} ignored: ${ue.version} is already loaded`);return}const St=["lib","scale","transform","mark","guide","interaction","renderer"],pe=["top","right","bottom","left"],xt={top:16,right:16,bottom:16,left:16},He=24,F=new Map,ce=new Map,se=new Map,he=new Map,Ke=new Map,je=64*1024*1024;function Ct(t){if(!t||St.indexOf(t.role)<0||typeof t.type!="string"||!t.type)throw new Error("BC.define: a block needs a valid role and type");const e=`${t.role}.${t.type}`;{const r=["position","color","size"],c=["number","date","category"];if(t.role==="scale"&&!(r.indexOf(t.output)>=0&&c.indexOf(t.input)>=0))throw new Error(`BC.define: ${e} must declare its output ("position", "color" or "size") and its input ("number", "date" or "category")`);if(t.role==="mark")for(const a of Object.keys(t.channels||{})){const y=t.channels[a].accepts;if(y&&!(r.indexOf(y.output)>=0&&(y.input===void 0||Array.isArray(y.input)&&y.input.every(m=>c.indexOf(m)>=0))))throw new Error(`BC.define: channel "${a}" of ${e} accepts { output: "position", "color" or "size", input: a list of "number", "date", "category" }`)}}const o=F.get(e);if(o){o.version!==t.version&&console.warn(`BC.define: ${e} v${t.version} ignored, v${o.version} is already registered`);return}F.set(e,t)}function Ze(t){if(t instanceof Float64Array)return t;for(let o=0;o<t.length;o++){const r=t[o];if(typeof r!="number"&&r!=null)return t}const e=new Float64Array(t.length);for(let o=0;o<t.length;o++){const r=t[o];e[o]=typeof r=="number"?r:NaN}return e}function Se(t){const e={};let o=0;const r=c=>{if(c==="__proto__")throw new Error('BC.data: a column cannot be named "__proto__"; rename it');return c};if(Array.isArray(t)){const c=new Set;t.forEach((a,y)=>{if(!a||typeof a!="object"||Array.isArray(a))throw new Error(`BC.data: row ${y} is not an object`);for(const m of Object.keys(a))c.add(r(m))});for(const a of c)e[a]=Ze(t.map(y=>y[a]));o=t.length}else if(t&&typeof t=="object"&&t.columns&&typeof t.columns=="object"){const c=t.columns,a=Object.keys(c).map(r);for(const y of a)if(!Array.isArray(c[y])&&!(c[y]instanceof Float64Array))throw new Error(`BC.data: column "${y}" is not an array`);o=a.length?c[a[0]].length:0;for(const y of a){if(c[y].length!==o)throw new Error(`BC.data: column "${y}" has ${c[y].length} values, expected ${o}`);e[y]=Ze(c[y])}}else throw new Error("BC.data: a dataset is an array of rows or { columns }");return{length:o,columns:e}}const xe=t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&typeof t.encoding=="string",Ge=function(e){const o=e.replace(/\s+/g,"");if(o.length%4===1||!/^[A-Za-z0-9+/]*={0,2}$/.test(o))throw new Error("the data is not valid base64");if(typeof atob!="function")throw new Error("this environment has no atob(), cannot decode base64");const r=atob(o),c=new Uint8Array(r.length);for(let a=0;a<r.length;a++)c[a]=r.charCodeAt(a);return c},Xe=async function(e,o){const r=globalThis.DecompressionStream;if(typeof r!="function"||typeof Blob!="function")throw new Error('this browser cannot decompress gzip data (no DecompressionStream); store the dataset as plain rows or "base64"');const c=new Blob([e]).stream().pipeThrough(new r("gzip")).getReader(),a=[];let y=0;for(;;){let w;try{w=await c.read()}catch{throw new Error("the data is not valid gzip")}const{done:N,value:z}=w;if(N)break;if(y+=z.length,y>o)throw await c.cancel(),new Error(`the decoded data is larger than ${je/1024/1024} MB, refusing to unpack it`);a.push(z)}const m=new Uint8Array(y);let $=0;for(const w of a)m.set(w,$),$+=w.length;return m},Ye={float32:{size:4,ctor:Float32Array,get:"getFloat32"},float64:{size:8,ctor:Float64Array,get:"getFloat64"},int8:{size:1,ctor:Int8Array,get:"getInt8"},int16:{size:2,ctor:Int16Array,get:"getInt16"},int32:{size:4,ctor:Int32Array,get:"getInt32"},uint8:{size:1,ctor:Uint8Array,get:"getUint8"},uint16:{size:2,ctor:Uint16Array,get:"getUint16"},uint32:{size:4,ctor:Uint32Array,get:"getUint32"}},Dt=new Uint8Array(new Uint16Array([1]).buffer)[0]===1,Qe=t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&!(t instanceof Float64Array)&&typeof t.dtype=="string",et=t=>{const e=t&&typeof t=="object"&&!Array.isArray(t)?t.columns:void 0;return!!e&&typeof e=="object"&&Object.keys(e).some(o=>Qe(e[o]))},Mt=async function(e,o,r){const c=Ye[o.dtype];if(!c)throw new Error(`column "${e}": unknown dtype "${o.dtype}" (use ${Object.keys(Ye).join(", ")})`);if(o.encoding!=="base64"&&o.encoding!=="gzip+base64")throw new Error(`column "${e}": unknown encoding "${o.encoding}" (use "base64" or "gzip+base64")`);if(typeof o.data!="string")throw new Error(`column "${e}": a binary column needs a "data" string`);let a;try{a=Ge(o.data),o.encoding==="gzip+base64"&&(a=await Xe(a,r.left))}catch($){throw new Error(`column "${e}": ${$ instanceof Error?$.message:String($)}`)}if(a.length%c.size!==0)throw new Error(`column "${e}": ${a.length} bytes is not a whole number of ${o.dtype} values`);const y=a.length/c.size;if(r.left-=y*8,r.left<0)throw new Error(`the decoded data is larger than ${je/1024/1024} MB, refusing to unpack it`);const m=new Float64Array(y);if(Dt){const $=a.byteOffset%c.size===0?a.buffer:a.slice().buffer,w=a.byteOffset%c.size===0?a.byteOffset:0;m.set(new c.ctor($,w,y))}else{const $=new DataView(a.buffer,a.byteOffset,a.length);for(let w=0;w<y;w++)m[w]=$[c.get](w*c.size,!0)}return m},tt=async function(e,o){if(!et(e))return e;const r=e.columns,c=Object.create(null);for(const a of Object.keys(r))c[a]=Qe(r[a])?await Mt(a,r[a],o):r[a];return{columns:c}},zt=async function(e){const o={left:je};if(!xe(e))return Se(await tt(e,o));if(typeof e.data!="string")throw new Error('an encoded dataset needs a "data" string');if(e.encoding!=="base64"&&e.encoding!=="gzip+base64")throw new Error(`unknown encoding "${e.encoding}" (use "base64" or "gzip+base64")`);let r=Ge(e.data);e.encoding==="gzip+base64"&&(r=await Xe(r,o.left)),o.left-=r.length;let c;try{c=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(r))}catch(a){throw new Error("the decoded data is not UTF-8 JSON: "+(a instanceof Error?a.message:String(a)))}if(xe(c))throw new Error("an encoded dataset cannot contain another encoded dataset");return Se(await tt(c,o))};function nt(t,e){if(xe(e)||et(e)){he.delete(t);const r=zt(e).then(c=>{se.get(t)===r&&ce.set(t,c)},c=>{if(se.get(t)!==r)return;const a=c instanceof Error?c.message:String(c);he.set(t,a),console.error(`[blockcharts] dataset "${t}": ${a}`)}).then(()=>{se.get(t)===r&&se.delete(t)});se.set(t,r);return}const o=Se(e);se.delete(t),he.delete(t),ce.set(t,o)}function Nt(){return Promise.all(Array.from(se.values())).then(()=>{})}function ie(t,e,o){const r=t[e];if(r===void 0)return o&&o.default!==void 0?{value:o.default}:null;const c=o&&o.unscaled?void 0:o&&o.sharesScale||e;if(typeof r=="string")return{field:r,scale:c};if(r&&typeof r=="object"){const a=r;if(typeof a.field=="string")return{field:a.field,scale:typeof a.scale=="string"?a.scale:c};if(a.value!==void 0){const y=typeof a.scale=="string"?a.scale:c==="x"||c==="y"?c:void 0;return y!==void 0?{value:a.value,scale:y}:{value:a.value}}}}function be(t,e){return e.range!==void 0?e.range:t==="x"?"width":t==="y"?"height":void 0}function Ce(t,e,o){const r=be(t,e);return r==="width"?[o.x,o.x+o.w]:r==="height"?[o.y+o.h,o.y]:Array.isArray(r)?r:[]}function rt(t){const e=t&&typeof t=="object"?t.data:void 0;return typeof e!="string"?"data must be the name of a dataset":se.has(e)?`dataset "${e}" is still being decoded (await BC.ready())`:he.has(e)?`dataset "${e}" could not be loaded: ${he.get(e)}`:ce.has(e)?null:`dataset "${e}" is not in the data lake`}const Ft=function(e){const o=[],r=(c,a)=>{const y=a&&a.type;if(typeof y=="string"){const m=`${c}.${y}`;o.indexOf(m)<0&&o.push(m)}};if(!e)return o;if(Array.isArray(e.transforms)&&e.transforms.forEach(c=>r("transform",c)),e.scales)for(const c of Object.keys(e.scales))r("scale",e.scales[c]);return Array.isArray(e.marks)&&e.marks.forEach(c=>r("mark",c)),Array.isArray(e.guides)&&e.guides.forEach(c=>r("guide",c)),Array.isArray(e.interaction)&&e.interaction.forEach(c=>r("interaction",c)),r("renderer",{type:e.renderer||"svg"}),o},ot=["id","data","transforms","size","padding","title","alt","scales","guides","marks","interaction","view","responsive","renderer","locale"],st=function(e){const o=[],r=(i,f)=>o.push({level:"error",path:i,message:f}),c=(i,f)=>o.push({level:"warn",path:i,message:f});if(!e||typeof e!="object")return r("","the spec must be an object"),o;const a=(i,f)=>i.output===f.output&&(!f.input||f.input.indexOf(i.input)>=0),y=(i,f)=>{const g=(p,I)=>{let U=Array.from({length:I.length+1},(S,R)=>R);for(let S=1;S<=p.length;S++){const R=[S];for(let x=1;x<=I.length;x++)R[x]=Math.min(U[x]+1,R[x-1]+1,U[x-1]+(p[S-1]===I[x-1]?0:1));U=R}return U[I.length]};let k,j=3;for(const p of f){const I=p.toLowerCase()===i.toLowerCase()?0:g(i,p);I<j&&([k,j]=[p,I])}return k},m=(i,f)=>{const g=y(i,f);return g?`; did you mean "${g}"?`:""};for(const i of Object.keys(e))ot.indexOf(i)<0&&c(i,`unknown key "${i}"${m(i,ot)}`);for(const i of["transforms","guides","interaction"])e[i]!==void 0&&!Array.isArray(e[i])&&r(i,`${i} must be a list: [{ "type": ... }]`);if(e.scales!==void 0&&(!e.scales||typeof e.scales!="object"||Array.isArray(e.scales))&&r("scales",'scales must map names to scales: { "x": { "type": "band" } }'),e.padding!==void 0)if(typeof e.padding=="number")(!isFinite(e.padding)||e.padding<0)&&r("padding","padding must be a number of px, 0 or more, or one per side");else if(!e.padding||typeof e.padding!="object"||Array.isArray(e.padding))r("padding",'padding must be { "top": 8, "right": 8, "bottom": 30, "left": 40 } in px, or one number for every side');else for(const i of Object.keys(e.padding)){const f=e.padding[i];pe.indexOf(i)<0?c(`padding.${i}`,`unknown side "${i}"${m(i,pe)}`):(typeof f!="number"||!isFinite(f)||f<0)&&r(`padding.${i}`,`padding.${i} must be a number of px, 0 or more`)}if(e.title!==void 0&&typeof e.title!="string"&&r("title","title must be text"),e.alt!==void 0&&typeof e.alt!="string"&&r("alt","alt must be text: what the chart shows, in a sentence"),e.id!==void 0&&typeof e.id!="string"&&r("id","id must be text"),e.responsive!==void 0&&typeof e.responsive!="boolean"&&r("responsive","responsive must be true or false"),e.renderer!==void 0&&typeof e.renderer!="string"&&r("renderer",'renderer must be the name of one: "svg", "canvas"'),e.locale!==void 0){let i=!1;try{i=typeof e.locale=="string"&&Intl.getCanonicalLocales(e.locale).length===1}catch{i=!1}i||r("locale",`locale ${JSON.stringify(e.locale)} is not a language tag like "en-US", "de" or "ja"`)}const $=(i,f,g)=>{try{Pe(g)}catch(k){r(i,`${f}: ${k.message}`)}},w=i=>typeof i=="string"&&/^\s*(?:#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})|(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\([-+\w.%,\s/]*\)|[a-z]+|var\(\s*--[\w-]+\s*(?:,\s*(?:#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})|(?:rgba?|hsla?)\([-+\w.%,\s/]*\)|[a-z]+)\s*)?\))\s*$/i.test(i),N=i=>`${{position:"places",color:"colors",size:"sizes"}[i.output]} ${i.input?i.input.map(f=>({number:"numbers",date:"dates",category:"categories"})[f]).join(" or "):"values"}`,z=typeof e.data=="string"&&!se.has(e.data)?ce.get(e.data):void 0,M=rt(e);M&&r("data",M);const _=[z?{...z.columns}:void 0];if(Array.isArray(e.transforms))for(const i of e.transforms){let f=_[_.length-1];const g=i&&typeof i.type=="string"?F.get(`transform.${i.type}`):void 0;if(f)if(g&&g.role==="transform"&&g.outputs)try{const k=g.outputs(i);f=g.replacesColumns?{}:{...f};for(const j of k)f[j]=!0}catch{f=void 0}else f=void 0;_.push(f)}const ee=_[_.length-1],G=(i,f,g)=>{i&&!Object.prototype.hasOwnProperty.call(i,g)&&r(f,`unknown field "${g}" in dataset "${e.data}"`)},te=(i,f)=>G(ee,i,f),L=Object.assign(Object.create(null),e.scales);e.size!==void 0&&!(Array.isArray(e.size)&&e.size.length===2&&e.size[0]>0&&e.size[1]>0)&&r("size","size must be [width, height] with positive numbers");const H=new Map,O=(i,f,g)=>{const k=f&&f.type;if(typeof k!="string"||!k){r(`${g}.type`,`${i} needs a "type"`);return}const j=`${i}.${k}`;H.has(j)||H.set(j,g);const p=F.get(j);return p||r(`${g}.type`,`block "${j}" is not loaded`),p},T=(i,f,g,k,j=te)=>{const p=`${g.role}.${g.type}`,I=g.params||{},U=g.role==="mark"?g.channels:{};for(const S of Object.keys(f)){if(S==="type"||k.indexOf(S)>=0||Object.prototype.hasOwnProperty.call(U,S))continue;const R=Object.prototype.hasOwnProperty.call(I,S)?I[S]:void 0;if(!R){c(`${i}.${S}`,`unknown parameter "${S}" for ${p}${m(S,Object.keys(I).concat(Object.keys(U)))}`);continue}const x=f[S];if(x===void 0)continue;const B=X=>r(`${i}.${S}`,`${S} of ${p} must be ${X}`);switch(R.kind){case"string":typeof x!="string"&&B("a string");break;case"number":typeof x!="number"&&B("a number");break;case"boolean":typeof x!="boolean"&&B("a boolean");break;case"list":Array.isArray(x)||B("a list");break;case"color":w(x)||B('a color: "#4e79a7", "rgb(78 121 167)", "steelblue" or "var(--bc-c0)"');break;case"enum":(typeof x!="string"||!R.values||R.values.indexOf(x)<0)&&B(`one of: ${(R.values||[]).join(", ")}`);break;case"field":typeof x!="string"?B("a field name"):j(`${i}.${S}`,x);break;case"scale":(typeof x!="string"||!L[x])&&B("the name of a declared scale");break;case"format":$(`${i}.${S}`,`${S} of ${p}`,x);break;case"formats":if(!x||typeof x!="object"||Array.isArray(x))B('an object of field names and formats: { "revenue": "currency" }');else for(const X of Object.keys(x))j(`${i}.${S}.${X}`,X),$(`${i}.${S}.${X}`,`the format of "${X}"`,x[X]);break;case"fields":!Array.isArray(x)||x.some(X=>typeof X!="string")?B("a list of field names"):x.forEach((X,_e)=>j(`${i}.${S}[${_e}]`,X));break}}for(const S of Object.keys(I))I[S].required&&I[S].default===void 0&&f[S]===void 0&&r(`${i}.${S}`,`${p} requires "${S}"`)},Z=Array.isArray(e.guides)&&e.guides.length>0;Array.isArray(e.marks)?!e.marks.length&&!Z&&r("marks","at least one mark is required (or a guide, such as a KPI)"):r("marks","marks must be a list (an empty one is fine when the chart has a guide, such as a KPI)");const E=(i,f)=>{const g=f.map(k=>i==="date"?we(k):typeof k=="number"?k:NaN);return f.length===2&&g.every(k=>isFinite(k))&&g[0]!==g[1]},A=i=>i==="date"?'dates ("2024-03-01" or ms)':"numbers";if(e.view!==void 0)if(!e.view||typeof e.view!="object")r("view","view must map scale names to domains");else for(const i of Object.keys(e.view)){const f=e.view[i],g=L[i]&&F.get(`scale.${L[i].type}`);L[i]?Array.isArray(f)?g&&g.input==="category"?f.length||r(`view.${i}`,"a view of categories lists at least one of them"):g&&!E(g.input,f)&&r(`view.${i}`,`a view of "${i}" is [from, to]: two different ${A(g.input)}, not ${JSON.stringify(f)}`):r(`view.${i}`,"a view is a list (the visible domain)"):r(`view.${i}`,`scale "${i}" is not declared in scales`)}Array.isArray(e.transforms)&&e.transforms.forEach((i,f)=>{const g=O("transform",i,`transforms[${f}]`);g&&T(`transforms[${f}]`,i,g,[],(k,j)=>G(_[f],k,j))});for(const i of Object.keys(L)){const f=L[i],g=`scales.${i}`,k=O("scale",f,g);if(!k)continue;T(g,f,k,["field","domain","range"]),typeof f.field=="string"&&te(`${g}.field`,f.field);const j=k;f.domain!==void 0&&!Array.isArray(f.domain)?r(`${g}.domain`,"domain must be a list: [min, max], or the categories in order"):Array.isArray(f.domain)&&j.input!=="category"&&!E(j.input,f.domain)&&r(`${g}.domain`,`the domain of scale "${i}" is [from, to]: two different ${A(j.input)}, not ${JSON.stringify(f.domain)}`+(j.output==="color"&&f.domain.length===3?'; a diverging scale is three colors in "range" and a domain even around the middle, such as [-10, 10]':"")),f.range!==void 0&&f.range!=="width"&&f.range!=="height"&&!Array.isArray(f.range)?r(`${g}.range`,'range must be "width", "height" or a list'):Array.isArray(f.range)&&k.output==="color"&&f.range.forEach((p,I)=>{w(p)||r(`${g}.range[${I}]`,`${JSON.stringify(p)} is not a color: "#4e79a7", "rgb(78 121 167)", "steelblue" or "var(--bc-c0)"`)})}const K=new Set;Array.isArray(e.marks)&&e.marks.forEach((i,f)=>{const g=`marks[${f}]`,k=O("mark",i,g);if(!k||k.role!=="mark")return;const j=`mark.${k.type}`;T(g,i,k,[]);for(const p of Object.keys(k.channels)){const I=k.channels[p],U=ie(i,p,I);if(U===null){I.required&&r(`${g}.${p}`,`${j} requires channel "${p}"`);continue}if(U===void 0){r(`${g}.${p}`,`channel "${p}" must be a field name, { field, scale } or { value }`);continue}if(U.field!==void 0&&te(`${g}.${p}`,U.field),I.unscaled)U.scale!==void 0&&r(`${g}.${p}`,`channel "${p}" of ${j} is read as it is and does not use a scale`);else if(U.scale!==void 0){const S=L[U.scale],R=S&&F.get(`scale.${S.type}`);if(!S)r(`${g}.${p}`,`scale "${U.scale}" is not declared in scales`);else if(R&&I.accepts&&!a(R,I.accepts)){const x=[];F.forEach((B,X)=>{B.role==="scale"&&a(B,I.accepts)&&x.push(X.slice(6))}),r(`${g}.${p}`,`channel "${p}" of ${j} needs a scale that ${N(I.accepts)}${x.length?` (${x.sort().join(", ")})`:""}; "${S.type}" ${N({output:R.output,input:[R.input]})}`)}else R&&R.output==="position"&&be(U.scale,S)===void 0&&(K.has(U.scale)||(K.add(U.scale),r(`scales.${U.scale}`,`scale "${U.scale}" places values but has no range, so nothing it places is drawn: give it "range": "width" or "height" (only x and y have one by default)`)))}}}),Array.isArray(e.guides)&&e.guides.forEach((i,f)=>{const g=`guides[${f}]`,k=O("guide",i,g);if(!k)return;T(g,i,k,["scale","position"]),i.scale!==void 0&&(typeof i.scale!="string"||!L[i.scale])&&r(`${g}.scale`,`scale "${String(i.scale)}" is not declared in scales`);const j=k.params&&k.params.position,p=j&&j.kind==="enum"&&j.values?j.values:pe;i.position!==void 0&&p.indexOf(i.position)<0&&r(`${g}.position`,`position must be one of: ${p.join(", ")}`)}),Array.isArray(e.interaction)&&e.interaction.forEach((i,f)=>{const g=O("interaction",i,`interaction[${f}]`);g&&T(`interaction[${f}]`,i,g,[])}),O("renderer",{type:e.renderer||"svg"},"renderer");const Q=new Set,W=(i,f)=>{if(Q.has(i))return;Q.add(i);const g=F.get(i);if(!(!g||!g.requires))for(const k of g.requires)F.has(k)?W(k,f):r(f,`${i} requires ${k}, which is not loaded`)};return H.forEach((i,f)=>W(f,i)),o},ge=["#3a6fe4","#16a39d","#f29b38","#e0527a","#8a6be8","#5d718f","#2e9e62","#ea7b4f","#8c6d46","#a3ad3a","#1f7a9c","#b0479a"];function ye(t){const e=(t%ge.length+ge.length)%ge.length;return`var(--bc-c${e}, ${ge[e]})`}const at=t=>t>=4352&&t<=4607||t>=11904&&t<=42191||t>=44032&&t<=55203||t>=63744&&t<=64255||t>=65072&&t<=65135||t>=65280&&t<=65376||t>=55360&&t<=55423;function Tt(t){for(let e=0;e<t.length;e++)if(at(t.charCodeAt(e)))return!0;return!1}function it(t,e=11){let o=0;for(let r=0;r<t.length;r++)o+=at(t.charCodeAt(r))?1:.6;return{w:o*e,h:e*1.2}}function De(t,e=11,o){let r=0;for(const a of t)a===" "||"iIl|!.,:;'".indexOf(a)>=0?r+=.28:"fjrt()[]-".indexOf(a)>=0?r+=.4:a==="M"||a==="W"||a==="m"||a==="w"||a==="%"||a==="@"?r+=.95:a>="0"&&a<="9"?r+=.6:a>="a"&&a<="z"?r+=.54:a>="A"&&a<="Z"?r+=.7:a.charCodeAt(0)<11904?r+=.62:r+=1;const c=o==="bold"||typeof o=="number"&&o>=700?1.08:typeof o=="number"&&o>=600?1.04:1;return r*e*c}const Me=new Map,ze=new Map,ct=new Set,Bt=4e3;let fe;function ft(){const t=typeof document=="object"&&document?document:null,e=t&&t.fonts;return e&&typeof e.check=="function"&&typeof e.load=="function"?e:null}function It(){if(fe!==void 0)return fe;fe=null;try{if(ft()){const t=document.createElement("canvas").getContext("2d");t&&typeof t.measureText=="function"&&(fe=t)}}catch{fe=null}return fe}function Pt(t,e){const o=It(),r=ft();let c="";try{c=o&&typeof getComputedStyle=="function"?String(getComputedStyle(t).fontFamily||""):""}catch{c=""}if(!o||!r||!c)return null;const a=(m,$)=>{o.font=m;const w=o.measureText($),N=w.width;if(typeof N!="number"||!isFinite(N)||N<0)return null;const z=typeof w.actualBoundingBoxLeft=="number"&&isFinite(w.actualBoundingBoxLeft)?w.actualBoundingBoxLeft:0,M=typeof w.actualBoundingBoxRight=="number"&&isFinite(w.actualBoundingBoxRight)?w.actualBoundingBoxRight-N:0;return[N,Math.max(0,z,M)]},y=(m,$,w)=>{if(typeof m!="string"||typeof $!="number"||!($>0)||!isFinite($))return null;const N=w==="bold"?700:typeof w=="number"&&w>=1&&w<=1e3?Math.round(w):400,z=`${N} ${c}`,M=`${N} ${$}px ${c}`;let _=Me.get(z);if(!_&&(_={widths:new Map,figures:new Map},Me.set(z,_),!ct.has(z))){let O=!0;try{O=r.check(M)}catch{O=!0}if(!O){ct.add(z);const T=()=>{ze.delete(z),Me.delete(z)};ze.set(z,Promise.resolve(r.load(M)).then(T,T))}}const ee=ze.get(z);ee&&e(ee);const G=$+" "+m,te=_.widths.get(G);if(te!==void 0)return te;let L=_.figures.get($);if(L===void 0){L="0";let O=-1;for(const T of"0123456789"){const Z=a(M,T);Z&&Z[0]>O&&([L,O]=[T,Z[0]])}_.figures.set($,L)}const H=a(M,/[0-9]/.test(m)?m.replace(/[0-9]/g,L):m);return H?(_.widths.size>=Bt&&_.widths.delete(_.widths.keys().next().value),_.widths.set(G,H),H):null};return{width(m,$=11,w){const N=y(m,$,w);return N?N[0]:De(m,$,w)},inked(m,$=11){const w=y(m,$,void 0);return w?w[0]+2*w[1]:De(m,$)}}}function _t(t,e){const o=[],r=typeof t.alt=="string"&&t.alt.trim()?t.alt:t.title;for(const c of[typeof r=="string"?r.trim():"",...e])c&&o.indexOf(c)<0&&o.push(c);return o.join(". ")}function Ne(t,e){return{x:e.left,y:e.top,w:Math.max(1,t.w-e.left-e.right),h:Math.max(1,t.h-e.top-e.bottom)}}function Ut(t,e){return t.length===e.length&&t.every((o,r)=>o.length===e[r].length&&o.every((c,a)=>c===e[r][a]||c instanceof Date&&e[r][a]instanceof Date&&c.getTime()===e[r][a].getTime()))}function Fe(t,e){for(let o=0;o<e.length;o++)t.push(e[o])}function qt(t){typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,0)}function Lt(t,e,o,r,c){const a=typeof e.locale=="string"&&e.locale?e.locale:void 0,y=()=>{Ie=a};y();const m=[],$=(n,s)=>{const l=s instanceof Error?s.message:String(s);m.some(d=>d.path===n&&d.message===l)||m.push({level:"error",path:n,message:l})},w=(n,s)=>{m.some(l=>l.path===n&&l.message===s)||m.push({level:"warn",path:n,message:s})};let N=!1;o.push(()=>{N=!0});let z=0,M=!1;const _=()=>{z||(M=typeof getComputedStyle=="function"&&getComputedStyle(t).position==="static",M&&(t.style.position="relative")),z++;let n=!1;return()=>{n||(n=!0,z--,z<=0&&(z=0,M&&(t.style.position="")))}},ee=[],G=e.transforms||[],te=n=>{const s=F.get(`transform.${n.type}`).viewDependent;return typeof s=="function"?s(n):!!s},L=G.findIndex(te),H=L<0?G.length:L,O=(n,s)=>{s&&(s.level==="error"?$:w)(n,s.message)},T=(n,s)=>typeof s=="string"&&Object.prototype.hasOwnProperty.call(n.columns,s)?n.columns[s]:void 0,Z=new Set,E=(n,s)=>{if(Z.has(n))return;Z.add(n);const l=G[n],d=F.get(`transform.${l.type}`).params||{};for(const u of Object.keys(d)){const h=d[u].reads,b=l[u];h&&typeof b=="string"&&O(`transforms[${n}].${u}`,Be(`transform.${l.type}`,b,T(s,b),h))}};let A=ce.get(e.data);G.slice(0,H).forEach((n,s)=>{const l=F.get(`transform.${n.type}`),d=m.length;E(s,A);try{A=l.apply(A,n)}catch(u){const h=m.slice(d).find(b=>b.level==="error");throw h?Object.assign(new Error(h.message),{path:h.path}):Object.assign(new Error(u instanceof Error?u.message:String(u)),{path:`transforms[${s}]`})}if(!A)throw new Error(`transforms[${s}] returned no table`)});const K=A,Q=G.slice(H);let W=0;for(const n of Q){const s=F.get(`transform.${n.type}`);if(s.viewDependent===!0)break;A=s.apply(A,n),W++}const i={w:e.size?e.size[0]:640,h:e.size?e.size[1]:400},f=e.padding,g=typeof f=="number"?{top:f,right:f,bottom:f,left:f}:{...xt,...f||{}};e.title&&(g.top+=He);let k=Ne(i,g);const j=e.scales||{},p=Object.create(null),I=new Map,U=new Map,S=new Map,R=new Map,x=n=>F.get(`mark.${n.type}`),B=Object.create(null),X=()=>{for(const n of Object.keys(p))p[n].setDomain(B[n]||null),B[n]&&(B[n]=p[n].domain());I.clear(),U.clear(),S.clear(),R.clear()},_e=n=>{const s=x(n),l=d=>s.channels[d]?ie(n,d,s.channels[d]):null;return{scale(d){const u=l(d),h=u&&u.scale!==void 0&&Object.prototype.hasOwnProperty.call(j,u.scale)?j[u.scale]:void 0,b=h?F.get(`scale.${h.type}`):void 0;return h&&b?{input:b.input,even:b.even===!0}:void 0},column(d){const u=l(d);return u&&u.field!==void 0?T(A,u.field):void 0}}},bt=(n={})=>{for(const s of Object.keys(j))en(s,Object.prototype.hasOwnProperty.call(n,s)?n[s]:[])},en=(n,s)=>{const l=j[n],d=F.get(`scale.${l.type}`),u=s.length?[s]:[],h=`scale "${n}"`;e.marks.forEach((v,D)=>{const C=x(v);for(const P of Object.keys(C.channels)){const V=ie(v,P,C.channels[P]);if(!(!V||V.scale!==n))if(V.field!==void 0){u.push(A.columns[V.field]),O(`marks[${D}].${P}`,Be(h,V.field,T(A,V.field),d.input));const J=C.reach?C.reach(v,P,_e(v)):null;J&&J.length&&u.push(J)}else d.fieldsOnly||u.push([V.value])}}),typeof l.field=="string"&&(u.push(A.columns[l.field]),O(`scales.${n}.field`,Be(h,l.field,T(A,l.field),d.input)));let b;try{b=d.create(l,{name:n,sources:u,range:Ce(n,l,k),color:ye})}catch(v){throw Object.assign(new Error(v instanceof Error?v.message:String(v)),{path:`scales.${n}`})}p[n]=Object.defineProperties(b,{output:{value:d.output},input:{value:d.input}})};bt();const Ue=e.view||{};for(const n of Object.keys(Ue))B[n]=Ue[n];for(const n of Object.keys(r||{}))p[n]&&!Object.prototype.hasOwnProperty.call(Ue,n)&&(B[n]=r[n]);for(const n of Object.keys(c||{})){const s=c[n];p[n]&&(s?B[n]=s:delete B[n])}X(),e.marks.forEach((n,s)=>{const l=x(n);for(const d of Object.keys(l.channels)){const u=ie(n,d,l.channels[d]),h=u&&u.field===void 0&&u.scale!==void 0?p[u.scale]:void 0,b=h?be(u.scale,j[u.scale]):void 0;if(!u||!h||b!=="width"&&b!=="height")continue;const v=h(u.value),[D,C]=h.range();v>=Math.min(D,C)-.5&&v<=Math.max(D,C)+.5||w(`marks[${s}].${d}`,`the constant ${String(u.value)} is outside scale "${u.scale}", so it is not drawn where you meant`)}});const wt=12,qe=new WeakMap,tn=(n,s,l)=>{const d=qe.get(n);if(d&&d.scale===s)return d.dir;if(n instanceof Float64Array&&s.invert&&l>=2){let D=!0,C=!0;for(let q=1;q<l&&(D||C);q++){const Y=n[q],ne=n[q-1];Y!==Y||ne!==ne?(D=!1,C=!1):(Y<ne&&(D=!1),Y>ne&&(C=!1))}const P=s(n[0]),V=s(n[l-1]);let J=0;if(isFinite(P)&&isFinite(V)&&P!==V){const q=V>P?1:-1;J=D?q:C?-q:0}return qe.set(n,{scale:s,dir:J}),J}let u=!0,h=!0,b=0;for(let D=0;D<l&&(u||h);D++){const C=s(n[D]);if(typeof C!="number"||C!==C){u=!1,h=!1;break}D>0&&(C<b&&(u=!1),C>b&&(h=!1)),b=C}const v=l<2?0:u?1:h?-1:0;return qe.set(n,{scale:s,dir:v}),v},ke=(n,s)=>{let l=0,d=n;for(;l<d;){const u=l+d>>1;s(u)?d=u:l=u+1}return l},nn=n=>{const s=A.length;let l=0,d=s;if(!Object.keys(B).length)return{from:l,to:d};const u=x(n);for(const h of Object.keys(u.channels)){const b=ie(n,h,u.channels[h]);if(!b||b.field===void 0||b.scale===void 0||!B[b.scale])continue;const v=p[b.scale],D=A.columns[b.field],C=v.range();if(!D||typeof C[0]!="number"||typeof C[1]!="number")continue;const P=tn(D,v,s);if(!P)continue;const V=Math.min(C[0],C[1])-wt,J=Math.max(C[0],C[1])+wt,q=oe=>v(D[oe]),Y=P===1?ke(s,oe=>q(oe)>=V):ke(s,oe=>q(oe)<=J),ne=P===1?ke(s,oe=>q(oe)>J):ke(s,oe=>q(oe)<V);l=Math.max(l,Y-1,0),d=Math.min(d,ne+1,s)}return d<l&&(d=l),{from:l,to:d}};let Le=[];const Re=new Set,Ae=Pt(t,n=>Re.add(n)),re={spec:e,format:(n,s)=>Pe(n,s,a),get table(){return A},baseTable:K,size:i,get plot(){return k},scales:p,measure:Ae?(n,s)=>{const l=it(n,s),d=Ae.inked(n,s);return d>l.w?{w:d,h:l.h}:l}:it,textWidth:Ae?Ae.width:De,wide:Tt,alongX:(e.interaction||[]).some(n=>{const s=F.get(`interaction.${n.type}`);return!!(s&&s.alongX)}),toggled(n){return(e.interaction||[]).some(s=>{const l=F.get(`interaction.${s.type}`);return!!(l&&l.toggles&&l.toggles(s,re)===n)})},say(n){typeof n=="string"&&n.trim()&&Le.push(n.trim())},orientation(n){const s=j[n]&&be(n,j[n]);return s==="width"?"horizontal":s==="height"?"vertical":null},ticks(n,s){const l=p[n];if(!l||!l.ticks)return[];const d=re.orientation(n);let u=s!==void 0?s:Math.max(2,Math.round(d==="vertical"?k.h/40:d==="horizontal"?k.w/80:6));if(s===void 0&&l.input==="category"&&d)for(const v of e.guides||[]){const D=v.scale===n?F.get(`guide.${v.type}`):void 0;D&&D.fits&&(u=Math.max(u,Math.min(l.domain().length,D.fits(v,re,d==="horizontal"?k.w:k.h))))}const h=`${n}:${u}`;let b=U.get(h);return b||U.set(h,b=l.ticks(u)),b},edgeTaken(n){const s={left:0,right:0};for(const l of e.interaction||[]){const d=F.get(`interaction.${l.type}`),u=d&&d.corner?d.corner(l,re):null;u&&u.edge===n&&(s[u.side]=Math.max(s[u.side],u.width))}return s},rows(n){let s=S.get(n);return s||S.set(n,s=nn(n)),s},series(n,s){const l=R.get(n);if(l&&l.xs===s)return l.out;const d=n.color!==void 0?re.channel(n,"color"):null,u=typeof n.group=="string"?n.group:d&&d.field,h=u?A.columns[u]:void 0,{from:b,to:v}=re.rows(n),D=new Map;for(let P=b;P<v;P++){const V=h?h[P]:0,J=D.get(V);J?J.push(P):D.set(V,[P])}const C=[];return D.forEach((P,V)=>{let J=!0;for(let q=1;q<P.length;q++)if(s[P[q]]<s[P[q-1]]){J=!1;break}J||P.sort((q,Y)=>s[q]!==s[q]?s[Y]!==s[Y]?0:1:s[Y]!==s[Y]?-1:s[q]-s[Y]),C.push({key:V,rows:P})}),R.set(n,{xs:s,out:C}),C},color:ye,channel(n,s){let l=I.get(n);if(l||I.set(n,l={}),l[s])return l[s];const d=x(n).channels[s],u=ie(n,s,d);let h;if(u)if(u.field===void 0){const b=u.scale!==void 0?p[u.scale]:void 0,v=new Array(A.length).fill(u.value),D=b?new Array(A.length).fill(b(u.value)):v;h={raw:v,mapped:D,scale:b,half:b&&b.bandwidth!==void 0?b.bandwidth/2:0}}else{const b=A.columns[u.field],v=u.scale!==void 0?p[u.scale]:void 0;if(!v)h={field:u.field,raw:b,mapped:b,half:0};else{const D=A.length,{from:C,to:P}=re.rows(n),J=typeof(P>C?v(b[C]):0)=="number"?new Float64Array(D).fill(NaN):new Array(D);for(let q=C;q<P;q++)J[q]=v(b[q]);h={field:u.field,scale:v,raw:b,mapped:J,half:v.bandwidth!==void 0?v.bandwidth/2:0}}}else{if(d&&d.required)throw new Error(`mark.${n.type}: channel "${s}" is required`);h={raw:[],mapped:[],half:0}}return l[s]=h}},$t=e.guides||[],Ve=[],kt=()=>{k=Ne(i,g);for(const d of Object.keys(p))p[d].setRange(Ce(d,j[d],k));U.clear();const n={top:0,right:0,bottom:0,left:0},s={top:0,right:0,bottom:0,left:0};Ve.length=0,$t.forEach((d,u)=>{Ve.push({...n});try{const h=F.get(`guide.${d.type}`),b=h.measure?h.measure(d,re):{};for(const v of pe)n[v]+=b[v]||0,b.overhang&&(s[v]=Math.max(s[v],b.overhang[v]||0))}catch(h){$(`guides[${u}]`,h)}});const l=d=>Math.max(g[d]+n[d],s[d]);k=Ne(i,{top:l("top"),right:l("right"),bottom:l("bottom"),left:l("left")}),l("top")+l("bottom")>i.h&&w("size",`padding and guides need ${l("top")+l("bottom")} px of height and the chart has ${i.h}, so its bottom is cut off`);for(const d of Object.keys(p))p[d].setRange(Ce(d,j[d],k));I.clear(),U.clear(),S.clear(),R.clear()};if(kt(),W){const n=()=>Object.keys(p).map(s=>p[s].baseDomain());for(let s=0;s<4;s++){for(const h of Object.keys(p))p[h].setDomain(null);let l=K;const d=Object.create(null);for(let h=0;h<W;h++){const b=H+h,v=F.get(`transform.${Q[h].type}`).apply(l,Q[h],{plot:k,scales:p,warn:D=>w(`transforms[${b}]`,D),fitting:!0,reach:(D,C)=>{typeof D=="string"&&Array.isArray(C)&&(d[D]=d[D]||[]).push(...C)}});if(!v)throw Object.assign(new Error("returned no table"),{path:`transforms[${b}]`});l=v}const u=n();if(A=l,bt(d),X(),Ut(u,n()))break;kt()}}let me;function At(){if(y(),Le=[],Q.length){let d=K;Q.forEach((u,h)=>{try{E(H+h,d);const b=F.get(`transform.${u.type}`).apply(d,u,{plot:k,scales:p,warn:v=>w(`transforms[${H+h}]`,v)});if(!b)throw new Error("returned no table");d=b}catch(b){$(`transforms[${H+h}]`,b)}}),A=d}I.clear(),U.clear(),S.clear(),R.clear();const n={grid:[],marks:[],axes:[],overlay:[]};e.marks.forEach((d,u)=>{try{const h=x(d);Fe(n.marks,h.render(d,re,u)),h.labels&&Fe(n.axes,h.labels(d,re,u))}catch(h){$(`marks[${u}]`,h)}}),$t.forEach((d,u)=>{try{const h=F.get(`guide.${d.type}`).render(d,re,Ve[u]);for(const b of Object.keys(h))Fe(n[b],h[b]||[])}catch(h){$(`guides[${u}]`,h)}}),e.title&&n.axes.push({type:"text",x:g.left,y:He-6,text:e.title,size:14,weight:600,style:{fill:"var(--bc-text, #444)"}});const s=Object.keys(B).length>0;me={size:i,plot:k,layers:["grid","marks","axes","overlay"].map(d=>({name:d,prims:n[d],clip:d==="marks"&&s?{...k}:void 0}))};const l=_t(e,Le);l&&(me.label=l),mt()}At();const le=F.get(`renderer.${e.renderer||"svg"}`).render(me,t);let We=!1;const Ot=(n,s)=>{if(!p[n]){console.warn(`[blockcharts] setView: unknown scale "${n}"`);return}s?B[n]=s:delete B[n],!We&&(We=!0,qt(()=>{if(We=!1,!N)try{X(),At(),le.update(me)}catch(l){$("view",l),console.error(l)}}))},vt=()=>{const n={};for(const s of Object.keys(p))n[s]=B[s]?B[s].slice():p[s].baseDomain();return n},rn=(n,s)=>{const l=j[n],d=j[s],u=B[s];if(!l||!d||!p[s]||!u)return null;const h=p[s].range(),b=typeof h[0]=="number"&&typeof h[1]=="number",v=b?Math.min(h[0],h[1]):0,D=b?Math.max(h[0],h[1]):0,C=F.get(`scale.${d.type}`).create({...d,domain:p[s].baseDomain()},{name:s,sources:[],range:p[s].range(),color:ye});C.setDomain(u);const P=Y=>{const ne=C(Y);return typeof ne=="number"?!b||ne>=v&&ne<=D:!!ne},V=[];let J=0;for(const Y of e.marks){const ne=x(Y),oe=de=>ie(Y,de,ne.channels[de]),Et=[],Je=[];for(const de of Object.keys(ne.channels)){const ae=oe(de);!ae||ae.field===void 0||(ae.scale===s?Et.push(A.columns[ae.field]):ae.scale===n&&Je.push(A.columns[ae.field]))}if(Je.length)for(const de of Je){const ae=[];for(let Oe=0;Oe<A.length;Oe++){let jt=!0;for(const an of Et)if(!P(an[Oe])){jt=!1;break}jt&&ae.push(de[Oe])}J+=ae.length,V.push(ae)}}return J?F.get(`scale.${l.type}`).create(l,{name:n,sources:V,range:p[n].range(),color:ye}).baseDomain():null},on=n=>{const s=n.target,l=s&&s.closest?s.closest("[data-bc-mark]"):null;return l?{mark:Number(l.getAttribute("data-bc-mark")),row:Number(l.getAttribute("data-bc-row"))}:null},sn=Object.create(re,{host:{value:t},dataAt:{value:n=>{if(le.dataAt)return le.dataAt(n);let s=n.target;for(;s&&s!==le.root.parentNode;){const l={};let d=!1;const u=s.attributes;for(let h=0;u&&h<u.length;h++)u[h].name.indexOf("data-")===0&&(l[u[h].name.slice(5)]=u[h].value,d=!0);if(d)return l;s=s.parentNode}return null}},root:{value:le.root},list:{get:()=>me},hit:{value:on},cleanup:{value:n=>{o.push(n)}},setView:{value:Ot},getView:{value:vt},fit:{value:rn},claimPosition:{value:_},claimDrag:{value:n=>ee.push(n)},dragClaimed:{value:n=>ee.some(s=>s(n))}});return(e.interaction||[]).forEach((n,s)=>{try{F.get(`interaction.${n.type}`).attach(n,sn)}catch(l){$(`interaction[${s}]`,l)}}),{rendered:le,diagnostics:m,setView:Ot,getView:vt,viewState:()=>{const n={};for(const s of Object.keys(B))n[s]=B[s].slice();return n},get fontsDue(){return Re.size?Promise.all(Array.from(Re)):null}}}function Rt(t,e){const o=document.createElement("div");o.setAttribute("class","bc-error"),o.setAttribute("style","font:12px/1.5 monospace;color:#b00020;border:1px solid #b00020;padding:8px;white-space:pre-wrap"),o.textContent=`blockcharts:
|
|
1
|
+
/*! blockcharts 0.0.3 kit "dashboard": lib.columns, lib.curve, lib.pointer, lib.ticks, scale.band, scale.color, scale.linear, scale.time, transform.aggregate, transform.calculate, transform.filter, transform.fold, transform.funnel, transform.sort, transform.treemap, transform.waterfall, transform.window, mark.arc, mark.area, mark.line, mark.point, mark.rect, mark.rule, mark.text, guide.axis, guide.grid, guide.kpi, guide.legend, interaction.click, interaction.legend-filter, interaction.tooltip, renderer.svg | MIT License */
|
|
2
|
+
"use strict";(function(){const ve="0.0.3",Ee=globalThis,he=Ee.BC;if(he&&typeof he.define=="function"&&typeof he.version=="string"){he.version!==ve&&console.warn(`blockcharts core ${ve} ignored: ${he.version} is already loaded`);return}const St=["lib","scale","transform","mark","guide","interaction","renderer"],pe=["top","right","bottom","left"],xt={top:16,right:16,bottom:16,left:16},He=24,F=new Map,ie=new Map,oe=new Map,fe=new Map,Ke=new Map,je=64*1024*1024;function Ct(t){if(!t||St.indexOf(t.role)<0||typeof t.type!="string"||!t.type)throw new Error("BC.define: a block needs a valid role and type");const e=`${t.role}.${t.type}`;{const r=["position","color","size"],c=["number","date","category"];if(t.role==="scale"&&!(r.indexOf(t.output)>=0&&c.indexOf(t.input)>=0))throw new Error(`BC.define: ${e} must declare its output ("position", "color" or "size") and its input ("number", "date" or "category")`);if(t.role==="mark")for(const a of Object.keys(t.channels||{})){const y=t.channels[a].accepts;if(y&&!(r.indexOf(y.output)>=0&&(y.input===void 0||Array.isArray(y.input)&&y.input.every(m=>c.indexOf(m)>=0))))throw new Error(`BC.define: channel "${a}" of ${e} accepts { output: "position", "color" or "size", input: a list of "number", "date", "category" }`)}}const o=F.get(e);if(o){o.version!==t.version&&console.warn(`BC.define: ${e} v${t.version} ignored, v${o.version} is already registered`);return}F.set(e,t)}function Ze(t){if(t instanceof Float64Array)return t;for(let o=0;o<t.length;o++){const r=t[o];if(typeof r!="number"&&r!=null)return t}const e=new Float64Array(t.length);for(let o=0;o<t.length;o++){const r=t[o];e[o]=typeof r=="number"?r:NaN}return e}function Se(t){const e={};let o=0;const r=c=>{if(c==="__proto__")throw new Error('BC.data: a column cannot be named "__proto__"; rename it');return c};if(Array.isArray(t)){const c=new Set;t.forEach((a,y)=>{if(!a||typeof a!="object"||Array.isArray(a))throw new Error(`BC.data: row ${y} is not an object`);for(const m of Object.keys(a))c.add(r(m))});for(const a of c)e[a]=Ze(t.map(y=>y[a]));o=t.length}else if(t&&typeof t=="object"&&t.columns&&typeof t.columns=="object"){const c=t.columns,a=Object.keys(c).map(r);for(const y of a)if(!Array.isArray(c[y])&&!(c[y]instanceof Float64Array))throw new Error(`BC.data: column "${y}" is not an array`);o=a.length?c[a[0]].length:0;for(const y of a){if(c[y].length!==o)throw new Error(`BC.data: column "${y}" has ${c[y].length} values, expected ${o}`);e[y]=Ze(c[y])}}else throw new Error("BC.data: a dataset is an array of rows or { columns }");return{length:o,columns:e}}const xe=t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&typeof t.encoding=="string",Ge=function(e){const o=e.replace(/\s+/g,"");if(o.length%4===1||!/^[A-Za-z0-9+/]*={0,2}$/.test(o))throw new Error("the data is not valid base64");if(typeof atob!="function")throw new Error("this environment has no atob(), cannot decode base64");const r=atob(o),c=new Uint8Array(r.length);for(let a=0;a<r.length;a++)c[a]=r.charCodeAt(a);return c},Xe=async function(e,o){const r=globalThis.DecompressionStream;if(typeof r!="function"||typeof Blob!="function")throw new Error('this browser cannot decompress gzip data (no DecompressionStream); store the dataset as plain rows or "base64"');const c=new Blob([e]).stream().pipeThrough(new r("gzip")).getReader(),a=[];let y=0;for(;;){let w;try{w=await c.read()}catch{throw new Error("the data is not valid gzip")}const{done:N,value:z}=w;if(N)break;if(y+=z.length,y>o)throw await c.cancel(),new Error(`the decoded data is larger than ${je/1024/1024} MB, refusing to unpack it`);a.push(z)}const m=new Uint8Array(y);let $=0;for(const w of a)m.set(w,$),$+=w.length;return m},Ye={float32:{size:4,ctor:Float32Array,get:"getFloat32"},float64:{size:8,ctor:Float64Array,get:"getFloat64"},int8:{size:1,ctor:Int8Array,get:"getInt8"},int16:{size:2,ctor:Int16Array,get:"getInt16"},int32:{size:4,ctor:Int32Array,get:"getInt32"},uint8:{size:1,ctor:Uint8Array,get:"getUint8"},uint16:{size:2,ctor:Uint16Array,get:"getUint16"},uint32:{size:4,ctor:Uint32Array,get:"getUint32"}},Dt=new Uint8Array(new Uint16Array([1]).buffer)[0]===1,Qe=t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&!(t instanceof Float64Array)&&typeof t.dtype=="string",et=t=>{const e=t&&typeof t=="object"&&!Array.isArray(t)?t.columns:void 0;return!!e&&typeof e=="object"&&Object.keys(e).some(o=>Qe(e[o]))},Mt=async function(e,o,r){const c=Ye[o.dtype];if(!c)throw new Error(`column "${e}": unknown dtype "${o.dtype}" (use ${Object.keys(Ye).join(", ")})`);if(o.encoding!=="base64"&&o.encoding!=="gzip+base64")throw new Error(`column "${e}": unknown encoding "${o.encoding}" (use "base64" or "gzip+base64")`);if(typeof o.data!="string")throw new Error(`column "${e}": a binary column needs a "data" string`);let a;try{a=Ge(o.data),o.encoding==="gzip+base64"&&(a=await Xe(a,r.left))}catch($){throw new Error(`column "${e}": ${$ instanceof Error?$.message:String($)}`)}if(a.length%c.size!==0)throw new Error(`column "${e}": ${a.length} bytes is not a whole number of ${o.dtype} values`);const y=a.length/c.size;if(r.left-=y*8,r.left<0)throw new Error(`the decoded data is larger than ${je/1024/1024} MB, refusing to unpack it`);const m=new Float64Array(y);if(Dt){const $=a.byteOffset%c.size===0?a.buffer:a.slice().buffer,w=a.byteOffset%c.size===0?a.byteOffset:0;m.set(new c.ctor($,w,y))}else{const $=new DataView(a.buffer,a.byteOffset,a.length);for(let w=0;w<y;w++)m[w]=$[c.get](w*c.size,!0)}return m},tt=async function(e,o){if(!et(e))return e;const r=e.columns,c=Object.create(null);for(const a of Object.keys(r))c[a]=Qe(r[a])?await Mt(a,r[a],o):r[a];return{columns:c}},zt=async function(e){const o={left:je};if(!xe(e))return Se(await tt(e,o));if(typeof e.data!="string")throw new Error('an encoded dataset needs a "data" string');if(e.encoding!=="base64"&&e.encoding!=="gzip+base64")throw new Error(`unknown encoding "${e.encoding}" (use "base64" or "gzip+base64")`);let r=Ge(e.data);e.encoding==="gzip+base64"&&(r=await Xe(r,o.left)),o.left-=r.length;let c;try{c=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(r))}catch(a){throw new Error("the decoded data is not UTF-8 JSON: "+(a instanceof Error?a.message:String(a)))}if(xe(c))throw new Error("an encoded dataset cannot contain another encoded dataset");return Se(await tt(c,o))};function nt(t,e){if(e===null){ie.delete(t),oe.delete(t),fe.delete(t);return}if(xe(e)||et(e)){fe.delete(t);const r=zt(e).then(c=>{oe.get(t)===r&&ie.set(t,c)},c=>{if(oe.get(t)!==r)return;const a=c instanceof Error?c.message:String(c);fe.set(t,a),console.error(`[blockcharts] dataset "${t}": ${a}`)}).then(()=>{oe.get(t)===r&&oe.delete(t)});oe.set(t,r);return}const o=Se(e);oe.delete(t),fe.delete(t),ie.set(t,o)}function Nt(){return Promise.all(Array.from(oe.values())).then(()=>{})}function ce(t,e,o){const r=t[e];if(r===void 0)return o&&o.default!==void 0?{value:o.default}:null;const c=o&&o.unscaled?void 0:o&&o.sharesScale||e;if(typeof r=="string")return{field:r,scale:c};if(r&&typeof r=="object"){const a=r;if(typeof a.field=="string")return{field:a.field,scale:typeof a.scale=="string"?a.scale:c};if(a.value!==void 0){const y=typeof a.scale=="string"?a.scale:c==="x"||c==="y"?c:void 0;return y!==void 0?{value:a.value,scale:y}:{value:a.value}}}}function be(t,e){return e.range!==void 0?e.range:t==="x"?"width":t==="y"?"height":void 0}function Ce(t,e,o){const r=be(t,e);return r==="width"?[o.x,o.x+o.w]:r==="height"?[o.y+o.h,o.y]:Array.isArray(r)?r:[]}function rt(t){const e=t&&typeof t=="object"?t.data:void 0;return typeof e!="string"?"data must be the name of a dataset":oe.has(e)?`dataset "${e}" is still being decoded (await BC.ready())`:fe.has(e)?`dataset "${e}" could not be loaded: ${fe.get(e)}`:ie.has(e)?null:`dataset "${e}" is not in the data lake`}const Ft=function(e){const o=[],r=(c,a)=>{const y=a&&a.type;if(typeof y=="string"){const m=`${c}.${y}`;o.indexOf(m)<0&&o.push(m)}};if(!e)return o;if(Array.isArray(e.transforms)&&e.transforms.forEach(c=>r("transform",c)),e.scales)for(const c of Object.keys(e.scales))r("scale",e.scales[c]);return Array.isArray(e.marks)&&e.marks.forEach(c=>r("mark",c)),Array.isArray(e.guides)&&e.guides.forEach(c=>r("guide",c)),Array.isArray(e.interaction)&&e.interaction.forEach(c=>r("interaction",c)),r("renderer",{type:e.renderer||"svg"}),o},ot=["$schema","id","data","transforms","size","padding","title","alt","scales","guides","marks","interaction","view","responsive","renderer","locale"],st=function(e){const o=[],r=(i,f)=>o.push({level:"error",path:i,message:f}),c=(i,f)=>o.push({level:"warn",path:i,message:f});if(!e||typeof e!="object")return r("","the spec must be an object"),o;const a=(i,f)=>i.output===f.output&&(!f.input||f.input.indexOf(i.input)>=0),y=(i,f)=>{const g=(p,I)=>{let U=Array.from({length:I.length+1},(S,R)=>R);for(let S=1;S<=p.length;S++){const R=[S];for(let x=1;x<=I.length;x++)R[x]=Math.min(U[x]+1,R[x-1]+1,U[x-1]+(p[S-1]===I[x-1]?0:1));U=R}return U[I.length]};let k,j=3;for(const p of f){const I=p.toLowerCase()===i.toLowerCase()?0:g(i,p);I<j&&([k,j]=[p,I])}return k},m=(i,f)=>{const g=y(i,f);return g?`; did you mean "${g}"?`:""};for(const i of Object.keys(e))ot.indexOf(i)<0&&c(i,`unknown key "${i}"${m(i,ot)}`);for(const i of["transforms","guides","interaction"])e[i]!==void 0&&!Array.isArray(e[i])&&r(i,`${i} must be a list: [{ "type": ... }]`);if(e.scales!==void 0&&(!e.scales||typeof e.scales!="object"||Array.isArray(e.scales))&&r("scales",'scales must map names to scales: { "x": { "type": "band" } }'),e.padding!==void 0)if(typeof e.padding=="number")(!isFinite(e.padding)||e.padding<0)&&r("padding","padding must be a number of px, 0 or more, or one per side");else if(!e.padding||typeof e.padding!="object"||Array.isArray(e.padding))r("padding",'padding must be { "top": 8, "right": 8, "bottom": 30, "left": 40 } in px, or one number for every side');else for(const i of Object.keys(e.padding)){const f=e.padding[i];pe.indexOf(i)<0?c(`padding.${i}`,`unknown side "${i}"${m(i,pe)}`):(typeof f!="number"||!isFinite(f)||f<0)&&r(`padding.${i}`,`padding.${i} must be a number of px, 0 or more`)}if(e.title!==void 0&&typeof e.title!="string"&&r("title","title must be text"),e.alt!==void 0&&typeof e.alt!="string"&&r("alt","alt must be text: what the chart shows, in a sentence"),e.id!==void 0&&typeof e.id!="string"&&r("id","id must be text"),e.responsive!==void 0&&typeof e.responsive!="boolean"&&r("responsive","responsive must be true or false"),e.renderer!==void 0&&typeof e.renderer!="string"&&r("renderer",'renderer must be the name of one: "svg", "canvas"'),e.locale!==void 0){let i=!1;try{i=typeof e.locale=="string"&&Intl.getCanonicalLocales(e.locale).length===1}catch{i=!1}i||r("locale",`locale ${JSON.stringify(e.locale)} is not a language tag like "en-US", "de" or "ja"`)}const $=(i,f,g)=>{try{Pe(g)}catch(k){r(i,`${f}: ${k.message}`)}},w=i=>typeof i=="string"&&/^\s*(?:#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})|(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\([-+\w.%,\s/]*\)|[a-z]+|var\(\s*--[\w-]+\s*(?:,\s*(?:#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})|(?:rgba?|hsla?)\([-+\w.%,\s/]*\)|[a-z]+)\s*)?\))\s*$/i.test(i),N=i=>`${{position:"places",color:"colors",size:"sizes"}[i.output]} ${i.input?i.input.map(f=>({number:"numbers",date:"dates",category:"categories"})[f]).join(" or "):"values"}`,z=typeof e.data=="string"&&!oe.has(e.data)?ie.get(e.data):void 0,M=rt(e);M&&r("data",M);const _=[z?{...z.columns}:void 0];if(Array.isArray(e.transforms))for(const i of e.transforms){let f=_[_.length-1];const g=i&&typeof i.type=="string"?F.get(`transform.${i.type}`):void 0;if(f)if(g&&g.role==="transform"&&g.outputs)try{const k=g.outputs(i);f=g.replacesColumns?{}:{...f};for(const j of k)f[j]=!0}catch{f=void 0}else f=void 0;_.push(f)}const ee=_[_.length-1],G=(i,f,g)=>{i&&!Object.prototype.hasOwnProperty.call(i,g)&&r(f,`unknown field "${g}" in dataset "${e.data}"`)},te=(i,f)=>G(ee,i,f),L=Object.assign(Object.create(null),e.scales);e.size!==void 0&&!(Array.isArray(e.size)&&e.size.length===2&&e.size[0]>0&&e.size[1]>0)&&r("size","size must be [width, height] with positive numbers");const H=new Map,O=(i,f,g)=>{const k=f&&f.type;if(typeof k!="string"||!k){r(`${g}.type`,`${i} needs a "type"`);return}const j=`${i}.${k}`;H.has(j)||H.set(j,g);const p=F.get(j);return p||r(`${g}.type`,`block "${j}" is not loaded`),p},T=(i,f,g,k,j=te)=>{const p=`${g.role}.${g.type}`,I=g.params||{},U=g.role==="mark"?g.channels:{};for(const S of Object.keys(f)){if(S==="type"||k.indexOf(S)>=0||Object.prototype.hasOwnProperty.call(U,S))continue;const R=Object.prototype.hasOwnProperty.call(I,S)?I[S]:void 0;if(!R){c(`${i}.${S}`,`unknown parameter "${S}" for ${p}${m(S,Object.keys(I).concat(Object.keys(U)))}`);continue}const x=f[S];if(x===void 0)continue;const B=X=>r(`${i}.${S}`,`${S} of ${p} must be ${X}`);switch(R.kind){case"string":typeof x!="string"&&B("a string");break;case"number":typeof x!="number"&&B("a number");break;case"boolean":typeof x!="boolean"&&B("a boolean");break;case"list":Array.isArray(x)||B("a list");break;case"color":w(x)||B('a color: "#4e79a7", "rgb(78 121 167)", "steelblue" or "var(--bc-c0)"');break;case"enum":(typeof x!="string"||!R.values||R.values.indexOf(x)<0)&&B(`one of: ${(R.values||[]).join(", ")}`);break;case"field":typeof x!="string"?B("a field name"):j(`${i}.${S}`,x);break;case"scale":(typeof x!="string"||!L[x])&&B("the name of a declared scale");break;case"format":$(`${i}.${S}`,`${S} of ${p}`,x);break;case"formats":if(!x||typeof x!="object"||Array.isArray(x))B('an object of field names and formats: { "revenue": "currency" }');else for(const X of Object.keys(x))j(`${i}.${S}.${X}`,X),$(`${i}.${S}.${X}`,`the format of "${X}"`,x[X]);break;case"fields":!Array.isArray(x)||x.some(X=>typeof X!="string")?B("a list of field names"):x.forEach((X,_e)=>j(`${i}.${S}[${_e}]`,X));break}}for(const S of Object.keys(I))I[S].required&&I[S].default===void 0&&f[S]===void 0&&r(`${i}.${S}`,`${p} requires "${S}"`)},Z=Array.isArray(e.guides)&&e.guides.length>0;Array.isArray(e.marks)?!e.marks.length&&!Z&&r("marks","at least one mark is required (or a guide, such as a KPI)"):r("marks","marks must be a list (an empty one is fine when the chart has a guide, such as a KPI)");const E=(i,f)=>{const g=f.map(k=>i==="date"?we(k):typeof k=="number"?k:NaN);return f.length===2&&g.every(k=>isFinite(k))&&g[0]!==g[1]},A=i=>i==="date"?'dates ("2024-03-01" or ms)':"numbers";if(e.view!==void 0)if(!e.view||typeof e.view!="object")r("view","view must map scale names to domains");else for(const i of Object.keys(e.view)){const f=e.view[i],g=L[i]&&F.get(`scale.${L[i].type}`);L[i]?Array.isArray(f)?g&&g.input==="category"?f.length||r(`view.${i}`,"a view of categories lists at least one of them"):g&&!E(g.input,f)&&r(`view.${i}`,`a view of "${i}" is [from, to]: two different ${A(g.input)}, not ${JSON.stringify(f)}`):r(`view.${i}`,"a view is a list (the visible domain)"):r(`view.${i}`,`scale "${i}" is not declared in scales`)}Array.isArray(e.transforms)&&e.transforms.forEach((i,f)=>{const g=O("transform",i,`transforms[${f}]`);g&&T(`transforms[${f}]`,i,g,[],(k,j)=>G(_[f],k,j))});for(const i of Object.keys(L)){const f=L[i],g=`scales.${i}`,k=O("scale",f,g);if(!k)continue;T(g,f,k,["field","domain","range"]),typeof f.field=="string"&&te(`${g}.field`,f.field);const j=k;f.domain!==void 0&&!Array.isArray(f.domain)?r(`${g}.domain`,"domain must be a list: [min, max], or the categories in order"):Array.isArray(f.domain)&&j.input!=="category"&&!E(j.input,f.domain)&&r(`${g}.domain`,`the domain of scale "${i}" is [from, to]: two different ${A(j.input)}, not ${JSON.stringify(f.domain)}`+(j.output==="color"&&f.domain.length===3?'; a diverging scale is three colors in "range" and a domain even around the middle, such as [-10, 10]':"")),f.range!==void 0&&f.range!=="width"&&f.range!=="height"&&!Array.isArray(f.range)?r(`${g}.range`,'range must be "width", "height" or a list'):Array.isArray(f.range)&&k.output==="color"&&f.range.forEach((p,I)=>{w(p)||r(`${g}.range[${I}]`,`${JSON.stringify(p)} is not a color: "#4e79a7", "rgb(78 121 167)", "steelblue" or "var(--bc-c0)"`)})}const K=new Set;Array.isArray(e.marks)&&e.marks.forEach((i,f)=>{const g=`marks[${f}]`,k=O("mark",i,g);if(!k||k.role!=="mark")return;const j=`mark.${k.type}`;T(g,i,k,[]);for(const p of Object.keys(k.channels)){const I=k.channels[p],U=ce(i,p,I);if(U===null){I.required&&r(`${g}.${p}`,`${j} requires channel "${p}"`);continue}if(U===void 0){r(`${g}.${p}`,`channel "${p}" must be a field name, { field, scale } or { value }`);continue}if(U.field!==void 0&&te(`${g}.${p}`,U.field),I.unscaled)U.scale!==void 0&&r(`${g}.${p}`,`channel "${p}" of ${j} is read as it is and does not use a scale`);else if(U.scale!==void 0){const S=L[U.scale],R=S&&F.get(`scale.${S.type}`);if(!S)r(`${g}.${p}`,`scale "${U.scale}" is not declared in scales`);else if(R&&I.accepts&&!a(R,I.accepts)){const x=[];F.forEach((B,X)=>{B.role==="scale"&&a(B,I.accepts)&&x.push(X.slice(6))}),r(`${g}.${p}`,`channel "${p}" of ${j} needs a scale that ${N(I.accepts)}${x.length?` (${x.sort().join(", ")})`:""}; "${S.type}" ${N({output:R.output,input:[R.input]})}`)}else R&&R.output==="position"&&be(U.scale,S)===void 0&&(K.has(U.scale)||(K.add(U.scale),r(`scales.${U.scale}`,`scale "${U.scale}" places values but has no range, so nothing it places is drawn: give it "range": "width" or "height" (only x and y have one by default)`)))}}}),Array.isArray(e.guides)&&e.guides.forEach((i,f)=>{const g=`guides[${f}]`,k=O("guide",i,g);if(!k)return;T(g,i,k,["scale","position"]),i.scale!==void 0&&(typeof i.scale!="string"||!L[i.scale])&&r(`${g}.scale`,`scale "${String(i.scale)}" is not declared in scales`);const j=k.params&&k.params.position,p=j&&j.kind==="enum"&&j.values?j.values:pe;i.position!==void 0&&p.indexOf(i.position)<0&&r(`${g}.position`,`position must be one of: ${p.join(", ")}`)}),Array.isArray(e.interaction)&&e.interaction.forEach((i,f)=>{const g=O("interaction",i,`interaction[${f}]`);g&&T(`interaction[${f}]`,i,g,[])}),O("renderer",{type:e.renderer||"svg"},"renderer");const Q=new Set,W=(i,f)=>{if(Q.has(i))return;Q.add(i);const g=F.get(i);if(!(!g||!g.requires))for(const k of g.requires)F.has(k)?W(k,f):r(f,`${i} requires ${k}, which is not loaded`)};return H.forEach((i,f)=>W(f,i)),o},ge=["#3a6fe4","#16a39d","#f29b38","#e0527a","#8a6be8","#5d718f","#2e9e62","#ea7b4f","#8c6d46","#a3ad3a","#1f7a9c","#b0479a"];function ye(t){const e=(t%ge.length+ge.length)%ge.length;return`var(--bc-c${e}, ${ge[e]})`}const at=t=>t>=4352&&t<=4607||t>=11904&&t<=42191||t>=44032&&t<=55203||t>=63744&&t<=64255||t>=65072&&t<=65135||t>=65280&&t<=65376||t>=55360&&t<=55423;function Tt(t){for(let e=0;e<t.length;e++)if(at(t.charCodeAt(e)))return!0;return!1}function it(t,e=11){let o=0;for(let r=0;r<t.length;r++)o+=at(t.charCodeAt(r))?1:.6;return{w:o*e,h:e*1.2}}function De(t,e=11,o){let r=0;for(const a of t)a===" "||"iIl|!.,:;'".indexOf(a)>=0?r+=.28:"fjrt()[]-".indexOf(a)>=0?r+=.4:a==="M"||a==="W"||a==="m"||a==="w"||a==="%"||a==="@"?r+=.95:a>="0"&&a<="9"?r+=.6:a>="a"&&a<="z"?r+=.54:a>="A"&&a<="Z"?r+=.7:a.charCodeAt(0)<11904?r+=.62:r+=1;const c=o==="bold"||typeof o=="number"&&o>=700?1.08:typeof o=="number"&&o>=600?1.04:1;return r*e*c}const Me=new Map,ze=new Map,ct=new Set,Bt=4e3;let le;function ft(){const t=typeof document=="object"&&document?document:null,e=t&&t.fonts;return e&&typeof e.check=="function"&&typeof e.load=="function"?e:null}function It(){if(le!==void 0)return le;le=null;try{if(ft()){const t=document.createElement("canvas").getContext("2d");t&&typeof t.measureText=="function"&&(le=t)}}catch{le=null}return le}function Pt(t,e){const o=It(),r=ft();let c="";try{c=o&&typeof getComputedStyle=="function"?String(getComputedStyle(t).fontFamily||""):""}catch{c=""}if(!o||!r||!c)return null;const a=(m,$)=>{o.font=m;const w=o.measureText($),N=w.width;if(typeof N!="number"||!isFinite(N)||N<0)return null;const z=typeof w.actualBoundingBoxLeft=="number"&&isFinite(w.actualBoundingBoxLeft)?w.actualBoundingBoxLeft:0,M=typeof w.actualBoundingBoxRight=="number"&&isFinite(w.actualBoundingBoxRight)?w.actualBoundingBoxRight-N:0;return[N,Math.max(0,z,M)]},y=(m,$,w)=>{if(typeof m!="string"||typeof $!="number"||!($>0)||!isFinite($))return null;const N=w==="bold"?700:typeof w=="number"&&w>=1&&w<=1e3?Math.round(w):400,z=`${N} ${c}`,M=`${N} ${$}px ${c}`;let _=Me.get(z);if(!_&&(_={widths:new Map,figures:new Map},Me.set(z,_),!ct.has(z))){let O=!0;try{O=r.check(M)}catch{O=!0}if(!O){ct.add(z);const T=()=>{ze.delete(z),Me.delete(z)};ze.set(z,Promise.resolve(r.load(M)).then(T,T))}}const ee=ze.get(z);ee&&e(ee);const G=$+" "+m,te=_.widths.get(G);if(te!==void 0)return te;let L=_.figures.get($);if(L===void 0){L="0";let O=-1;for(const T of"0123456789"){const Z=a(M,T);Z&&Z[0]>O&&([L,O]=[T,Z[0]])}_.figures.set($,L)}const H=a(M,/[0-9]/.test(m)?m.replace(/[0-9]/g,L):m);return H?(_.widths.size>=Bt&&_.widths.delete(_.widths.keys().next().value),_.widths.set(G,H),H):null};return{width(m,$=11,w){const N=y(m,$,w);return N?N[0]:De(m,$,w)},inked(m,$=11){const w=y(m,$,void 0);return w?w[0]+2*w[1]:De(m,$)}}}function _t(t,e){const o=[],r=typeof t.alt=="string"&&t.alt.trim()?t.alt:t.title;for(const c of[typeof r=="string"?r.trim():"",...e])c&&o.indexOf(c)<0&&o.push(c);return o.join(". ")}function Ne(t,e){return{x:e.left,y:e.top,w:Math.max(1,t.w-e.left-e.right),h:Math.max(1,t.h-e.top-e.bottom)}}function Ut(t,e){return t.length===e.length&&t.every((o,r)=>o.length===e[r].length&&o.every((c,a)=>c===e[r][a]||c instanceof Date&&e[r][a]instanceof Date&&c.getTime()===e[r][a].getTime()))}function Fe(t,e){for(let o=0;o<e.length;o++)t.push(e[o])}function qt(t){typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,0)}function Lt(t,e,o,r,c){const a=typeof e.locale=="string"&&e.locale?e.locale:void 0,y=()=>{Ie=a};y();const m=[],$=(n,s)=>{const l=s instanceof Error?s.message:String(s);m.some(d=>d.path===n&&d.message===l)||m.push({level:"error",path:n,message:l})},w=(n,s)=>{m.some(l=>l.path===n&&l.message===s)||m.push({level:"warn",path:n,message:s})};let N=!1;o.push(()=>{N=!0});let z=0,M=!1;const _=()=>{z||(M=typeof getComputedStyle=="function"&&getComputedStyle(t).position==="static",M&&(t.style.position="relative")),z++;let n=!1;return()=>{n||(n=!0,z--,z<=0&&(z=0,M&&(t.style.position="")))}},ee=[],G=e.transforms||[],te=n=>{const s=F.get(`transform.${n.type}`).viewDependent;return typeof s=="function"?s(n):!!s},L=G.findIndex(te),H=L<0?G.length:L,O=(n,s)=>{s&&(s.level==="error"?$:w)(n,s.message)},T=(n,s)=>typeof s=="string"&&Object.prototype.hasOwnProperty.call(n.columns,s)?n.columns[s]:void 0,Z=new Set,E=(n,s)=>{if(Z.has(n))return;Z.add(n);const l=G[n],d=F.get(`transform.${l.type}`).params||{};for(const u of Object.keys(d)){const h=d[u].reads,b=l[u];h&&typeof b=="string"&&O(`transforms[${n}].${u}`,Be(`transform.${l.type}`,b,T(s,b),h))}};let A=ie.get(e.data);G.slice(0,H).forEach((n,s)=>{const l=F.get(`transform.${n.type}`),d=m.length;E(s,A);try{A=l.apply(A,n)}catch(u){const h=m.slice(d).find(b=>b.level==="error");throw h?Object.assign(new Error(h.message),{path:h.path}):Object.assign(new Error(u instanceof Error?u.message:String(u)),{path:`transforms[${s}]`})}if(!A)throw new Error(`transforms[${s}] returned no table`)});const K=A,Q=G.slice(H);let W=0;for(const n of Q){const s=F.get(`transform.${n.type}`);if(s.viewDependent===!0)break;A=s.apply(A,n),W++}const i={w:e.size?e.size[0]:640,h:e.size?e.size[1]:400},f=e.padding,g=typeof f=="number"?{top:f,right:f,bottom:f,left:f}:{...xt,...f||{}};e.title&&(g.top+=He);let k=Ne(i,g);const j=e.scales||{},p=Object.create(null),I=new Map,U=new Map,S=new Map,R=new Map,x=n=>F.get(`mark.${n.type}`),B=Object.create(null),X=()=>{for(const n of Object.keys(p))p[n].setDomain(B[n]||null),B[n]&&(B[n]=p[n].domain());I.clear(),U.clear(),S.clear(),R.clear()},_e=n=>{const s=x(n),l=d=>s.channels[d]?ce(n,d,s.channels[d]):null;return{scale(d){const u=l(d),h=u&&u.scale!==void 0&&Object.prototype.hasOwnProperty.call(j,u.scale)?j[u.scale]:void 0,b=h?F.get(`scale.${h.type}`):void 0;return h&&b?{input:b.input,even:b.even===!0}:void 0},column(d){const u=l(d);return u&&u.field!==void 0?T(A,u.field):void 0}}},bt=(n={})=>{for(const s of Object.keys(j))en(s,Object.prototype.hasOwnProperty.call(n,s)?n[s]:[])},en=(n,s)=>{const l=j[n],d=F.get(`scale.${l.type}`),u=s.length?[s]:[],h=`scale "${n}"`;e.marks.forEach((v,D)=>{const C=x(v);for(const P of Object.keys(C.channels)){const V=ce(v,P,C.channels[P]);if(!(!V||V.scale!==n))if(V.field!==void 0){u.push(A.columns[V.field]),O(`marks[${D}].${P}`,Be(h,V.field,T(A,V.field),d.input));const J=C.reach?C.reach(v,P,_e(v)):null;J&&J.length&&u.push(J)}else d.fieldsOnly||u.push([V.value])}}),typeof l.field=="string"&&(u.push(A.columns[l.field]),O(`scales.${n}.field`,Be(h,l.field,T(A,l.field),d.input)));let b;try{b=d.create(l,{name:n,sources:u,range:Ce(n,l,k),color:ye})}catch(v){throw Object.assign(new Error(v instanceof Error?v.message:String(v)),{path:`scales.${n}`})}p[n]=Object.defineProperties(b,{output:{value:d.output},input:{value:d.input}})};bt();const Ue=e.view||{};for(const n of Object.keys(Ue))B[n]=Ue[n];for(const n of Object.keys(r||{}))p[n]&&!Object.prototype.hasOwnProperty.call(Ue,n)&&(B[n]=r[n]);for(const n of Object.keys(c||{})){const s=c[n];p[n]&&(s?B[n]=s:delete B[n])}X(),e.marks.forEach((n,s)=>{const l=x(n);for(const d of Object.keys(l.channels)){const u=ce(n,d,l.channels[d]),h=u&&u.field===void 0&&u.scale!==void 0?p[u.scale]:void 0,b=h?be(u.scale,j[u.scale]):void 0;if(!u||!h||b!=="width"&&b!=="height")continue;const v=h(u.value),[D,C]=h.range();v>=Math.min(D,C)-.5&&v<=Math.max(D,C)+.5||w(`marks[${s}].${d}`,`the constant ${String(u.value)} is outside scale "${u.scale}", so it is not drawn where you meant`)}});const wt=12,qe=new WeakMap,tn=(n,s,l)=>{const d=qe.get(n);if(d&&d.scale===s)return d.dir;if(n instanceof Float64Array&&s.invert&&l>=2){let D=!0,C=!0;for(let q=1;q<l&&(D||C);q++){const Y=n[q],ne=n[q-1];Y!==Y||ne!==ne?(D=!1,C=!1):(Y<ne&&(D=!1),Y>ne&&(C=!1))}const P=s(n[0]),V=s(n[l-1]);let J=0;if(isFinite(P)&&isFinite(V)&&P!==V){const q=V>P?1:-1;J=D?q:C?-q:0}return qe.set(n,{scale:s,dir:J}),J}let u=!0,h=!0,b=0;for(let D=0;D<l&&(u||h);D++){const C=s(n[D]);if(typeof C!="number"||C!==C){u=!1,h=!1;break}D>0&&(C<b&&(u=!1),C>b&&(h=!1)),b=C}const v=l<2?0:u?1:h?-1:0;return qe.set(n,{scale:s,dir:v}),v},ke=(n,s)=>{let l=0,d=n;for(;l<d;){const u=l+d>>1;s(u)?d=u:l=u+1}return l},nn=n=>{const s=A.length;let l=0,d=s;if(!Object.keys(B).length)return{from:l,to:d};const u=x(n);for(const h of Object.keys(u.channels)){const b=ce(n,h,u.channels[h]);if(!b||b.field===void 0||b.scale===void 0||!B[b.scale])continue;const v=p[b.scale],D=A.columns[b.field],C=v.range();if(!D||typeof C[0]!="number"||typeof C[1]!="number")continue;const P=tn(D,v,s);if(!P)continue;const V=Math.min(C[0],C[1])-wt,J=Math.max(C[0],C[1])+wt,q=se=>v(D[se]),Y=P===1?ke(s,se=>q(se)>=V):ke(s,se=>q(se)<=J),ne=P===1?ke(s,se=>q(se)>J):ke(s,se=>q(se)<V);l=Math.max(l,Y-1,0),d=Math.min(d,ne+1,s)}return d<l&&(d=l),{from:l,to:d}};let Le=[];const Re=new Set,Ae=Pt(t,n=>Re.add(n)),re={spec:e,format:(n,s)=>Pe(n,s,a),get table(){return A},baseTable:K,size:i,get plot(){return k},scales:p,measure:Ae?(n,s)=>{const l=it(n,s),d=Ae.inked(n,s);return d>l.w?{w:d,h:l.h}:l}:it,textWidth:Ae?Ae.width:De,wide:Tt,alongX:(e.interaction||[]).some(n=>{const s=F.get(`interaction.${n.type}`);return!!(s&&s.alongX)}),toggled(n){return(e.interaction||[]).some(s=>{const l=F.get(`interaction.${s.type}`);return!!(l&&l.toggles&&l.toggles(s,re)===n)})},say(n){typeof n=="string"&&n.trim()&&Le.push(n.trim())},orientation(n){const s=j[n]&&be(n,j[n]);return s==="width"?"horizontal":s==="height"?"vertical":null},ticks(n,s){const l=p[n];if(!l||!l.ticks)return[];const d=re.orientation(n);let u=s!==void 0?s:Math.max(2,Math.round(d==="vertical"?k.h/40:d==="horizontal"?k.w/80:6));if(s===void 0&&l.input==="category"&&d)for(const v of e.guides||[]){const D=v.scale===n?F.get(`guide.${v.type}`):void 0;D&&D.fits&&(u=Math.max(u,Math.min(l.domain().length,D.fits(v,re,d==="horizontal"?k.w:k.h))))}const h=`${n}:${u}`;let b=U.get(h);return b||U.set(h,b=l.ticks(u)),b},edgeTaken(n){const s={left:0,right:0};for(const l of e.interaction||[]){const d=F.get(`interaction.${l.type}`),u=d&&d.corner?d.corner(l,re):null;u&&u.edge===n&&(s[u.side]=Math.max(s[u.side],u.width))}return s},rows(n){let s=S.get(n);return s||S.set(n,s=nn(n)),s},series(n,s){const l=R.get(n);if(l&&l.xs===s)return l.out;const d=n.color!==void 0?re.channel(n,"color"):null,u=typeof n.group=="string"?n.group:d&&d.field,h=u?A.columns[u]:void 0,{from:b,to:v}=re.rows(n),D=new Map;for(let P=b;P<v;P++){const V=h?h[P]:0,J=D.get(V);J?J.push(P):D.set(V,[P])}const C=[];return D.forEach((P,V)=>{let J=!0;for(let q=1;q<P.length;q++)if(s[P[q]]<s[P[q-1]]){J=!1;break}J||P.sort((q,Y)=>s[q]!==s[q]?s[Y]!==s[Y]?0:1:s[Y]!==s[Y]?-1:s[q]-s[Y]),C.push({key:V,rows:P})}),R.set(n,{xs:s,out:C}),C},color:ye,channel(n,s){let l=I.get(n);if(l||I.set(n,l={}),l[s])return l[s];const d=x(n).channels[s],u=ce(n,s,d);let h;if(u)if(u.field===void 0){const b=u.scale!==void 0?p[u.scale]:void 0,v=new Array(A.length).fill(u.value),D=b?new Array(A.length).fill(b(u.value)):v;h={raw:v,mapped:D,scale:b,half:b&&b.bandwidth!==void 0?b.bandwidth/2:0}}else{const b=A.columns[u.field],v=u.scale!==void 0?p[u.scale]:void 0;if(!v)h={field:u.field,raw:b,mapped:b,half:0};else{const D=A.length,{from:C,to:P}=re.rows(n),J=typeof(P>C?v(b[C]):0)=="number"?new Float64Array(D).fill(NaN):new Array(D);for(let q=C;q<P;q++)J[q]=v(b[q]);h={field:u.field,scale:v,raw:b,mapped:J,half:v.bandwidth!==void 0?v.bandwidth/2:0}}}else{if(d&&d.required)throw new Error(`mark.${n.type}: channel "${s}" is required`);h={raw:[],mapped:[],half:0}}return l[s]=h}},$t=e.guides||[],Ve=[],kt=()=>{k=Ne(i,g);for(const d of Object.keys(p))p[d].setRange(Ce(d,j[d],k));U.clear();const n={top:0,right:0,bottom:0,left:0},s={top:0,right:0,bottom:0,left:0};Ve.length=0,$t.forEach((d,u)=>{Ve.push({...n});try{const h=F.get(`guide.${d.type}`),b=h.measure?h.measure(d,re):{};for(const v of pe)n[v]+=b[v]||0,b.overhang&&(s[v]=Math.max(s[v],b.overhang[v]||0))}catch(h){$(`guides[${u}]`,h)}});const l=d=>Math.max(g[d]+n[d],s[d]);k=Ne(i,{top:l("top"),right:l("right"),bottom:l("bottom"),left:l("left")}),l("top")+l("bottom")>i.h&&w("size",`padding and guides need ${l("top")+l("bottom")} px of height and the chart has ${i.h}, so its bottom is cut off`);for(const d of Object.keys(p))p[d].setRange(Ce(d,j[d],k));I.clear(),U.clear(),S.clear(),R.clear()};if(kt(),W){const n=()=>Object.keys(p).map(s=>p[s].baseDomain());for(let s=0;s<4;s++){for(const h of Object.keys(p))p[h].setDomain(null);let l=K;const d=Object.create(null);for(let h=0;h<W;h++){const b=H+h,v=F.get(`transform.${Q[h].type}`).apply(l,Q[h],{plot:k,scales:p,warn:D=>w(`transforms[${b}]`,D),fitting:!0,reach:(D,C)=>{typeof D=="string"&&Array.isArray(C)&&(d[D]=d[D]||[]).push(...C)}});if(!v)throw Object.assign(new Error("returned no table"),{path:`transforms[${b}]`});l=v}const u=n();if(A=l,bt(d),X(),Ut(u,n()))break;kt()}}let me;function At(){if(y(),Le=[],Q.length){let d=K;Q.forEach((u,h)=>{try{E(H+h,d);const b=F.get(`transform.${u.type}`).apply(d,u,{plot:k,scales:p,warn:v=>w(`transforms[${H+h}]`,v)});if(!b)throw new Error("returned no table");d=b}catch(b){$(`transforms[${H+h}]`,b)}}),A=d}I.clear(),U.clear(),S.clear(),R.clear();const n={grid:[],marks:[],axes:[],overlay:[]};e.marks.forEach((d,u)=>{try{const h=x(d);Fe(n.marks,h.render(d,re,u)),h.labels&&Fe(n.axes,h.labels(d,re,u))}catch(h){$(`marks[${u}]`,h)}}),$t.forEach((d,u)=>{try{const h=F.get(`guide.${d.type}`).render(d,re,Ve[u]);for(const b of Object.keys(h))Fe(n[b],h[b]||[])}catch(h){$(`guides[${u}]`,h)}}),e.title&&n.axes.push({type:"text",x:g.left,y:He-6,text:e.title,size:14,weight:600,style:{fill:"var(--bc-text, #444)"}});const s=Object.keys(B).length>0;me={size:i,plot:k,layers:["grid","marks","axes","overlay"].map(d=>({name:d,prims:n[d],clip:d==="marks"&&s?{...k}:void 0}))};const l=_t(e,Le);l&&(me.label=l),mt()}At();const de=F.get(`renderer.${e.renderer||"svg"}`).render(me,t);let We=!1;const Ot=(n,s)=>{if(!p[n]){console.warn(`[blockcharts] setView: unknown scale "${n}"`);return}s?B[n]=s:delete B[n],!We&&(We=!0,qt(()=>{if(We=!1,!N)try{X(),At(),de.update(me)}catch(l){$("view",l),console.error(l)}}))},vt=()=>{const n={};for(const s of Object.keys(p))n[s]=B[s]?B[s].slice():p[s].baseDomain();return n},rn=(n,s)=>{const l=j[n],d=j[s],u=B[s];if(!l||!d||!p[s]||!u)return null;const h=p[s].range(),b=typeof h[0]=="number"&&typeof h[1]=="number",v=b?Math.min(h[0],h[1]):0,D=b?Math.max(h[0],h[1]):0,C=F.get(`scale.${d.type}`).create({...d,domain:p[s].baseDomain()},{name:s,sources:[],range:p[s].range(),color:ye});C.setDomain(u);const P=Y=>{const ne=C(Y);return typeof ne=="number"?!b||ne>=v&&ne<=D:!!ne},V=[];let J=0;for(const Y of e.marks){const ne=x(Y),se=ue=>ce(Y,ue,ne.channels[ue]),Et=[],Je=[];for(const ue of Object.keys(ne.channels)){const ae=se(ue);!ae||ae.field===void 0||(ae.scale===s?Et.push(A.columns[ae.field]):ae.scale===n&&Je.push(A.columns[ae.field]))}if(Je.length)for(const ue of Je){const ae=[];for(let Oe=0;Oe<A.length;Oe++){let jt=!0;for(const an of Et)if(!P(an[Oe])){jt=!1;break}jt&&ae.push(ue[Oe])}J+=ae.length,V.push(ae)}}return J?F.get(`scale.${l.type}`).create(l,{name:n,sources:V,range:p[n].range(),color:ye}).baseDomain():null},on=n=>{const s=n.target,l=s&&s.closest?s.closest("[data-bc-mark]"):null;return l?{mark:Number(l.getAttribute("data-bc-mark")),row:Number(l.getAttribute("data-bc-row"))}:null},sn=Object.create(re,{host:{value:t},dataAt:{value:n=>{if(de.dataAt)return de.dataAt(n);let s=n.target;for(;s&&s!==de.root.parentNode;){const l={};let d=!1;const u=s.attributes;for(let h=0;u&&h<u.length;h++)u[h].name.indexOf("data-")===0&&(l[u[h].name.slice(5)]=u[h].value,d=!0);if(d)return l;s=s.parentNode}return null}},root:{value:de.root},list:{get:()=>me},hit:{value:on},cleanup:{value:n=>{o.push(n)}},setView:{value:Ot},getView:{value:vt},fit:{value:rn},claimPosition:{value:_},claimDrag:{value:n=>ee.push(n)},dragClaimed:{value:n=>ee.some(s=>s(n))}});return(e.interaction||[]).forEach((n,s)=>{try{F.get(`interaction.${n.type}`).attach(n,sn)}catch(l){$(`interaction[${s}]`,l)}}),{rendered:de,diagnostics:m,setView:Ot,getView:vt,viewState:()=>{const n={};for(const s of Object.keys(B))n[s]=B[s].slice();return n},get fontsDue(){return Re.size?Promise.all(Array.from(Re)):null}}}function Rt(t,e){const o=document.createElement("div");o.setAttribute("class","bc-error"),o.setAttribute("style","font:12px/1.5 monospace;color:#b00020;border:1px solid #b00020;padding:8px;white-space:pre-wrap"),o.textContent=`blockcharts:
|
|
3
3
|
`+e.map(r=>`${r.level} ${r.path||"(spec)"}: ${r.message}`).join(`
|
|
4
|
-
`),t.appendChild(o)}function ln(t){if(!t||typeof t!="object")return[{level:"error",path:"",message:"the spec must be an object"}];const e=rt(t);return e?[{level:"error",path:"data",message:e}]:[]}const Vt=200,Wt=100;function lt(t){const e=(o,r)=>Array.isArray(r)&&r.every(c=>{if(!c||typeof c!="object"||typeof c.type!="string")return!1;const a=F.get(`${o}.${c.type}`),y=a&&a.role===o?a.narrow:void 0;try{return typeof y=="function"?y(c)===!0:y===!0}catch{return!1}});return e("mark",t.marks)&&(t.guides===void 0||e("guide",t.guides))}function dt(t,e){let o=e,r=null,c=[],a=null,y=[],m=0,$=!1,w=null,N={},z;const M=new Promise(E=>{z=E}),_=()=>a?c.concat(a.diagnostics):c;function ee(){for(const E of y)try{E()}catch(A){console.error(A)}y=[],a&&a.rendered.destroy(),a=null,t.textContent=""}function G(){const E=document.createElement("div");E.setAttribute("class","bc-loading"),E.setAttribute("style","font:12px system-ui,sans-serif;color:#777;padding:8px"),E.textContent="Loading data\u2026",t.appendChild(E)}function te(E){ee();const A=o&&typeof o.data=="string"?
|
|
4
|
+
`),t.appendChild(o)}function ln(t){if(!t||typeof t!="object")return[{level:"error",path:"",message:"the spec must be an object"}];const e=rt(t);return e?[{level:"error",path:"data",message:e}]:[]}const Vt=200,Wt=100;function lt(t){const e=(o,r)=>Array.isArray(r)&&r.every(c=>{if(!c||typeof c!="object"||typeof c.type!="string")return!1;const a=F.get(`${o}.${c.type}`),y=a&&a.role===o?a.narrow:void 0;try{return typeof y=="function"?y(c)===!0:y===!0}catch{return!1}});return e("mark",t.marks)&&(t.guides===void 0||e("guide",t.guides))}function dt(t,e){let o=e,r=null,c=[],a=null,y=[],m=0,$=!1,w=null,N={},z;const M=new Promise(E=>{z=E}),_=()=>a?c.concat(a.diagnostics):c;function ee(){for(const E of y)try{E()}catch(A){console.error(A)}y=[],a&&a.rendered.destroy(),a=null,t.textContent=""}function G(){const E=document.createElement("div");E.setAttribute("class","bc-loading"),E.setAttribute("style","font:12px system-ui,sans-serif;color:#777;padding:8px"),E.textContent="Loading data\u2026",t.appendChild(E)}function te(E){ee();const A=o&&typeof o.data=="string"?oe.get(o.data):void 0;if(A){G(),A.then(()=>{!$&&E===m&&te(E)});return}c=st(o);const K=w,Q=N;if(w=null,N={},!c.some(i=>i.level==="error"))try{r=H(o);const i=r===null?o:{...o,size:[r,Array.isArray(o.size)?o.size[1]:400]};a=Lt(t,i,y,K||void 0,Q);const f=a.fontsDue;f&&f.then(()=>{$||E!==m||(w=a?a.viewState():w,L())})}catch(i){mt();const f=i&&typeof i.path=="string"?i.path:"";c.push({level:"error",path:f,message:i instanceof Error?i.message:String(i)})}const W=_();if(W.length){for(const i of W)(i.level==="error"?console.error:console.warn)(`[blockcharts] ${i.path||"(spec)"}: ${i.message}`);c.some(i=>i.level==="error")&&Rt(t,W)}z()}const L=()=>te(++m),H=E=>{if(!E||typeof E!="object"||E.responsive===!1)return null;const A=t.clientWidth,K=Array.isArray(E.size)&&typeof E.size[0]=="number"?E.size[0]:640;if(typeof A!="number"||!isFinite(A)||A<=0)return null;const Q=lt(E)?Wt:Vt,W=Math.max(Math.round(A),Math.min(K,Q));return Math.abs(W-K)<1?null:W},O=globalThis;let T=null,Z=!1;if(typeof O.ResizeObserver=="function"){const E=new O.ResizeObserver(()=>{if(Z||$)return;Z=!0,(typeof requestAnimationFrame=="function"?requestAnimationFrame:K=>setTimeout(K,16))(()=>{Z=!1,!($||H(o)===r)&&(w=a?a.viewState():w,L())})});E.observe(t),T=E}return L(),{host:t,get spec(){return o},get diagnostics(){return _()},ready:M,update(E,A){if($)return;const K=a?a.viewState():w||{},Q={};if(!(A&&A.resetView)){const W=o&&o.scales||{},i=E&&E.scales||{};for(const f of Object.keys(K))W[f]&&i[f]&&W[f].type===i[f].type&&(Q[f]=K[f])}for(const W of Object.keys(N)){const i=o&&o.scales||{},f=E&&E.scales||{};(A&&A.resetView||!i[W]||!f[W]||i[W].type!==f[W].type)&&delete N[W]}o=E,w=Q,L()},setView(E,A){if(!$){if(a)return a.setView(E,A);if(!(o&&o.scales&&Object.prototype.hasOwnProperty.call(o.scales,E))){console.warn(`[blockcharts] setView: unknown scale "${E}"`);return}N[E]=A}},getView(){if(a)return a.getView();const E={...o&&o.view||{}};for(const A of Object.keys(w||{}))Object.prototype.hasOwnProperty.call(E,A)||(E[A]=w[A]);for(const A of Object.keys(N)){const K=N[A];K?E[A]=K:delete E[A]}return E},destroy(){$=!0,T&&T.disconnect(),m++,ee(),z()}}}const ut=new WeakMap,ht=new WeakSet;function Te(t){const e=t||document,o=e.ownerDocument||e,r=[];return e.querySelectorAll("script#bc-data").forEach(c=>{try{const a=JSON.parse(c.textContent||"{}");for(const y of Object.keys(a))nt(y,a[y])}catch(a){console.error("[blockcharts] #bc-data:",a)}}),e.querySelectorAll("script[data-bc-chart]").forEach(c=>{if(ut.has(c))return;let a;try{a=JSON.parse(c.textContent||"")}catch($){console.error("[blockcharts] chart spec is not valid JSON:",$);return}const y=a&&typeof a=="object"&&typeof a.id=="string"&&a.id?a.id:null;let m=y?o.getElementById(y):null;m&&ht.has(m)?(console.error(`[blockcharts] chart id "${y}" is used by another chart on the page; this one is drawn where its spec is`),m=null):m&&/^script$/i.test(m.tagName||"")&&(m=null),m||(m=o.createElement("div"),y&&!o.getElementById(y)&&(m.id=y),m.className="bc-chart",c.parentNode&&c.parentNode.insertBefore(m,c.nextSibling));try{const $=dt(m,a);ht.add(m),ut.set(c,$),r.push($)}catch($){console.error("[blockcharts] chart could not be mounted:",$)}}),r}const Jt=864e13,Ht=/^(\d{4}-\d{2}-\d{2})[T ](\d{2}:\d{2}(?::\d{2}(?:[.,]\d+)?)?)\s*(Z|[+-]\d{2}(?::?\d{2})?)?$/i,Kt=/^(?:\d{4}|[+-]\d{6})(?:-\d{2}(?:-\d{2})?)?$/;function we(t){if(typeof t=="number")return Math.abs(t)<=Jt?t:NaN;if(typeof t=="string"){const e=t.trim(),o=Ht.exec(e);if(!o)return Kt.test(e)?Date.parse(e):NaN;const r=o[3]===void 0?"Z":o[3].length===3?o[3]+":00":o[3].length===5?o[3].slice(0,3)+":"+o[3].slice(3):o[3];return Date.parse(`${o[1]}T${o[2].replace(",",".")}${r.toUpperCase()}`)}if(t&&typeof t.getTime=="function"){const e=t.getTime();return typeof e=="number"?e:NaN}return NaN}const Zt=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;function Be(t,e,o,r){if(!o||typeof o!="object"||ArrayBuffer.isView(o)||r!=="number"&&r!=="date")return null;let c=0,a=0;const y=[],m=[];for(let z=0;z<o.length;z++){const M=o[z];if(!(M==null||M===""||typeof M=="number"&&isNaN(M)))if(c++,r==="number"?typeof M=="number"&&isFinite(M):isFinite(we(M)))a++;else{const _=typeof M=="string"&&Zt.test(M.trim())?m:y;_.length<3&&_.indexOf(M)<0&&_.push(M)}}if(a===c)return null;const $=r==="number"?"numbers":"dates",w=y.concat(m).slice(0,3).map(z=>{const M=JSON.stringify(z)||String(z);return M.length>28?M.slice(0,27)+"\u2026":M}).join(", "),N=r==="number"?'A number is written as a number: 1750.5, not "1750.5", "1,750.50", "1750,5" or "$1,750"':'A date is ISO text ("2024-03-15", "2024-03-15T09:30") or epoch milliseconds';return a?{level:"warn",path:"",message:`${t} reads ${$} from "${e}", and ${c-a} of its ${c} values ${c-a===1?`is not a ${$.slice(0,-1)}, so it is`:`are not ${$}, so they are`} left out: ${w}. ${N}; where there is no value, null`}:{level:"error",path:"",message:`${t} reads ${$} from "${e}", and it has none: its values are like ${w}, so nothing of it is drawn. ${N}; where there is no value, null`}}const Gt="en-US",gt=["era","year","month","day","weekday","hour","minute","second","dayPeriod","fractionalSecondDigits","timeZoneName","dateStyle","timeStyle","hour12","hourCycle"],$e={percent:{kind:"number",style:"percent",maximumFractionDigits:1},compact:{kind:"number",notation:"compact",maximumFractionDigits:1},integer:{kind:"number",maximumFractionDigits:0},year:{kind:"date",year:"numeric"},quarter:{kind:"date",year:"numeric"},month:{kind:"date",month:"short",year:"numeric"},day:{kind:"date",month:"short",day:"numeric"},date:{kind:"date",dateStyle:"medium"},datetime:{kind:"date",dateStyle:"medium",timeStyle:"short"}},yt=new Map;let Ie;const mt=()=>{Ie=void 0},Xt=["style","currency","currencyDisplay","currencySign","unit","unitDisplay","notation","compactDisplay","signDisplay","useGrouping","minimumIntegerDigits","minimumFractionDigits","maximumFractionDigits","minimumSignificantDigits","maximumSignificantDigits","roundingMode","roundingIncrement","roundingPriority","trailingZeroDisplay","numberingSystem"],Yt={ko:(t,e)=>`${e}\uB144 ${t}\uBD84\uAE30`,zh:(t,e)=>`${e}\u5E74\u7B2C${t}\u5B63\u5EA6`,ja:(t,e)=>`${e}\u5E74\u7B2C${t}\u56DB\u534A\u671F`};function Pe(t,e,o){let r;if(typeof t=="string"){if(!Object.prototype.hasOwnProperty.call($e,t))throw new Error(`unknown format "${t}" (presets: ${Object.keys($e).join(", ")}; or an object of Intl options)`);r=$e[t]}else if(t&&typeof t=="object"&&!Array.isArray(t))r=t;else throw new Error("a format is a preset name or an object of Intl options");const c=r===$e.quarter,a=typeof r.locale=="string"&&r.locale||o||Ie||Gt,y=(e||"")+"|"+a+"|"+(c?"quarter":JSON.stringify(r)),m=yt.get(y);if(m)return m;const{locale:$,kind:w,prefix:N,suffix:z,...M}=r;if($!==void 0&&typeof $!="string")throw new Error('format "locale" must be a string like "en-US"');for(const[O,T]of[["prefix",N],["suffix",z]])if(T!==void 0&&typeof T!="string")throw new Error(`format "${O}" must be a string`);if(w!==void 0&&w!=="number"&&w!=="date")throw new Error('format "kind" must be "number" or "date"');for(const O of Object.keys(M))if(Xt.indexOf(O)<0&>.indexOf(O)<0&&O!=="timeZone"&&O!=="calendar"&&O!=="era"&&O!=="dayPeriod")throw new Error(`format option "${O}" is not known (a preset is written as the format itself, "quarter", and the language comes from "locale" or the chart)`);const _=(e||w||(Object.keys(M).some(O=>gt.indexOf(O)>=0)?"date":"number"))==="date";let ee,G;try{_?G=new Intl.DateTimeFormat(a,{timeZone:"UTC",...M}):ee=new Intl.NumberFormat(a,M)}catch(O){throw new Error(`invalid format ${JSON.stringify(t)}: ${O instanceof Error?O.message:String(O)}`)}const te=Yt[a.split("-")[0].toLowerCase()],L=O=>{if(!c)return G.format(O);const T=new Date(O),Z=Math.floor(T.getUTCMonth()/3)+1;return te?te(Z,T.getUTCFullYear()):"Q"+Z+" "+G.format(O)},H=O=>{if(O==null||typeof O=="number"&&isNaN(O))return"";let T;if(ee)T=typeof O=="number"&&isFinite(O)?ee.format(O):String(O);else{const Z=we(O);T=isFinite(Z)?L(Z):String(O)}return(N||"")+T+(z||"")};return yt.set(y,H),H}const Qt={version:ve,define:Ct,has:t=>F.has(t),get:t=>F.get(t),blocks:()=>Array.from(F.keys()),color:ye,palette:Object.freeze(ge.slice()),data:nt,ready:Nt,defineFn:(t,e)=>{if(typeof e!="function")throw new Error("BC.defineFn: "+t+" is not a function");Ke.set(t,e)},getFn:t=>Ke.get(t),formatter:(t,e)=>Pe(t,e),time:we,needs:Ft,validate:st,narrow:t=>!!t&&typeof t=="object"&<(t),table:t=>ie.get(t),chart:dt,mount:Te};Ee.BC=Qt;const pt=Ee.BC_CONFIG;typeof document<"u"&&!(pt&&pt.autoMount===!1)&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>Te()):setTimeout(()=>Te(),0))})();
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
"use strict";(function(i){function r(c,f,l,h,m){const o=e=>{throw new Error(c+": "+e)},a=e=>Object.prototype.hasOwnProperty.call(f.columns,e);for(const[e,n]of l)n!==void 0&&(typeof n!="string"||!a(n))&&o(`unknown field "${String(n)}" in "${e}"`);const t=new Map;for(const[e,n]of h)n==="__proto__"&&o(`a column cannot be named "__proto__": give "${e}" another name`),t.has(n)&&o(`"${t.get(n)}" and "${e}" both name the new column "${n}"`),t.set(n,e),a(n)&&m.indexOf(n)<0&&o(`"${n}" is already a column of the data: give the new one another name with "${e}"`)}const s={role:"lib",type:"columns",version:2,exports:{check:r}};i.define(s)})(globalThis.BC);
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"use strict";(function(u){const e=n=>Math.round(n*100)/100;function k(n,f){const c=n.length,r=[];for(let o=0;o<c-1;o++){const h=n[o+1]-n[o];r.push(h?(f[o+1]-f[o])/h:0)}const s=new Array(c);s[0]=r[0]||0,s[c-1]=r[c-2]||0;for(let o=1;o<c-1;o++)s[o]=r[o-1]*r[o]<=0?0:(r[o-1]+r[o])/2;for(let o=0;o<c-1;o++){if(!r[o]){s[o]=0,s[o+1]=0;continue}const h=s[o]/r[o],i=s[o+1]/r[o],t=h*h+i*i;if(t>9){const l=3/Math.sqrt(t);s[o]=l*h*r[o],s[o+1]=l*i*r[o]}}return s}function d(n,f,c,r){const s=n.length;let o="";if(c==="step"){if(r)for(let t=s-1;t>0;t--)o+="V"+e(f[t-1])+"H"+e(n[t-1]);else for(let t=1;t<s;t++)o+="H"+e(n[t])+"V"+e(f[t]);return o}if(!(c===!0||c==="smooth")||s<3){if(r)for(let t=s-2;t>=0;t--)o+="L"+e(n[t])+" "+e(f[t]);else for(let t=1;t<s;t++)o+="L"+e(n[t])+" "+e(f[t]);return o}const i=k(n,f);if(r)for(let t=s-1;t>0;t--){const l=(n[t]-n[t-1])/3;o+="C"+e(n[t]-l)+" "+e(f[t]-i[t]*l)+" "+e(n[t-1]+l)+" "+e(f[t-1]+i[t-1]*l)+" "+e(n[t-1])+" "+e(f[t-1])}else for(let t=0;t<s-1;t++){const l=(n[t+1]-n[t])/3;o+="C"+e(n[t]+l)+" "+e(f[t]+i[t]*l)+" "+e(n[t+1]-l)+" "+e(f[t+1]-i[t+1]*l)+" "+e(n[t+1])+" "+e(f[t+1])}return o}const g={role:"lib",type:"curve",version:2,exports:{through:d}};u.define(g)})(globalThis.BC);
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
"use strict";(function(
|
|
13
|
+
"use strict";(function(v){function m(t,i){const e=t.root.getBoundingClientRect();return{x:(i.clientX-e.left)*t.size.w/e.width,y:(i.clientY-e.top)*t.size.h/e.height}}function w(t,i,e=0){const r=t.plot;return i.x>=r.x-e&&i.x<=r.x+r.w+e&&i.y>=r.y-e&&i.y<=r.y+r.h+e}function x(t,i){let e=null;return t.spec.marks.forEach((r,n)=>{const c=v.get(`mark.${r.type}`);if(!c||!c.pick)return;let s=null;try{s=c.pick(r,t,n,i.x,i.y)}catch{return}s&&isFinite(s.dist)&&(!e||s.dist<=e.pick.dist)&&(e={pick:s,mark:r,def:c,index:n})}),e}function b(t){typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>t()):setTimeout(t,0)}function g(t,i,e,r){const n=t.root,c=t.host,s=c.ownerDocument||document;let u=null,a=!1,L=!1;const f=o=>o.pointerType==="touch",p=o=>{if(o.buttons&&!f(o))return u=null,e();u=o,!a&&(a=!0,b(()=>{if(a=!1,L||!u)return;const d=u;u=null;try{i(d)}catch{e()}}))},y=o=>{(!r||f(o))&&p(o)},l=()=>{u=null,e()},E=o=>{f(o)||l()},h=o=>{const d=o.target;f(o)&&d&&typeof c.contains=="function"&&!c.contains(d)&&l()};n.addEventListener("pointermove",p),n.addEventListener("pointerdown",y),n.addEventListener("pointerleave",E),n.addEventListener("pointercancel",l),n.addEventListener("wheel",l),typeof s.addEventListener=="function"&&s.addEventListener("pointerdown",h,!0),t.cleanup(()=>{L=!0,n.removeEventListener("pointermove",p),n.removeEventListener("pointerdown",y),n.removeEventListener("pointerleave",E),n.removeEventListener("pointercancel",l),n.removeEventListener("wheel",l),typeof s.removeEventListener=="function"&&s.removeEventListener("pointerdown",h,!0)})}const k={role:"lib",type:"pointer",version:3,exports:{toLogical:m,inPlot:w,pickAt:x,follow:g}};v.define(k)})(globalThis.BC);
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
"use strict";(function(M){function h(s,e){const a=s/Math.max(1,e),o=Math.pow(10,Math.floor(Math.log10(a))),t=a/o;return(t<1.5?1:t<3?2:t<7?5:10)*o}const f=1e3;function u(s,e,a){const o=Math.min(s,e),t=Math.max(s,e),i=[];if(!(isFinite(o)&&isFinite(t)&&t-o>1e-12*Math.max(Math.abs(o),Math.abs(t))))return i;const n=h(t-o,a);if(!(n>0&&isFinite(n)))return i;const r=Math.min(100,Math.max(0,-Math.floor(Math.log10(n)))),p=Math.ceil(o/n-1e-9),x=Math.floor(t/n+1e-9);for(let c=p;c<=x&&i.length<f;c++){const l=+(c*n).toFixed(r);i.push({value:l,label:l.toFixed(r)})}return i}const m={role:"lib",type:"ticks",version:2,exports:{niceStep:h,roundTicks:u}};M.define(m)})(globalThis.BC);
|
|
@@ -88,10 +88,13 @@
|
|
|
88
88
|
"use strict";(function(j){const M="var(--bc-text, #444)",z=t=>t.output==="color"&&t.input==="category";function Y(t,e){const n=t.scale?e.scales[t.scale]:void 0;if(!n||!(n.output==="color"||n.output==="size"&&n.input==="number"))throw new Error("guide.legend needs a scale of colors, or of sizes for numbers");return n}function x(t,e,n){return C(t,e,3).filter(o=>isFinite(o.pos)&&o.pos>0).map(o=>({label:o.label,r:o.pos,w:E(o.label,n),drawn:n.textWidth(o.label,11)}))}const tt="var(--bc-label, var(--bc-text, #888))",N=t=>2*t.r+6+t.w,et=t=>2*t.r+6+t.drawn,p=(t,e)=>{const n=q(t,e);return Math.max(1,t.size.w-Math.max(8,n.left)-Math.max(8,n.right))},q=(t,e)=>e==="top"||e==="bottom"?t.edgeTaken(e):{left:0,right:0},W=(t,e,n,s)=>{const o=q(t,e);return Math.max(Math.max(8,o.left),Math.min(n,t.size.w-Math.max(8,o.right)-s))};function K(t,e){const n=[];let s=0;for(const o of t){const r=n[n.length-1];!r||r.items.length&&s+O+N(o)>e?(n.push({items:[o],h:Math.max(2*o.r,16)+4}),s=N(o)):(r.items.push(o),r.h=Math.max(r.h,Math.max(2*o.r,16)+4),s+=O+N(o))}return n}const E=(t,e)=>Math.max(e.measure(t,11).w,e.textWidth(t,11));function F(t,e,n=1/0){const s=new Set(t.domain()),o=t.range();return t.baseDomain().map((r,i)=>{const l=String(r),h=U(l,n-10-6,e);return{label:h,full:l,color:o[i],w:E(h,e),drawn:e.textWidth(h,11),hidden:!s.has(r),index:i}})}function U(t,e,n){if(!(e<1/0)||E(t,n)<=e)return t;const s=Array.from(t);let o=0,r=s.length;for(;o<r;){const i=o+r+1>>1;E(s.slice(0,i).join("")+"\u2026",n)<=e?o=i:r=i-1}return s.slice(0,o).join("").trimEnd()+"\u2026"}function C(t,e,n=4){const s=t.ticks?t.ticks(n):[];if(e.format===void 0)return s;const o=j.formatter(e.format,"number");return s.map(r=>({value:r.value,pos:r.pos,label:o(r.value)}))}const R=t=>typeof t.title=="string"&&t.title?t.title:"",H=t=>R(t)?16:0,nt=(t,e)=>R(t)?e.measure(R(t),11).w:0,ot=.2;function st(t,e){if(!z(t))return"right";const n=p(e,"top");return I(F(t,e,n),n).length<=2?"top":"right"}function k(t,e,n){const s=nt(t,n),o=H(t);if(e.output==="size"){const i=x(e,t,n),l=i.reduce((h,b)=>Math.max(h,b.r),0);return{w:Math.max(2*l+6+i.reduce((h,b)=>Math.max(h,b.w),0),s)+16,h:4+o+i.reduce((h,b)=>h+Math.max(2*b.r,16)+4,0)}}if(!z(e)){const i=C(e,t).reduce((l,h)=>Math.max(l,n.measure(h.label,11).w),0);return{w:Math.max(18+i,s)+16,h:0}}const r=F(e,n);return{w:Math.max(16+r.reduce((i,l)=>Math.max(i,l.w),0),s)+16,h:4+o+r.length*16+4}}function X(t,e,n){const s=t.position==="auto"?st(e,n):t.position||"right";if(!B(s))return s;const o=k(t,e,n);return o.w<=n.size.w*ot&&o.h<=n.size.h?s:"top"}const B=t=>t==="left"||t==="right",Z=(t,e,n)=>Math.max(e,Math.min(n,t)),O=14,J=t=>16+t.w,it=t=>16+t.drawn;function I(t,e){const n=[];let s=[],o=0;for(const r of t){const i=J(r);s.length&&o+O+i>e&&(n.push(s),s=[],o=0),o+=(s.length?O:0)+i,s.push(r)}return s.length&&n.push(s),n}function rt(t,e){return t?Z(e.plot.h*.6,80,200):Z(e.plot.w*.4,100,240)}const lt={role:"guide",type:"legend",version:16,shownOnce:!0,params:{scale:{kind:"scale",required:!0},position:{kind:"enum",values:["top","right","bottom","left","auto"],default:"right"},title:{kind:"string"},format:{kind:"format"}},measure(t,e){const n=Y(t,e),s=X(t,n,e),o=B(s),r=H(t),i={};if(n.output==="size"){const b=x(n,t,e);return i[s]=b.length?o?k(t,n,e).w:K(b,p(e,s)).reduce((T,w)=>T+w.h,0)+8+r:0,i}if(!z(n))return i[s]=o?k(t,n,e).w:12+e.measure("0",11).h+16+r,i;const l=p(e,s),h=F(n,e,o?1/0:l);return i[s]=h.length?o?k(t,n,e).w:I(h,l).length*16+8+r:0,i},render(t,e,n){const s=Y(t,e),o=X(t,s,e),r=B(o),{x:i,y:l,w:h,h:b}=e.plot,T=[],w=H(t),v=r?R(t):U(R(t),p(e,o),e),y=v?e.measure(v,11).w:0,S=(u,d)=>{w&&T.push({type:"text",x:u,y:d+16/2,text:v,size:11,weight:600,baseline:"middle",style:{fill:M},cls:"bc-legend-title"})};if(s.output==="size"){const u=x(s,t,e),d=u.reduce((m,f)=>Math.max(m,f.r),0),a=(m,f,A,c)=>{T.push({type:"circle",cx:m,cy:f,r:A.r,style:{fill:"none",stroke:tt,strokeWidth:1},cls:"bc-legend-size"}),T.push({type:"text",x:c,y:f,text:A.label,size:11,baseline:"middle",style:{fill:M}})};if(r){const m=Math.max(2*d+6+u.reduce((c,g)=>Math.max(c,g.w),0),y)+16,f=(o==="right"?i+h+n.right:i-n.left-m)+8;S(f,l+4);let A=l+4+w;for(const c of u){const g=Math.max(2*c.r,16)+4;a(f+d,A+g/2,c,f+2*d+6),A+=g}}else{const m=K(u,p(e,o));let f=o==="top"?l-n.top-(m.reduce((A,c)=>A+c.h,0)+8+w):l+b+n.bottom+8/2;S(W(e,o,i,y),f),f+=w;for(const A of m){let c=W(e,o,i,A.items.reduce((g,D,G)=>g+(G?O:0)+N(D),0));for(const g of A.items)a(c+g.r,f+A.h/2,g,c+2*g.r+6),c+=et(g)+O;f+=A.h}}return{axes:T}}if(!z(s)){const[u,d]=s.domain(),a=rt(r,e),m=C(s,t),f=m.reduce((P,L)=>Math.max(P,e.measure(L.label,11).w),0),A=Math.max(18+f,y)+16,c=o==="right"?i+h+n.right+8:i-n.left-A+8,g=o==="top"?l-n.top-(12+e.measure("0",11).h+16+w)+8:l+b+n.bottom+8,D=g+w,G=l+4+w+(w?11/2:0);r?S(c,l+4):S(W(e,o,i,y),g);const V=a/48*1.05;for(let P=0;P<48;P++){const L=r?d-(P+.5)/48*(d-u):u+(P+.5)/48*(d-u),$=s(L);T.push(r?{type:"rect",x:c,y:G+P*a/48,w:12,h:V,style:{fill:$},cls:"bc-legend-bar"}:{type:"rect",x:i+P*a/48,y:D,w:V,h:12,style:{fill:$},cls:"bc-legend-bar"})}for(const P of m)T.push(r?{type:"text",x:c+12+6,y:G+(1-P.pos)*a,text:P.label,size:11,baseline:"middle",style:{fill:M}}:{type:"text",x:i+P.pos*a,y:D+12+3,text:P.label,size:11,anchor:"middle",baseline:"hanging",style:{fill:M}});return{axes:T}}const _=F(s,e,r?1/0:p(e,o)),at=e.toggled(String(t.scale)),Q=(u,d,a)=>{T.push({type:"g",cls:"bc-legend-item",data:{"bc-legend-scale":String(t.scale),"bc-legend-index":String(a.index)},pressed:at?!a.hidden:void 0,style:a.hidden?{opacity:.4}:void 0,title:a.label!==a.full?a.full:void 0,children:[{type:"rect",x:u,y:d+6/2,w:10,h:10,r:10/2,style:{fill:a.color},cls:"bc-legend-swatch"},{type:"text",x:u+10+6,y:d+16/2,text:a.label,size:11,baseline:"middle",style:{fill:M}}]})};if(r){const u=Math.max(16+_.reduce((a,m)=>Math.max(a,m.w),0),y)+16,d=o==="right"?i+h+n.right:i-n.left-u;S(d+8,l+4),_.forEach((a,m)=>Q(d+8,l+4+w+m*16,a))}else{const u=I(_,p(e,o)),d=o==="top"?l-n.top-(u.length*16+8+w):l+b+n.bottom+8/2,a=d+w;S(W(e,o,i,y),d),u.forEach((m,f)=>{let A=W(e,o,i,m.reduce((c,g,D)=>c+(D?O:0)+J(g),0));for(const c of m)Q(A,a+f*16,c),A+=it(c)+O})}return{axes:T}}};j.define(lt)})(globalThis.BC);
|
|
89
89
|
|
|
90
90
|
|
|
91
|
+
"use strict";(function(p){const x=["bc-mark","bc-row","bc-layer"],s=()=>p.get("lib.pointer").exports,L={role:"interaction",type:"click",version:1,requires:["lib.pointer"],events:["bc-click"],params:{cursor:{kind:"boolean",default:!0}},attach(O,o){const c=o.root,u=o.host,g=u.ownerDocument||document,C=t=>{const n=o.dataAt(t);return!!n&&Object.keys(n).some(l=>x.indexOf(l)<0)},w=t=>{const n=s().toLogical(o,t);return!s().inPlot(o,n,12)||C(t)?null:s().pickAt(o,n)};let a=null;const b=t=>{a={x:t.clientX,y:t.clientY}},m=t=>{const n=a;if(a=null,t.detail>1||n&&Math.hypot(t.clientX-n.x,t.clientY-n.y)>4)return;const l=w(t);if(!l)return;const{pick:e,mark:D,index:A}=l,d=o.table,y={};for(const E of Object.keys(d.columns))y[E]=d.columns[E][e.row];const P={row:e.row,rows:e.rows&&e.rows.length?e.rows.slice():[e.row],values:y,mark:D,markIndex:A,x:e.x,y:e.y,table:d,event:t},h=g.defaultView||globalThis;typeof h.CustomEvent!="function"||typeof u.dispatchEvent!="function"||u.dispatchEvent(new h.CustomEvent("bc-click",{bubbles:!0,detail:P}))};c.addEventListener("pointerdown",b),c.addEventListener("click",m);let i=!1,k="";const r=c.style,f=()=>{i&&r.cursor==="pointer"&&(r.cursor=k),i=!1};O.cursor!==!1&&r&&s().follow(o,t=>{if(!w(t))return f();i||r.cursor==="pointer"||(k=r.cursor||"",r.cursor="pointer",i=!0)},f,!0),o.cleanup(()=>{c.removeEventListener("pointerdown",b),c.removeEventListener("click",m),f()})}};p.define(L)})(globalThis.BC);
|
|
92
|
+
|
|
93
|
+
|
|
91
94
|
"use strict";(function(x){const O="bc-legend-scale",K="bc-legend-index",S="bc-legend-filter",A=s=>s.output==="color"&&s.input==="category",E=(s,o,a)=>{const l=(o.guides||[]).find(m=>typeof m.scale=="string"&&!!a[m.scale]&&A(a[m.scale])),d=typeof s.scale=="string"?s.scale:l?l.scale:void 0;return d&&a[d]&&A(a[d])?d:void 0},T=s=>s.key==="Enter"||s.key===" "||s.key==="Spacebar",I={role:"interaction",type:"legend-filter",version:6,outerLegend:!0,params:{scale:{kind:"scale"},legend:{kind:"string"},fit:{kind:"list"}},toggles:(s,o)=>typeof s.legend=="string"?void 0:E(s,o.spec,o.scales),attach(s,o){const a=typeof s.legend=="string"?s.legend:null,l=E(s,o.spec,o.scales),d=l?o.scales[l]:void 0;if(!l||!d){console.warn('[blockcharts] interaction.legend-filter: needs a categorical color scale (set "scale", or add a legend guide for one); ignored');return}const m=(Array.isArray(s.fit)?s.fit:[]).filter(t=>{const e=typeof t=="string"&&!!o.scales[t]&&t!==l;return!e&&typeof t=="string"&&console.warn(`[blockcharts] interaction.legend-filter: cannot fit scale "${t}"`),e}),i=o.root,c=d.baseDomain(),V=o.host.ownerDocument||document,f=a?V.getElementById(a):null;if(a&&!f)return;const k=()=>o.getView()[l],h=t=>{o.setView(l,t.length===0||t.length===c.length?null:t);for(const e of m)o.setView(e,o.fit(e,l));if(f){const e=t.length?t:c;f.querySelectorAll("[data-bc-legend-index]").forEach(n=>{const r=e.indexOf(c[Number(n.getAttribute("data-bc-legend-index"))])>=0;n.setAttribute("aria-pressed",r?"true":"false")})}},p=t=>{if(f){const r=t.target?.closest?.("[data-bc-legend-index]"),u=r?Number(r.getAttribute("data-bc-legend-index")):NaN;return Number.isInteger(u)&&u>=0&&u<c.length?{value:c[u]}:null}const e=o.dataAt(t);if(!e||e[O]!==l)return null;const n=Number(e[K]);return Number.isInteger(n)&&n>=0&&n<c.length?{value:c[n]}:null};let g=null;const v=t=>{if(t.detail>1)return;const e=p(t);if(!e)return;const n=k();g={shown:n.slice(),at:Date.now()},h(c.filter(r=>r===e.value?n.indexOf(r)<0:n.indexOf(r)>=0))},L=t=>{const e=p(t);if(!e)return;t.preventDefault();const n=g&&Date.now()-g.at<700?g.shown:k();g=null,h(n.length===1&&n[0]===e.value?c.slice():[e.value])},C=t=>{const e=t;if(!T(e)||e.altKey||e.ctrlKey||e.metaKey)return;const n=p(t);if(!n||(t.preventDefault(),e.repeat))return;const r=k();g=null,e.shiftKey?h(r.length===1&&r[0]===n.value?c.slice():[n.value]):h(c.filter(u=>u===n.value?r.indexOf(u)<0:r.indexOf(u)>=0))},b=f||i;b.addEventListener("click",v),b.addEventListener("dblclick",L),b.addEventListener("keydown",C);let y=null;const N=t=>{const e=i.style,n=!!p(t);n&&y===null?(y=e.cursor,e.cursor="pointer"):!n&&y!==null&&(e.cursor=y,y=null)},D=!f&&typeof i.getContext=="function";D&&i.addEventListener("pointermove",N);const w=i.getAttribute("class");i.setAttribute("class",((w||"")+" "+S).trim()),o.cleanup(()=>{b.removeEventListener("click",v),b.removeEventListener("dblclick",L),b.removeEventListener("keydown",C),D&&i.removeEventListener("pointermove",N),w===null?i.removeAttribute?i.removeAttribute("class"):i.setAttribute("class",""):i.setAttribute("class",w)})}};x.define(I)})(globalThis.BC);
|
|
92
95
|
|
|
93
96
|
|
|
94
|
-
"use strict";(function(M){const ht=i=>i==null||i===""||typeof i=="number"&&isNaN(i),bt=/\d|[a-z][A-Z]|_/;function gt(i){if(i==null)return"\u2013";if(typeof i=="number")return isNaN(i)?"\u2013":Number.isInteger(i)?String(i):String(+i.toPrecision(6));const o=String(i);return o.length>80?o.slice(0,79)+"\u2026":o}const Y=()=>M.get("lib.pointer").exports,yt=(i,o,S,H)=>M.get("lib.pointer").exports.follow(i,o,S,H),mt={role:"interaction",type:"tooltip",version:23,requires:["lib.pointer"],params:{fields:{kind:"fields"},formats:{kind:"formats"},labels:{kind:"any"},content:{kind:"any"},heading:{kind:"field"},marker:{kind:"enum",values:["auto","dot","box","none"],default:"auto"}},attach(i,o){const S=o.host,H=o.root,u=S.ownerDocument||document,_={};if(i.formats&&typeof i.formats=="object"&&!Array.isArray(i.formats)){const t=i.formats;for(const n of Object.keys(t))try{_[n]=o.format(t[n])}catch(r){console.warn(`[blockcharts] interaction.tooltip: format of "${n}" ignored: ${r instanceof Error?r.message:String(r)}`)}}else i.formats!==void 0&&console.warn('[blockcharts] interaction.tooltip: "formats" must be an object of field name to format; ignored');const v=o.format("date"),I={};for(const t of Array.isArray(o.spec.transforms)?o.spec.transforms:[]){const n=t&&M.get(`transform.${t.type}`);if(!(!n||typeof n.labels!="function"))try{Object.assign(I,n.labels(t))}catch{}}if(i.labels&&typeof i.labels=="object"&&!Array.isArray(i.labels)){const t=i.labels;for(const n of Object.keys(t))o.table.columns[n]?typeof t[n]!="string"?console.warn(`[blockcharts] interaction.tooltip: label of "${n}" must be text; ignored`):I[n]=t[n]:console.warn(`[blockcharts] interaction.tooltip: label of "${n}" ignored: no such field`)}else i.labels!==void 0&&console.warn('[blockcharts] interaction.tooltip: "labels" must be an object of field name to text; ignored');const G=Array.isArray(i.fields)?i.fields.filter(t=>typeof t=="string"):null,xt=o.claimPosition(),a=u.createElement("div");a.setAttribute("class","bc-tooltip"),a.setAttribute("role","tooltip"),Object.assign(a.style,{position:"absolute",display:"none",pointerEvents:"none",zIndex:"10",boxSizing:"border-box",whiteSpace:"normal",overflowWrap:"anywhere",fontSize:"12px",lineHeight:"1.45",fontVariantNumeric:"tabular-nums",padding:"8px 11px",borderRadius:"10px",background:"var(--bc-tooltip-bg, #fff)",color:"var(--bc-text, #333)",border:"1px solid var(--bc-tooltip-border, rgba(127,127,127,.22))",boxShadow:"var(--bc-tooltip-shadow, 0 10px 28px rgba(15,23,42,.14), 0 2px 6px rgba(15,23,42,.08))"});const b=u.createElement("div");b.setAttribute("class","bc-tooltip-dot"),Object.assign(b.style,{position:"absolute",display:"none",pointerEvents:"none",width:"12px",height:"12px",marginLeft:"-6px",marginTop:"-6px",boxSizing:"border-box",borderRadius:"50%",border:"2.5px solid var(--bc-tooltip-bg, #fff)",background:"var(--bc-text, #333)",boxShadow:"0 1px 4px rgba(15,23,42,.3)"});const j=u.createElement("div");j.setAttribute("class","bc-tooltip-highlight"),Object.assign(j.style,{position:"absolute",display:"none",pointerEvents:"none",boxSizing:"border-box",borderRadius:"3px",background:"var(--bc-tooltip-highlight-fill, rgba(127,127,127,.14))",outline:"1.5px solid var(--bc-tooltip-highlight-line, rgba(127,127,127,.45))",outlineOffset:"-1.5px"});const m=u.createElementNS("http://www.w3.org/2000/svg","svg");m.setAttribute("class","bc-tooltip-flows"),Object.assign(m.style,{position:"absolute",display:"none",pointerEvents:"none"}),S.appendChild(m),S.appendChild(b),S.appendChild(j),S.appendChild(a);const V=i.marker==="dot"||i.marker==="box"||i.marker==="none"?i.marker:"auto";let tt=!1,et=!1;const wt=()=>{const t=i.content;if(typeof t=="function")return t;if(typeof t!="string")return;const n=M.getFn(t);return!n&&!tt&&(tt=!0,console.warn(`[blockcharts] interaction.tooltip: no function "${t}" is registered (BC.defineFn); showing the default content`)),n},kt=t=>!!t&&typeof t=="object"&&typeof t.nodeType=="number",nt=t=>{if(!(t==null||t===!1)){if(typeof t=="string"||typeof t=="number"){if(t==="")return;const n=u.createElement("div");n.textContent=String(t),a.appendChild(n)}else if(Array.isArray(t))t.forEach(nt);else if(kt(t))a.appendChild(t);else if(typeof t.html=="string"){const n=u.createElement("div");n.innerHTML=t.html,a.appendChild(n)}}},X=()=>{a.style.display="none",b.style.display="none",j.style.display="none",m.style.display="none"},N=(t,n)=>{const r=o.table.columns[t][n];return _[t]?_[t](r)||"\u2013":gt(r)};function ot(t){if(typeof i.heading=="string"&&o.table.columns[i.heading])return i.heading;for(const n of["category","date"])for(const r of["x","y"])try{const e=o.channel(t,r);if(e.field&&e.scale&&e.scale.input===n&&o.table.columns[e.field])return e.field}catch{}return null}function st(t,n){for(const[r,e]of[["x","x2"],["y","y2"]])try{const s=o.channel(t,r),d=o.channel(t,e);if(!s.field||!d.field||s.field===d.field||!s.scale||s.scale!==d.scale||s.scale.input==="category"||!o.table.columns[s.field]||!o.table.columns[d.field]||n.indexOf(s.field)<0||n.indexOf(d.field)<0)continue;return{from:s.field,to:d.field,date:s.scale.input==="date"}}catch{}return null}const q=t=>M.get(`mark.${t.type}`);function Z(t,n,r){const e=q(t);if(!e||typeof e.color!="function")return"";try{const s=e.color(t,o,n,r);return typeof s=="string"?s:""}catch{return""}}function L(t,n){const r=[];for(const e of Object.keys(n.channels))try{const s=o.channel(t,e);s.field&&r.push(s.field)}catch{}return typeof t.group=="string"&&r.push(t.group),r}function Et(t,n,r,e,s){const d=Z(t,r,e);if(s===null||L(t,n).includes(s))return d;const p=o.spec.marks;for(let c=p.length-1;c>=0;c--){const x=q(p[c]);if(c===r||!x||!L(p[c],x).includes(s))continue;const h=Z(p[c],c,e);if(h)return h}return d}function it(t,n){const r=new Set;for(const e of Object.keys(n.channels))try{const s=o.channel(t,e);s.field&&s.scale&&s.scale.input==="date"&&r.add(s.field)}catch{}return(e,s)=>!_[e]&&r.has(e)&&v(o.table.columns[e][s])||N(e,s)}function At(t,n,r,e,s){const d=[],p=[],c=new Set(s),x=it(t,n),h=w=>{const $=o.table.columns[w];if(!$||c.has(w)||(c.add(w),ht($[r])))return;const k=x(w,r);e.some(T=>x(w,T)!==k)||(d.push([I[w]||w,k]),p.push(w))};return(G||L(t,n)).forEach(h),{lines:d,fields:p}}function Ot(t){const n=Y().toLogical(o,t);if(!Y().inPlot(o,n,12))return X();let r=null;if(o.spec.marks.forEach((f,l)=>{const g=M.get(`mark.${f.type}`);if(!g||!g.pick)return;let y=null;try{y=g.pick(f,o,l,n.x,n.y)}catch{return}y&&isFinite(y.dist)&&(!r||y.dist<=r.pick.dist)&&(r={pick:y,mark:f,def:g,index:l})}),!r)return X();const{pick:e,mark:s,def:d,index:p}=r,c=e.card,x=e.rows&&e.rows.length>1?e.rows:[e.row],h=c?null:ot(s),w=typeof i.heading=="string"&&!!o.table.columns[i.heading],$=c||w?null:st(s,G||L(s,d)),k=$&&(!h||h===$.from||h===$.to)?$:null,T=c?N:it(s,d),E=k&&x.every(f=>T(k.from,f)===T(k.from,e.row)&&T(k.to,f)===T(k.to,e.row))?k:null,O=!k&&h&&x.every(f=>N(h,f)===N(h,e.row))?h:null,rt=c?{lines:c.lines,fields:[]}:At(s,d,e.row,x,E?[E.from,E.to]:[]),J=rt.lines,lt=O?I[O]||O:null;let z;const at=c?void 0:wt();if(at){const f={};for(const l of Object.keys(o.table.columns))f[l]=o.table.columns[l][e.row];try{z=at({row:e.row,values:f,rows:x,lines:J,mark:s,markIndex:p,x:e.x,y:e.y,table:o.table})}catch(l){et||(et=!0,console.error("[blockcharts] interaction.tooltip: the content function threw, showing the default content:",l)),z=void 0}}if(z===null||z===!1)return X();a.textContent="";const Ct=Z(s,p,e.row),ct=rt.fields.find((f,l)=>J[l][0]!==lt),ft=c?c.color||"":Et(s,d,p,e.row,G&&ct!==void 0?ct:null);if(z===void 0){if(O||c||E){const l=u.createElement("div");if(l.setAttribute("class","bc-tooltip-heading"),O?l.setAttribute("data-bc-field",O):E&&l.setAttribute("data-bc-field",`${E.from} ${E.to}`),Object.assign(l.style,{display:"flex",alignItems:"center",gap:"7px",fontWeight:"600",marginBottom:"4px"}),ft){const F=u.createElement("span");F.setAttribute("class","bc-tooltip-swatch"),Object.assign(F.style,{width:"8px",height:"8px",borderRadius:"50%",background:ft,boxShadow:"inset 0 0 0 1px var(--bc-tooltip-highlight-line, rgba(127,127,127,.45))",flex:"none"}),l.appendChild(F)}const g=u.createElement("span"),y=o.table.columns[O],D=(()=>{for(const F of["x","y"])try{const W=o.channel(s,F);if(W.field===O&&W.scale&&W.scale.input==="date")return!0}catch{}return!1})(),U=O;if(c)g.textContent=c.title;else if(E){const F=[T(E.from,e.row),T(E.to,e.row)];g.textContent=F.join(F.some(W=>W.indexOf(" ")>=0)?" \u2013 ":"\u2013")}else g.textContent=!_[U]&&D&&v(y[e.row])||N(U,e.row);l.appendChild(g),a.appendChild(l)}const f=u.createElement("div");f.setAttribute("class","bc-tooltip-lines"),Object.assign(f.style,{display:"grid",gridTemplateColumns:"auto auto",columnGap:"16px",rowGap:"1px"});for(const[l,g]of J){if(l===lt)continue;const y=u.createElement("span");y.textContent=l,y.style.opacity="0.68";const D=u.createElement("span");D.textContent=g,Object.assign(D.style,{textAlign:"right",fontWeight:"600"}),f.appendChild(y),f.appendChild(D)}f.children.length&&a.appendChild(f)}else nt(z);if(!(a.childNodes?a.childNodes.length>0:a.children.length>0))return X();const C=H.getBoundingClientRect(),A=S.getBoundingClientRect(),R=C.width/o.size.w,P=C.left-A.left+e.x*R,B=C.top-A.top+e.y*R;m.textContent="";for(const f of e.flows||[]){const l=u.createElementNS("http://www.w3.org/2000/svg","path");l.setAttribute("d",f.d),l.setAttribute("fill",f.fill),l.setAttribute("fill-opacity","0.5"),m.appendChild(l)}e.flows&&e.flows.length?(m.setAttribute("viewBox",`0 0 ${o.size.w} ${o.size.h}`),Object.assign(m.style,{left:C.left-A.left+"px",top:C.top-A.top+"px",width:C.width+"px",height:C.height+"px",display:"block"})):m.style.display="none",(V==="box"||V==="auto"&&!!e.box)&&e.box?(Object.assign(j.style,{left:C.left-A.left+e.box.x*R+"px",top:C.top-A.top+e.box.y*R+"px",width:Math.max(0,e.box.w*R)+"px",height:Math.max(0,e.box.h*R)+"px",display:"block"}),b.style.display="none"):V!=="none"?(b.style.left=P+"px",b.style.top=B+"px",b.style.background=Ct||"var(--bc-text, #333)",b.style.display="block",j.style.display="none"):(b.style.display="none",j.style.display="none");const K=u.defaultView||globalThis,Q=Math.max(0,-A.left),dt=typeof K.innerWidth=="number"&&K.innerWidth>0?Math.min(A.width,K.innerWidth-A.left):A.width;a.style.display="block",a.style.maxWidth=Math.max(120,dt-Q)+"px",a.style.left=Q+"px";const pt=a.offsetWidth||0,ut=a.offsetHeight||0,St=P+12+pt>dt?P-12-pt:P+12,jt=B-12-ut>=0?B-12-ut:B+12;a.style.left=Math.max(Q,St)+"px",a.style.top=Math.max(0,jt)+"px"}if(i.content===void 0&&o.table){const t=[];for(const n of o.spec.marks){const r=q(n);if(!r||!r.pick)continue;const e=G||L(n,r),s=ot(n),d=typeof i.heading=="string"?null:st(n,e);for(const p of e)p===s||d&&(p===d.from||p===d.to)||!I[p]&&bt.test(p)&&o.table.columns[p]&&t.indexOf(p)<0&&t.push(p)}t.length&&console.warn(`[blockcharts] interaction.tooltip: the card shows ${t.map(n=>`"${n}"`).join(", ")} under ${t.length>1?"their own names; give them names":"its own name; give it a name"} a reader knows in "labels"`)}yt(o,Ot,X),o.cleanup(()=>{for(const t of[a,b,j,m])t.parentNode&&t.parentNode.removeChild(t);xt()})}};M.define(mt)})(globalThis.BC);
|
|
97
|
+
"use strict";(function(M){const ht=i=>i==null||i===""||typeof i=="number"&&isNaN(i),bt=/\d|[a-z][A-Z]|_/;function gt(i){if(i==null)return"\u2013";if(typeof i=="number")return isNaN(i)?"\u2013":Number.isInteger(i)?String(i):String(+i.toPrecision(6));const s=String(i);return s.length>80?s.slice(0,79)+"\u2026":s}const H=()=>M.get("lib.pointer").exports,yt=(i,s,O,V)=>M.get("lib.pointer").exports.follow(i,s,O,V),mt={role:"interaction",type:"tooltip",version:24,requires:["lib.pointer"],params:{fields:{kind:"fields"},formats:{kind:"formats"},labels:{kind:"any"},content:{kind:"any"},heading:{kind:"field"},marker:{kind:"enum",values:["auto","dot","box","none"],default:"auto"}},attach(i,s){const O=s.host,V=s.root,u=O.ownerDocument||document,D={};if(i.formats&&typeof i.formats=="object"&&!Array.isArray(i.formats)){const t=i.formats;for(const n of Object.keys(t))try{D[n]=s.format(t[n])}catch(r){console.warn(`[blockcharts] interaction.tooltip: format of "${n}" ignored: ${r instanceof Error?r.message:String(r)}`)}}else i.formats!==void 0&&console.warn('[blockcharts] interaction.tooltip: "formats" must be an object of field name to format; ignored');const v=s.format("date"),W={};for(const t of Array.isArray(s.spec.transforms)?s.spec.transforms:[]){const n=t&&M.get(`transform.${t.type}`);if(!(!n||typeof n.labels!="function"))try{Object.assign(W,n.labels(t))}catch{}}if(i.labels&&typeof i.labels=="object"&&!Array.isArray(i.labels)){const t=i.labels;for(const n of Object.keys(t))s.table.columns[n]?typeof t[n]!="string"?console.warn(`[blockcharts] interaction.tooltip: label of "${n}" must be text; ignored`):W[n]=t[n]:console.warn(`[blockcharts] interaction.tooltip: label of "${n}" ignored: no such field`)}else i.labels!==void 0&&console.warn('[blockcharts] interaction.tooltip: "labels" must be an object of field name to text; ignored');const B=Array.isArray(i.fields)?i.fields.filter(t=>typeof t=="string"):null,xt=s.claimPosition(),l=u.createElement("div");l.setAttribute("class","bc-tooltip"),l.setAttribute("role","tooltip"),Object.assign(l.style,{position:"absolute",display:"none",pointerEvents:"none",zIndex:"10",boxSizing:"border-box",whiteSpace:"normal",overflowWrap:"anywhere",fontSize:"12px",lineHeight:"1.45",fontVariantNumeric:"tabular-nums",padding:"8px 11px",borderRadius:"10px",background:"var(--bc-tooltip-bg, #fff)",color:"var(--bc-text, #333)",border:"1px solid var(--bc-tooltip-border, rgba(127,127,127,.22))",boxShadow:"var(--bc-tooltip-shadow, 0 10px 28px rgba(15,23,42,.14), 0 2px 6px rgba(15,23,42,.08))"});const b=u.createElement("div");b.setAttribute("class","bc-tooltip-dot"),Object.assign(b.style,{position:"absolute",display:"none",pointerEvents:"none",width:"12px",height:"12px",marginLeft:"-6px",marginTop:"-6px",boxSizing:"border-box",borderRadius:"50%",border:"2.5px solid var(--bc-tooltip-bg, #fff)",background:"var(--bc-text, #333)",boxShadow:"0 1px 4px rgba(15,23,42,.3)"});const C=u.createElement("div");C.setAttribute("class","bc-tooltip-highlight"),Object.assign(C.style,{position:"absolute",display:"none",pointerEvents:"none",boxSizing:"border-box",borderRadius:"3px",background:"var(--bc-tooltip-highlight-fill, rgba(127,127,127,.14))",outline:"1.5px solid var(--bc-tooltip-highlight-line, rgba(127,127,127,.45))",outlineOffset:"-1.5px"});const g=u.createElementNS("http://www.w3.org/2000/svg","svg");g.setAttribute("class","bc-tooltip-flows"),Object.assign(g.style,{position:"absolute",display:"none",pointerEvents:"none"}),O.appendChild(g),O.appendChild(b),O.appendChild(C),O.appendChild(l);const q=i.marker==="dot"||i.marker==="box"||i.marker==="none"?i.marker:"auto";let tt=!1,et=!1;const wt=()=>{const t=i.content;if(typeof t=="function")return t;if(typeof t!="string")return;const n=M.getFn(t);return!n&&!tt&&(tt=!0,console.warn(`[blockcharts] interaction.tooltip: no function "${t}" is registered (BC.defineFn); showing the default content`)),n},kt=t=>!!t&&typeof t=="object"&&typeof t.nodeType=="number",nt=t=>{if(!(t==null||t===!1)){if(typeof t=="string"||typeof t=="number"){if(t==="")return;const n=u.createElement("div");n.textContent=String(t),l.appendChild(n)}else if(Array.isArray(t))t.forEach(nt);else if(kt(t))l.appendChild(t);else if(typeof t.html=="string"){const n=u.createElement("div");n.innerHTML=t.html,l.appendChild(n)}}},_=()=>{l.style.display="none",b.style.display="none",C.style.display="none",g.style.display="none"},T=(t,n)=>{const r=s.table.columns[t][n];return D[t]?D[t](r)||"\u2013":gt(r)};function ot(t){if(typeof i.heading=="string"&&s.table.columns[i.heading])return i.heading;for(const n of["category","date"])for(const r of["x","y"])try{const e=s.channel(t,r);if(e.field&&e.scale&&e.scale.input===n&&s.table.columns[e.field])return e.field}catch{}return null}function st(t,n){for(const[r,e]of[["x","x2"],["y","y2"]])try{const o=s.channel(t,r),f=s.channel(t,e);if(!o.field||!f.field||o.field===f.field||!o.scale||o.scale!==f.scale||o.scale.input==="category"||!s.table.columns[o.field]||!s.table.columns[f.field]||n.indexOf(o.field)<0||n.indexOf(f.field)<0)continue;return{from:o.field,to:f.field,date:o.scale.input==="date"}}catch{}return null}const Z=t=>M.get(`mark.${t.type}`);function J(t,n,r){const e=Z(t);if(!e||typeof e.color!="function")return"";try{const o=e.color(t,s,n,r);return typeof o=="string"?o:""}catch{return""}}function I(t,n){const r=[];for(const e of Object.keys(n.channels))try{const o=s.channel(t,e);o.field&&r.push(o.field)}catch{}return typeof t.group=="string"&&r.push(t.group),r}function Et(t,n,r,e,o){const f=J(t,r,e);if(o===null||I(t,n).includes(o))return f;const d=s.spec.marks;for(let a=d.length-1;a>=0;a--){const y=Z(d[a]);if(a===r||!y||!I(d[a],y).includes(o))continue;const h=J(d[a],a,e);if(h)return h}return f}function it(t,n){const r=new Set;for(const e of Object.keys(n.channels))try{const o=s.channel(t,e);o.field&&o.scale&&o.scale.input==="date"&&r.add(o.field)}catch{}return(e,o)=>!D[e]&&r.has(e)&&v(s.table.columns[e][o])||T(e,o)}function At(t,n,r,e,o){const f=[],d=[],a=new Set(o),y=it(t,n),h=m=>{const F=s.table.columns[m];if(!F||a.has(m)||(a.add(m),ht(F[r])))return;const x=y(m,r);e.some(S=>y(m,S)!==x)||(f.push([W[m]||m,x]),d.push(m))};return(B||I(t,n)).forEach(h),{lines:f,fields:d}}function Ot(t){const n=H().toLogical(s,t);if(!H().inPlot(s,n,12))return _();const r=H().pickAt(s,n);if(!r)return _();const{pick:e,mark:o,def:f,index:d}=r,a=e.card,y=e.rows&&e.rows.length>1?e.rows:[e.row],h=a?null:ot(o),m=typeof i.heading=="string"&&!!s.table.columns[i.heading],F=a||m?null:st(o,B||I(o,f)),x=F&&(!h||h===F.from||h===F.to)?F:null,S=a?T:it(o,f),w=x&&y.every(p=>S(x.from,p)===S(x.from,e.row)&&S(x.to,p)===S(x.to,e.row))?x:null,E=!x&&h&&y.every(p=>T(h,p)===T(h,e.row))?h:null,rt=a?{lines:a.lines,fields:[]}:At(o,f,e.row,y,w?[w.from,w.to]:[]),K=rt.lines,lt=E?W[E]||E:null;let N;const at=a?void 0:wt();if(at){const p={};for(const c of Object.keys(s.table.columns))p[c]=s.table.columns[c][e.row];try{N=at({row:e.row,values:p,rows:y,lines:K,mark:o,markIndex:d,x:e.x,y:e.y,table:s.table})}catch(c){et||(et=!0,console.error("[blockcharts] interaction.tooltip: the content function threw, showing the default content:",c)),N=void 0}}if(N===null||N===!1)return _();l.textContent="";const Ct=J(o,d,e.row),ct=rt.fields.find((p,c)=>K[c][0]!==lt),ft=a?a.color||"":Et(o,f,d,e.row,B&&ct!==void 0?ct:null);if(N===void 0){if(E||a||w){const c=u.createElement("div");if(c.setAttribute("class","bc-tooltip-heading"),E?c.setAttribute("data-bc-field",E):w&&c.setAttribute("data-bc-field",`${w.from} ${w.to}`),Object.assign(c.style,{display:"flex",alignItems:"center",gap:"7px",fontWeight:"600",marginBottom:"4px"}),ft){const j=u.createElement("span");j.setAttribute("class","bc-tooltip-swatch"),Object.assign(j.style,{width:"8px",height:"8px",borderRadius:"50%",background:ft,boxShadow:"inset 0 0 0 1px var(--bc-tooltip-highlight-line, rgba(127,127,127,.45))",flex:"none"}),c.appendChild(j)}const z=u.createElement("span"),X=s.table.columns[E],L=(()=>{for(const j of["x","y"])try{const R=s.channel(o,j);if(R.field===E&&R.scale&&R.scale.input==="date")return!0}catch{}return!1})(),Y=E;if(a)z.textContent=a.title;else if(w){const j=[S(w.from,e.row),S(w.to,e.row)];z.textContent=j.join(j.some(R=>R.indexOf(" ")>=0)?" \u2013 ":"\u2013")}else z.textContent=!D[Y]&&L&&v(X[e.row])||T(Y,e.row);c.appendChild(z),l.appendChild(c)}const p=u.createElement("div");p.setAttribute("class","bc-tooltip-lines"),Object.assign(p.style,{display:"grid",gridTemplateColumns:"auto auto",columnGap:"16px",rowGap:"1px"});for(const[c,z]of K){if(c===lt)continue;const X=u.createElement("span");X.textContent=c,X.style.opacity="0.68";const L=u.createElement("span");L.textContent=z,Object.assign(L.style,{textAlign:"right",fontWeight:"600"}),p.appendChild(X),p.appendChild(L)}p.children.length&&l.appendChild(p)}else nt(N);if(!(l.childNodes?l.childNodes.length>0:l.children.length>0))return _();const A=V.getBoundingClientRect(),k=O.getBoundingClientRect(),$=A.width/s.size.w,G=A.left-k.left+e.x*$,P=A.top-k.top+e.y*$;g.textContent="";for(const p of e.flows||[]){const c=u.createElementNS("http://www.w3.org/2000/svg","path");c.setAttribute("d",p.d),c.setAttribute("fill",p.fill),c.setAttribute("fill-opacity","0.5"),g.appendChild(c)}e.flows&&e.flows.length?(g.setAttribute("viewBox",`0 0 ${s.size.w} ${s.size.h}`),Object.assign(g.style,{left:A.left-k.left+"px",top:A.top-k.top+"px",width:A.width+"px",height:A.height+"px",display:"block"})):g.style.display="none",(q==="box"||q==="auto"&&!!e.box)&&e.box?(Object.assign(C.style,{left:A.left-k.left+e.box.x*$+"px",top:A.top-k.top+e.box.y*$+"px",width:Math.max(0,e.box.w*$)+"px",height:Math.max(0,e.box.h*$)+"px",display:"block"}),b.style.display="none"):q!=="none"?(b.style.left=G+"px",b.style.top=P+"px",b.style.background=Ct||"var(--bc-text, #333)",b.style.display="block",C.style.display="none"):(b.style.display="none",C.style.display="none");const Q=u.defaultView||globalThis,U=Math.max(0,-k.left),dt=typeof Q.innerWidth=="number"&&Q.innerWidth>0?Math.min(k.width,Q.innerWidth-k.left):k.width;l.style.display="block",l.style.maxWidth=Math.max(120,dt-U)+"px",l.style.left=U+"px";const pt=l.offsetWidth||0,ut=l.offsetHeight||0,St=G+12+pt>dt?G-12-pt:G+12,jt=P-12-ut>=0?P-12-ut:P+12;l.style.left=Math.max(U,St)+"px",l.style.top=Math.max(0,jt)+"px"}if(i.content===void 0&&s.table){const t=[];for(const n of s.spec.marks){const r=Z(n);if(!r||!r.pick)continue;const e=B||I(n,r),o=ot(n),f=typeof i.heading=="string"?null:st(n,e);for(const d of e)d===o||f&&(d===f.from||d===f.to)||!W[d]&&bt.test(d)&&s.table.columns[d]&&t.indexOf(d)<0&&t.push(d)}t.length&&console.warn(`[blockcharts] interaction.tooltip: the card shows ${t.map(n=>`"${n}"`).join(", ")} under ${t.length>1?"their own names; give them names":"its own name; give it a name"} a reader knows in "labels"`)}yt(s,Ot,_),s.cleanup(()=>{for(const t of[l,b,C,g])t.parentNode&&t.parentNode.removeChild(t);xt()})}};M.define(mt)})(globalThis.BC);
|
|
95
98
|
|
|
96
99
|
|
|
97
100
|
"use strict";(function(k){const x="http://www.w3.org/2000/svg";let w=0,m=0;function s(e){return document.createElementNS(x,e)}function r(e,i,t){t!==void 0&&e.setAttribute(i,String(t))}function C(e,i,t){const n=e+"|"+i,l=t.fades.get(n);if(l)return l;const o=`bc-fade-${++m}`,a=s("linearGradient");a.setAttribute("id",o),a.setAttribute("gradientUnits","userSpaceOnUse"),a.setAttribute("x1","0"),a.setAttribute("x2","0"),r(a,"y1",t.plot.y),r(a,"y2",t.plot.y+t.plot.h);for(const[b,c]of[[0,i],[1,0]]){const f=s("stop");f.setAttribute("offset",String(b)),f.setAttribute("style",`stop-color:${e.replace(/[;{}<>]/g,"")};stop-opacity:${c}`),a.appendChild(f)}t.defs.appendChild(a);const u=`url(#${o})`;return t.fades.set(n,u),u}function $(e,i,t){i&&(i.fill!==void 0&&i.fade&&i.fill!=="none"?e.setAttribute("fill",C(i.fill,i.fillOpacity===void 0?1:i.fillOpacity,t)):i.fill!==void 0&&e.setAttribute("fill",i.fill),i.stroke!==void 0&&e.setAttribute("stroke",i.stroke),r(e,"stroke-width",i.strokeWidth),i.strokeDash&&e.setAttribute("stroke-dasharray",i.strokeDash.join(" ")),r(e,"opacity",i.opacity),i.fade||r(e,"fill-opacity",i.fillOpacity),i.strokeLinejoin&&e.setAttribute("stroke-linejoin",i.strokeLinejoin),i.strokeLinecap&&e.setAttribute("stroke-linecap",i.strokeLinecap),i.paintOrder&&e.setAttribute("paint-order",i.paintOrder))}function y(e,i,t){const n=`bc-clip-${++w}`,l=s("clipPath");l.setAttribute("id",n);const o=s("rect");r(o,"x",i.x),r(o,"y",i.y),r(o,"width",i.w),r(o,"height",i.h),l.appendChild(o),t.appendChild(l),e.setAttribute("clip-path",`url(#${n})`)}function g(e,i){let t;switch(e.type){case"path":t=s("path"),t.setAttribute("d",e.d);break;case"rect":t=s("rect"),r(t,"x",e.x),r(t,"y",e.y),r(t,"width",e.w),r(t,"height",e.h),r(t,"rx",e.r);break;case"circle":t=s("circle"),r(t,"cx",e.cx),r(t,"cy",e.cy),r(t,"r",e.r);break;case"text":t=s("text"),r(t,"x",e.x),r(t,"y",e.y),r(t,"font-size",e.size),e.weight!==void 0&&t.setAttribute("font-weight",String(e.weight)),e.anchor&&t.setAttribute("text-anchor",e.anchor),e.baseline&&t.setAttribute("dominant-baseline",e.baseline),e.rotate&&t.setAttribute("transform",`rotate(${e.rotate} ${e.x} ${e.y})`),t.textContent=e.text;break;case"g":t=s("g"),e.translate&&t.setAttribute("transform",`translate(${e.translate[0]} ${e.translate[1]})`),e.clip&&y(t,e.clip,i.defs);for(const n of e.children)t.appendChild(g(n,i));break}if($(t,e.style,i),e.cls&&t.setAttribute("class",e.cls),e.data)for(const n of Object.keys(e.data))t.setAttribute("data-"+n,e.data[n]);if(e.ref&&(t.setAttribute("data-bc-mark",String(e.ref.mark)),t.setAttribute("data-bc-row",String(e.ref.row))),e.pressed!==void 0&&(t.setAttribute("tabindex","0"),t.setAttribute("role","button"),t.setAttribute("aria-pressed",e.pressed?"true":"false"),i.controls.push(t)),e.title){const n=s("title");n.textContent=e.title,t.appendChild(n)}return t}const S={role:"renderer",type:"svg",version:6,render(e,i){const t=s("svg");t.setAttribute("width","100%"),t.setAttribute("role","img"),t.setAttribute("style","display:block;height:auto");let n=[];const l=o=>{const a=t.ownerDocument||(typeof document>"u"?null:document),u=a&&a.activeElement?n.indexOf(a.activeElement):-1;t.textContent="",t.setAttribute("viewBox",`0 0 ${o.size.w} ${o.size.h}`);const b=s("defs");t.appendChild(b);const c={defs:b,plot:o.plot,fades:new Map,controls:[]},f=[];for(const d of o.layers){const h=s("g");h.setAttribute("data-bc-layer",d.name),d.clip&&y(h,d.clip,b);for(const v of d.prims){const O=c.controls.length,p=g(v,c);c.controls.length===O&&f.push(p),h.appendChild(p)}t.appendChild(h)}if(n=c.controls,t.setAttribute("role",n.length?"group":"img"),n.length)for(const d of f)d.setAttribute("aria-hidden","true");o.label?t.setAttribute("aria-label",o.label):t.removeAttribute("aria-label");const A=u>=0?n[u]:void 0;A&&typeof A.focus=="function"&&A.focus({preventScroll:!0})};return l(e),i.appendChild(t),{root:t,update:l,destroy(){t.parentNode&&t.parentNode.removeChild(t)}}}};k.define(S)})(globalThis.BC);
|