-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom JS code chart improvements #1873
Changes from 4 commits
3fd90c6
73466dc
605a70d
aacc4b7
1a8078a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -499,6 +499,9 @@ const CustomPlotlyChart = (clientConfig) => { | |
return; | ||
} | ||
const refresh = () => { | ||
// Clear existing data | ||
element[0].children[0].calcdata = []; | ||
element[0].children[0].data = []; | ||
// eslint-disable-next-line no-eval | ||
const codeCall = eval(`codeCall = function(x, ys, element, Plotly){ ${scope.options.customCode} }`); | ||
codeCall(scope.x, scope.ys, element[0].children[0], Plotly); | ||
|
@@ -514,9 +517,11 @@ const CustomPlotlyChart = (clientConfig) => { | |
}); | ||
}); | ||
}; | ||
scope.$watch('options.customCode', () => { | ||
scope.$watch('[options.customCode, options.autoRedraw]', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to watch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought so too. But I realized that I would want the graph to redraw 'when I ticked the auto-redraw'. Without this watch, only the next change in code will update the graph. I think, writing a lengthy code without autoRadraw, then placing a tick on autoRedraw, should trigger the graph redraw immediately. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then why not just watch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I am editing a small script, I would like to refresh graph as I type. This is done by watching |
||
try { | ||
refresh(); | ||
if (scope.options.autoRedraw) { | ||
refresh(); | ||
} | ||
} catch (err) { | ||
if (scope.options.enableConsoleLogs) { | ||
// eslint-disable-next-line no-console | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This piece is related to
and used by
The code above appends a trace to an already existing plot. So without clearing
data
from the already drawn plotly graph, every update in code editor will cause the trace in the graph to multiply. One-trace bar graph becomes two-trace bar graph, three-trace bar graph, and so on, each time you type in code editor.Using Plotly.newPlot() might be another option to avoid appending, but haven't tried it yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see 1a8078a .
This less hackish way fixes the problem too.