Skip to content

Commit

Permalink
feat: add an error message when chart container is not found (#1392)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update src/core/creation.ts

Co-authored-by: Dan Onoshko <[email protected]>

* chore: update size-limit threshhold

* refactor: fix prettier error

* chore: update size-limit threshhold again

Co-authored-by: Gion Kunz <[email protected]>
Co-authored-by: Dan Onoshko <[email protected]>
  • Loading branch information
3 people authored Jan 4, 2023
1 parent 89bcbb5 commit 6ee19be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
{
"path": "dist/index.cjs",
"limit": "7.40 kB",
"limit": "7.45 kB",
"import": "{ BarChart }"
},
{
Expand Down
6 changes: 5 additions & 1 deletion src/charts/BaseChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export abstract class BaseChart<TEventsTypes = BaseChartEventsTypes> {
typeof query === 'string' ? document.querySelector(query) : query;

if (!container) {
throw new Error('Target element is not found');
throw new Error(
`Target element ${
typeof query === 'string' ? `"${query}"` : ''
} is not found`
);
}

this.container = container;
Expand Down
4 changes: 4 additions & 0 deletions src/core/creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export function createSvg(
height: number | string = '100%',
className?: string
) {
if (!container) {
throw new Error('Container element is not found');
}

// Check if there is a previous SVG element in the container that contains the Chartist XML namespace and remove it
// Since the DOM API does not support namespaces we need to manually search the returned list http://www.w3.org/TR/selectors-api/
Array.from(container.querySelectorAll('svg'))
Expand Down

0 comments on commit 6ee19be

Please sign in to comment.