-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
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> |
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.
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.
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.
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: |
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.
Cool, I like this API.
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.
Ack.
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.
+1
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.
Thank you.
const X_TYPE = { | ||
STEP: 'step', | ||
RELATIVE: 'relative', | ||
WALL: 'wall', |
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.
wall_time
? (Not that the values of X_TYPE
are ever 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.
Done.
|
||
_dataUrl: { | ||
type: Function, | ||
value: () => getRouter().pluginRunTagRoute('scalars', '/scalars'), |
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.
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.
#491 LGTM
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.
Thanks to @dandelionmane for reviewing.
A card that contains an individual scalar chart. | ||
--> | ||
<dom-module id="tf-scalar-card"> | ||
<template> |
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.
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.
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.
+1, done. It seems like cards could indeed differ in header logic (for instance, due to differences in merging descriptions).
At a high level:
After the change, we will have:
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. |
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.
Could this be more descriptive? It should be clear to a reader of the docstring why this is different from tf-scalar-chart
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.
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.
76b8487
to
55ec296
Compare
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.
I verified that the scalars dashboard WAI. The buttons still work. The CSV and JSON links still work.
@dandelionmane, merging with vz-line-chart SG. How about we do that in 3 steps.
- We extract scalars logic from tf-scalar-chart (this PR).
- We move tf-scalar-chart into components/ and rename it to say
tf-line-chart-loader
(analogous toimage-loader
). - 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> |
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.
+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. |
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.
How about now?
const X_TYPE = { | ||
STEP: 'step', | ||
RELATIVE: 'relative', | ||
WALL: 'wall', |
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.
Done.
|
||
_dataUrl: { | ||
type: Function, | ||
value: () => getRouter().pluginRunTagRoute('scalars', '/scalars'), |
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.
Thanks to @dandelionmane for reviewing.
</div> | ||
</div> | ||
</template> | ||
<content select=".buttons"></content> |
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.
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: |
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.
Ack.
Are there any other actionable items? |
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.
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'; |
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.
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.
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.
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 |
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.
[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.
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.
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: |
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.
+1
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.
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.
Not sure that I agree with this. I'd write:
At a higher level: What do you think? |
SG. Lets just keep them separate and avoid the onus of refactoring then fixing what's broken. |
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):