hello,
looking in the bokeh source code for a while now and after many attempts, I am still unable to have a working example with a dict parameter to be passed to a typescript extension. It always complain, no matter how !
No problem with cds, but my dict struct is key string and value array. Arrays are number or strings of various length depending on the key.
Minimal running code below (uncommenting comments does NOT work)
I would so super appreciate if somebody would know how to do it, I had all my extensions working in coffeescript times and trying to catch up… Thx !
Mat
TSCODE = """
import * as _ from "underscore"
import * as p from "core/properties"
import {Line, LineView} from "models/glyphs/line"
import {ColumnDataSource} from "models/sources/column_data_source"
export class MyLineView extends LineView {
model: MyLine
_map_data(): void {
const cds = this.model.properties.dummy_cds.value()
console.log('cds y',cds.data['y'])
//const dic = this.model.properties.dummy_dic.value()
//console.log('dic',dic)
const ynorm = 1.0
const y = []
for (var i = 0; i < this._y.length; ++i) { y.push(this._y[i]/ynorm) }
[this.sx, this.sy] = this.renderer.coordinates.map_to_screen(this._x, y)
}
}
export namespace MyLine {
export type Attrs = p.AttrsOf<Props>
export type Props = Line.Props & {
dummy_cds: p.Property<ColumnDataSource | null>
//dummy_dic: p.Property<{[key: string]: number[]}>
}
}
export interface MyLine extends MyLine.Attrs {}
export class MyLine extends Line {
properties: MyLine.Props
__view_type__: MyLineView
constructor(attrs?: Partial<MyLine.Attrs>) {
super(attrs)
}
static init_MyLine(): void {
this.prototype.default_view = MyLineView
this.define<MyLine.Props>(({Ref,Nullable}) => ({
dummy_cds: [ Nullable(Ref(ColumnDataSource)), null ],
//dummy_dic: [ Dict(String), {} ],
}))
}
}
"""
from bokeh.core.properties import Float,Bool,Instance,Enum,String,Dict,Any
from bokeh.models import Line
from bokeh.util.compiler import TypeScript
from bokeh.models import Line,ColumnDataSource
from bokeh.plotting import figure,curdoc
class MyLine(Line):
__implementation__ = TypeScript(TSCODE)
dummy_cds = Any()
#dummy_dic = Any()
cds = ColumnDataSource(data=dict(x=[1,2,3],y=[1,2,3]))
#dic={'a':[1,2,3,4],'b':['A','AB']}
p = figure()
l = MyLine(x='x', y='y', dummy_cds=cds)
#l = MyLine(x='x', y='y', dummy_cds=cds, dummy_dic=dic)
p.add_glyph(cds, l)
curdoc().add_root(p)