Skip to content
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 title and settings and fix datetime to Perspective #6482

Merged
merged 5 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions panel/models/perspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class Perspective(HTMLBox):

selectable = Bool(default=True)

settings = Bool(default=True)

schema = Dict(String, String)

sort = Either(List(List(String)), Null())
Expand All @@ -76,6 +78,8 @@ class Perspective(HTMLBox):

theme = Enum(*PERSPECTIVE_THEMES, default="pro")

title = String()

__javascript_module_exports__ = ['perspective']

__javascript_modules_raw__ = [
Expand Down
47 changes: 31 additions & 16 deletions panel/models/perspective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class PerspectiveView extends HTMLBoxView {
const {
schema, toggle_config, columns, expressions, split_by, group_by,
aggregates, filters, sort, plugin, selectable, editable, theme,
title, settings
} = this.model.properties

const not_updating = (fn: () => void) => {
Expand Down Expand Up @@ -115,6 +116,12 @@ export class PerspectiveView extends HTMLBoxView {
this.on_change(filters, not_updating(() => {
this.perspective_element.restore({filter: this.model.filters})
}))
this.on_change(settings, not_updating(() => {
this.perspective_element.restore({settings: this.model.settings})
}))
this.on_change(title, not_updating(() => {
this.perspective_element.restore({title: this.model.title})
}))
this.on_change(sort, not_updating(() => {
this.perspective_element.restore({sort: this.model.sort})
}))
Expand Down Expand Up @@ -163,6 +170,7 @@ export class PerspectiveView extends HTMLBoxView {
set_size(container, this.model)
this.shadow_el.appendChild(container)

console.log(this.model.schema)
philippjfr marked this conversation as resolved.
Show resolved Hide resolved
this.worker.table(this.model.schema).then((table: any) => {
this.table = table
this.table.update(this.data)
Expand All @@ -183,8 +191,10 @@ export class PerspectiveView extends HTMLBoxView {
group_by: this.model.group_by,
plugin: PLUGINS[this.model.plugin ],
plugin_config,
settings: this.model.settings,
sort: this.model.sort,
theme: THEMES[this.model.theme ],
title: this.model.title
}).catch(() => {})

this.perspective_element.save().then((config: any) => {
Expand All @@ -208,7 +218,7 @@ export class PerspectiveView extends HTMLBoxView {
const props: any = {}
for (let option in config) {
let value = config[option]
if (value === undefined || (option == "plugin" && value === "debug") || this.model.properties.hasOwnProperty(option) === undefined) {
if (value === undefined || (option == "plugin" && value === "debug") || option == "version" || this.model.properties.hasOwnProperty(option) === undefined) {
continue
}
if (option === "filter") {
Expand All @@ -221,6 +231,7 @@ export class PerspectiveView extends HTMLBoxView {
props[option] = value
}
this._updating = true
console.log(props)
philippjfr marked this conversation as resolved.
Show resolved Hide resolved
this.model.setv(props)
this._updating = false
})
Expand Down Expand Up @@ -279,9 +290,11 @@ export namespace Perspective {
selectable: p.Property<boolean | null>
toggle_config: p.Property<boolean>
schema: p.Property<any>
settings: p.Property<boolean>
sort: p.Property<any[] | null>
source: p.Property<ColumnDataSource>
theme: p.Property<any>
title: p.Property<string>
}
}

Expand All @@ -300,21 +313,23 @@ export class Perspective extends HTMLBox {
this.prototype.default_view = PerspectiveView

this.define<Perspective.Props>(({Any, List, Bool, Ref, Nullable, Str}) => ({
aggregates: [ Any, {} ],
columns: [ List(Nullable(Str)), [] ],
expressions: [ Any, {} ],
split_by: [ Nullable(List(Str)), null ],
editable: [ Bool, true ],
filters: [ Nullable(List(Any)), null ],
group_by: [ Nullable(List(Str)), null ],
plugin: [ Str ],
plugin_config: [ Any, {} ],
selectable: [ Bool, true ],
schema: [ Any, {} ],
toggle_config: [ Bool, true ],
sort: [ Nullable(List(List(Str))), null ],
source: [ Ref(ColumnDataSource) ],
theme: [ Str, "pro" ],
aggregates: [ Any, {} ],
columns: [ List(Nullable(Str)), [] ],
expressions: [ Any, {} ],
split_by: [ Nullable(List(Str)), null ],
editable: [ Bool, true ],
filters: [ Nullable(List(Any)), null ],
group_by: [ Nullable(List(Str)), null ],
plugin: [ Str ],
plugin_config: [ Any, {} ],
selectable: [ Bool, true ],
settings: [ Bool, true ],
schema: [ Any, {} ],
toggle_config: [ Bool, true ],
sort: [ Nullable(List(List(Str))), null ],
source: [ Ref(ColumnDataSource) ],
theme: [ Str, "pro" ],
title: [ Str, "untitled" ]
}))
}
}
9 changes: 6 additions & 3 deletions panel/pane/perspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ class Perspective(ModelPane, ReactiveData):
theme = param.ObjectSelector(default='pro', objects=THEMES, doc="""
The style of the PerspectiveViewer. For example pro-dark""")

title = param.String(default='Table', doc="""
Title for the Perspective viewer.""")

priority: ClassVar[float | bool | None] = None

_bokeh_model: ClassVar[Type[Model] | None] = None
Expand Down Expand Up @@ -404,10 +407,10 @@ def _get_properties(self, doc, source=None):
else:
if len(array):
value = array[0]
if isinstance(value, dt.date):
schema[col] = 'date'
elif isinstance(value, datetime_types):
if isinstance(value, datetime_types) and type(value) is not dt.date:
schema[col] = 'datetime'
elif isinstance(value, dt.date):
schema[col] = 'date'
elif isinstance(value, str):
schema[col] = 'string'
elif isinstance(value, (float, np.floating)):
Expand Down
Loading