def concat_files(self, vendor_paths): content_list = [] for path in vendor_paths: full_path = doodle_files.vendor_path(path) content = open(full_path).read() content_list.append(content) return "\n\n".join(content_list)
import jp_proxy_widget from jp_doodle import dual_canvas, doodle_files bfs_js = doodle_files.vendor_path("js/bounded_value_slider.js") def load_requirements(widget, additional=()): additional = [bfs_js] + list(additional) dual_canvas.load_requirements(widget, additional=[bfs_js]) class BoundedValueSlider(jp_proxy_widget.JSProxyWidget): def __init__( self, length=500, horizontal=True, minimum=0, maximum=100, initial=25, on_stop=None, on_change=None, integral=False, aspect_ratio=0.2, radius=10, selected_radius=15, base_color="silver", low_color="royalblue", high_color="orange", current_color="cyan", forbidden="black", verbose=False, border=5,
""" Python wrapper for DataTables functionality using proxy widgets For details please refer to: http://www.datatables.net """ from jp_doodle import doodle_files import jp_proxy_widget import csv from IPython.display import display, HTML datatables_js = doodle_files.vendor_path("DataTables/datatables.js") datatables_helper_js = doodle_files.vendor_path("js/jp_datatables_helper.js") datatables_css = doodle_files.vendor_path("DataTables/datatables.css") def widen_notebook(): display(HTML("<style>.container { width:100% !important; }</style>")) def load_datatable_requirements(widget): widget.load_css(datatables_css) widget.require_js("datatables_js", datatables_js) widget.load_js_files([datatables_helper_js]) class Table1(jp_proxy_widget.JSProxyWidget): "Very simple wrapper." def __init__(self, headers,
from jp_doodle import doodle_files from jp_doodle import dual_canvas import jp_proxy_widget import numpy as np array_explorer_js = doodle_files.vendor_path("js/array_explorer.js") def read_tsv_array(fn): """ Read a table of numbers in a tab separated value representation. The first line gives the column names. The remaining lines give the row name followed by numeric entry values for that row. """ # open with universal newline support f = open(fn, "rU") heading = f.readline() assert heading[0] == "\t", "expect tab first in headings " + repr(heading) column_names = [x.strip() for x in heading[1:].split("\t")] row_names = [] all_data = [] for dataline in f: data = [x.strip() for x in dataline.split("\t")] rowname = data[0] valuestr = data[1:] values = map(float, valuestr) assert len(values) == len(column_names), repr( (len(values), len(column_names))) row_names.append(rowname) all_data.append(values)
from jp_doodle import doodle_files qf_js = doodle_files.vendor_path("js/quantity_forest.js") from jp_doodle import dual_canvas import jp_proxy_widget import os from subprocess import check_output import pprint if bytes != str: unicode = str def directory_usage(directory, epsilon=0.02): if not os.path.isdir(directory): return None ls = os.listdir(directory) result = {} total = 0.0 for fn in ls: path = os.path.join(directory, fn) try: usage = check_output(["du", "-s", path]) except Exception: pass else: usage = unicode(usage, "utf8") # py 3 [snum, sname] = usage.strip().split("\t") num = float(snum) total += num result[fn] = (path, num) final = {}
""" Python wrapper and related helpers for nd_frame functionality using proxy widgets. """ from jp_doodle import doodle_files, dual_canvas import jp_proxy_widget import csv from IPython.display import display, HTML from jp_doodle.dual_canvas import clean_dict nd_frame_js = doodle_files.vendor_path("js/nd_frame.js") def load_requirements(widget=None, silent=True, additional=()): all_files = [nd_frame_js] + list(additional) return dual_canvas.load_requirements(widget, silent, additional=all_files) default_axes = { "x": { "x": 1 }, "y": { "y": 1 }, "z": { "z": 1 }, }
""" Python wrapper and related helpers for nd_scatter functionality using proxy widgets. """ from jp_doodle import doodle_files, dual_canvas, nd_frame, data_tables import jp_proxy_widget import csv from IPython.display import display, HTML from sklearn.preprocessing import StandardScaler import numpy as np nd_scatter_js = doodle_files.vendor_path("js/nd_scatter.js") class ND_Scatter_Widget(jp_proxy_widget.JSProxyWidget): "Wrapper for an nd-scatter structure." def __init__(self, jsondata=None, config=None, *pargs, **kwargs): "Create a canvas drawing area widget." super(ND_Scatter_Widget, self).__init__(*pargs, **kwargs) data_tables.widen_notebook() nd_frame.load_requirements(self, additional=[nd_scatter_js]) if config is None: config = {} self.js_init(""" element.empty(); element.scatter_plot = element.nd_scatter(config); element.scatter_plot.make_scaffolding(); """, config=config)
def check_file(self): "If snapshot doesn't exist save a placeholder image initially." filename = self.snapshot_filename if not os.path.isfile(filename): placeholder_source = doodle_files.vendor_path("js/NoSnapshot.png") shutil.copyfile(placeholder_source, filename)
""" Python convenience wrapper for creating dual canvases within proxy widgets. """ import jp_proxy_widget from jp_doodle import doodle_files from IPython.display import HTML, display, Image import os import shutil import time import ipywidgets as widgets from imageio import imsave, imread import numpy as np required_javascript_modules = [ doodle_files.vendor_path("js/canvas_2d_widget_helper.js"), doodle_files.vendor_path("js/dual_canvas_helper.js"), ] def load_requirements(widget=None, silent=True, additional=()): """ Load Javascript prerequisites into the notebook page context. """ if widget is None: widget = jp_proxy_widget.JSProxyWidget() silent = False # Make sure jQuery and jQueryUI are loaded. widget.check_jquery() # load additional jQuery plugin code. all_requirements = list(required_javascript_modules) + list(additional)
""" Python wrapper and related helpers for directed_network using proxy widgets. """ from jp_doodle import doodle_files, dual_canvas, nd_frame, data_tables, svg_translation from jp_doodle.dual_canvas import clean_dict import jp_proxy_widget import csv from IPython.display import display, HTML import numpy as np directed_network_js = doodle_files.vendor_path("js/directed_network.js") gd_graph_js = doodle_files.vendor_path("js/gd_graph.js") additional_js = [gd_graph_js, directed_network_js] class Network_Widget(jp_proxy_widget.JSProxyWidget, dual_canvas.SaveImageMixin): "Wrapper for an nd-scatter structure." def __init__(self, config=None, display=False, *pargs, **kwargs): "Create a canvas drawing area widget." super(Network_Widget, self).__init__(*pargs, **kwargs) data_tables.widen_notebook() nd_frame.load_requirements(self, additional=additional_js) if config is None: config = {} self.js_init(""" element.empty(); element.d_network = element.directed_network(config);