Skip to content

Conversation

@pared
Copy link
Contributor

@pared pared commented Sep 7, 2021

Thank you for the contribution - we'll try to review it as soon as possible. πŸ™

Fixes #6513
Prerequisit to #6389

This change makes the default plot interactive. The previous default plot is now named "simple".
Since we are changing the default template, the repositories created before this change would not be affected by this change. In order to prevent that we remove dumping plots templates on dvc init and make dvc try to match template by name (same as we do in the case of non-dvc repositories).

One drawback is that users lose the ability to edit default templates, as well as producing their own templates is harder since default ones are not simply under .dvc/plots. We could fix that by improving our docs with the "Create your custom template" example in plots documentation.

Marking as draft to not merge before appropriate docs update.

EDIT:

This change is moving the templates from within the code to package data. The order of looking for template when provided in case of dvc plots show/diff is cwd -> .dvc/plots -> package_data.

After this change the default plot will be linear, and previous default is renamed to simple.

In following change I will introduce command letting user dump the templates into .dvc/plots

@pared pared requested a review from a team as a code owner September 7, 2021 15:05
@pared pared requested review from dberenbaum and pmrowla September 7, 2021 15:05
@pared pared force-pushed the 6513_change_default_plot branch from 93559f5 to d4ee1be Compare September 7, 2021 15:09
@pared pared marked this pull request as draft September 7, 2021 15:12
@dberenbaum
Copy link
Contributor

dberenbaum commented Sep 7, 2021

The previous default plot is now named "simple".

I was thinking that these two templates should be called "linear" and "simple" or "linear_simple" rather than calling either "default." I think it's more helpful to have descriptive names even for the default, and it's easy to document that the default is "linear." In fact, the current documentation is confusing in that it doesn't differentiate between "default" and "linear" even though they are different templates: https://dvc.org/doc/command-reference/plots#plot-templates. Thoughts?


One drawback is that users lose the ability to edit default templates, as well as producing their own templates is harder since default ones are not simply under .dvc/plots. We could fix that by improving our docs with the "Create your custom template" example in plots documentation.

I'm not sure what's best, or whether this should be included in this PR.

  • Is it expected that existing plots may change when updating DVC versions?
  • What happens if someone adds a "smooth.json" with a different format?

One drawback is that users lose the ability to edit default templates, as well as producing their own templates is harder since default ones are not simply under .dvc/plots. We could fix that by improving our docs with the "Create your custom template" example in plots documentation.

A couple other ideas that might help with this problem:

  • Include only the simple linear json file and treat this as an example custom plot (get rid of the existing simple linear template class).
  • Read the content for the built-in templates from json files inside the package as package data. Is there a benefit to keeping the full template content as a massive dict inside each class definition?

@pared pared changed the title plots: make default interactive [WIP] plots: make default interactive Sep 8, 2021
@pared
Copy link
Contributor Author

pared commented Sep 9, 2021

I was thinking that these two templates should be called "linear" and "simple" or "linear_simple" rather than calling either "default."

That makes more sense, I will do proper changes.

Is it expected that existing plots may change when updating DVC versions?

This was never discussed, I think the main reason to dump the templates was to make them easily accessible for users so that they can modify default ones, and start working on their own just by copying pre-existing ones.

What happens if someone adds a "smooth.json" with a different format?

Depends where. If it will be put into .dvc/plots - it will overwrite existing template and user will be able to access it by using --template smooth. If it will be somewhere else in repo, user needs to specify full path and filename. (using smooth without .json was a convenience feature added to make access to plots stored in .dvc/plots easy).

Include only the simple linear json file and treat this as an example custom plot (get rid of the existing simple linear template class).

Do I understand right? Include only simple.json in .dvc/plots?

Read the content for the built-in templates from json files inside the package as package data. Is there a benefit to keeping the full template content as a massive dict inside each class definition?

Makes sense, it would tie the plot to DVC version, and not the repository.

I think that one more reason to get rid of the templates from repo is that it creates additional files that some users consider garbage. #6389
We could also make plots lazier - initialize them in repo only when they are used the first time.

@dberenbaum
Copy link
Contributor

cc @skshetry

@dberenbaum
Copy link
Contributor

Do I understand right? Include only simple.json in .dvc/plots?

πŸ‘ That's my suggestion.

To my understanding, current issues are:

  • Templates may be out of date relative to dvc version.
  • Including in .dvc/plots makes it easier for users to understand and create custom templates.
  • Including the templates creates a lot of unnecessary additional files for many users.

So I propose:

  • Include only simple.json (or maybe call it example.json) in .dvc/plots (and get rid of the Python class for this template altogether).
  • Read the contents of the other included templates directly from the json files (so that we can still link to those for docs and users can copy them), but bundle those files with the package instead of the repo.

By the way, can templates be in $HOME/.config/dvc/plots for reuse across projects?

Interested to hear what you and others think.

@skshetry Do you think this makes sense for stage templates in dvc exp init?

@shcheklein Do you see any impacts for other products?

@shcheklein
Copy link
Member

It might affect a bit other products. It should be fine with Studio (since it's Python), it might not be as fine for VS Code. We might need an interface to access templates in some way (e.g. to determine if that template merges data or not). I think it's doable even if dvc returns fully baked Vega JS in such cases, but it might be less efficient.

I think the point here is that by hiding them in the package we are indeed increasing complexity of people accessing them (manually, programmatically), so I would weight the benefits one more time to be honest. Not an obvious thing to do.

@dberenbaum
Copy link
Contributor

@pared Even though it will not get automatically pushed to existing repos, can we merge the changes to those linear templates for now and discuss the template organization in a separate issue/PR?

@pared pared force-pushed the 6513_change_default_plot branch from d4ee1be to 7247664 Compare September 16, 2021 13:09
@pared pared force-pushed the 6513_change_default_plot branch 2 times, most recently from 58a9918 to 369e129 Compare September 20, 2021 12:18
@pared
Copy link
Contributor Author

pared commented Sep 20, 2021

@dberenbaum I added update to issue description.

Comment on lines 170 to 185
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Preserving previous behaviour of writing default templates to .dvc/plots. It will be removed in next change.

@pared pared changed the title [WIP] plots: make default interactive plots: make default interactive Sep 20, 2021
@pared pared marked this pull request as ready for review September 20, 2021 12:40
@dberenbaum
Copy link
Contributor

Thanks @pared! I meant that this PR could be limited to making the linear plot the default and renaming the current default. I didn't expect you to already move all the templates into json files in a pkg resources dir, but not sure it's worth reverting at this point.

@pared pared force-pushed the 6513_change_default_plot branch from 541cf4d to f809486 Compare September 24, 2021 15:32
@pared pared requested review from pmrowla and removed request for pmrowla September 30, 2021 13:34
@pared
Copy link
Contributor Author

pared commented Oct 4, 2021

@pmrowla, @dberenbaum, the PR is ready for review

Copy link
Contributor

@dberenbaum dberenbaum Oct 4, 2021

Choose a reason for hiding this comment

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

Is this temporary for backwards compatibility or is intended that we will keep it long-term?

Plots included in pkg dir + being able to specify custom template path should be enough, and dropping TEMPLATES_DIR will ignore outdated templates in .dvc/plots.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem here is what in a case when user modified hers/his plots in .dvc/plots? If we drop .dvc/plots user will need to specify the path. It's not a big problem but will be annoying. Also .dvc/plots seems like a good default place for users to put their own templates if they don't want to clutter their repo with templates dir. On the other hand, repos created pre-this-release will keep using outdated templates which is also not good.

We can always consider dropping .dvc/plots in 3.0

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's document how users with old repos can get updated templates by deleting the old ones. Also, are you planning a follow-up to dump the templates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I didn't include it here to not clutter it anymore.

Copy link
Contributor

@dberenbaum dberenbaum left a comment

Choose a reason for hiding this comment

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

It might be good to rename the PR since it seems to extend pretty far beyond the original title.

@pared pared changed the title plots: make default interactive plots: load templates from package Oct 6, 2021
@pared pared force-pushed the 6513_change_default_plot branch from f809486 to 23fbce4 Compare October 8, 2021 12:49
Copy link
Contributor

@pmrowla pmrowla left a comment

Choose a reason for hiding this comment

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

The changes on the code side LGTM

@pared pared requested a review from skshetry October 11, 2021 09:40
@pared pared added A: plots Related to the plots enhancement Enhances DVC labels Oct 11, 2021
@pared pared force-pushed the 6513_change_default_plot branch from c47ce6a to 4c98f0e Compare October 11, 2021 16:04
templates = self._get_templates()
for template in templates:
content = (
importlib_resources.files(__package__)
Copy link
Collaborator

@skshetry skshetry Oct 14, 2021

Choose a reason for hiding this comment

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

This Traversable thing with files() is giving me ideas to implement this for dvc.api for directories. πŸ˜„

@pared pared merged commit a1b1466 into iterative:master Oct 14, 2021
@skshetry
Copy link
Collaborator

@pared, you may also need to add files to the pyinstaller: https://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-files-to-the-bundle

@pared
Copy link
Contributor Author

pared commented Oct 15, 2021

@skshetry thanks, can confirm it's not working for the binary package, preparing a fix...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A: plots Related to the plots enhancement Enhances DVC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plots: render dots with annotations without Vega spec

5 participants