Skip to content

Commit

Permalink
Hide overflowing (too small) children (#78)
Browse files Browse the repository at this point in the history
Co-authored-by: Jukka Kurkela <[email protected]>
  • Loading branch information
kurkle and Jukka Kurkela committed Dec 28, 2021
1 parent e9bf30d commit 3930e5b
Show file tree
Hide file tree
Showing 10 changed files with 2,157 additions and 1,487 deletions.
3,591 changes: 2,113 additions & 1,478 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "chartjs-chart-treemap",
"homepage": "https://chartjs-chart-treemap.pages.dev/",
"version": "2.0.1",
"version": "2.0.2",
"description": "Chart.js module for creating treemap charts",
"main": "dist/chartjs-chart-treemap.js",
"module": "dist/chartjs-chart-treemap.esm.js",
Expand Down
15 changes: 7 additions & 8 deletions src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,14 @@ export default class TreemapController extends DatasetController {
for (let i = start; i < start + count; i++) {
const sq = dataset.data[i];
const options = sharedOptions || me.resolveDataElementOptions(i, mode);
const height = reset ? 0 : sq.h - options.spacing * 2;
const width = reset ? 0 : sq.w - options.spacing * 2;
const x = sq.x + options.spacing;
const y = sq.y + options.spacing;
const sp = options.spacing;
const sp2 = sp * 2;
const properties = {
x,
y,
width,
height
x: sq.x + sp,
y: sq.y + sp,
width: reset ? 0 : sq.w - sp2,
height: reset ? 0 : sq.h - sp2,
hidden: sp2 > sq.w || sp2 > sq.h,
};

if (includeOptions) {
Expand Down
35 changes: 35 additions & 0 deletions test/fixtures/issues/77.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const tree = [
{
p1: '/etc',
p2: 'passwd',
value: 1000
},
{
p1: '/etc',
p2: 'shadow',
value: 5
}
];

export default {
config: {
type: 'treemap',
data: {
datasets: [{
tree,
groups: ['p1', 'p2'],
key: 'value',
spacing: 20,
borderWidth: 1,
backgroundColor: (ctx) => ctx.index === 2 ? 'red' : 'rgba(0,0,0,0.5)',
}]
},
},
options: {
canvas: {
height: 256,
width: 512
},
spriteText: true
}
};
Binary file added test/fixtures/issues/77.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/specs/controller.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
describe('auto', jasmine.fixtures('basic'));
describe('auto', jasmine.fixtures('grouped'));
describe('auto', jasmine.fixtures('events'));
describe('auto', jasmine.fixtures('issues'));

describe('controller', function() {
it('should be registered', function() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3930e5b

Please sign in to comment.