chartjs-chart-treemap 5.0.0-next.9 → 5.0.1

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 CHANGED
@@ -42,7 +42,7 @@ new Chart(document.getElementById('chart'), {
42
42
  data: {
43
43
  datasets: [
44
44
  {
45
- tree: [6, 6, 4, 3, 2, 2, 1],
45
+ data: [6, 6, 4, 3, 2, 2, 1],
46
46
  backgroundColor: 'rgba(54, 162, 235, 0.6)',
47
47
  },
48
48
  ],
@@ -74,6 +74,13 @@ The following commands will then be available from the repository root:
74
74
  > npm package // create an archive with dist files and samples
75
75
  ```
76
76
 
77
+ ### Release branches
78
+
79
+ - `main`: the current major, published to the `latest` dist-tag.
80
+ - `next`: prereleases of the next major, published to the `next` dist-tag.
81
+ - `4.x`: maintenance branch for the 4.x line, the last one that supports Chart.js 3. Fixes for those users go here and are published to the `release-4.x` dist-tag, so `latest` is not affected.
82
+ - `2.x`: Chart.js 2, no longer released.
83
+
77
84
  ## License
78
85
 
79
86
  chartjs-chart-treemap is available under the [MIT license](https://opensource.org/licenses/MIT).
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * chartjs-chart-treemap v5.0.0-next.9
2
+ * chartjs-chart-treemap v5.0.1
3
3
  * https://chartjs-chart-treemap.pages.dev/
4
4
  * (c) 2026 Jukka Kurkela
5
5
  * Released under the MIT license
@@ -10,7 +10,7 @@ typeof define === 'function' && define.amd ? define(['exports', 'chart.js', 'cha
10
10
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["chartjs-chart-treemap"] = {}, global.Chart, global.Chart.helpers));
11
11
  })(this, (function (exports, chart_js, helpers) { 'use strict';
12
12
 
13
- var version = "5.0.0-next.9";
13
+ var version = "5.0.1";
14
14
 
15
15
  function scaleRect(sq, xScale, yScale, sp) {
16
16
  const sp2 = sp * 2;
@@ -1233,17 +1233,20 @@ class TreemapController extends chart_js.DatasetController {
1233
1233
  valueScale: options.valueScale || 'linear'
1234
1234
  };
1235
1235
  }
1236
- buildOrUpdateElements(_resetNewElements) {
1236
+ buildOrUpdateElements(resetNewElements) {
1237
+ super.configure();
1237
1238
  this.parse(0, 0);
1238
1239
  const meta = this.getMeta();
1239
1240
  const count = meta._parsed.length;
1240
1241
  const elements = meta.data;
1241
- if (elements.length > count) {
1242
- elements.splice(count, elements.length - count);
1242
+ const previous = elements.length;
1243
+ if (previous > count) {
1244
+ elements.splice(count, previous - count);
1243
1245
  }
1244
1246
  while(elements.length < count){
1245
1247
  elements.push(new this.dataElementType());
1246
1248
  }
1249
+ this._resetFrom = resetNewElements && count > previous ? previous : undefined;
1247
1250
  }
1248
1251
  parse(_start, _count) {
1249
1252
  const dataset = this.getDataset();
@@ -1254,10 +1257,17 @@ class TreemapController extends chart_js.DatasetController {
1254
1257
  const keys = [
1255
1258
  options.key || ''
1256
1259
  ].concat(options.sumKeys || []);
1257
- const nodes = buildNodes(dataset.data || [], keys, this._layoutOptions());
1260
+ const layoutOptions = this._layoutOptions();
1261
+ const nodes = buildNodes(dataset.data || [], keys, layoutOptions);
1258
1262
  const flat = flattenNodes(nodes);
1259
1263
  const fingerprint = flat.map((node)=>`${node.v}\u0000${node.g}\u0000${node.l}`).join('\u0001');
1264
+ const layoutKey = JSON.stringify(layoutOptions, (_key, value)=>typeof value === 'function' ? String(value) : value);
1265
+ const layoutChanged = this._layoutKey !== layoutKey;
1266
+ this._layoutKey = layoutKey;
1260
1267
  if (this._fingerprint === fingerprint) {
1268
+ if (layoutChanged) {
1269
+ this._layoutDirty = true;
1270
+ }
1261
1271
  return;
1262
1272
  }
1263
1273
  this._fingerprint = fingerprint;
@@ -1302,6 +1312,11 @@ class TreemapController extends chart_js.DatasetController {
1302
1312
  this._layoutDirty = false;
1303
1313
  this._rectChanged = false;
1304
1314
  }
1315
+ const resetFrom = this._resetFrom;
1316
+ this._resetFrom = undefined;
1317
+ if (resetFrom !== undefined && mode !== 'reset') {
1318
+ this.updateElements(data, resetFrom, data.length - resetFrom, 'reset');
1319
+ }
1305
1320
  this.updateElements(data, 0, data.length, mode);
1306
1321
  }
1307
1322
  updateElements(rects, start, count, mode) {
@@ -1309,7 +1324,7 @@ class TreemapController extends chart_js.DatasetController {
1309
1324
  const firstOpts = this.resolveDataElementOptions(start, mode);
1310
1325
  this._rect.options = firstOpts;
1311
1326
  const sharedOptions = this.getSharedOptions(firstOpts);
1312
- const includeOptions = this.includeOptions(mode, sharedOptions || {});
1327
+ const includeOptions = this.includeOptions(mode, sharedOptions);
1313
1328
  const { xScale, yScale } = this.getMeta();
1314
1329
  const spacing = this.options.spacing;
1315
1330
  for(let i = start; i < start + count; i++){
@@ -1326,7 +1341,7 @@ class TreemapController extends chart_js.DatasetController {
1326
1341
  }
1327
1342
  this.updateElement(rects[i], i, properties, mode);
1328
1343
  }
1329
- this.updateSharedOptions(sharedOptions || {}, mode, firstOpts);
1344
+ this.updateSharedOptions(sharedOptions, mode, firstOpts);
1330
1345
  }
1331
1346
  draw() {
1332
1347
  const { ctx, chartArea } = this.chart;
@@ -1354,6 +1369,7 @@ class TreemapController extends chart_js.DatasetController {
1354
1369
  this._nodes = [];
1355
1370
  this._layoutDirty = true;
1356
1371
  this._fingerprint = undefined;
1372
+ this._resetFrom = undefined;
1357
1373
  }
1358
1374
  }
1359
1375
  TreemapController.id = 'treemap';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * chartjs-chart-treemap v5.0.0-next.9
2
+ * chartjs-chart-treemap v5.0.1
3
3
  * https://chartjs-chart-treemap.pages.dev/
4
4
  * (c) 2026 Jukka Kurkela
5
5
  * Released under the MIT license
@@ -7,7 +7,7 @@
7
7
  import { DatasetController, registry, Chart, Element } from 'chart.js';
8
8
  import { toTRBL, toTRBLCorners, isObject, toFont, isArray, defined, isNumber, valueOrDefault, clipArea, unclipArea, addRoundedRectPath } from 'chart.js/helpers';
9
9
 
10
- var version = "5.0.0-next.9";
10
+ var version = "5.0.1";
11
11
 
12
12
  function scaleRect(sq, xScale, yScale, sp) {
13
13
  const sp2 = sp * 2;
@@ -1207,17 +1207,20 @@ class TreemapController extends DatasetController {
1207
1207
  valueScale: options.valueScale || 'linear'
1208
1208
  };
1209
1209
  }
1210
- buildOrUpdateElements(_resetNewElements) {
1210
+ buildOrUpdateElements(resetNewElements) {
1211
+ super.configure();
1211
1212
  this.parse(0, 0);
1212
1213
  const meta = this.getMeta();
1213
1214
  const count = meta._parsed.length;
1214
1215
  const elements = meta.data;
1215
- if (elements.length > count) {
1216
- elements.splice(count, elements.length - count);
1216
+ const previous = elements.length;
1217
+ if (previous > count) {
1218
+ elements.splice(count, previous - count);
1217
1219
  }
1218
1220
  while(elements.length < count){
1219
1221
  elements.push(new this.dataElementType());
1220
1222
  }
1223
+ this._resetFrom = resetNewElements && count > previous ? previous : undefined;
1221
1224
  }
1222
1225
  parse(_start, _count) {
1223
1226
  const dataset = this.getDataset();
@@ -1228,10 +1231,17 @@ class TreemapController extends DatasetController {
1228
1231
  const keys = [
1229
1232
  options.key || ''
1230
1233
  ].concat(options.sumKeys || []);
1231
- const nodes = buildNodes(dataset.data || [], keys, this._layoutOptions());
1234
+ const layoutOptions = this._layoutOptions();
1235
+ const nodes = buildNodes(dataset.data || [], keys, layoutOptions);
1232
1236
  const flat = flattenNodes(nodes);
1233
1237
  const fingerprint = flat.map((node)=>`${node.v}\u0000${node.g}\u0000${node.l}`).join('\u0001');
1238
+ const layoutKey = JSON.stringify(layoutOptions, (_key, value)=>typeof value === 'function' ? String(value) : value);
1239
+ const layoutChanged = this._layoutKey !== layoutKey;
1240
+ this._layoutKey = layoutKey;
1234
1241
  if (this._fingerprint === fingerprint) {
1242
+ if (layoutChanged) {
1243
+ this._layoutDirty = true;
1244
+ }
1235
1245
  return;
1236
1246
  }
1237
1247
  this._fingerprint = fingerprint;
@@ -1276,6 +1286,11 @@ class TreemapController extends DatasetController {
1276
1286
  this._layoutDirty = false;
1277
1287
  this._rectChanged = false;
1278
1288
  }
1289
+ const resetFrom = this._resetFrom;
1290
+ this._resetFrom = undefined;
1291
+ if (resetFrom !== undefined && mode !== 'reset') {
1292
+ this.updateElements(data, resetFrom, data.length - resetFrom, 'reset');
1293
+ }
1279
1294
  this.updateElements(data, 0, data.length, mode);
1280
1295
  }
1281
1296
  updateElements(rects, start, count, mode) {
@@ -1283,7 +1298,7 @@ class TreemapController extends DatasetController {
1283
1298
  const firstOpts = this.resolveDataElementOptions(start, mode);
1284
1299
  this._rect.options = firstOpts;
1285
1300
  const sharedOptions = this.getSharedOptions(firstOpts);
1286
- const includeOptions = this.includeOptions(mode, sharedOptions || {});
1301
+ const includeOptions = this.includeOptions(mode, sharedOptions);
1287
1302
  const { xScale, yScale } = this.getMeta();
1288
1303
  const spacing = this.options.spacing;
1289
1304
  for(let i = start; i < start + count; i++){
@@ -1300,7 +1315,7 @@ class TreemapController extends DatasetController {
1300
1315
  }
1301
1316
  this.updateElement(rects[i], i, properties, mode);
1302
1317
  }
1303
- this.updateSharedOptions(sharedOptions || {}, mode, firstOpts);
1318
+ this.updateSharedOptions(sharedOptions, mode, firstOpts);
1304
1319
  }
1305
1320
  draw() {
1306
1321
  const { ctx, chartArea } = this.chart;
@@ -1328,6 +1343,7 @@ class TreemapController extends DatasetController {
1328
1343
  this._nodes = [];
1329
1344
  this._layoutDirty = true;
1330
1345
  this._fingerprint = undefined;
1346
+ this._resetFrom = undefined;
1331
1347
  }
1332
1348
  }
1333
1349
  TreemapController.id = 'treemap';
@@ -1,8 +1,8 @@
1
1
  /*!
2
- * chartjs-chart-treemap v5.0.0-next.9
2
+ * chartjs-chart-treemap v5.0.1
3
3
  * https://chartjs-chart-treemap.pages.dev/
4
4
  * (c) 2026 Jukka Kurkela
5
5
  * Released under the MIT license
6
6
  */
7
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["exports","chart.js","chart.js/helpers"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["chartjs-chart-treemap"]={},t.Chart,t.Chart.helpers)}(this,function(t,e,n){"use strict";function i(t,e,n,i){const r=2*i,o=e.getPixelForValue(t.x),s=n.getPixelForValue(t.y),a=e.getPixelForValue(t.x+t.w)-o,h=n.getPixelForValue(t.y+t.h)-s;return{height:h-r,hidden:r>a||r>h,width:a-r,x:o+i,y:s+i}}const r={displayMode:"containerBoxes",rtl:!1,spacing:.5};function o(t,e,n){return Math.max(Math.min(t,n),e)}function s(t,e,i){const r=n.toTRBL(t);return{b:o(r.bottom,0,i),l:o(r.left,0,e),r:o(r.right,0,e),t:o(r.top,0,i)}}function a(t,e,n,i){const r=t._normalized;if(!r)return{d1:0,d2:0,h:0,w:0};const o=e*r/n,s=Math.sqrt(r*o),a=r/s;return{d1:s,d2:a,h:"_ix"===i?a:s,w:"_ix"===i?s:a}}function h(t,e,n,i){e.a=e._normalized,e.h=n.h,e.s=i,e.w=n.w,e.x=((t,e)=>t.rtl?t.x+t.iw-e:t.x+t._ix)(t,n.w),e.y=t.y+t._iy,delete e._normalized}class l{get area(){return this.w*this.h}get iw(){return this.w-this._ix}get ih(){return this.h-this._iy}get dir(){const t=this.ih;return t<=this.iw&&t>0?"y":"x"}get side(){return"x"===this.dir?this.iw:this.ih}map(t){const{dir:e,side:n}=this,i="x"===e?"_ix":"_iy",r=t.nsum,o=t.get(),s=n*n,l=r*r;let c=0,u=0;for(const e of o){const n=a(e,s,l,i);u+=n.d1,c=Math.max(c,n.d2),h(this,e,n,t.sum),this[i]+=n.d1}this["x"===e?"_iy":"_ix"]+=c,this[i]-=u}constructor(t){t=t||{h:1,w:1},this.rtl=!!t.rtl,this.unsorted=!!t.unsorted,this.x=t.x||t.left||0,this.y=t.y||t.top||0,this._ix=0,this._iy=0,this.w=t.w||t.width||t.right-t.left,this.h=t.h||t.height||t.bottom-t.top}}const c=Math.min,u=Math.max;function d(t,e){const n=+e[t.key],i=n*t.ratio;return e._normalized=i,{max:u(t.max,n),min:c(t.min,n),nmax:u(t.nmax,i),nmin:c(t.nmin,i),nsum:t.nsum+i,sum:t.sum+n}}function f(t,e,n){t._arr.push(e),function(t,e){Object.assign(t,e)}(t,n)}class g{get length(){return this._arr.length}reset(){this._arr=[],this._hist=[],this.sum=0,this.nsum=0,this.min=1/0,this.max=-1/0,this.nmin=1/0,this.nmax=-1/0}push(t){f(this,t,d(this,t))}pushIf(t,e,...n){const i=d(this,t);if(!e((r=this,{max:r.max,min:r.min,nmax:r.nmax,nmin:r.nmin,nsum:r.nsum,sum:r.sum}),i,n))return t;var r;f(this,t,i)}get(){return this._arr}constructor(t,e){this._arr=[],this._hist=[],this.sum=0,this.nsum=0,this.min=1/0,this.max=-1/0,this.nmin=1/0,this.nmax=-1/0,this.key=t,this.ratio=e,this.reset()}}const p=(t,e)=>e>t||t.length>e.length&&t.startsWith(e),m=t=>String(t),x=t=>null!=t&&""!==t;function y(t,e,i,r=[],o=0,s=[]){const a=o-1;if(t[0]in i&&o>0){const n=r.reduce((t,e,n)=>(n!==a&&(t[m(n)]=e),t),{});n[e]=r[a],t.forEach(t=>{n[t]=i[t]}),s.push(n)}else for(const a of Object.keys(i)){const h=i[a];n.isObject(h)&&(r.push(a),y(t,e,h,r,o+1,s))}return r.splice(a,1),s}function b(t,e,n){const i=y(t,e,n);if(!i.length)return i;const r=i.reduce((t,e)=>{const n=Object.keys(e).length-2;return Math.max(t,n)},0);return i.forEach(t=>{for(let e=0;e<r;e++){const n=m(e);t[n]||(t[n]="")}}),i}function w(t,e,n){const i=[];for(const n of t){const t=e[n];x(t)&&i.push(t)}return i.length?i.join("."):n}function v(t,e,n,i){for(let e=i;e<n.length;e++){const i=m(n[e]);if(x(t[i]))return{group:i,groupIndex:e,value:t[i]}}if(x(t[e]))return{group:e,groupIndex:i,value:t[e]}}function _(t,e,n,i){if(n in t)return;t[n]={value:0};const r=t[n];i.forEach(t=>{r[t]=0}),e[n]=[]}function M(t,e,n,i,r,o,s=[],a=s,h=s.length-1){const l=n[0],c=n.slice(1),u=Object.create(null),d=Object.create(null),f=[],g=a.length?a:[e],p=a.length?h:0;let m,x;for(m=0,x=t.length;m<x;++m){const e=t[m];if(r&&e[r]!==o)continue;const n=v(e,i,g,p);if(!n)return[];const s=n.value;_(u,d,s,c),u[s].value+=+e[l],u[s].label=s,u[s].group=n.group,u[s].groupIndex=n.groupIndex;const a=u[s];c.forEach(t=>{a[t]+=e[t]}),u[s].path=w(g.slice(0,n.groupIndex+1),e,s),d[s].push(e)}return Object.keys(u).forEach(t=>{const n={children:d[t]};n[l]=+u[t].value,c.forEach(e=>{n[e]=+u[t][e]}),n[e]=u[t].label,n.group=u[t].group,n.groupIndex=u[t].groupIndex,n.label=t,n.path=u[t].path,r&&(n[r]=o),f.push(n)}),f}function O(t,e){let i,r=t.length;if(!r)return e;const o=n.isObject(t[0]);for(e=o?e:"v",i=0,r=t.length;i<r;++i)o?t[i]._idx=i:t[i]={_idx:i,v:t[i]};return e}function j(t,e){e?t.sort((t,n)=>+n[e]-+t[e]):t.sort((t,e)=>+e-+t)}function C(t,e){let n,i,r;for(n=0,i=0,r=t.length;i<r;++i)n+=e?+t[i][e]:+t[i];return n}function P(t,e,n,i=!0){const r=n.split(".");let o=0;for(const s of e.split(".")){const a=r[o++];if(Number.parseInt(s,10)<Number.parseInt(a,10))break;if(p(a,s)){if(i)throw new Error(`${t} v${n} is not supported. v${e} or newer is required.`);return!1}}return!0}const R="_weight";function k(t,e,n){if(0===t.sum)return!0;const[i]=n,r=t.nsum*t.nsum,o=e.nsum*e.nsum,s=i*i,a=Math.max(s*t.nmax/r,r/(s*t.nmin));return Math.max(s*e.nmax/o,o/(s*e.nmin))<=a}function E(t,e,n,i){const r=t?t.slice():[],o=O(r,e[0]);return r.map(r=>{const s={_data:t[r._idx],v:o?+r[o]:+r,vs:void 0};return n&&(s.g=r[n],s.gs=void 0,s.l=r.groupIndex??i,s.vs=e.reduce((t,e)=>(t[e]=+r[e],t),{})),s})}function A(t,e=!1){j(t,e?R:"v")}const $=new Map,L=(t,e)=>t[Math.min(e,t.length-1)];function S(t,e,n){const i=n.reduce((t,e)=>t+=e.string,""),r=e.join()+i+(t._measureText?"-spriting":"");let o=$.get(r);if(!o){t.save();const i=e.length;let s=0,a=0;for(let r=0;r<i;r++){const i=n[Math.min(r,n.length-1)];t.font=i.string;const o=e[r];s=Math.max(s,t.measureText(o).width),a+=i.lineHeight}t.restore(),o={height:a,width:s},$.size>=4096&&$.clear(),$.set(r,o)}return o}function T(t,e,n,i){let r=0,o=0;return e.forEach((e,s)=>{const a=L(i,n[s]);r=Math.max(r,S(t,[e],[a]).width),o+=a.lineHeight}),{height:o,width:r}}function D(t,e,n){const{align:i,colors:r,fonts:o,lines:s,padding:a,styles:h,textAlign:l,top:c,width:u}=n,d=l||i,f=function(t,e,n,i,r){if(e===n)return"left"===e?t.x+i:"right"===e?t.x+t.w-i:t.x+t.w/2;const o=function(t,e,n,i){if("left"===e)return t.x+n;if("right"===e)return t.x+t.w-n-i;return t.x+(t.w-i)/2}(t,e,i,r);if("left"===n)return o;if("right"===n)return o+r;return o+r/2}(e,i,d,a,u);t.textAlign=d,t.textBaseline="middle";let g=0;s.forEach((e,n)=>{const i=h[n],s=L(o,i);t.font=s.string,t.fillStyle=r[Math.min(i,r.length-1)],t.fillText(e,f,c+g+s.lineHeight/2),g+=s.lineHeight})}function F(t,e,n){const{position:i,padding:r}=e;return"top"===i?t.y+r:"bottom"===i?t.y+t.h-r-n.height:t.y+(t.h-n.height)/2+r}function I(t,e,n,i){const r=S(t,["..."],i).width;if(r>=n)return"";let o,s=1,a=e.length;for(;s<=a;){const h=Math.floor((s+a)/2);o=S(t,[e.slice(0,h)],i).width,o+r>n?a=h-1:s=h+1}const h=e.slice(0,Math.max(0,s-1));return h?h+"...":""}function B(t,e,n,i){if(i<=0)return[e];const r=e=>S(t,[e],[n]).width<=i,o=[];let s="";const a=t=>{if(r(t))return void(s=t);let e="";for(const n of t)e&&!r(e+n)&&(o.push(e),e=""),e+=n;s=e};for(const t of e.split(" ")){const e=s?`${s} ${t}`:t;r(e)?s=e:(s&&(o.push(s),s=""),a(t))}return s&&o.push(s),o.length?o:[""]}function H(t,e,i,r,o){const s=(n.isArray(e)?e:[e]).map(t=>`${t}`),a=[],h=[];return s.forEach((e,n)=>{const s=L(i,n);for(const i of e.split("\n"))for(const e of o?B(t,i,s,r):[i])a.push(e),h.push(n)}),{lines:a,styles:h}}function z(t,e,i){if(!i||!1===i.display)return!1;if("headerBoxes"===t)return!0;const{w:r,h:o}=e,s=n.toFont(i.font||{}).lineHeight,a=Math.max(Math.min(2*n.valueOrDefault(i.padding,3),Math.min(r,o)),0);return r-a>s&&o-a>s}function W(t,e,n,i){if("headerBoxes"!==t)return n.lineHeight+2*i;const r=n.lineHeight+2*i;return e.h<2*r?e.h/3:r}function K(t,e,i,r,o,s){const{captions:a,labels:h}=i,{displayMode:l}=s;let c;r&&(!n.defined(r.l)||r.isLeaf)?h.display&&(c=function(t,e,i,r,o){const s=i.labels,a=V(s.formatter,q(o,r));if(!a)return;const{align:h,color:l,hoverColor:c,overflow:u,padding:d,wrap:f}=s,g=e.w-2*d,p=e.h-2*d;let m=function(t,e){const{font:i,hoverFont:r}=e,o=(t.active?r:i)||i;return Array.isArray(o)?o.map(t=>n.toFont(t)):[n.toFont(o)]}(e,s),{lines:x,styles:y}=H(t,a,m,g,!!f),b=T(t,x,y,m);const w=function(t,e,n){const{overflow:i,padding:r}=e,{width:o,height:s}=n;if("hidden"===i)return!(o+2*r>t.w||s+2*r>t.h);if("fit"===i){const e=Math.min(t.w/(o+2*r),t.h/(s+2*r));if(e<1)return e}return!0}(e,s,b);if(!w)return;if(n.isNumber(w))if(m=function(t,e){return t.map(t=>{const{lineHeight:i,...r}=t;return n.toFont({...r,size:Math.floor(t.size*e)})})}(m,w),f){const e=H(t,a,m,g,!0);x=e.lines,y=e.styles,b=T(t,x,y,m)}else b={height:b.height*w,width:b.width*w};if("ellipsis"===u){const e=function(t,e,n,i,r,o){const s=[],a=[];let h=0;for(let t=0;t<e.length;t++){const r=L(i,n[t]);if(s.length&&h+r.lineHeight>o)break;h+=r.lineHeight,s.push(e[t]),a.push(n[t])}const l=s.length<e.length,c=s.length-1;for(let e=0;e<s.length;e++){const n=L(i,a[e]);(S(t,[s[e]],[n]).width>r||l&&e===c)&&(s[e]=I(t,s[e],r,[n]))}return{lines:s,styles:a}}(t,x,y,m,g,p);x=e.lines,y=e.styles,b=T(t,x,y,m)}const v=(e.active?c:l)||l;return{align:h,clipY:d,colors:n.isArray(v)?v:[v],fonts:m,lines:x,padding:d,styles:y,textAlign:s.textAlign,top:F(e,s,b),width:b.width}}(t,e,i,r,o)):z(l,e,a)&&(c=function(t,e,i,r,o,s){const{displayMode:a,rtl:h,spacing:l}=s,{captions:c}=i,{color:u,hoverColor:d,font:f,hoverFont:g,padding:p,align:m}=c,x=(e.active?g:f)||f,y=n.toFont(x);if(y.lineHeight>e.h)return;const b=function(t,e,n,i,r,o){const s=function(t,e,n){return V(t.formatter,q(e,n))||n.g||""}(n,i,r);if(!s)return;const a=n.padding;if(S(t,[s],o).width+2*a<=e.w)return s;const h=n.overflow||"ellipsis";if("hidden"===h)return;if("cut"===h)return s;return I(t,s,e.w-2*a,o)}(t,e,c,o,r,[y]);if(void 0===b)return;const w=[y],v="headerBoxes"===a?e.y+(e.h-y.lineHeight)/2:e.y+p+l;return{align:m||(h?"right":"left"),clipY:"headerBoxes"===a?0:p,colors:[(e.active?d:u)||u],fonts:w,lines:[b],padding:p,styles:[0],textAlign:c.textAlign,top:v,width:S(t,[b],w).width}}(t,e,i,r,o,s)),c&&(t.save(),function(t,e,n,i){const r=Math.max(0,n),o=Math.max(0,i);t.beginPath(),t.rect(e.x+r,e.y+o,Math.max(0,e.w-2*r),Math.max(0,e.h-2*o)),t.clip()}(t,e,c.padding,c.clipY),D(t,e,c),t.restore())}function q(t,e){const n=t.$context||{active:!!t.active,raw:e,type:"data"};return n.active=!!t.active,n.raw=e,n}function V(t,e){return"function"==typeof t?t(e):t}function N(t,e,n,i,r,o){const{groups:s,leafKey:a,unsorted:h}=i,l=s.length,c=m(s[e]),u=M(t,c,n,a,void 0,o,s.filter((t,n)=>n<=e),s,e),d=E(u,n,c,e);for(const t of d){const o=t._data,s=o.groupIndex+1,a=e<l-1&&s<l?N(o.children,s,n,i,r,t.g):[];Object.defineProperty(t,"_children",{configurable:!0,value:a,writable:!0}),t.isLeaf=!a.length}r&&Y(d,et(i));const f=i.others?U(d,i.others,r):d;return h||A(f,r),f}function Y(t,e){for(const n of t){const t=n._children;let i;if(t?.length)Y(t,e),i=t.reduce((t,e)=>t+e[R],0);else{const t=e(n.v,n._data);i=Number.isFinite(t)&&t>0?t:0}Object.defineProperty(n,R,{configurable:!0,value:i,writable:!0})}}function U(t,e,n){const{label:i="Other",minCount:r=2,threshold:o}=e;if(!(o>0)||t.some(t=>t._children?.length))return t;const s=t=>n?t[R]:t.v,a=t.reduce((t,e)=>t+s(e),0);if(!(a>0))return t;const h=t.filter(t=>s(t)/a<o);if(h.length<Math.max(2,r))return t;const l=t.filter(t=>!h.includes(t)),c={_data:{label:i,others:h.map(t=>t._data)},h:0,isLeaf:!0,isOthers:!0,s:0,v:h.reduce((t,e)=>t+e.v,0),vs:G(h),w:0,x:0,y:0},u=t.find(t=>void 0!==t.g);return u&&(c.g=i,c.l=u.l),n&&Object.defineProperty(c,R,{configurable:!0,value:h.reduce((t,e)=>t+s(e),0),writable:!0}),l.push(c),l}function G(t){const e={};for(const n of t)for(const[t,i]of Object.entries(n.vs||{}))e[t]=(e[t]||0)+i;return Object.keys(e).length?e:void 0}const X={log:t=>Math.log1p(Math.max(t,0)),sqrt:t=>Math.sqrt(Math.max(t,0))};function J(t){const e=t.slice();for(const n of t)n._children?.length&&e.push(...J(n._children));return e}function Q(t,e,n,i,r){if(void 0!==r)for(const e of t)e.gs=r;!function(t,e,n=!1){const i=t.length;if(!i)return;const r=n?R:"v",o=new l(e),s=new g(r,o.area/C(t,r));let a,h=o.side;for(let e=0;e<i;++e)a=s.pushIf(t[e],k,h),a&&(o.map(s),h=o.side,s.reset(),s.push(a));s.length&&o.map(s)}(t,e,i);for(const r of t)r._children?.length&&Q(r._children,nt(r,e,n),n,i,r.s)}function Z(t,e,i){Q(t,e,i,tt(i)),function(t,e){const{captions:i,displayMode:r}=e;if("headerBoxes"!==r)return;const o=n.toFont(i.font),s=n.valueOrDefault(i.padding,3);for(const e of t)e.isLeaf||(z(r,e,i)?(e.h=W(r,e,o,s),e.hidden=!1):e.hidden=!0)}(J(t),i)}function tt(t){const e=t.valueScale;return"linear"!==e&&void 0!==e}function et(t){const e=t.valueScale;return"function"==typeof e?e:X[e]||(t=>t)}function nt(t,e,i){const{borderWidth:r,captions:o,displayMode:a}=i,h="headerBoxes"===a?0:i.spacing,l="headerBoxes"===a?{b:0,l:0,r:0,t:0}:s(r,t.w/2,t.h/2),c={...e,h:t.h-2*h-l.t-l.b,w:t.w-2*h-l.l-l.r,x:t.x+h+l.l,y:t.y+h+l.t};if(z(a,c,o)){const t=W(a,c,n.toFont(o.font),n.valueOrDefault(o.padding,3));c.y+=t,c.h-=t}return c}function it(t,e,i){const{groups:r,leafKey:o,unsorted:s}=i,a=n.isObject(t)?b(e,o,t):t,h=tt(i);let l;return r.length?l=N(a,0,e,i,h):(l=E(a||[],e),h&&Y(l,et(i)),i.others&&(l=U(l,i.others,h)),s||A(l,h)),l}function rt(t,e){return void 0===t?e:Math.min(Math.max(t,0),1)}function ot(){const t=e.registry.plugins.get("tooltip");t&&!t.positioners.treemap&&(t.positioners.treemap=t=>{if(!t.length)return!1;return t.at(-1).element.tooltipPosition()})}class st extends e.DatasetController{initialize(){ot(),this.enableOptionSharing=!0,super.initialize()}getMinMax(t){return{max:"x"===t.axis?t.right-t.left:t.bottom-t.top,min:0}}configure(){super.configure();const{xScale:t,yScale:e}=this.getMeta();if(!t||!e)return;const n=t.right-t.left,i=e.bottom-e.top,r={...this._regionBounds(n,i),rtl:!!this.options.rtl,unsorted:!!this.options.unsorted};var o,s;o=this._rect,s=r,o&&s&&o.x===s.x&&o.y===s.y&&o.w===s.w&&o.h===s.h&&o.rtl===s.rtl&&o.unsorted===s.unsorted||(this._rect=r,this._rectChanged=!0),this._rectChanged&&(t.max=n,t.configure(),e.max=i,e.configure())}_regionBounds(t,e){const n=this.options.region;if(!n)return{h:e,w:t,x:0,y:0};const i=rt(n.left,0),r=rt(n.top,0),o=rt(n.width,1),s=rt(n.height,1);return!this._regionWarned&&(i+o>1||r+s>1)&&(this._regionWarned=!0,console.warn("chartjs-chart-treemap: a dataset region reaches outside the chart area and is clipped to it.")),{h:e*Math.min(s,1-r),w:t*Math.min(o,1-i),x:t*i,y:e*r}}_layoutOptions(){const t=this.getDataset(),e=this.options;return{borderWidth:t.borderWidth,captions:t.captions||{},displayMode:e.displayMode,groups:e.groups||[],leafKey:e.leafKey,others:e.others||!1,spacing:n.valueOrDefault(t.spacing,0),unsorted:!!e.unsorted,valueScale:e.valueScale||"linear"}}buildOrUpdateElements(t){this.parse(0,0);const e=this.getMeta(),n=e._parsed.length,i=e.data;for(i.length>n&&i.splice(n,i.length-n);i.length<n;)i.push(new this.dataElementType)}parse(t,e){const n=this.getDataset();if(void 0!==n.tree)throw new Error('chartjs-chart-treemap v5: the "tree" option was renamed to "data". See https://chartjs-chart-treemap.pages.dev/usage/');const i=this.options,r=[i.key||""].concat(i.sumKeys||[]),o=it(n.data||[],r,this._layoutOptions()),s=J(o),a=s.map(t=>`${t.v}\0${t.g}\0${t.l}`).join("");this._fingerprint!==a&&(this._fingerprint=a,this._nodes=o,this.getMeta()._parsed=s,this._layoutDirty=!0)}getContext(t,n,i){const r=e.DatasetController.prototype.getContext.call(this,t,n,i),o="number"==typeof t?this.getParsed(t):void 0;return o&&(r.raw=o,r.parsed=o),r}getLabelAndValue(t){const e=this.getParsed(t);if(!e)return{label:"",value:""};const n=this.getDataset(),i=e.g??e._data?.label??n.label,r=void 0===i?"":`${i}`,o=e.isOthers?e._data?.others?.length:void 0;return{label:o?`${r} (${o} items)`:r,value:`${e.v}`}}update(t){const{data:e}=this.getMeta();"reset"===t&&this.configure(),(this._layoutDirty||this._rectChanged)&&(Z(this._nodes,this._rect,this._layoutOptions()),this._layoutDirty=!1,this._rectChanged=!1),this.updateElements(e,0,e.length,t)}updateElements(t,e,n,r){const o="reset"===r,s=this.resolveDataElementOptions(e,r);this._rect.options=s;const a=this.getSharedOptions(s),h=this.includeOptions(r,a||{}),{xScale:l,yScale:c}=this.getMeta(),u=this.options.spacing;for(let s=e;s<e+n;s++){const e=a||this.resolveDataElementOptions(s,r),n=this.getParsed(s),d=i(n,l,c,u);d.hidden=d.hidden||!!n.hidden,o&&(d.width=0,d.height=0),h&&(d.options=e),this.updateElement(t[s],s,d,r)}this.updateSharedOptions(a||{},r,s)}draw(){const{ctx:t,chartArea:e}=this.chart,i=this.getMeta().data||[],{displayMode:r,rtl:o,spacing:s}=this.options,a={displayMode:r,rtl:o,spacing:s};n.clipArea(t,e);for(let e=0,n=i.length;e<n;++e){const n=i[e];n.hidden||n.draw(t,this.getParsed(e),a)}n.unclipArea(t)}constructor(t,e){super(t,e),this._rect=void 0,this._rectChanged=!0,this._regionWarned=!1,this._nodes=[],this._layoutDirty=!0,this._fingerprint=void 0}}function at(t,e){const{x:n,y:i,width:r,height:o}=t.getProps(["x","y","width","height"],e);return{bottom:i+o,left:n,right:n+r,top:i}}function ht(t){const e=at(t),i=e.right-e.left,r=e.bottom-e.top,a=s(t.options.borderWidth,i/2,r/2),h=function(t,e,i){const r=n.toTRBLCorners(t),s=Math.min(e,i);return{bottomLeft:o(r.bottomLeft,0,s),bottomRight:o(r.bottomRight,0,s),topLeft:o(r.topLeft,0,s),topRight:o(r.topRight,0,s)}}(t.options.borderRadius,i/2,r/2),l={active:t.active,h:r,radius:h,w:i,x:e.left,y:e.top};return{inner:{active:t.active,h:l.h-a.t-a.b,radius:{bottomLeft:Math.max(0,h.bottomLeft-Math.max(a.b,a.l)),bottomRight:Math.max(0,h.bottomRight-Math.max(a.b,a.r)),topLeft:Math.max(0,h.topLeft-Math.max(a.t,a.l)),topRight:Math.max(0,h.topRight-Math.max(a.t,a.r))},w:l.w-a.l-a.r,x:l.x+a.l,y:l.y+a.t},outer:l}}function lt(t,e,n,i){const r=null===e,o=null===n,s=!(!t||r&&o)&&at(t,i);return s&&(r||e>=s.left&&e<=s.right)&&(o||n>=s.top&&n<=s.bottom)}function ct(t,e){t.rect(e.x,e.y,e.w,e.h)}st.id="treemap",st.version="5.0.0-next.9",st.defaults={animations:{numbers:{properties:["x","y","width","height"],type:"number"}},dataElementType:"treemap",displayMode:r.displayMode,groups:[],key:"",leafKey:"_leaf",others:!1,region:void 0,rtl:r.rtl,spacing:r.spacing,sumKeys:[],unsorted:!1,valueScale:"linear"},st.descriptors={_indexable:!1,_scriptable:!0,captions:{_fallback:!0,_scriptable:t=>"formatter"!==t},labels:{_fallback:!0,_scriptable:t=>"formatter"!==t}},st.overrides={hover:{},interaction:{includeInvisible:!0,intersect:!0,mode:"point"},plugins:{tooltip:{callbacks:{label(t){const e=t.parsed,n=e.g||e._data?.label||t.dataset.label;return(n?`${n}: `:"")+e.v},title(t){if(t.length){return t[0].dataset.key||""}return""}},intersect:!0,position:"treemap"}},scales:{x:{alignToPixels:!0,bounds:"data",display:!1,type:"linear"},y:{alignToPixels:!0,bounds:"data",display:!1,reverse:!0,type:"linear"}}},st.beforeRegister=()=>{P("chart.js","4.0",e.Chart.version)},st.afterRegister=()=>{ot()},st.afterUnregister=()=>{const t=e.registry.plugins.get("tooltip");t&&delete t.positioners.treemap};class ut extends e.Element{draw(t,e,i=r){if(!e)return;const o=this.options,{inner:s,outer:a}=ht(this),h=(l=a.radius).topLeft||l.topRight||l.bottomLeft||l.bottomRight?n.addRoundedRectPath:ct;var l;t.save(),a.w===s.w&&a.h===s.h||(t.beginPath(),h(t,a),t.clip(),h(t,s),t.fillStyle=o.borderColor,t.fill("evenodd")),t.beginPath(),h(t,s),t.fillStyle=o.backgroundColor,t.fill(),K(t,s,o,e,this,i),t.restore()}inRange(t,e,n){return lt(this,t,e,n)}inXRange(t,e){return lt(this,t,null,e)}inYRange(t,e){return lt(this,null,t,e)}getCenterPoint(t){const{x:e,y:n,width:i,height:r}=this.getProps(["x","y","width","height"],t);return{x:e+i/2,y:n+r/2}}tooltipPosition(){return this.getCenterPoint()}constructor(t){super(),this.width=void 0,this.height=void 0,t&&Object.assign(this,t)}}ut.id="treemap",ut.defaults={borderRadius:0,borderWidth:0,captions:{align:void 0,color:"black",display:!0,font:{},formatter:t=>{const e=t.raw._data?.label;return t.raw.g||("string"==typeof e?e:"")},overflow:"ellipsis",padding:3,textAlign:void 0},labels:{align:"center",color:"black",display:!1,font:{},formatter(t){const e=t.raw._data?.label;return t.raw.g?[t.raw.g,`${t.raw.v}`]:"string"==typeof e?[e,`${t.raw.v}`]:`${t.raw.v}`},overflow:"cut",padding:3,position:"middle",textAlign:void 0,wrap:!1}},ut.descriptors={_indexable:!1,_scriptable:!0,captions:{_fallback:!0,_scriptable:t=>"formatter"!==t},labels:{_fallback:!0,_scriptable:t=>"formatter"!==t}},ut.defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"},e.Chart.register(st,ut),t.TreemapController=st,t.TreemapElement=ut,t.flatten=function(t){const e=[...t],n=[];for(;e.length;){const t=e.pop();Array.isArray(t)?e.push(...t):n.push(t)}return n.reverse()},t.flattenTree=function(t,e,n){return b(e,n,t)},t.getGroupKey=m,t.group=M,t.index=O,t.normalizeTreeToArray=b,t.requireVersion=P,t.sort=j,t.sum=C});
7
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("chart.js"),require("chart.js/helpers")):"function"==typeof define&&define.amd?define(["exports","chart.js","chart.js/helpers"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["chartjs-chart-treemap"]={},t.Chart,t.Chart.helpers)}(this,function(t,e,n){"use strict";function i(t,e,n,i){const r=2*i,o=e.getPixelForValue(t.x),s=n.getPixelForValue(t.y),a=e.getPixelForValue(t.x+t.w)-o,h=n.getPixelForValue(t.y+t.h)-s;return{height:h-r,hidden:r>a||r>h,width:a-r,x:o+i,y:s+i}}const r={displayMode:"containerBoxes",rtl:!1,spacing:.5};function o(t,e,n){return Math.max(Math.min(t,n),e)}function s(t,e,i){const r=n.toTRBL(t);return{b:o(r.bottom,0,i),l:o(r.left,0,e),r:o(r.right,0,e),t:o(r.top,0,i)}}function a(t,e,n,i){const r=t._normalized;if(!r)return{d1:0,d2:0,h:0,w:0};const o=e*r/n,s=Math.sqrt(r*o),a=r/s;return{d1:s,d2:a,h:"_ix"===i?a:s,w:"_ix"===i?s:a}}function h(t,e,n,i){e.a=e._normalized,e.h=n.h,e.s=i,e.w=n.w,e.x=((t,e)=>t.rtl?t.x+t.iw-e:t.x+t._ix)(t,n.w),e.y=t.y+t._iy,delete e._normalized}class l{get area(){return this.w*this.h}get iw(){return this.w-this._ix}get ih(){return this.h-this._iy}get dir(){const t=this.ih;return t<=this.iw&&t>0?"y":"x"}get side(){return"x"===this.dir?this.iw:this.ih}map(t){const{dir:e,side:n}=this,i="x"===e?"_ix":"_iy",r=t.nsum,o=t.get(),s=n*n,l=r*r;let c=0,u=0;for(const e of o){const n=a(e,s,l,i);u+=n.d1,c=Math.max(c,n.d2),h(this,e,n,t.sum),this[i]+=n.d1}this["x"===e?"_iy":"_ix"]+=c,this[i]-=u}constructor(t){t=t||{h:1,w:1},this.rtl=!!t.rtl,this.unsorted=!!t.unsorted,this.x=t.x||t.left||0,this.y=t.y||t.top||0,this._ix=0,this._iy=0,this.w=t.w||t.width||t.right-t.left,this.h=t.h||t.height||t.bottom-t.top}}const c=Math.min,u=Math.max;function d(t,e){const n=+e[t.key],i=n*t.ratio;return e._normalized=i,{max:u(t.max,n),min:c(t.min,n),nmax:u(t.nmax,i),nmin:c(t.nmin,i),nsum:t.nsum+i,sum:t.sum+n}}function f(t,e,n){t._arr.push(e),function(t,e){Object.assign(t,e)}(t,n)}class g{get length(){return this._arr.length}reset(){this._arr=[],this._hist=[],this.sum=0,this.nsum=0,this.min=1/0,this.max=-1/0,this.nmin=1/0,this.nmax=-1/0}push(t){f(this,t,d(this,t))}pushIf(t,e,...n){const i=d(this,t);if(!e((r=this,{max:r.max,min:r.min,nmax:r.nmax,nmin:r.nmin,nsum:r.nsum,sum:r.sum}),i,n))return t;var r;f(this,t,i)}get(){return this._arr}constructor(t,e){this._arr=[],this._hist=[],this.sum=0,this.nsum=0,this.min=1/0,this.max=-1/0,this.nmin=1/0,this.nmax=-1/0,this.key=t,this.ratio=e,this.reset()}}const p=(t,e)=>e>t||t.length>e.length&&t.startsWith(e),m=t=>String(t),x=t=>null!=t&&""!==t;function y(t,e,i,r=[],o=0,s=[]){const a=o-1;if(t[0]in i&&o>0){const n=r.reduce((t,e,n)=>(n!==a&&(t[m(n)]=e),t),{});n[e]=r[a],t.forEach(t=>{n[t]=i[t]}),s.push(n)}else for(const a of Object.keys(i)){const h=i[a];n.isObject(h)&&(r.push(a),y(t,e,h,r,o+1,s))}return r.splice(a,1),s}function b(t,e,n){const i=y(t,e,n);if(!i.length)return i;const r=i.reduce((t,e)=>{const n=Object.keys(e).length-2;return Math.max(t,n)},0);return i.forEach(t=>{for(let e=0;e<r;e++){const n=m(e);t[n]||(t[n]="")}}),i}function v(t,e,n){const i=[];for(const n of t){const t=e[n];x(t)&&i.push(t)}return i.length?i.join("."):n}function w(t,e,n,i){for(let e=i;e<n.length;e++){const i=m(n[e]);if(x(t[i]))return{group:i,groupIndex:e,value:t[i]}}if(x(t[e]))return{group:e,groupIndex:i,value:t[e]}}function _(t,e,n,i){if(n in t)return;t[n]={value:0};const r=t[n];i.forEach(t=>{r[t]=0}),e[n]=[]}function M(t,e,n,i,r,o,s=[],a=s,h=s.length-1){const l=n[0],c=n.slice(1),u=Object.create(null),d=Object.create(null),f=[],g=a.length?a:[e],p=a.length?h:0;let m,x;for(m=0,x=t.length;m<x;++m){const e=t[m];if(r&&e[r]!==o)continue;const n=w(e,i,g,p);if(!n)return[];const s=n.value;_(u,d,s,c),u[s].value+=+e[l],u[s].label=s,u[s].group=n.group,u[s].groupIndex=n.groupIndex;const a=u[s];c.forEach(t=>{a[t]+=e[t]}),u[s].path=v(g.slice(0,n.groupIndex+1),e,s),d[s].push(e)}return Object.keys(u).forEach(t=>{const n={children:d[t]};n[l]=+u[t].value,c.forEach(e=>{n[e]=+u[t][e]}),n[e]=u[t].label,n.group=u[t].group,n.groupIndex=u[t].groupIndex,n.label=t,n.path=u[t].path,r&&(n[r]=o),f.push(n)}),f}function O(t,e){let i,r=t.length;if(!r)return e;const o=n.isObject(t[0]);for(e=o?e:"v",i=0,r=t.length;i<r;++i)o?t[i]._idx=i:t[i]={_idx:i,v:t[i]};return e}function j(t,e){e?t.sort((t,n)=>+n[e]-+t[e]):t.sort((t,e)=>+e-+t)}function C(t,e){let n,i,r;for(n=0,i=0,r=t.length;i<r;++i)n+=e?+t[i][e]:+t[i];return n}function P(t,e,n,i=!0){const r=n.split(".");let o=0;for(const s of e.split(".")){const a=r[o++];if(Number.parseInt(s,10)<Number.parseInt(a,10))break;if(p(a,s)){if(i)throw new Error(`${t} v${n} is not supported. v${e} or newer is required.`);return!1}}return!0}const E="_weight";function R(t,e,n){if(0===t.sum)return!0;const[i]=n,r=t.nsum*t.nsum,o=e.nsum*e.nsum,s=i*i,a=Math.max(s*t.nmax/r,r/(s*t.nmin));return Math.max(s*e.nmax/o,o/(s*e.nmin))<=a}function k(t,e,n,i){const r=t?t.slice():[],o=O(r,e[0]);return r.map(r=>{const s={_data:t[r._idx],v:o?+r[o]:+r,vs:void 0};return n&&(s.g=r[n],s.gs=void 0,s.l=r.groupIndex??i,s.vs=e.reduce((t,e)=>(t[e]=+r[e],t),{})),s})}function A(t,e=!1){j(t,e?E:"v")}const S=new Map,F=(t,e)=>t[Math.min(e,t.length-1)];function $(t,e,n){const i=n.reduce((t,e)=>t+=e.string,""),r=e.join()+i+(t._measureText?"-spriting":"");let o=S.get(r);if(!o){t.save();const i=e.length;let s=0,a=0;for(let r=0;r<i;r++){const i=n[Math.min(r,n.length-1)];t.font=i.string;const o=e[r];s=Math.max(s,t.measureText(o).width),a+=i.lineHeight}t.restore(),o={height:a,width:s},S.size>=4096&&S.clear(),S.set(r,o)}return o}function L(t,e,n,i){let r=0,o=0;return e.forEach((e,s)=>{const a=F(i,n[s]);r=Math.max(r,$(t,[e],[a]).width),o+=a.lineHeight}),{height:o,width:r}}function D(t,e,n){const{align:i,colors:r,fonts:o,lines:s,padding:a,styles:h,textAlign:l,top:c,width:u}=n,d=l||i,f=function(t,e,n,i,r){if(e===n)return"left"===e?t.x+i:"right"===e?t.x+t.w-i:t.x+t.w/2;const o=function(t,e,n,i){if("left"===e)return t.x+n;if("right"===e)return t.x+t.w-n-i;return t.x+(t.w-i)/2}(t,e,i,r);if("left"===n)return o;if("right"===n)return o+r;return o+r/2}(e,i,d,a,u);t.textAlign=d,t.textBaseline="middle";let g=0;s.forEach((e,n)=>{const i=h[n],s=F(o,i);t.font=s.string,t.fillStyle=r[Math.min(i,r.length-1)],t.fillText(e,f,c+g+s.lineHeight/2),g+=s.lineHeight})}function T(t,e,n){const{position:i,padding:r}=e;return"top"===i?t.y+r:"bottom"===i?t.y+t.h-r-n.height:t.y+(t.h-n.height)/2+r}function I(t,e,n,i){const r=$(t,["..."],i).width;if(r>=n)return"";let o,s=1,a=e.length;for(;s<=a;){const h=Math.floor((s+a)/2);o=$(t,[e.slice(0,h)],i).width,o+r>n?a=h-1:s=h+1}const h=e.slice(0,Math.max(0,s-1));return h?h+"...":""}function B(t,e,n,i){if(i<=0)return[e];const r=e=>$(t,[e],[n]).width<=i,o=[];let s="";const a=t=>{if(r(t))return void(s=t);let e="";for(const n of t)e&&!r(e+n)&&(o.push(e),e=""),e+=n;s=e};for(const t of e.split(" ")){const e=s?`${s} ${t}`:t;r(e)?s=e:(s&&(o.push(s),s=""),a(t))}return s&&o.push(s),o.length?o:[""]}function H(t,e,i,r,o){const s=(n.isArray(e)?e:[e]).map(t=>`${t}`),a=[],h=[];return s.forEach((e,n)=>{const s=F(i,n);for(const i of e.split("\n"))for(const e of o?B(t,i,s,r):[i])a.push(e),h.push(n)}),{lines:a,styles:h}}function z(t,e,i){if(!i||!1===i.display)return!1;if("headerBoxes"===t)return!0;const{w:r,h:o}=e,s=n.toFont(i.font||{}).lineHeight,a=Math.max(Math.min(2*n.valueOrDefault(i.padding,3),Math.min(r,o)),0);return r-a>s&&o-a>s}function K(t,e,n,i){if("headerBoxes"!==t)return n.lineHeight+2*i;const r=n.lineHeight+2*i;return e.h<2*r?e.h/3:r}function W(t,e,i,r,o,s){const{captions:a,labels:h}=i,{displayMode:l}=s;let c;r&&(!n.defined(r.l)||r.isLeaf)?h.display&&(c=function(t,e,i,r,o){const s=i.labels,a=V(s.formatter,q(o,r));if(!a)return;const{align:h,color:l,hoverColor:c,overflow:u,padding:d,wrap:f}=s,g=e.w-2*d,p=e.h-2*d;let m=function(t,e){const{font:i,hoverFont:r}=e,o=(t.active?r:i)||i;return Array.isArray(o)?o.map(t=>n.toFont(t)):[n.toFont(o)]}(e,s),{lines:x,styles:y}=H(t,a,m,g,!!f),b=L(t,x,y,m);const v=function(t,e,n){const{overflow:i,padding:r}=e,{width:o,height:s}=n;if("hidden"===i)return!(o+2*r>t.w||s+2*r>t.h);if("fit"===i){const e=Math.min(t.w/(o+2*r),t.h/(s+2*r));if(e<1)return e}return!0}(e,s,b);if(!v)return;if(n.isNumber(v))if(m=function(t,e){return t.map(t=>{const{lineHeight:i,...r}=t;return n.toFont({...r,size:Math.floor(t.size*e)})})}(m,v),f){const e=H(t,a,m,g,!0);x=e.lines,y=e.styles,b=L(t,x,y,m)}else b={height:b.height*v,width:b.width*v};if("ellipsis"===u){const e=function(t,e,n,i,r,o){const s=[],a=[];let h=0;for(let t=0;t<e.length;t++){const r=F(i,n[t]);if(s.length&&h+r.lineHeight>o)break;h+=r.lineHeight,s.push(e[t]),a.push(n[t])}const l=s.length<e.length,c=s.length-1;for(let e=0;e<s.length;e++){const n=F(i,a[e]);($(t,[s[e]],[n]).width>r||l&&e===c)&&(s[e]=I(t,s[e],r,[n]))}return{lines:s,styles:a}}(t,x,y,m,g,p);x=e.lines,y=e.styles,b=L(t,x,y,m)}const w=(e.active?c:l)||l;return{align:h,clipY:d,colors:n.isArray(w)?w:[w],fonts:m,lines:x,padding:d,styles:y,textAlign:s.textAlign,top:T(e,s,b),width:b.width}}(t,e,i,r,o)):z(l,e,a)&&(c=function(t,e,i,r,o,s){const{displayMode:a,rtl:h,spacing:l}=s,{captions:c}=i,{color:u,hoverColor:d,font:f,hoverFont:g,padding:p,align:m}=c,x=(e.active?g:f)||f,y=n.toFont(x);if(y.lineHeight>e.h)return;const b=function(t,e,n,i,r,o){const s=function(t,e,n){return V(t.formatter,q(e,n))||n.g||""}(n,i,r);if(!s)return;const a=n.padding;if($(t,[s],o).width+2*a<=e.w)return s;const h=n.overflow||"ellipsis";if("hidden"===h)return;if("cut"===h)return s;return I(t,s,e.w-2*a,o)}(t,e,c,o,r,[y]);if(void 0===b)return;const v=[y],w="headerBoxes"===a?e.y+(e.h-y.lineHeight)/2:e.y+p+l;return{align:m||(h?"right":"left"),clipY:"headerBoxes"===a?0:p,colors:[(e.active?d:u)||u],fonts:v,lines:[b],padding:p,styles:[0],textAlign:c.textAlign,top:w,width:$(t,[b],v).width}}(t,e,i,r,o,s)),c&&(t.save(),function(t,e,n,i){const r=Math.max(0,n),o=Math.max(0,i);t.beginPath(),t.rect(e.x+r,e.y+o,Math.max(0,e.w-2*r),Math.max(0,e.h-2*o)),t.clip()}(t,e,c.padding,c.clipY),D(t,e,c),t.restore())}function q(t,e){const n=t.$context||{active:!!t.active,raw:e,type:"data"};return n.active=!!t.active,n.raw=e,n}function V(t,e){return"function"==typeof t?t(e):t}function N(t,e,n,i,r,o){const{groups:s,leafKey:a,unsorted:h}=i,l=s.length,c=m(s[e]),u=M(t,c,n,a,void 0,o,s.filter((t,n)=>n<=e),s,e),d=k(u,n,c,e);for(const t of d){const o=t._data,s=o.groupIndex+1,a=e<l-1&&s<l?N(o.children,s,n,i,r,t.g):[];Object.defineProperty(t,"_children",{configurable:!0,value:a,writable:!0}),t.isLeaf=!a.length}r&&Y(d,et(i));const f=i.others?U(d,i.others,r):d;return h||A(f,r),f}function Y(t,e){for(const n of t){const t=n._children;let i;if(t?.length)Y(t,e),i=t.reduce((t,e)=>t+e[E],0);else{const t=e(n.v,n._data);i=Number.isFinite(t)&&t>0?t:0}Object.defineProperty(n,E,{configurable:!0,value:i,writable:!0})}}function U(t,e,n){const{label:i="Other",minCount:r=2,threshold:o}=e;if(!(o>0)||t.some(t=>t._children?.length))return t;const s=t=>n?t[E]:t.v,a=t.reduce((t,e)=>t+s(e),0);if(!(a>0))return t;const h=t.filter(t=>s(t)/a<o);if(h.length<Math.max(2,r))return t;const l=t.filter(t=>!h.includes(t)),c={_data:{label:i,others:h.map(t=>t._data)},h:0,isLeaf:!0,isOthers:!0,s:0,v:h.reduce((t,e)=>t+e.v,0),vs:G(h),w:0,x:0,y:0},u=t.find(t=>void 0!==t.g);return u&&(c.g=i,c.l=u.l),n&&Object.defineProperty(c,E,{configurable:!0,value:h.reduce((t,e)=>t+s(e),0),writable:!0}),l.push(c),l}function G(t){const e={};for(const n of t)for(const[t,i]of Object.entries(n.vs||{}))e[t]=(e[t]||0)+i;return Object.keys(e).length?e:void 0}const J={log:t=>Math.log1p(Math.max(t,0)),sqrt:t=>Math.sqrt(Math.max(t,0))};function X(t){const e=t.slice();for(const n of t)n._children?.length&&e.push(...X(n._children));return e}function Q(t,e,n,i,r){if(void 0!==r)for(const e of t)e.gs=r;!function(t,e,n=!1){const i=t.length;if(!i)return;const r=n?E:"v",o=new l(e),s=new g(r,o.area/C(t,r));let a,h=o.side;for(let e=0;e<i;++e)a=s.pushIf(t[e],R,h),a&&(o.map(s),h=o.side,s.reset(),s.push(a));s.length&&o.map(s)}(t,e,i);for(const r of t)r._children?.length&&Q(r._children,nt(r,e,n),n,i,r.s)}function Z(t,e,i){Q(t,e,i,tt(i)),function(t,e){const{captions:i,displayMode:r}=e;if("headerBoxes"!==r)return;const o=n.toFont(i.font),s=n.valueOrDefault(i.padding,3);for(const e of t)e.isLeaf||(z(r,e,i)?(e.h=K(r,e,o,s),e.hidden=!1):e.hidden=!0)}(X(t),i)}function tt(t){const e=t.valueScale;return"linear"!==e&&void 0!==e}function et(t){const e=t.valueScale;return"function"==typeof e?e:J[e]||(t=>t)}function nt(t,e,i){const{borderWidth:r,captions:o,displayMode:a}=i,h="headerBoxes"===a?0:i.spacing,l="headerBoxes"===a?{b:0,l:0,r:0,t:0}:s(r,t.w/2,t.h/2),c={...e,h:t.h-2*h-l.t-l.b,w:t.w-2*h-l.l-l.r,x:t.x+h+l.l,y:t.y+h+l.t};if(z(a,c,o)){const t=K(a,c,n.toFont(o.font),n.valueOrDefault(o.padding,3));c.y+=t,c.h-=t}return c}function it(t,e,i){const{groups:r,leafKey:o,unsorted:s}=i,a=n.isObject(t)?b(e,o,t):t,h=tt(i);let l;return r.length?l=N(a,0,e,i,h):(l=k(a||[],e),h&&Y(l,et(i)),i.others&&(l=U(l,i.others,h)),s||A(l,h)),l}function rt(t,e){return void 0===t?e:Math.min(Math.max(t,0),1)}function ot(){const t=e.registry.plugins.get("tooltip");t&&!t.positioners.treemap&&(t.positioners.treemap=t=>{if(!t.length)return!1;return t.at(-1).element.tooltipPosition()})}class st extends e.DatasetController{initialize(){ot(),this.enableOptionSharing=!0,super.initialize()}getMinMax(t){return{max:"x"===t.axis?t.right-t.left:t.bottom-t.top,min:0}}configure(){super.configure();const{xScale:t,yScale:e}=this.getMeta();if(!t||!e)return;const n=t.right-t.left,i=e.bottom-e.top,r={...this._regionBounds(n,i),rtl:!!this.options.rtl,unsorted:!!this.options.unsorted};var o,s;o=this._rect,s=r,o&&s&&o.x===s.x&&o.y===s.y&&o.w===s.w&&o.h===s.h&&o.rtl===s.rtl&&o.unsorted===s.unsorted||(this._rect=r,this._rectChanged=!0),this._rectChanged&&(t.max=n,t.configure(),e.max=i,e.configure())}_regionBounds(t,e){const n=this.options.region;if(!n)return{h:e,w:t,x:0,y:0};const i=rt(n.left,0),r=rt(n.top,0),o=rt(n.width,1),s=rt(n.height,1);return!this._regionWarned&&(i+o>1||r+s>1)&&(this._regionWarned=!0,console.warn("chartjs-chart-treemap: a dataset region reaches outside the chart area and is clipped to it.")),{h:e*Math.min(s,1-r),w:t*Math.min(o,1-i),x:t*i,y:e*r}}_layoutOptions(){const t=this.getDataset(),e=this.options;return{borderWidth:t.borderWidth,captions:t.captions||{},displayMode:e.displayMode,groups:e.groups||[],leafKey:e.leafKey,others:e.others||!1,spacing:n.valueOrDefault(t.spacing,0),unsorted:!!e.unsorted,valueScale:e.valueScale||"linear"}}buildOrUpdateElements(t){super.configure(),this.parse(0,0);const e=this.getMeta(),n=e._parsed.length,i=e.data,r=i.length;for(r>n&&i.splice(n,r-n);i.length<n;)i.push(new this.dataElementType);this._resetFrom=t&&n>r?r:void 0}parse(t,e){const n=this.getDataset();if(void 0!==n.tree)throw new Error('chartjs-chart-treemap v5: the "tree" option was renamed to "data". See https://chartjs-chart-treemap.pages.dev/usage/');const i=this.options,r=[i.key||""].concat(i.sumKeys||[]),o=this._layoutOptions(),s=it(n.data||[],r,o),a=X(s),h=a.map(t=>`${t.v}\0${t.g}\0${t.l}`).join(""),l=JSON.stringify(o,(t,e)=>"function"==typeof e?String(e):e),c=this._layoutKey!==l;this._layoutKey=l,this._fingerprint!==h?(this._fingerprint=h,this._nodes=s,this.getMeta()._parsed=a,this._layoutDirty=!0):c&&(this._layoutDirty=!0)}getContext(t,n,i){const r=e.DatasetController.prototype.getContext.call(this,t,n,i),o="number"==typeof t?this.getParsed(t):void 0;return o&&(r.raw=o,r.parsed=o),r}getLabelAndValue(t){const e=this.getParsed(t);if(!e)return{label:"",value:""};const n=this.getDataset(),i=e.g??e._data?.label??n.label,r=void 0===i?"":`${i}`,o=e.isOthers?e._data?.others?.length:void 0;return{label:o?`${r} (${o} items)`:r,value:`${e.v}`}}update(t){const{data:e}=this.getMeta();"reset"===t&&this.configure(),(this._layoutDirty||this._rectChanged)&&(Z(this._nodes,this._rect,this._layoutOptions()),this._layoutDirty=!1,this._rectChanged=!1);const n=this._resetFrom;this._resetFrom=void 0,void 0!==n&&"reset"!==t&&this.updateElements(e,n,e.length-n,"reset"),this.updateElements(e,0,e.length,t)}updateElements(t,e,n,r){const o="reset"===r,s=this.resolveDataElementOptions(e,r);this._rect.options=s;const a=this.getSharedOptions(s),h=this.includeOptions(r,a),{xScale:l,yScale:c}=this.getMeta(),u=this.options.spacing;for(let s=e;s<e+n;s++){const e=a||this.resolveDataElementOptions(s,r),n=this.getParsed(s),d=i(n,l,c,u);d.hidden=d.hidden||!!n.hidden,o&&(d.width=0,d.height=0),h&&(d.options=e),this.updateElement(t[s],s,d,r)}this.updateSharedOptions(a,r,s)}draw(){const{ctx:t,chartArea:e}=this.chart,i=this.getMeta().data||[],{displayMode:r,rtl:o,spacing:s}=this.options,a={displayMode:r,rtl:o,spacing:s};n.clipArea(t,e);for(let e=0,n=i.length;e<n;++e){const n=i[e];n.hidden||n.draw(t,this.getParsed(e),a)}n.unclipArea(t)}constructor(t,e){super(t,e),this._rect=void 0,this._rectChanged=!0,this._regionWarned=!1,this._nodes=[],this._layoutDirty=!0,this._fingerprint=void 0,this._resetFrom=void 0}}function at(t,e){const{x:n,y:i,width:r,height:o}=t.getProps(["x","y","width","height"],e);return{bottom:i+o,left:n,right:n+r,top:i}}function ht(t){const e=at(t),i=e.right-e.left,r=e.bottom-e.top,a=s(t.options.borderWidth,i/2,r/2),h=function(t,e,i){const r=n.toTRBLCorners(t),s=Math.min(e,i);return{bottomLeft:o(r.bottomLeft,0,s),bottomRight:o(r.bottomRight,0,s),topLeft:o(r.topLeft,0,s),topRight:o(r.topRight,0,s)}}(t.options.borderRadius,i/2,r/2),l={active:t.active,h:r,radius:h,w:i,x:e.left,y:e.top};return{inner:{active:t.active,h:l.h-a.t-a.b,radius:{bottomLeft:Math.max(0,h.bottomLeft-Math.max(a.b,a.l)),bottomRight:Math.max(0,h.bottomRight-Math.max(a.b,a.r)),topLeft:Math.max(0,h.topLeft-Math.max(a.t,a.l)),topRight:Math.max(0,h.topRight-Math.max(a.t,a.r))},w:l.w-a.l-a.r,x:l.x+a.l,y:l.y+a.t},outer:l}}function lt(t,e,n,i){const r=null===e,o=null===n,s=!(!t||r&&o)&&at(t,i);return s&&(r||e>=s.left&&e<=s.right)&&(o||n>=s.top&&n<=s.bottom)}function ct(t,e){t.rect(e.x,e.y,e.w,e.h)}st.id="treemap",st.version="5.0.1",st.defaults={animations:{numbers:{properties:["x","y","width","height"],type:"number"}},dataElementType:"treemap",displayMode:r.displayMode,groups:[],key:"",leafKey:"_leaf",others:!1,region:void 0,rtl:r.rtl,spacing:r.spacing,sumKeys:[],unsorted:!1,valueScale:"linear"},st.descriptors={_indexable:!1,_scriptable:!0,captions:{_fallback:!0,_scriptable:t=>"formatter"!==t},labels:{_fallback:!0,_scriptable:t=>"formatter"!==t}},st.overrides={hover:{},interaction:{includeInvisible:!0,intersect:!0,mode:"point"},plugins:{tooltip:{callbacks:{label(t){const e=t.parsed,n=e.g||e._data?.label||t.dataset.label;return(n?`${n}: `:"")+e.v},title(t){if(t.length){return t[0].dataset.key||""}return""}},intersect:!0,position:"treemap"}},scales:{x:{alignToPixels:!0,bounds:"data",display:!1,type:"linear"},y:{alignToPixels:!0,bounds:"data",display:!1,reverse:!0,type:"linear"}}},st.beforeRegister=()=>{P("chart.js","4.0",e.Chart.version)},st.afterRegister=()=>{ot()},st.afterUnregister=()=>{const t=e.registry.plugins.get("tooltip");t&&delete t.positioners.treemap};class ut extends e.Element{draw(t,e,i=r){if(!e)return;const o=this.options,{inner:s,outer:a}=ht(this),h=(l=a.radius).topLeft||l.topRight||l.bottomLeft||l.bottomRight?n.addRoundedRectPath:ct;var l;t.save(),a.w===s.w&&a.h===s.h||(t.beginPath(),h(t,a),t.clip(),h(t,s),t.fillStyle=o.borderColor,t.fill("evenodd")),t.beginPath(),h(t,s),t.fillStyle=o.backgroundColor,t.fill(),W(t,s,o,e,this,i),t.restore()}inRange(t,e,n){return lt(this,t,e,n)}inXRange(t,e){return lt(this,t,null,e)}inYRange(t,e){return lt(this,null,t,e)}getCenterPoint(t){const{x:e,y:n,width:i,height:r}=this.getProps(["x","y","width","height"],t);return{x:e+i/2,y:n+r/2}}tooltipPosition(){return this.getCenterPoint()}constructor(t){super(),this.width=void 0,this.height=void 0,t&&Object.assign(this,t)}}ut.id="treemap",ut.defaults={borderRadius:0,borderWidth:0,captions:{align:void 0,color:"black",display:!0,font:{},formatter:t=>{const e=t.raw._data?.label;return t.raw.g||("string"==typeof e?e:"")},overflow:"ellipsis",padding:3,textAlign:void 0},labels:{align:"center",color:"black",display:!1,font:{},formatter(t){const e=t.raw._data?.label;return t.raw.g?[t.raw.g,`${t.raw.v}`]:"string"==typeof e?[e,`${t.raw.v}`]:`${t.raw.v}`},overflow:"cut",padding:3,position:"middle",textAlign:void 0,wrap:!1}},ut.descriptors={_indexable:!1,_scriptable:!0,captions:{_fallback:!0,_scriptable:t=>"formatter"!==t},labels:{_fallback:!0,_scriptable:t=>"formatter"!==t}},ut.defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"},e.Chart.register(st,ut),t.TreemapController=st,t.TreemapElement=ut,t.flatten=function(t){const e=[...t],n=[];for(;e.length;){const t=e.pop();Array.isArray(t)?e.push(...t):n.push(t)}return n.reverse()},t.flattenTree=function(t,e,n){return b(e,n,t)},t.getGroupKey=m,t.group=M,t.index=O,t.normalizeTreeToArray=b,t.requireVersion=P,t.sort=j,t.sum=C});
8
8
  //# sourceMappingURL=chartjs-chart-treemap.min.js.map