Skip to content

Commit

Permalink
Merge pull request #345 from pl0xz0rz/bokeh3_migration
Browse files Browse the repository at this point in the history
Bokeh3 migration
  • Loading branch information
miranov25 authored Jan 4, 2024
2 parents d64eb26 + b77a5d7 commit d00f59d
Show file tree
Hide file tree
Showing 29 changed files with 163 additions and 168 deletions.
2 changes: 1 addition & 1 deletion RootInteractive/InteractiveDrawing/bokeh/CDSAlias.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class CDSAlias(ColumnarDataSource):
source=Instance(ColumnarDataSource, help="The source to draw from")
mapping=Dict(String, Any, help="The mapping from new columns to old columns and possibly mappers")
includeOrigColumns=Bool()
columnDependencies=List(Instance(Model), [], help="Hacky way of improving performance and fixing a weird serialization bug")
columnDependencies=List(Instance(Model), help="Hacky way of improving performance and fixing a weird serialization bug")
print("Import ", __implementation__)
4 changes: 2 additions & 2 deletions RootInteractive/InteractiveDrawing/bokeh/CDSAlias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export class CDSAlias extends ColumnarDataSource {

_locked_columns: Set<string>

static init_CDSAlias() {
static {
this.define<CDSAlias.Props>(({Any, Boolean, Array, Ref})=>({
source: [Ref(ColumnarDataSource)],
mapping: [ p.Instance, {} ],
mapping: [ Any, {} ],
includeOrigColumns: [Boolean, true],
columnDependencies: [Array(Any), []]
}))
Expand Down
12 changes: 6 additions & 6 deletions RootInteractive/InteractiveDrawing/bokeh/CDSCompress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export namespace CDSCompress {
export type Attrs = p.AttrsOf<Props>

export type Props = ColumnDataSource.Props & {
inputData : p.Property<Record<string, any>>
sizeMap : p.Property<Record<string, any>>
inputData : p.Property<any>
sizeMap : p.Property<any>
}
}

Expand All @@ -95,11 +95,11 @@ export class CDSCompress extends ColumnDataSource {

static __name__ = "CDSCompress"

static init_CDSCompress() {
static {

this.define<CDSCompress.Props>(()=>({
inputData: [ p.Instance ],
sizeMap: [ p.Instance ]
this.define<CDSCompress.Props>(({Any})=>({
inputData: [ Any, {} ],
sizeMap: [ Any, {} ]
}))
}

Expand Down
8 changes: 4 additions & 4 deletions RootInteractive/InteractiveDrawing/bokeh/CDSJoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export class CDSJoin extends ColumnarDataSource {

static __name__ = "CDSJoin"

static init_CDSJoin() {
static {
this.define<CDSJoin.Props>(({Ref, Array, String, Number})=>({
left: [Ref(ColumnarDataSource)],
right: [Ref(ColumnarDataSource)],
on_left: [ Array(String), [] ],
on_right: [ Array(String), [] ],
prefix_left: [String],
prefix_right: [String],
how: [ String ],
prefix_left: [String, ""],
prefix_right: [String, ""],
how: [ String, "inner" ],
tolerance: [Number, 1e-5]
}))
}
Expand Down
6 changes: 3 additions & 3 deletions RootInteractive/InteractiveDrawing/bokeh/CDSStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export class CDSStack extends ColumnarDataSource {

static __name__ = "CDSStack"

static init_CDSStack() {
this.define<CDSStack.Props>(({Ref, Array, String})=>({
static {
this.define<CDSStack.Props>(({Ref, Array, String, Any})=>({
sources: [Array(Ref(ColumnarDataSource)), []],
mapping: [p.Instance],
mapping: [Any],
activeSources: [Array(String), []]
}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ClientLinearFitter extends Model {

static __name__ = "ClientLinearFitter"

static init_ClientLinearFitter() {
static {
this.define<ClientLinearFitter.Props>(({Array, String, Number, Ref, Nullable})=>({
varX: [Array(String), []],
source: [Ref(ColumnarDataSource)],
Expand Down
2 changes: 1 addition & 1 deletion RootInteractive/InteractiveDrawing/bokeh/ColumnFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ColumnFilter extends RIFilter {

static __name__ = "ColumnFilter"

static init_ColumnFilter() {
static {
this.define<ColumnFilter.Props>(({Ref, String})=>({
source: [Ref(ColumnarDataSource)],
field: [String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ConcatenatedString extends Model {
#is_dirty: boolean
#value: string

static init_ConcatenatedString() {
static {
this.define<ConcatenatedString.Props>(({Array, String})=>({
components: [Array(String), []]
}))
Expand Down
26 changes: 17 additions & 9 deletions RootInteractive/InteractiveDrawing/bokeh/CustomJSNAryFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export namespace CustomJSNAryFunction {
export type Props = Model.Props & {
parameters: p.Property<Record<string, any>>
fields: p.Property<Array<string>>
func: p.Property<string>
v_func: p.Property<string>
func: p.Property<string | null>
v_func: p.Property<string | null>
}
}

Expand All @@ -23,12 +23,12 @@ export class CustomJSNAryFunction extends Model {

static __name__ = "CustomJSNAryFunction"

static init_CustomJSNAryFunction() {
this.define<CustomJSNAryFunction.Props>(({Array, String})=>({
parameters: [p.Instance, {}],
static {
this.define<CustomJSNAryFunction.Props>(({Array, String, Any, Nullable})=>({
parameters: [Any, {}],
fields: [Array(String), []],
func: [ String ],
v_func: [String]
func: [ Nullable(String), null ],
v_func: [Nullable(String), null]
}))
}

Expand All @@ -41,14 +41,18 @@ export class CustomJSNAryFunction extends Model {
args_keys: Array<string>
args_values: Array<any>

scalar_func: Function
vector_func: Function
scalar_func: Function | null
vector_func: Function | null

connect_signals(): void {
super.connect_signals()
}

update_func(){
if(!this.func){
this.scalar_func = null
return
}
this.args_keys = Object.keys(this.parameters)
this.args_values = Object.values(this.parameters)
this.scalar_func = new Function(...this.args_keys, ...this.fields, '"use strict";\n'+this.func)
Expand All @@ -60,6 +64,10 @@ export class CustomJSNAryFunction extends Model {
}

update_vfunc(){
if(!this.v_func){
this.vector_func = null
return
}
this.args_keys = Object.keys(this.parameters)
this.args_values = Object.values(this.parameters)
this.vector_func = new Function(...this.args_keys, ...this.fields, "data_source", "$output",'"use strict";\n'+this.v_func)
Expand Down
26 changes: 13 additions & 13 deletions RootInteractive/InteractiveDrawing/bokeh/DownsamplerCDS.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import {ColumnarDataSource} from "models/sources/columnar_data_source"
import {CDSAlias} from "./CDSAlias"
import {RIFilter} from "./RIFilter"
import {ColumnDataSource} from "models/sources/column_data_source"
import {Model} from "model"
import * as p from "core/properties"

export namespace DownsamplerCDS {
export type Attrs = p.AttrsOf<Props>

export type Props = ColumnarDataSource.Props & {
source: p.Property<CDSAlias>
export type Props = ColumnDataSource.Props & {
source: p.Property<any>
nPoints: p.Property<number>
watched: p.Property<boolean>
filter: p.Property<null|RIFilter>
filter: p.Property<any>
}
}

export interface DownsamplerCDS extends DownsamplerCDS.Attrs {}

export class DownsamplerCDS extends ColumnarDataSource {
export class DownsamplerCDS extends ColumnDataSource {
properties: DownsamplerCDS.Props

constructor(attrs?: Partial<DownsamplerCDS.Attrs>) {
Expand All @@ -25,12 +24,12 @@ export class DownsamplerCDS extends ColumnarDataSource {

static __name__ = "DownsamplerCDS"

static init_DownsamplerCDS() {
static {
this.define<DownsamplerCDS.Props>(({Ref, Int, Boolean, Nullable})=>({
source: [Ref(CDSAlias)],
source: [Ref(Model)],
nPoints: [ Int, 300 ],
watched: [Boolean, true],
filter: [Nullable(Ref(RIFilter)), null]
filter: [Nullable(Ref(Model)), null]
}))
}

Expand All @@ -52,6 +51,7 @@ export class DownsamplerCDS extends ColumnarDataSource {
super.initialize()
this.booleans = null
this._indices = []
this._downsampled_indices = []
this.data = {}
this.low = 0
this.high = -1
Expand All @@ -64,7 +64,7 @@ export class DownsamplerCDS extends ColumnarDataSource {
const {_indices, source} = this
_indices.length = source.get_length()!
// Fisher-Yates random permutation
for(let i=0; i<_indices.length; ++i){
for(let i=0; i <_indices.length; ++i){
let random_index = (Math.random()*(i+1)) | 0
_indices[i] = i
_indices[i] = _indices[random_index]
Expand Down Expand Up @@ -138,7 +138,7 @@ export class DownsamplerCDS extends ColumnarDataSource {
update_selection(){
if(this._is_trivial) return
const downsampled_indices = this.data.index
const selected_indices = this.selected.indices.map((x:number)=>downsampled_indices[x])
const selected_indices = Array.from(this.selected.indices).map((x:number)=>downsampled_indices[x])
selected_indices.sort((a,b)=>a-b)
const original_indices = this.source.selected.indices
// TODO: Change original CDS selection indices
Expand Down Expand Up @@ -195,7 +195,7 @@ export class DownsamplerCDS extends ColumnarDataSource {
new_column = Array(_downsampled_indices.length)
}
if(new_column.length < _downsampled_indices.length) new_column.length = _downsampled_indices.length
for(let i=0; i<_downsampled_indices.length; i++){
for(let i=0; i <_downsampled_indices.length; i++){
new_column[i] = column_orig[_downsampled_indices[i]]
}
data[columnName] = new_column
Expand Down
10 changes: 5 additions & 5 deletions RootInteractive/InteractiveDrawing/bokeh/HistoNdCDS.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {ColumnarDataSource} from "models/sources/columnar_data_source"
import {RIFilter} from "./RIFilter"
import {Model} from "model"
import * as p from "core/properties"

export namespace HistoNdCDS {
export type Attrs = p.AttrsOf<Props>

export type Props = ColumnarDataSource.Props & {
source: p.Property<ColumnarDataSource>
filter: p.Property<RIFilter | null>
filter: p.Property<any | null>
nbins: p.Property<number[]>
range: p.Property<(number[] | null)[] | null>
sample_variables: p.Property<string[]>
Expand All @@ -34,11 +34,11 @@ export class HistoNdCDS extends ColumnarDataSource {

static __name__ = "HistoNdCDS"

static init_HistoNdCDS() {
static {

this.define<HistoNdCDS.Props>(({Ref, Array, Nullable, Number, Int, String, Any})=>({
source: [Ref(ColumnarDataSource)],
filter: [Nullable(Ref(RIFilter)), null],
filter: [Nullable(Ref(Model)), null],
nbins: [Array(Int)],
range: [Nullable(Array(Nullable(Array(Number))))],
sample_variables: [Array(String)],
Expand Down Expand Up @@ -499,7 +499,7 @@ export class HistoNdCDS extends ColumnarDataSource {
let cumulativeHistogram = [...histogram]
let acc = 0
let l = histogram.length
for (let i=0; i<l; i++){
for (let i=0; i < l; i++){
acc += histogram[i]
cumulativeHistogram[i] = acc
}
Expand Down
8 changes: 4 additions & 4 deletions RootInteractive/InteractiveDrawing/bokeh/HistoNdProfile.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {ColumnarDataSource} from "models/sources/columnar_data_source"
import {HistoNdCDS} from "./HistoNdCDS"
import {Model} from "model"
import * as p from "core/properties"
import { kth_value, weighted_kth_value } from "./MathUtils"

export namespace HistoNdProfile {
export type Attrs = p.AttrsOf<Props>

export type Props = ColumnarDataSource.Props & {
source: p.Property<HistoNdCDS>
source: p.Property<any>
axis_idx: p.Property<number>
quantiles: p.Property<number[]>
sum_range: p.Property<number[][]>
Expand All @@ -29,10 +29,10 @@ export class HistoNdProfile extends ColumnarDataSource {

static __name__ = "HistoNdProfile"

static init_HistoNdProfile() {
static {

this.define<HistoNdProfile.Props>(({Ref, Array, Number, Int, Boolean, String, Nullable, Or})=>({
source: [Ref(HistoNdCDS)],
source: [Ref(Model)],
axis_idx: [Int, 0],
quantiles: [Array(Number), []], // This is the list of all quantiles to compute, length is NOT equal to CDS length
sum_range: [Array(Array(Number)), []],
Expand Down
8 changes: 4 additions & 4 deletions RootInteractive/InteractiveDrawing/bokeh/HistoStatsCDS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ export class HistoStatsCDS extends ColumnDataSource {

static __name__ = "HistoStatsCDS"

static init_HistoStatsCDS() {
static {

this.define<HistoStatsCDS.Props>(({Ref, Array, String, Boolean, Number, Nullable})=>({
sources: [Array(Ref(ColumnarDataSource))],
names: [Array(String)],
bincount_columns: [Array(String)],
bin_centers: [Array(String)],
rowwise: [Boolean],
rowwise: [Boolean, false],
quantiles: [Array(Number), []], // This is the list of all quantiles to compute, length is NOT equal to CDS length
compute_quantile: [Nullable(Array(Boolean))],
edges_left: [Array(String)],
edges_right: [Array(String)],
edges_left: [Array(String), []],
edges_right: [Array(String), []],
sum_range: [Array(Array(Number)), []]
}))
}
Expand Down
13 changes: 6 additions & 7 deletions RootInteractive/InteractiveDrawing/bokeh/HistogramCDS.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {ColumnarDataSource} from "models/sources/columnar_data_source"
import {ColumnDataSource} from "models/sources/column_data_source"
import {RIFilter} from "./RIFilter"
import {Model} from "model"
import * as p from "core/properties"
//import { kth_value, weighted_kth_value } from "./MathUtils"

export namespace HistogramCDS {
export type Attrs = p.AttrsOf<Props>

export type Props = ColumnarDataSource.Props & {
source: p.Property<ColumnDataSource>
filter: p.Property<RIFilter | null>
source: p.Property<ColumnarDataSource>
filter: p.Property<any>
nbins: p.Property<number>
range: p.Property<number[] | null>
sample: p.Property<string>
Expand All @@ -29,11 +28,11 @@ export class HistogramCDS extends ColumnarDataSource {

static __name__ = "HistogramCDS"

static init_HistogramCDS() {
static {

this.define<HistogramCDS.Props>(({Ref, Number, Array, Nullable, String, Any})=>({
source: [Ref(ColumnDataSource)],
filter: [Nullable(Ref(RIFilter)), null],
source: [Ref(ColumnarDataSource)],
filter: [Nullable(Ref(Model)), null],
nbins: [Number],
range: [Nullable(Array(Number))],
sample: [String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class LazyIntersectionFilter extends RIFilter {

static __name__ = "LazyIntersectionFilter"

static init_LazyIntersectionFilter() {
static {
this.define<LazyIntersectionFilter.Props>(({Ref, Array})=>({
filters: [Array(Ref(RIFilter)), []],
}))
Expand Down
2 changes: 1 addition & 1 deletion RootInteractive/InteractiveDrawing/bokeh/LazyTabs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from bokeh.models.widgets import Tabs
from bokeh.models.layouts import Tabs
from bokeh.core.properties import List, Instance, Bool
from bokeh.model import Model

Expand Down
Loading

0 comments on commit d00f59d

Please sign in to comment.