Skip to content

Commit

Permalink
add unsorted option
Browse files Browse the repository at this point in the history
  • Loading branch information
ogom committed Jul 28, 2024
1 parent 32dbdbf commit 49d54ca
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ TreemapElement.defaults = {
padding: 3
},
rtl: false,
unsorted: false,
spacing: 0.5
};

Expand Down
3 changes: 2 additions & 1 deletion src/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/squarify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 49d54ca

Please sign in to comment.