Skip to content
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

IDE uses new visualization API #3661

Merged
merged 28 commits into from
Sep 1, 2022
Merged

IDE uses new visualization API #3661

merged 28 commits into from
Sep 1, 2022

Conversation

4e6
Copy link
Contributor

@4e6 4e6 commented Aug 22, 2022

Pull Request Description

PR integrates new visualization API that uses method pointers instead of lambdas as visualization expressions.

Important Notes

Checklist

Please include the following checklist in your PR:

  • The documentation has been updated if necessary.
  • All code conforms to the
    Scala,
    Java,
    and
    Rust
    style guides.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed: Enso GUI was tested when built using BOTH
      ./run ide build and ./run ide watch.

Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#3655 needs an ability to invoke the Enso part of the visualization with arguments. How can one do that with setPreprocessor(module, method)?

app/gui/docs/product/visualizations.md Outdated Show resolved Hide resolved
port. In case it is not connected, the visualization becomes an interactive
widget allowing the user to specify data. For example, a map visualization
will allow the user to manually pick locations. After each change, the new
locations will be sent to the output port. Under the hood, widgets are
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That almost sounds like "dynamic widgets" to me!

data to visualization. If not called, a default unspecified code is used
- #### Method `setPreprocessor(module,method)`
Set an Enso method which will be evaluated on the server-side before sending
data to visualization. If not called, a default unspecified method is used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default unspecified? That's a strange formulation in a specification of the behavior ;-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Specification explicitly opts-out from defining this.
There'll be some code present, but custom visualization should not make any assumptions about it. Thanks to that, we can adjust it without breaking public API.

where visualization is defined - you may use any symbol defined or imported in
that module.
The code will be evaluated in the context of the module where the preprocessor
method is defined - you may use any symbol defined or imported in that module.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can one pass arguments to the method? #3655 needs to be able to invoke the Enso engine part of the visualization with different arguments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect that arguments are part of the expression, as the arguments change we update the expression.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it was removed. Then some mechanism for arguments is necessary,

app/gui/controller/double-representation/src/module.rs Outdated Show resolved Hide resolved
Comment on lines -50 to -52
* When visualization is attached to a node, each time a new value is produced from node,
* the preprocessor shall be invoked with it. Result such call shall be serialized and
* transported to visualization by invoking onDataReceived(data) method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I miss such detailed documentation in the new version.

We have a special documentation page for contributors wanting to create new visualizations, and these docs AFAIK refers to this file for specific documentation of JS methods they can use inside their visualizations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the doc with more details and examples. Should be better now

app/gui/src/model/execution_context.rs Outdated Show resolved Hide resolved
where visualization is defined - you may use any symbol defined or imported in
that module.
The code will be evaluated in the context of the module where the preprocessor
method is defined - you may use any symbol defined or imported in that module.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it was removed. Then some mechanism for arguments is necessary,

@@ -44,7 +43,7 @@ class Histogram extends Visualization {

constructor(data) {
super(data)
this.setPreprocessor('process_to_json_text', 'Standard.Visualization.Histogram')
this.setPreprocessor('Standard.Visualization.Histogram', 'process_to_json_text')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to revert the order of arguments?

Copy link
Contributor Author

@4e6 4e6 Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it more. Imagine calling a method by a fully qualified name Foo.Bar.Baz.quux a b c. The setPreprocessor method just splits the call into three sections (arguments are optional in this case)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please double-check that all calls to this have been update. This is a change that can easily cause issues as the arguments have the same type and this will only fail at runtime.

@4e6 4e6 requested a review from kazcw as a code owner August 23, 2022 15:50
@4e6 4e6 requested a review from JaroslavTulach August 23, 2022 20:00
Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This should be good enough for the scatterplot visualization.

setArguments(...args) {
if (args !== this.__preprocessorArguments__) {
this.__preprocessorArguments__ = args
this.__emitPreprocessorChange__()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally changing only the setArguments shall be a lightweight operation. Something that invokes already existing code on the engine side, without re-parsing the code. But I guess this is provided by definition when using method pointers...

@@ -2198,7 +2204,176 @@ class RuntimeVisualizationsTest
"Enso_Test.Test.Visualisation",
"Enso_Test.Test.Visualisation",
"incAndEncode"
),
Vector("2", "3")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other types are supported? Text? Booleans True, False? Complex atoms? Function invocations?

Copy link
Contributor Author

@4e6 4e6 Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An argument can be an arbitrary Enso expression that can be interpreted in the context of the visualization module

@@ -94,6 +75,7 @@ pub enum Notification {

/// Describes the state of the visualization on the Language Server.
#[derive(Clone, Debug, PartialEq)]
#[allow(clippy::large_enum_variant)]
Copy link
Contributor Author

@4e6 4e6 Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy complains about the size of enum variant. I though that it is safe to ignore because most of the variants have comparable sizes (the size of Visualization struct). And the variant having two Visualization fields is the one that Clippy complains about.

app/gui/src/model/execution_context.rs Outdated Show resolved Hide resolved
@@ -44,7 +43,7 @@ class Histogram extends Visualization {

constructor(data) {
super(data)
this.setPreprocessor('process_to_json_text', 'Standard.Visualization.Histogram')
this.setPreprocessor('Standard.Visualization.Histogram', 'process_to_json_text')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please double-check that all calls to this have been update. This is a change that can easily cause issues as the arguments have the same type and this will only fail at runtime.

@4e6
Copy link
Contributor Author

4e6 commented Aug 25, 2022

Please double-check that all calls to this have been update. This is a change that can easily cause issues as the arguments have the same type and this will only fail at runtime.

I'm pretty sure I updated all of them. Unless grep failed me 😅

app/gui/src/model/execution_context.rs Outdated Show resolved Hide resolved
app/gui/docs/product/visualizations.md Outdated Show resolved Hide resolved
@4e6 4e6 merged commit de0a231 into develop Sep 1, 2022
@4e6 4e6 deleted the wip/db/lazy-vis-ide branch September 1, 2022 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants