-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Allow plot tooltip to show extra columns #9800
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a881aa1
changes
dfb95b8
add changeset
gradio-pr-bot 9bd453c
Merge branch 'main' into allow_tooltip_to_show_extra_columns
abidlabs aeaf5be
Merge branch 'main' into allow_tooltip_to_show_extra_columns
abidlabs b640a43
changes
8caa98a
Merge remote-tracking branch 'origin' into allow_tooltip_to_show_extr…
1862c56
Merge branch 'main' into allow_tooltip_to_show_extra_columns
abidlabs 8cf45cf
changes
abidlabs f5aa3a2
chanes
387eebd
changes
dc15451
Merge branch 'main' into allow_tooltip_to_show_extra_columns
abidlabs 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ | |
export let x_axis_labels_visible = true; | ||
export let caption: string | null = null; | ||
export let sort: "x" | "y" | "-x" | "-y" | string[] | null = null; | ||
export let tooltip: "axis" | "none" | "all" = "axis"; | ||
function reformat_sort( | ||
_sort: typeof sort | ||
): | ||
|
@@ -114,19 +115,29 @@ | |
function reformat_data(data: PlotData): { | ||
[x: string]: string | number; | ||
}[] { | ||
let x_index = data.columns.indexOf(x); | ||
let y_index = data.columns.indexOf(y); | ||
let color_index = color ? data.columns.indexOf(color) : null; | ||
return data.data.map((row) => { | ||
const obj = { | ||
[x]: row[x_index], | ||
[y]: row[y_index] | ||
}; | ||
if (color && color_index !== null) { | ||
obj[color] = row[color_index]; | ||
} | ||
return obj; | ||
}); | ||
if (tooltip == "all") { | ||
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. can't filter out "irrelevant" columns if tooltip == "all" |
||
return data.data.map((row) => { | ||
const obj: { [x: string]: string | number } = {}; | ||
data.columns.forEach((col, i) => { | ||
obj[col] = row[i]; | ||
}); | ||
return obj; | ||
}); | ||
} else { | ||
let x_index = data.columns.indexOf(x); | ||
let y_index = data.columns.indexOf(y); | ||
let color_index = color ? data.columns.indexOf(color) : null; | ||
return data.data.map((row) => { | ||
const obj = { | ||
[x]: row[x_index], | ||
[y]: row[y_index] | ||
}; | ||
if (color && color_index !== null) { | ||
obj[color] = row[color_index]; | ||
} | ||
return obj; | ||
}); | ||
} | ||
} | ||
$: _data = value ? reformat_data(value) : []; | ||
|
||
|
@@ -411,29 +422,42 @@ | |
type: value.datatypes[color] | ||
} | ||
: undefined, | ||
tooltip: [ | ||
{ | ||
field: y, | ||
type: value.datatypes[y], | ||
aggregate: aggregating ? _y_aggregate : undefined, | ||
title: y_title || y | ||
}, | ||
{ | ||
field: x, | ||
type: value.datatypes[x], | ||
title: x_title || x, | ||
format: x_temporal ? "%Y-%m-%d %H:%M:%S" : undefined, | ||
bin: _x_bin ? { step: _x_bin } : undefined | ||
}, | ||
...(color | ||
? [ | ||
tooltip: | ||
tooltip == "none" | ||
? undefined | ||
: [ | ||
{ | ||
field: color, | ||
type: value.datatypes[color] | ||
} | ||
field: y, | ||
type: value.datatypes[y], | ||
aggregate: aggregating ? _y_aggregate : undefined, | ||
title: y_title || y | ||
}, | ||
{ | ||
field: x, | ||
type: value.datatypes[x], | ||
title: x_title || x, | ||
format: x_temporal ? "%Y-%m-%d %H:%M:%S" : undefined, | ||
bin: _x_bin ? { step: _x_bin } : undefined | ||
}, | ||
...(color | ||
? [ | ||
{ | ||
field: color, | ||
type: value.datatypes[color] | ||
} | ||
] | ||
: []), | ||
...(tooltip === "axis" | ||
? [] | ||
: value?.columns | ||
.filter( | ||
(col) => col !== x && col !== y && col !== color | ||
) | ||
.map((column) => ({ | ||
field: column, | ||
type: value.datatypes[column] | ||
}))) | ||
] | ||
: []) | ||
] | ||
}, | ||
strokeDash: {}, | ||
mark: { clip: true, type: mode === "hover" ? "point" : value.mark }, | ||
|
Oops, something went wrong.
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.
I think a better api would be to just let it take a list of column names. Often, dataframes will have a large number of irrelevant columns and I'm sure we'll get the request to be able to select specific columns to show in the tooltip
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 added support for passing list of column names