diff --git a/src/controller.js b/src/controller.js index 9a9ab39..e55e0bc 100644 --- a/src/controller.js +++ b/src/controller.js @@ -83,7 +83,7 @@ export default class TreemapController extends DatasetController { const w = xScale.right - xScale.left; const h = yScale.bottom - yScale.top; - const rect = {x: 0, y: 0, w, h, rtl: !!this.options.rtl}; + const rect = {x: 0, y: 0, w, h, rtl: !!this.options.rtl, unsorted: !!this.options.unsorted}; if (rectNotEqual(this._rect, rect)) { this._rect = rect; diff --git a/src/element.js b/src/element.js index 417dd27..1da6c30 100644 --- a/src/element.js +++ b/src/element.js @@ -391,6 +391,7 @@ TreemapElement.defaults = { padding: 3 }, rtl: false, + unsorted: false, spacing: 0.5 }; diff --git a/src/helpers/index.js b/src/helpers/index.js index a3d66f8..57ee9b8 100644 --- a/src/helpers/index.js +++ b/src/helpers/index.js @@ -19,7 +19,8 @@ export function rectNotEqual(r1, r2) { || r1.y !== r2.y || r1.w !== r2.w || r1.h !== r2.h - || r1.rtl !== r2.rtl; + || r1.rtl !== r2.rtl + || r1.unsorted !== r2.unsorted; } export function arrayNotEqual(a, b) { diff --git a/src/rect.js b/src/rect.js index 4e0b1ac..7273297 100644 --- a/src/rect.js +++ b/src/rect.js @@ -35,6 +35,7 @@ export default class Rect { constructor(r) { r = r || {w: 1, h: 1}; this.rtl = !!r.rtl; + this.unsorted = !!r.unsorted; this.x = r.x || r.left || 0; this.y = r.y || r.top || 0; this._ix = 0; diff --git a/src/squarify.js b/src/squarify.js index b53bada..a58609a 100644 --- a/src/squarify.js +++ b/src/squarify.js @@ -40,7 +40,10 @@ export default function squarify(values, rectangle, keys = [], grp, lvl, gsum) { const tmp = values.slice(); let key = index(tmp, keys[0]); - sort(tmp, key); + + if (!rectangle.unsorted) { + sort(tmp, key); + } const val = (idx) => key ? +tmp[idx][key] : +tmp[idx]; const gval = (idx) => grp && tmp[idx][grp];