Skip to content

Commit 6ee19be

Browse files
Arantiryogionkunzdangreen
authored
feat: add an error message when chart container is not found (#1392)
* feat: add an error message when chart container is not found * feat: enrich target element is not found error message * Update src/charts/BaseChart.ts Co-authored-by: Dan Onoshko <danon0404@gmail.com> * Update src/core/creation.ts Co-authored-by: Dan Onoshko <danon0404@gmail.com> * chore: update size-limit threshhold * refactor: fix prettier error * chore: update size-limit threshhold again Co-authored-by: Gion Kunz <gion@syncrea.ch> Co-authored-by: Dan Onoshko <danon0404@gmail.com>
1 parent 89bcbb5 commit 6ee19be

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

.size-limit.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
{
99
"path": "dist/index.cjs",
10-
"limit": "7.40 kB",
10+
"limit": "7.45 kB",
1111
"import": "{ BarChart }"
1212
},
1313
{

src/charts/BaseChart.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ export abstract class BaseChart<TEventsTypes = BaseChartEventsTypes> {
3131
typeof query === 'string' ? document.querySelector(query) : query;
3232

3333
if (!container) {
34-
throw new Error('Target element is not found');
34+
throw new Error(
35+
`Target element ${
36+
typeof query === 'string' ? `"${query}"` : ''
37+
} is not found`
38+
);
3539
}
3640

3741
this.container = container;

src/core/creation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export function createSvg(
2727
height: number | string = '100%',
2828
className?: string
2929
) {
30+
if (!container) {
31+
throw new Error('Container element is not found');
32+
}
33+
3034
// Check if there is a previous SVG element in the container that contains the Chartist XML namespace and remove it
3135
// Since the DOM API does not support namespaces we need to manually search the returned list http://www.w3.org/TR/selectors-api/
3236
Array.from(container.querySelectorAll('svg'))

0 commit comments

Comments
 (0)