コード例 #1
0
def test_Bezier():
    glyph = Bezier()
    assert glyph.x0 == "x0"
    assert glyph.y0 == "y0"
    assert glyph.x1 == "x1"
    assert glyph.y1 == "y1"
    assert glyph.cx0 == "cx0"
    assert glyph.cy0 == "cy0"
    assert glyph.cx1 == "cx1"
    assert glyph.cy1 == "cy1"
    yield check_line, glyph
    yield check_props, glyph, [
        "x0", "y0", "x1", "y1", "cx0", "cy0", "cx1", "cy1"
    ], LINE
コード例 #2
0
    def yield_renderers(self):
        """Use the marker glyphs to display the arcs and beziers.
        Takes reference points from data loaded at the ColumnDataSource.
        """
        beziers = Bezier(x0='start_x',
                         y0='start_y',
                         x1='end_x',
                         y1='end_y',
                         cx0='cx0',
                         cy0='cy0',
                         cx1='cx1',
                         cy1='cy1',
                         line_alpha='weight',
                         line_color='colors')

        yield GlyphRenderer(data_source=self.connection_data, glyph=beziers)

        arcs = Arc(x=0,
                   y=0,
                   radius=1,
                   line_width=10,
                   start_angle='start_angle',
                   end_angle='end_angle',
                   line_color='line_color')

        yield GlyphRenderer(data_source=self.arcs_data, glyph=arcs)

        if self.label:

            text_props = {
                "text_color": "#000000",
                "text_font_size": "8pt",
                "text_align": "left",
                "text_baseline": "middle"
            }

            labels = Text(x='text_x',
                          y='text_y',
                          text='text',
                          angle='angles',
                          **text_props
                          )

            yield GlyphRenderer(data_source=self.text_data, glyph=labels)
コード例 #3
0
def test_Bezier() -> None:
    glyph = Bezier()
    assert glyph.x0 == field("x0")
    assert glyph.y0 == field("y0")
    assert glyph.x1 == field("x1")
    assert glyph.y1 == field("y1")
    assert glyph.cx0 == field("cx0")
    assert glyph.cy0 == field("cy0")
    assert glyph.cx1 == field("cx1")
    assert glyph.cy1 == field("cy1")
    check_line_properties(glyph)
    check_properties_existence(glyph, [
        "x0",
        "y0",
        "x1",
        "y1",
        "cx0",
        "cy0",
        "cx1",
        "cy1",
    ], LINE, GLYPH)
コード例 #4
0
def test_Bezier():
    glyph = Bezier()
    assert glyph.x0 is None
    assert glyph.y0 is None
    assert glyph.x1 is None
    assert glyph.y1 is None
    assert glyph.cx0 is None
    assert glyph.cy0 is None
    assert glyph.cx1 is None
    assert glyph.cy1 is None
    check_line_properties(glyph)
    check_properties_existence(glyph, [
        "x0",
        "y0",
        "x1",
        "y1",
        "cx0",
        "cy0",
        "cx1",
        "cy1",
    ], LINE, GLYPH)
コード例 #5
0
ファイル: test_glyphs.py プロジェクト: pgnepal/bokeh
def test_Bezier():
    glyph = Bezier()
    assert glyph.x0 is None
    assert glyph.y0 is None
    assert glyph.x1 is None
    assert glyph.y1 is None
    assert glyph.cx0 is None
    assert glyph.cy0 is None
    assert glyph.cx1 is None
    assert glyph.cy1 is None
    yield check_line, glyph
    yield (check_props, glyph, [
        "x0",
        "y0",
        "x1",
        "y1",
        "cx0",
        "cy0",
        "cx1",
        "cy1",
    ], LINE)
コード例 #6
0
 def draw_line(scene: Plot, start: tuple, ctrl1: tuple, ctrl2: tuple,
               end: tuple, is_curved: bool, edge_color: tuple):
     if is_curved:  # cubic Bezier curve
         glyph = Bezier(
             x0=start[0],
             y0=start[1],
             x1=end[0],
             y1=end[1],
             cx0=ctrl1[0],
             cy0=ctrl1[1],
             cx1=ctrl2[0],
             cy1=ctrl2[1],
             line_color='#{0:02x}{1:02x}{2:02x}'.format(*edge_color),
             line_width=1)
         scene.add_glyph(glyph)
     else:
         source = ColumnDataSource(
             dict(x=[start[0], end[0]], y=[start[1], end[1]]))
         glyph = Line(
             x="x",
             y="y",
             line_width=1,
             line_color='#{0:02x}{1:02x}{2:02x}'.format(*edge_color))
         scene.add_glyph(source, glyph)
コード例 #7
0
        xm01=x - 0.1,
        yp01=y + 0.2,
        ym01=y - 0.2,
    ))

plot = Plot(title=None,
            plot_width=300,
            plot_height=300,
            min_border=0,
            toolbar_location=None)

glyph = Bezier(x0="x",
               y0="y",
               x1="xp02",
               y1="y",
               cx0="xp01",
               cy0="yp01",
               cx1="xm01",
               cy1="ym01",
               line_color="#d95f02",
               line_width=2)
plot.add_glyph(source, glyph)

xaxis = LinearAxis()
plot.add_layout(xaxis, 'below')

yaxis = LinearAxis()
plot.add_layout(yaxis, 'left')

plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))
コード例 #8
0
ファイル: glyphs.py プロジェクト: PhilWa/bokeh-1
          outer_radius=screen(20),
          fill_color="#7FC97F")),
 ("arc",
  Arc(x="x",
      y="y",
      radius=screen(20),
      start_angle=0.6,
      end_angle=4.1,
      line_color="#BEAED4",
      line_width=3)),
 ("bezier",
  Bezier(x0="x",
         y0="y",
         x1="xp02",
         y1="y",
         cx0="xp01",
         cy0="yp01",
         cx1="xm01",
         cy1="ym01",
         line_color="#D95F02",
         line_width=2)),
 ("gear",
  Gear(x="x",
       y="y",
       module=0.1,
       teeth=8,
       angle=0,
       shaft_size=0.02,
       fill_color="#FDF6E3",
       line_color="#D95F02")),
 ("image_url",
  ImageURL(
コード例 #9
0
        d['x1'].append(_layout[v][0])
        d['y1'].append(_layout[v][1])
        d['cx0'].append(_layout[u][0] - 0.2)
        d['cy0'].append(_layout[u][1] - 0.2)
        d['cx1'].append(_layout[v][0] + 0.2)
        d['cy1'].append(_layout[v][1] + 0.2)

    return d


lines_source = ColumnDataSource(get_edges_specs(G, pos))

glyph = Bezier(x0='x0',
               y0='y0',
               x1='x1',
               y1='y1',
               cx0='cx0',
               cy0='cy0',
               cx1='cx1',
               cy1='cy1',
               line_color="#d95f02",
               line_width=.5)
plot.add_glyph(lines_source, glyph)
# print(get_edges_specs(G, pos))
# r_lines = plot.multi_line('xs', 'ys', line_width=.5,
#                           color='grey',source=lines_source)  # This function sets the color of the edges
plot.add_layout(labels)
output_file("interactive_graphs.html")
show(plot)
# write_dot(G, 'multi.dot')
コード例 #10
0
ファイル: forestry.py プロジェクト: UMCUGenetics/targetclone
def plantTree(
        nameList,
        parentList,
        muList,
        weightList,
        descList,
        xNodeSpread=.775,
        lineMaxWidth=8,  #.675
        linePullFactor=0.5,
        lineStartDist=0.1):

    if None not in parentList:
        nameList.insert(0, 'Precursor')
        parentList.insert(0, None)
        weightList.insert(0, 0)
        descList.insert(0, [])
        muList.insert(0, 0)

    #maxWeight = max(weightList)
    #weightList = [x/maxWeight for x in weightList]

    dataTable = list(
        zip(*[nameList, parentList, muList, weightList, descList]))

    nameDict = {}
    parentDict = {}
    for index, node in enumerate(dataTable):
        if node[0] not in nameDict:
            nameDict[node[0]] = [node[1]]
        else:
            print 'ERROR Node specified twice: ' + node[0]
            exit()

        if node[1] not in parentDict:
            parentDict[node[1]] = []
        parentDict[node[1]].append(node[0])

    byHeightList = []

    def makeTree(curChild, curDepth):
        #byHeightList
        while len(byHeightList) <= curDepth:
            byHeightList.append([])
        byHeightList[curDepth].append(curChild)
        if curChild in parentDict:
            for child in parentDict[curChild]:
                makeTree(child, curDepth + 1)

    makeTree(None, 0)
    byHeightList.pop(0)

    maxWidth = max([len(x) for x in byHeightList])
    #print 'Maximum amount of nodes on a single line:',maxWidth

    xList = []
    yList = []
    nList = []
    dList = []
    wList = []
    mList = []
    for height, nodes in enumerate(byHeightList):
        heightWidth = len(nodes)
        for horz, node in enumerate(nodes):
            #print height,horz,node,heightWidth
            xList.append((horz - heightWidth / 2.) * xNodeSpread)
            yList.append(height)
            nList.append(node)
            dList.append(descList[nameList.index(node)])
            wList.append(weightList[nameList.index(node)])
            mList.append(muList[nameList.index(node)])

    yMax = max(yList)
    yList = [yMax - y for y in yList]

    hover = HoverTool(
        tooltips=[("Name",
                   "@name"), ("Events",
                              "@desc"), ("Distance to parent",
                                         "@weight"), ("Tumor fraction",
                                                      "@mu")])

    plotSize = max(max(xList), len(byHeightList))

    mins = plotSize / 2
    maxes = plotSize / 2
    print mins, maxes
    margin = 1
    treePlot = figure(plot_width=800,
                      plot_height=800,
                      x_range=Range1d(-plotSize * .5 - margin,
                                      plotSize * .5 + margin),
                      y_range=Range1d(-.5 - margin, -.5 + plotSize + margin),
                      x_axis_location=None,
                      y_axis_location=None,
                      min_border=64,
                      v_symmetry=True,
                      h_symmetry=True,
                      active_scroll='wheel_zoom',
                      tools=['pan', 'wheel_zoom', 'tap', 'save', hover])
    treePlot.xgrid.grid_line_color = None
    treePlot.ygrid.grid_line_color = None

    for parent in parentDict:
        if parent not in nList:
            continue
        parentIndex = nList.index(parent)
        fromX = xList[parentIndex]
        fromY = yList[parentIndex]

        for child in parentDict[parent]:
            childIndex = nList.index(child)
            toX = xList[childIndex]
            toY = yList[childIndex]

            maxD = max(len(x) for x in dList)
            dWidth = len(dList[childIndex]) / float(maxD) * lineMaxWidth + 1

            oldIndex = nameList.index(child)
            childWeight = weightList[oldIndex]

            anglePull = linePullFactor
            startDist = lineStartDist
            bezGlyph = Bezier(
                x0=fromX,
                y0=fromY - startDist,
                x1=toX,
                y1=toY + startDist,
                cx0=fromX,
                cy0=fromY - anglePull,
                cx1=toX,
                cy1=toY + anglePull,
                line_color='black',
                line_width=dWidth,  #childWeight*lineMaxWidth,
                line_alpha=1 - childWeight * .75)
            treePlot.add_glyph(bezGlyph)

    source = ColumnDataSource(data=dict(
        x=xList, y=yList, desc=dList, name=nList, weight=wList, mu=mList))

    renderer = treePlot.circle('x',
                               'y',
                               source=source,
                               color=colors[1],
                               line_color='#000000',
                               line_width=2,
                               radius=0.35)  #0.25
    selected_circle = Circle(line_width=2,
                             fill_color=colors[4],
                             line_color='#000000',
                             fill_alpha=1)
    nonselected_circle = Circle(line_width=2,
                                fill_color=colors[2],
                                line_color='#000000',
                                fill_alpha=1)
    renderer.selection_glyph = selected_circle
    renderer.nonselection_glyph = nonselected_circle

    labels = LabelSet(x='x',
                      y='y',
                      text='name',
                      text_align='center',
                      text_font_size='10px',
                      text_baseline='middle',
                      text_alpha=0.9,
                      x_offset=0,
                      y_offset=0,
                      source=source)
    treePlot.add_layout(labels)

    return treePlot
コード例 #11
0
    def draw_arrow_w_text_middle(scene: Plot, start: tuple, point1: tuple,
                                 point2: tuple, end: tuple, height: int,
                                 arrowsize: int, is_curved: bool, text: str,
                                 font_size: int, font_family: str, over: bool,
                                 color: tuple):
        """
        # Store the appropriate function ouside of the loop
        if is_curved:
            shape = [Path.MOVETO, Path.CURVE4, Path.CURVE4, Path.CURVE4]
        else:
            shape = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO]
        # This should work, but matplotlib is not ready yet: FancyArrowPatch(path=Path([start, point1, point2, end],
         s hape)
        scene.add_patch(PathPatch(Path([start, point1, point2, end], shape),
                        edgecolor='#{0:02x}{1:02x}{2:02x}'.format(*color),
                        facecolor=(1, 1, 1, 0),  # Transparent...
                        linewidth=1))  # TODO Line width!
        """
        if is_curved:  # cubic Bezier curve
            glyph = Bezier(x0=start[0],
                           y0=start[1],
                           x1=end[0],
                           y1=end[1],
                           cx0=point1[0],
                           line_color='#{0:02x}{1:02x}{2:02x}'.format(*color),
                           cy0=point1[1],
                           cx1=point2[0],
                           cy1=point2[1],
                           line_width=1)
            scene.add_glyph(glyph)
        else:
            source = ColumnDataSource(
                dict(x=[start[0], end[0]], y=[start[1], end[1]]))
            glyph = Line(x="x",
                         y="y",
                         line_width=1,
                         line_color='#{0:02x}{1:02x}{2:02x}'.format(*color))
            scene.add_glyph(source, glyph)

        # Draw arrow
        scene.line([end[0] - arrowsize, end[0], end[0] + arrowsize],
                   [end[1] - arrowsize, end[1], end[1] - arrowsize],
                   line_color='#{0:02x}{1:02x}{2:02x}'.format(*color))

        direction = 1
        if over:
            direction = -1

        # Write label in the middle under
        labelx = min(start[0], point2[0]) + abs(start[0] - point2[0]) // 2
        labely = height + direction * font_size  # TODO: Should be font height!

        source = ColumnDataSource(dict(x=[labelx], y=[labely], text=[text]))
        glyph = Text(x="x",
                     y="y",
                     text="text",
                     text_align="center",
                     text_color='#{0:02x}{1:02x}{2:02x}'.format(*color),
                     text_font_size=str(font_size) + "pt",
                     text_font=font_family)
        # TODO: Here was TextToken (must align to left)
        scene.add_glyph(source, glyph)