@quartic/bokehjs
Version:
Interactive, novel data visualization
53 lines (47 loc) • 1.73 kB
text/coffeescript
import {RemoteDataSource} from "./remote_data_source"
import {logger} from "core/logging"
import * as p from "core/properties"
export class AjaxDataSource extends RemoteDataSource
type: 'AjaxDataSource'
{
mode: [ p.String, 'replace' ]
content_type: [ p.String, 'application/json' ]
http_headers: [ p.Any, {} ] # TODO (bev)
max_size: [ p.Number ]
method: [ p.String, 'POST' ] # TODO (bev) enum?
if_modified: [ p.Bool, false ]
}
destroy : () =>
if ?
clearInterval()
setup : (plot_view, glyph) =>
= plot_view
if
= setInterval(, ,
, , )
get_data : (mode, max_size=0, if_modified=false) =>
xhr = new XMLHttpRequest()
xhr.open(, , true)
xhr.withCredentials = false
xhr.setRequestHeader("Content-Type", )
for name, value of
xhr.setRequestHeader(name, value)
# TODO: if_modified
xhr.addEventListener("load", () =>
if xhr.status == 200
data = JSON.parse(xhr.responseText)
switch mode
when 'replace'
= data
when 'append'
original_data =
for column in
data[column] = original_data[column].concat(data[column])[-max_size..]
= data
)
xhr.addEventListener("error", () =>
logger.error("Failed to fetch JSON from #{@data_url} with code #{xhr.status}")
)
xhr.send()
return null