Skip to content

Commit 2c4c31a

Browse files
committed
Fix CRLF to LF and Prettier errors
1 parent 90b3efb commit 2c4c31a

File tree

7 files changed

+183
-182
lines changed

7 files changed

+183
-182
lines changed

dist/module.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{"name": "Panel", "path": "img/panel.png"}
2222
],
2323
"version": "0.4.0",
24-
"updated": "2021-08-06"
24+
"updated": "2021-08-09"
2525
},
2626

2727
"dependencies": {

src/PanelOptionCode.tsx

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
//Code from https://github.com/gapitio/gapit-htmlgraphics-panel
22
import React from 'react';
33
import { StandardEditorProps } from '@grafana/data';
4-
import { CodeEditor, useTheme } from '@grafana/ui'
4+
import { CodeEditor, useTheme } from '@grafana/ui';
55
import AutoSizer from 'react-virtualized-auto-sizer';
6-
import {css} from 'emotion'
6+
import { css } from 'emotion';
77

8-
interface Props extends StandardEditorProps<string, any, any> { }
8+
interface Props extends StandardEditorProps<string, any, any> {}
99

1010
export const PanelOptionCode: React.FC<Props> = ({ value, item, onChange }) => {
11-
if (typeof value !== "string") {
12-
value = JSON.stringify(value, null, 2)
11+
if (typeof value !== 'string') {
12+
value = JSON.stringify(value, null, 2);
1313
}
1414
const theme = useTheme();
15-
return <AutoSizer
16-
disableHeight
17-
className={css`
18-
margin-bottom: ${theme.spacing.sm};
19-
`}
20-
>
21-
{({ width }) => (
22-
<CodeEditor
23-
language={item.settings?.language}
24-
showLineNumbers={item.settings?.language === 'javascript' ? true : false}
25-
value={value === 'null' ? JSON.stringify(item.settings?.initValue, null, 2) : value}
26-
width={width}
27-
height="200px"
28-
onBlur={code => {
29-
if (item.settings?.language === 'json' && code) {
30-
code = JSON.parse(code);
31-
}
32-
onChange(code)
33-
}
34-
}
35-
/>
36-
)}
37-
</AutoSizer>;
38-
};
15+
return (
16+
<AutoSizer
17+
disableHeight
18+
className={css`
19+
margin-bottom: ${theme.spacing.sm};
20+
`}
21+
>
22+
{({ width }) => (
23+
<CodeEditor
24+
language={item.settings?.language}
25+
showLineNumbers={item.settings?.language === 'javascript' ? true : false}
26+
value={value === 'null' ? JSON.stringify(item.settings?.initValue, null, 2) : value}
27+
width={width}
28+
height="200px"
29+
onBlur={(code) => {
30+
if (item.settings?.language === 'json' && code) {
31+
code = JSON.parse(code);
32+
}
33+
onChange(code);
34+
}}
35+
/>
36+
)}
37+
</AutoSizer>
38+
);
39+
};

src/SimplePanel.tsx

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { PureComponent } from 'react';
22
import { PanelProps } from '@grafana/data';
3-
import { getTemplateSrv, getLocationSrv } from '@grafana/runtime'
3+
import { getTemplateSrv, getLocationSrv } from '@grafana/runtime';
44
import { SimpleOptions, defaults } from 'types';
55
import merge from 'deepmerge';
66
import _ from 'lodash';
@@ -19,73 +19,67 @@ declare global {
1919
window.Plotly = Plotly;
2020
//window.LocationSrv = getLocationSrv();
2121

22-
let templateSrv:any = getTemplateSrv();
22+
let templateSrv: any = getTemplateSrv();
2323

2424
interface Props extends PanelProps<SimpleOptions> {}
2525

2626
export class SimplePanel extends PureComponent<Props> {
2727
render() {
28-
2928
//Get all variables
3029
const context = {
3130
//interval: templateSrv.getBuiltInIntervalValue(),//dataSource.templateSrv.builtIns.__interval.value,
32-
__from:this.props.replaceVariables('$__from'),
33-
__to:this.props.replaceVariables('$__to'),
34-
__interval:this.props.replaceVariables('$__interval'),
35-
__interval_ms:this.props.replaceVariables('$__interval_ms')
31+
__from: this.props.replaceVariables('$__from'),
32+
__to: this.props.replaceVariables('$__to'),
33+
__interval: this.props.replaceVariables('$__interval'),
34+
__interval_ms: this.props.replaceVariables('$__interval_ms'),
3635
} as any;
37-
templateSrv.getVariables().forEach((elt: any)=>{
38-
context[elt.name]=elt.current.text;
39-
})
40-
41-
36+
templateSrv.getVariables().forEach((elt: any) => {
37+
context[elt.name] = elt.current.text;
38+
});
39+
4240
//const NbValues = data.series[0].rows.length;
4341

44-
let config = this.props.options.config || defaults.config
45-
let data = this.props.options.data || defaults.data
42+
let config = this.props.options.config || defaults.config;
43+
let data = this.props.options.data || defaults.data;
4644
let layout = this.props.options.layout || defaults.layout;
4745
let frames = this.props.options.frames || defaults.frames;
4846

4947
let parameters: any;
50-
parameters = [this.props.options.data,layout,config];
48+
parameters = [this.props.options.data, layout, config];
5149

5250
let error: any;
5351
try {
5452
if (this.props.options.script !== '' && this.props.data.state !== 'Error') {
5553
var f = new Function('data,variables', this.props.options.script);
5654
parameters = f(this.props.data, context);
57-
if(!parameters){
55+
if (!parameters) {
5856
throw new Error('Script must return values');
5957
}
6058
}
6159
} catch (e) {
6260
error = e;
6361
console.error(e);
64-
62+
6563
//Can't update chart when script is changing if throw error?!?
6664
//throw new Error('There\'s an error in your script. Check the console to see error\'s details');
67-
6865
}
6966

67+
const combineMerge = (target, source, options) => {
68+
const destination = target.slice();
7069

71-
72-
73-
const combineMerge = (target, source, options) => {
74-
const destination = target.slice()
75-
76-
source.forEach((item, index) => {
77-
if (typeof destination[index] === 'undefined') {
78-
destination[index] = options.cloneUnlessOtherwiseSpecified(item, options)
79-
} else if (options.isMergeableObject(item)) {
80-
destination[index] = merge(target[index], item, options)
81-
} else if (target.indexOf(item) === -1) {
82-
destination.push(item)
83-
}
84-
})
85-
return destination
86-
}
87-
//Merge data field and data transformed by script
88-
/*let series: any[] = [];
70+
source.forEach((item, index) => {
71+
if (typeof destination[index] === 'undefined') {
72+
destination[index] = options.cloneUnlessOtherwiseSpecified(item, options);
73+
} else if (options.isMergeableObject(item)) {
74+
destination[index] = merge(target[index], item, options);
75+
} else if (target.indexOf(item) === -1) {
76+
destination.push(item);
77+
}
78+
});
79+
return destination;
80+
};
81+
//Merge data field and data transformed by script
82+
/*let series: any[] = [];
8983
if (data2.length && data2.length > 0) {
9084
data2.forEach((serie, index) => {
9185
let options = this.props.options.data[index];
@@ -95,35 +89,41 @@ export class SimplePanel extends PureComponent<Props> {
9589
});
9690
});
9791
}*/
98-
99-
layout = {...layout, autosize: true, height: this.props.height};
100-
let display: any;
101-
if(error){
102-
let matches = error.stack.match(/anonymous>:.*\)/m);
103-
let lines = matches?matches[0].slice(0,-1).split(':'):null
104-
display = <div >There's an error in your script : <br/><span style={{color:'#D00'}}>{ error.toString()}</span> {lines?"- line "+(parseInt(lines[1])-2)+":"+lines[2]:""} (Check your console for more details)</div>
105-
}else{
106-
display = <Plot
107-
style={{
108-
width: '100%',
109-
height: '100%',
110-
}}
111-
data={parameters.data?merge(data,parameters.data,{ arrayMerge: combineMerge }):data}
112-
frames={parameters.frames?merge(data,parameters.frames,{ arrayMerge: combineMerge }):frames}
113-
onInitialized={(figure: any, graphDiv: any) => this.setState({ figure: figure, graphDiv: graphDiv })}
114-
//layout={ {autosize:true, height:this.props.height, title: this.props.options.title} }
115-
layout={parameters.layout?merge(layout,parameters.layout):layout}
116-
config={parameters.config?merge(config,parameters.config):config}
117-
useResizeHandler={true}
118-
onClick={data=>{
119-
//console.log(data)
120-
var f = new Function('data', 'getLocationSrv','getTemplateSrv', this.props.options.onclick);
121-
f(data,getLocationSrv,getTemplateSrv);
122-
}}
123-
></Plot>
124-
125-
}
126-
return display;
12792

93+
layout = { ...layout, autosize: true, height: this.props.height };
94+
let display: any;
95+
if (error) {
96+
let matches = error.stack.match(/anonymous>:.*\)/m);
97+
let lines = matches ? matches[0].slice(0, -1).split(':') : null;
98+
display = (
99+
<div>
100+
There&apos;s an error in your script : <br />
101+
<span style={{ color: '#D00' }}>{error.toString()}</span>{' '}
102+
{lines ? '- line ' + (parseInt(lines[1], 10) - 2) + ':' + lines[2] : ''} (Check your console for more details)
103+
</div>
104+
);
105+
} else {
106+
display = (
107+
<Plot
108+
style={{
109+
width: '100%',
110+
height: '100%',
111+
}}
112+
data={parameters.data ? merge(data, parameters.data, { arrayMerge: combineMerge }) : data}
113+
frames={parameters.frames ? merge(data, parameters.frames, { arrayMerge: combineMerge }) : frames}
114+
onInitialized={(figure: any, graphDiv: any) => this.setState({ figure: figure, graphDiv: graphDiv })}
115+
//layout={ {autosize:true, height:this.props.height, title: this.props.options.title} }
116+
layout={parameters.layout ? merge(layout, parameters.layout) : layout}
117+
config={parameters.config ? merge(config, parameters.config) : config}
118+
useResizeHandler={true}
119+
onClick={(data) => {
120+
//console.log(data)
121+
var f = new Function('data', 'getLocationSrv', 'getTemplateSrv', this.props.options.onclick);
122+
f(data, getLocationSrv, getTemplateSrv);
123+
}}
124+
></Plot>
125+
);
126+
}
127+
return display;
128128
}
129129
}

0 commit comments

Comments
 (0)