Skip to content

Commit 8789747

Browse files
committed
feat: handle render errors
1 parent 78f6a7d commit 8789747

4 files changed

Lines changed: 12 additions & 15 deletions

File tree

src/Error.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ const containerStyles = {
3333

3434
const messageStyles = {
3535
marginLeft: 10
36-
}
36+
}

src/Sankey.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,13 @@ export class Sankey {
5050
this._calculateSankey();
5151
}
5252

53-
5453
// ---------------------------- DIMENSIONS ----------------------------
5554

5655
_setBoundDimensions() {
5756
this._boundedWidth = this._width - this._marginLeft - this._marginRight;
5857
this._boundedHeight = this._height - this._marginTop - this._marginBottom;
5958
}
6059

61-
6260
// ------------------------------ COLOR -------------------------------
6361

6462
_setColorScale() {
@@ -69,7 +67,6 @@ export class Sankey {
6967
return this._colorScale(node.name);
7068
}
7169

72-
7370
// ------------------------------ SANKEY -------------------------------
7471

7572
_configureSankey() {
@@ -97,7 +94,6 @@ export class Sankey {
9794
this._links = sankeyData.links;
9895
}
9996

100-
10197
// ---------------------------- VALIDATIONS -----------------------------
10298

10399
_validate() {
@@ -291,7 +287,6 @@ export class Sankey {
291287
}
292288

293289

294-
295290
// -----------------------------------------------------------------------
296291
// ------------------------------ API ------------------------------
297292
// -----------------------------------------------------------------------
@@ -330,14 +325,12 @@ export class Sankey {
330325

331326
render() {
332327
if (!this._validate()) {
333-
// error
334-
console.log('error')
328+
// no graph data
335329
}
336330
else {
337-
this._init();
338-
this._renderSVG()
331+
this._init();
332+
this._renderSVG()
339333
}
340334
return this;
341335
}
342-
343-
}
336+
}

src/SankeyPanel.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const SankeyPanel: React.FC<Props> = ({ options, data, width, height }) =
6565
const values = valueAccesor?.values.toArray();
6666

6767
const isValid = validate(sources, targets, values);
68-
if (!isValid) return
68+
if (!isValid) {return}
6969

7070
const zip = d3.zip(sources, targets, values);
7171

@@ -88,7 +88,11 @@ export const SankeyPanel: React.FC<Props> = ({ options, data, width, height }) =
8888
.highlightOnHover(options.highlightOnHover)
8989
.data(graph)
9090

91-
sankey.render()
91+
try {
92+
sankey.render();
93+
} catch (renderError) {
94+
setError({isError: true, message: renderError.message})
95+
}
9296
};
9397

9498
return (error.isError ?

src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { PanelPlugin } from '@grafana/data';
22
import { SankeyOptions } from './types';
33
import { SankeyPanel } from './SankeyPanel';
44

5-
export const plugin = new PanelPlugin<SankeyOptions>(SankeyPanel).setPanelOptions(builder => {
5+
export const plugin = new PanelPlugin<SankeyOptions>(SankeyPanel).setPanelOptions((builder) => {
66
return builder
77
.addSelect({
88
path: 'align',

0 commit comments

Comments
 (0)