-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add legend to zoomed in plots #1794
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fd81d2a
add legend to zoomed in plot
mattseddon 170100d
add legend for zoomed in checkpoint plots
mattseddon adf92cf
refactor removal of legend suppression up to top level function
mattseddon c78dbbd
commit broken storybook for now
mattseddon 2e404cd
create zoomed in plot component and do not mutate props
mattseddon 4fef580
Merge branch 'main' into add-legend-to-zoomed
mattseddon 0f7848f
Merge branch 'main' into add-legend-to-zoomed
mattseddon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,86 +4,90 @@ import { ColorScale } from 'dvc/src/plots/webview/contract' | |
export const createSpec = ( | ||
title: string, | ||
scale?: ColorScale | ||
): VisualizationSpec => ({ | ||
$schema: 'https://vega.github.io/schema/vega-lite/v5.json', | ||
data: { name: 'values' }, | ||
encoding: { | ||
x: { | ||
axis: { format: '0d', tickMinStep: 1 }, | ||
field: 'iteration', | ||
title: 'iteration', | ||
type: 'quantitative' | ||
): VisualizationSpec => | ||
({ | ||
$schema: 'https://vega.github.io/schema/vega-lite/v5.json', | ||
data: { name: 'values' }, | ||
encoding: { | ||
color: { | ||
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. [F] The change is to move the color out here so that we can overwrite it in the same way we do for Data Series plots. |
||
field: 'group', | ||
legend: { disable: true }, | ||
scale, | ||
title: 'rev', | ||
type: 'nominal' | ||
}, | ||
x: { | ||
axis: { format: '0d', tickMinStep: 1 }, | ||
field: 'iteration', | ||
title: 'iteration', | ||
type: 'quantitative' | ||
}, | ||
y: { | ||
field: 'y', | ||
scale: { zero: false }, | ||
title, | ||
type: 'quantitative' | ||
} | ||
}, | ||
y: { | ||
field: 'y', | ||
scale: { zero: false }, | ||
title, | ||
type: 'quantitative' | ||
} | ||
}, | ||
height: 'container', | ||
layer: [ | ||
{ | ||
encoding: { | ||
color: { field: 'group', legend: null, scale, type: 'nominal' } | ||
height: 'container', | ||
layer: [ | ||
{ | ||
layer: [ | ||
{ mark: { type: 'line' } }, | ||
{ | ||
mark: { type: 'point' }, | ||
transform: [ | ||
{ | ||
filter: { empty: false, param: 'hover' } | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
|
||
layer: [ | ||
{ mark: { type: 'line' } }, | ||
{ | ||
mark: { type: 'point' }, | ||
transform: [ | ||
{ | ||
encoding: { | ||
opacity: { value: 0 }, | ||
tooltip: [ | ||
{ field: 'group', title: 'name' }, | ||
{ | ||
filter: { empty: false, param: 'hover' } | ||
field: 'y', | ||
title: title.slice(Math.max(0, title.indexOf(':') + 1)), | ||
type: 'quantitative' | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
encoding: { | ||
opacity: { value: 0 }, | ||
tooltip: [ | ||
{ field: 'group', title: 'name' }, | ||
}, | ||
mark: { type: 'rule' }, | ||
params: [ | ||
{ | ||
field: 'y', | ||
title: title.slice(Math.max(0, title.indexOf(':') + 1)), | ||
type: 'quantitative' | ||
name: 'hover', | ||
select: { | ||
clear: 'mouseout', | ||
fields: ['iteration', 'y'], | ||
nearest: true, | ||
on: 'mouseover', | ||
type: 'point' | ||
} | ||
} | ||
] | ||
}, | ||
mark: { type: 'rule' }, | ||
params: [ | ||
{ | ||
name: 'hover', | ||
select: { | ||
clear: 'mouseout', | ||
fields: ['iteration', 'y'], | ||
nearest: true, | ||
on: 'mouseover', | ||
type: 'point' | ||
{ | ||
encoding: { | ||
color: { field: 'group', scale }, | ||
x: { aggregate: 'max', field: 'iteration', type: 'quantitative' }, | ||
y: { | ||
aggregate: { argmax: 'iteration' }, | ||
field: 'y', | ||
type: 'quantitative' | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
encoding: { | ||
color: { field: 'group', scale }, | ||
x: { aggregate: 'max', field: 'iteration', type: 'quantitative' }, | ||
y: { | ||
aggregate: { argmax: 'iteration' }, | ||
field: 'y', | ||
type: 'quantitative' | ||
} | ||
}, | ||
mark: { stroke: null, type: 'circle' } | ||
} | ||
], | ||
transform: [ | ||
{ | ||
as: 'y', | ||
calculate: "format(datum['y'],'.5f')" | ||
} | ||
], | ||
width: 'container' | ||
}) | ||
}, | ||
mark: { stroke: null, type: 'circle' } | ||
} | ||
], | ||
transform: [ | ||
{ | ||
as: 'y', | ||
calculate: "format(datum['y'],'.5f')" | ||
} | ||
], | ||
width: 'container' | ||
} as VisualizationSpec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Instead of having
removeLegendSuppression
everywhere, can we just add its content to theVegaLite
component on line 159?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 is definitely the better way to go. I still have a couple of issues hanging around though:
useEffect
in<ZoomablePlot/>
causes an infinite loop if you don't exclude disabling of the legend from the props comparison at the top of the function.Will investigate more today with a fresher(-ish) mind. Thanks a lot for looking!