Skip to content

Commit

Permalink
Merge pull request #200 from mhkeller/verbose-mode
Browse files Browse the repository at this point in the history
Add option to suppress layout warnings
  • Loading branch information
mhkeller committed May 17, 2024
2 parents aa0d80e + a2d9554 commit 8174a0c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
===

# 8.2.0

> 2024-05-17
Adds an option to suppress layout warnings. By default, Layer Cake warns you when you create a div that is too small. But sometimes you want to create a chart inside a hidden element or something and make the chart expand. In these cases, the warnings are annoying.

* [PR#200](https://github.com/mhkeller/layercake/pull/200)

# 8.1.4

> 2024-05-06
Expand Down
22 changes: 13 additions & 9 deletions src/lib/LayerCake.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@
/** @type {Boolean} debug Enable debug printing to the console. Useful to inspect your scales and dimensions. */
export let debug = false;
/** @type {Boolean} [verbose=true] Show warnings in the console. */
export let verbose = true;
/**
* Make this reactive
Expand Down Expand Up @@ -289,15 +291,17 @@
b.left = $padding.left;
b.width = b.right - b.left;
b.height = b.bottom - b.top;
if (b.width <= 0 && isMounted === true) {
console.warn(
'[LayerCake] Target div has zero or negative width. Did you forget to set an explicit width in CSS on the container?'
);
}
if (b.height <= 0 && isMounted === true) {
console.warn(
'[LayerCake] Target div has zero or negative height. Did you forget to set an explicit height in CSS on the container?'
);
if (verbose === true) {
if (b.width <= 0 && isMounted === true) {
console.warn(
'[LayerCake] Target div has zero or negative width. Did you forget to set an explicit width in CSS on the container?'
);
}
if (b.height <= 0 && isMounted === true) {
console.warn(
'[LayerCake] Target div has zero or negative height. Did you forget to set an explicit height in CSS on the container?'
);
}
}
return b;
}
Expand Down
1 change: 0 additions & 1 deletion src/lib/utils/padScale.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const unpaddable = ['scaleThreshold', 'scaleQuantile', 'scaleQuantize', 'scaleSe

export default function padScale (scale, padding) {
if (typeof scale.range !== 'function') {
console.log(scale);
throw new Error('Scale method `range` must be a function');
}
if (typeof scale.domain !== 'function') {
Expand Down

0 comments on commit 8174a0c

Please sign in to comment.