File: export_tool.py

package info (click to toggle)
dask.distributed 2021.01.0%2Bds.1-2.1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,668 kB
  • sloc: python: 54,131; javascript: 1,549; makefile: 207; sh: 100
file content (28 lines) | stat: -rw-r--r-- 728 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os

from bokeh.core.properties import Int, String
from bokeh.embed import file_html
from bokeh.models import Tool
from bokeh.resources import CDN
from bokeh.util.compiler import JavaScript


fn = __file__
fn = os.path.join(os.path.dirname(fn), "export_tool.js")
with open(fn) as f:
    JS_CODE = f.read()


class ExportTool(Tool):
    __implementation__ = JavaScript(JS_CODE)
    event = Int(default=0)
    content = String()

    def register_plot(self, plot):
        def export_callback(attr, old, new):
            # really, export the doc as JSON
            self.content = None
            html = file_html(plot, CDN, "Task Stream")
            self.content = html

        self.on_change("event", export_callback)