Skip to content

Generalize tf-scalar-chart.html #470

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

Merged
merged 1 commit into from
Sep 15, 2017
Merged

Conversation

chihuahua
Copy link
Member

Before this change, tf-scalar-chart.html contains much logic specific to
the scalars plugin. We extract that scalars-specific logic into a new
component called tf-scalar-card. Some of the logic extracted includes
properties that allow for setting X and Y axes, the buttons under the
chart, and the callback that is run when data is received from the
server.

This change is a step towards allowing any plugin to make use of the
tf-scalar-chart component (albeit a subsequent change will move and
rename this component to clarify that it is generally applicable). That
goal is desirable because tf-scalar-chart contains a lot of fixes that
correct for bugs in the vz-line-chart component and Plottable. Those fixes
include #163, #189, and #204.

Screenshot (The scalars dashboard WAI):

anf0v4j2pqa

@chihuahua chihuahua requested review from jart and wchargin and removed request for jart and wchargin September 4, 2017 01:03
@chihuahua
Copy link
Member Author

Ping. Could someone review? An internal team is considering a new plugin that uses line charts, and they're about to use vz-line-charts. We might be able to generalize this in time.

</div>
</div>
</template>
<content select=".buttons"></content>
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 recommend against having tf-scalar-chart own the DOM for the buttons: we had something like this before I removed all the chart scaffolding logic, and anything nontrivial required a super hacky implementation, was not accessible, etc.

Let's just have the parent element write

<tf-scalar-chart  />
<div>
  <!-- buttons -->
</div>

If there's a benefit to doing it as currently written that I'm not seeing—maybe in terms of CSS/layout?—I'm sure that there is an easy way to redesign it for equivalent functionality.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Indeed, I see no major benefits there - maybe we write the CSS for buttons once, but that's not too compelling.

showDownloadLinks: Boolean,

/**
* A function that takes as inputs:
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, I like this API.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you.

const X_TYPE = {
STEP: 'step',
RELATIVE: 'relative',
WALL: 'wall',
Copy link
Contributor

Choose a reason for hiding this comment

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

wall_time? (Not that the values of X_TYPE are ever used.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


_dataUrl: {
type: Function,
value: () => getRouter().pluginRunTagRoute('scalars', '/scalars'),
Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't mind, I'd like to merge #494 and its dependency family before this; that family is currently halfway merged, blocking on review of #491, and it would be preferable to not introduce occurrences of old-style code right as we're trying to excise them.

Choose a reason for hiding this comment

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

#491 LGTM

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks to @dandelionmane for reviewing.

A card that contains an individual scalar chart.
-->
<dom-module id="tf-scalar-card">
<template>
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me that tf-scalar-card should own the tf-card-heading. That is, the tf-scalar-chart component should display just a chart and nothing more: the log scale toggle, download links, etc. should be handled by the enclosing component.

Copy link
Member Author

Choose a reason for hiding this comment

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

+1, done. It seems like cards could indeed differ in header logic (for instance, due to differences in merging descriptions).

@teamdandelion
Copy link

At a high level:
The intended factorization of components was:

  • tf-scalar-chart - specific to the scalar dashboard
  • vz-line-chart - good for generic usage

After the change, we will have:

  • tf-scalar-card - specific to the scalar dashbaord
  • tf-scalar-chart - good for generic usage
  • vz-line-chart - useless?

Should we just be moving all of the tf-scalar-chart behaviors that are needed for general usage into vz-line-chart?

Or is there a more subtle factorization of functionality here that I'm missing (e.g. vz-line-chart is useful for non-tf applications where we don't assume you have point/step/wall_time structuring? I don't think this is true because lots of the true application logic live in the Plottable code inside vz-line-chart)

<link rel="import" href="tf-scalar-chart.html">

<!--
A card that contains an individual scalar chart.

Choose a reason for hiding this comment

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

Could this be more descriptive? It should be clear to a reader of the docstring why this is different from tf-scalar-chart

Copy link
Member Author

Choose a reason for hiding this comment

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

How about now?

Before this change, tf-scalar-chart.html contains much logic specific to
the scalars plugin. We extract that scalars-specific logic into a new
component called tf-scalar-card. Some of the logic extracted includes
properties that allow for setting X and Y axes, the buttons under the
chart, and the callback that is run when data is received from the
server.

This change is a step towards allowing any plugin to make use of the
tf-scalar-chart component (albeit a subsequent change will move and
rename this component to clarify that it is generally applicable). That
goal is desirable because tf-scalar-chart contains a lot of logic that
corrects for bugs in the vz-line-chart component and Plottable. That
logic includes #163, #189, and #204.
@chihuahua chihuahua force-pushed the chihuahua-scalars-refactoring branch from 76b8487 to 55ec296 Compare September 12, 2017 03:59
Copy link
Member Author

@chihuahua chihuahua left a comment

Choose a reason for hiding this comment

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

I verified that the scalars dashboard WAI. The buttons still work. The CSV and JSON links still work.

odmzhtxecwn

@dandelionmane, merging with vz-line-chart SG. How about we do that in 3 steps.

  1. We extract scalars logic from tf-scalar-chart (this PR).
  2. We move tf-scalar-chart into components/ and rename it to say tf-line-chart-loader (analogous to image-loader).
  3. We move vz-line-chart into tf-scalar-chart and make the former only visible to the latter.

A card that contains an individual scalar chart.
-->
<dom-module id="tf-scalar-card">
<template>
Copy link
Member Author

Choose a reason for hiding this comment

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

+1, done. It seems like cards could indeed differ in header logic (for instance, due to differences in merging descriptions).

<link rel="import" href="tf-scalar-chart.html">

<!--
A card that contains an individual scalar chart.
Copy link
Member Author

Choose a reason for hiding this comment

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

How about now?

const X_TYPE = {
STEP: 'step',
RELATIVE: 'relative',
WALL: 'wall',
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


_dataUrl: {
type: Function,
value: () => getRouter().pluginRunTagRoute('scalars', '/scalars'),
Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks to @dandelionmane for reviewing.

</div>
</div>
</template>
<content select=".buttons"></content>
Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Indeed, I see no major benefits there - maybe we write the CSS for buttons once, but that's not too compelling.

showDownloadLinks: Boolean,

/**
* A function that takes as inputs:
Copy link
Member Author

Choose a reason for hiding this comment

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

Ack.

@chihuahua chihuahua requested a review from wchargin September 12, 2017 04:04
@chihuahua
Copy link
Member Author

Are there any other actionable items?

Copy link
Contributor

@jart jart left a comment

Choose a reason for hiding this comment

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

I'll second what @dandelionmane said earlier, about how it might be better if some of this was further generalized and documented, and moved into the vz_line_chart package. Since this appears to be a step in that direction, LGTM.

</style>
</template>
<script>
import {addParams} from '../tf-backend/urlPathHelpers.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: Sometime in Q4 we're most likely going to be refactoring the codebase to move these script tags out into separate .js or .ts files, so we can use rules_typescript. Doesn't need to happen now.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. @wchargin noted advantages to keeping scripts inline to make them easier to follow, but it would be nice to support the BUILD rules.

-->
<dom-module id="tf-scalar-card">
<template>
<tf-card-heading
Copy link
Contributor

Choose a reason for hiding this comment

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

[optional] Consider putting a <figure> tag around all this stuff, since I programmed tf-card-heading earlier to use figcaption. I'm not sure what the benefit would be, but it is nice semantic HTML. Possibly also make the div buttons below a figcaption.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, the hard part is that <figcaption> must be the first or last child within a <figure> element. How about we achieve that in a separate refactoring. The use of figure semantics seems promising though.

showDownloadLinks: Boolean,

/**
* A function that takes as inputs:
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@chihuahua chihuahua merged commit c27023e into master Sep 15, 2017
@chihuahua chihuahua deleted the chihuahua-scalars-refactoring branch September 15, 2017 00:10
chihuahua added a commit that referenced this pull request Sep 15, 2017
The scalars dashboard had been broken by #470 because the buttons had not been moved out of the tf-scalar-chart container.

Furthermore, the tf-card-heading now must be block-positioned for the margin to take effect.
chihuahua added a commit that referenced this pull request Sep 15, 2017
The scalars dashboard had been broken by #470 because the buttons had not been moved out of the tf-scalar-chart container.

Furthermore, the tf-card-heading now must be block-positioned for the margin to take effect.
@wchargin
Copy link
Contributor

@dandelionmane:

After the change, we will have:

  • tf-scalar-card - specific to the scalar dashbaord
  • tf-scalar-chart - good for generic usage
  • vz-line-chart - useless?

Not sure that I agree with this. I'd write:

  • tf-scalar-card - specific to the scalar dashbaord
  • tf-scalar-chart (now "tf-line-chart-data-loader") - good for usage that loads data from the network using the standard TensorBoard run–tag organization
  • vz-line-chart - good if the above does not apply

At a higher level: vz-line-chart is a "dumb component" and tf-scalar-chart is a "smart component." Especially given that they're already separate, which is usually considered the best practice, I don't see a need to inline vz-line-chart into tf-scalar-chart.

What do you think?

@chihuahua
Copy link
Member Author

SG. Lets just keep them separate and avoid the onus of refactoring then fixing what's broken.

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

Successfully merging this pull request may close these issues.

4 participants