Draw a model-node's box and all children nodes
972417
def DrawBox( self, dc, node, x,y,w,h, hot_map, depth=0 ):
        """"""
        log.debug( 'Draw: %s to (%s,%s,%s,%s) depth %s',
            node, x,y,w,h, depth,
        )
        if self.max_depth and depth > self.max_depth:
            return
        self.max_depth_seen = max( (self.max_depth_seen,depth))
        dc.SetBrush( self.BrushForNode( node, depth ) )
        dc.SetPen( self.PenForNode( node, depth ) )
        # drawing offset by margin within the square...
        dx,dy,dw,dh = x+self.margin,y+self.margin,w-(self.margin*2),h-(self.margin*2)
        if sys.platform == 'darwin':
            # Macs don't like drawing small rounded rects...
            if w < self.padding*2 or h < self.padding*2:
                dc.DrawRectangle( dx,dy,dw,dh )
            else:
                dc.DrawRoundedRectangle( dx,dy,dw,dh, self.padding )
        else:
            dc.DrawRoundedRectangle( dx,dy,dw,dh, self.padding*3 )
#        self.DrawIconAndLabel(dc, node, x, y, w, h, depth)
        children_hot_map = []
        hot_map.append( (wx.Rect( int(x),int(y),int(w),int(h)), node, children_hot_map ) )
        x += self.padding
        y += self.padding
        w -= self.padding*2
        h -= self.padding*2
        

        empty = self.adapter.empty( node )
        icon_drawn = False
        if self.max_depth and depth == self.max_depth:
            self.DrawIconAndLabel(dc, node, x, y, w, h, depth)
            icon_drawn = True
        elif empty:
            # is a fraction of the space which is empty...
            log.debug( '  empty space fraction: %s', empty )
            new_h = h * (1.0-empty)
            self.DrawIconAndLabel(dc, node, x, y, w, h-new_h, depth)
            icon_drawn = True
            y += (h-new_h)
            h = new_h

        if w >self.padding*2 and h> self.padding*2:
            children = self.adapter.children( node )
            if children:
                log.debug( '  children: %s', children )
                self.LayoutChildren( dc, children, node, x,y,w,h, children_hot_map, depth+1 )
            else:
                log.debug( '  no children' )
                if not icon_drawn:
                    self.DrawIconAndLabel(dc, node, x, y, w, h, depth)
        else:
            log.debug( '  not enough space: children skipped' )
161690
function drawGroupedBar() {
            // Not ideal, we need to figure out how to call exit for nested elements
            if (layerElements) {
                svg.selectAll('.layer').remove();
            }

            let series = svg.select('.chart-group').selectAll('.layer');

            animationDelays = d3Array.range(animationDelayStep, (layers.length + 1) * animationDelayStep, animationDelayStep)
            if (isHorizontal) {
                drawHorizontalBars(series);
            } else {
                drawVerticalBars(series);
            }

            // Exit
            series.exit()
                .transition()
                .style('opacity', 0)
                .remove();
        }
1006211
def all_node_style(self, **kwargs):
        '''
        
        '''
        for node in self.nodes:
            self.node_style(node, **kwargs)
901859
def fill_treeview(self, tree, input_dict):
        

        tree.model().removeRows(0, tree.model().rowCount())

        def add_element(item, key, value):
            child_name = QtWidgets.QStandardItem(key)

            if isinstance(value, dict):
                for key_child, value_child in value.items():
                    add_element(child_name, key_child, value_child)
                item.appendRow(child_name)
            else:
                child_value = QtWidgets.QStandardItem(str(value))

                item.appendRow([child_name, child_value])

        for index, (key, value) in enumerate(input_dict.items()):

            if isinstance(value, dict):
                item = QtWidgets.QStandardItem(key)
                for sub_key, sub_value in value.items():
                    add_element(item, sub_key, sub_value)
                tree.model().appendRow(item)
            elif isinstance(value, str):
                item = QtGui.QStandardItem(key)
                item_value = QtGui.QStandardItem(value)
                item_value.setEditable(True)
                item_value.setSelectable(True)
                tree.model().appendRow([item, item_value])
579830
function(nodes) {
                var i, node, matrix, treeBox;
                var box = new kity.Box();
                if (!(nodes instanceof Array)) nodes = [ nodes ];
                for (i = 0; i < nodes.length; i++) {
                    node = nodes[i];
                    matrix = node.getLayoutTransform();
                    treeBox = node.getContentBox();
                    if (node.isExpanded() && node.children.length) {
                        treeBox = treeBox.merge(this.getTreeBox(node.children));
                    }
                    box = box.merge(matrix.transformBox(treeBox));
                }
                return box;
            }
1236563
def _generate_draw_order(self, node=None):
        
        if node is None:
            node = self._scene
        order = [(node, True)]
        children = node.children
        children.sort(key=lambda ch: ch.order)
        for ch in children:
            order.extend(self._generate_draw_order(ch))
        order.append((node, False))
        return order
1004517
function CytoDraw(graph, focus_node_list,
		  layout_name, context, elt_id,
		  start_wait, stop_wait, data_call){
    
    var logger = new bbop.logger('CD');
    logger.DEBUG = true;
    function ll(str){ logger.kvetch(str); }

    ll('in');

    // Convert the focus node list into a usable hash.
    var focus_nodes = {};
    each(focus_node_list, function(fn){
	focus_nodes[fn] = true;
    });
    
    // Get the layout information into the position object
    // required by cytoscape.js for sugiyama in grid, if required.
    var position_object = {};
    if( layout_name === 'sugiyama' ){
	var renderer = new bbop.layout.sugiyama.render();
	var layout = renderer.layout(graph);
	var layout_nodes = layout.nodes;
	each(layout_nodes, function(ln){
	    position_object[ln['id']] = {x: ln['x'], y: ln['y']};
	});
    }
    function get_pos(cn){
	var po = position_object[cn.id()];
	return {row: po['y'], col: po['x']};
    }
	
    // Nodes.
    var cyroots = [];
    var cynodes = [];
    var info_lookup = {};
    each(graph.all_nodes(), function(node){
	ll('node: ' + node.id());
	info_lookup[node.id()] = {
	    'id': node.id(), 
	    'label': node.label() || node.id()
	};
	if( graph.is_root_node(node.id()) ){
	    cyroots.push(node.id());
	}
	var node_opts = {
	    //'group': 'nodes',
	    'data': {
		'id': node.id(), 
		'label': node.label() || node.id()
	    },
	    'grabbable': true
	};
	// Highlight the focus if there.
	if( focus_nodes[node.id()] ){
	    node_opts['css'] = { 'background-color': '#111111' };
	}
	cynodes.push(node_opts);
    });
    
    // Edges.
    var cyedges = [];
    each(graph.all_edges(), function(edge){
	var sub = edge.subject_id();
	var obj = edge.object_id();
	var prd = edge.predicate_id();
	var clr = context.color(prd);
        var eid = '' + prd + '_' + sub + '_' + obj;
	ll('edge: ' + eid);
	cyedges.push(
            {
		//'group': 'edges',
		'data': {
                    'id': eid,
                    'pred': prd,
                    // 'source': sub,
                    // 'target': obj
                    'source': obj,
                    'target': sub
		},
		css: {
		    'line-color': clr
		}
            });
    });
    
    // Render.
    var elements = {nodes: cynodes, edges: cyedges};
	
    var layout_opts = {
	'sugiyama': {
            'name': 'grid',
	    'padding': 30,
	    'position': get_pos
	},
	'random': {
	    name: 'random'//,
	    // fit: true
	},
	'grid': {
	    name: 'grid',
	    // fit: true,
	    padding: 30,
	    rows: undefined,
	    columns: undefined
	},
	'circle': {
	    name: 'circle'//,
	    //fit: true
	},
	'concentric': {
	    name: 'concentric'//,
	    //fit: true
	},
	'breadthfirst': {
            'name': 'breadthfirst',
            'directed': true,
            //'fit': true,
	    //'maximalAdjustments': 0,
	    'circle': false,
	    'roots': cyroots
	},
	// 'arbor': {
	// },
	'cose': {
            'name': 'cose'//,
            // 'directed': true,
            // //'fit': true,
	    // //'maximalAdjustments': 0,
	    // 'circle': false,
	    // 'roots': cyroots
	}
    };
    
    jQuery('#' + elt_id).cytoscape(
        {
	    userPanningEnabled: true, // pan over box select
	    'elements': elements,
	    'layout': layout_opts[layout_name],
	    hideLabelsOnViewport: true, // opt
	    hideEdgesOnViewport: true, // opt
	    textureOnViewport: true, // opt
	    'style': [
                {
		    selector: 'node',
		    css: {
                        'content': 'data(label)',
			'font-size': 8,
			'min-zoomed-font-size': 6, //10,
                        'text-valign': 'center',
                        'color': 'white',
			'shape': 'roundrectangle',
                        'text-outline-width': 2,
                        'text-outline-color': '#222222'
		    }
                },
                {
		    selector: 'edge',
		    css: {
                        //'content': 'data(pred)', // opt
                        'width': 2,
			//'curve-style': 'haystack', // opt
                        'line-color': '#6fb1fc'
                        //'source-arrow-shape': 'triangle' // opt
		    }
                }
	    ]
        });
    
    var cy = jQuery('#' + elt_id).cytoscape('get');

    // Bind event.
    cy.nodes().bind('click',
		    function(e){
			e.stopPropagation();
			var nid = e.cyTarget.id();
			start_wait();
			data_call(nid);
		    });
    cy.nodes().bind('mouseover',
		    function(e){
			e.stopPropagation();
			var nid = e.cyTarget.id();
			var nlbl = info_lookup[nid]['label'];
 			var popt = {
			    title: nid,
			    content: nlbl,
			    animation: false,
			    placement: 'top',
			    trigger: 'manual'
			};
			//jQuery(this).popover(popt);
			//jQuery(this).popover('show');
			// TODO/BUG: this popover positioning got out of
			// hand; just rewrite doing it manually with a
			// div from bootstrap like normal people.
			// (couldn't do it the obvious way because the
			// canvas elements are just layers with nothing
			// to adere to).
			var epos = e.cyRenderedPosition;
			jQuery(e.originalEvent.target).popover(popt);
			jQuery(e.originalEvent.target).popover('show');
			jQuery('.arrow').hide();
			jQuery('.popover').css('top', epos.y -100);
			jQuery('.popover').css('left', epos.x -100);
			// TODO/BUG: Also, unfortunately, I cannot
			// figure out why I am stuck with the
			// single frozen pop-up on the versions of
			// jQuery/UI that monarch is using. I cannot
			// change from the intial, probably a quirk of
			// bs3). Manually change it.
			var new_html = '<div style="display: none;" class="arrow"></div><h3 class="popover-title">' + nid + '</h3><div class="popover-content">' + nlbl + '</div>';
			jQuery('.popover').html(new_html);

			//ll('node: ' + nid);
		    });
    cy.nodes().bind('mouseout',
		    function(e){
			e.stopPropagation();
			jQuery(e.originalEvent.target).popover('destroy');
		    });

    // 
    cy.edges().unselectify(); // opt
    cy.boxSelectionEnabled(false);
    cy.resize();
    
    // Make sure re respect resizing.
    jQuery(window).off('resize');
    jQuery(window).on('resize',
		      function(){
			  cy.resize(); 
		      });
    
    stop_wait();
    ll('done');
    return cy;
}
1228960
def parse_drawing
      drawing_node = parse_xml(OOXMLDocumentObject.current_xml)
      drawing_node.xpath('xdr:wsDr/*').each do |drawing_node_child|
        @drawings << XlsxDrawing.new(parent: self).parse(drawing_node_child)
      end
    end
536564
function drawGameList(games) {
    $(GAMES).empty();
    var thead = "<th>Game Room</th><th>Players</th><th></th>";
    for (var i in games) {
        if (!games.hasOwnProperty(i)) {
            continue;
        }
        var name = games[i].name;
        var numplayers = Object.keys(games[i].players).length;
        var full = "";
        var node = $("<td>" + esc(name) + "</td>")[0];
        if (numplayers < PLAYERLMT) {
            // only allow joining rooms if player limit is not met
            node = $("<td><a href='#game_room'>" + esc(name) + "</a></td>")[0];
            node.onclick = function (name) {
                // nested function to capture name in a closure
                return function() {
                    $.cookie('game', name);
                    clearTimeout(GETGAMESTID);
                    location.reload();
                };
            }(name);
        } else {
            full = " (full)";
        }
        $(GAMES).append(
            "<tr><td>" + numplayers + full + "</td><td></td></tr>");
        $(GAMES+">tbody>tr:last-child").prepend(node);
    }

    if (!$(GAMES+">*").length) {
        $(NOGAMESMSG).show();
        $(GAMESHR).hide();
    } else {
        $(NOGAMESMSG).hide();
        $(GAMESHR).show();
        $(GAMES).prepend(thead);
    }

    function submit() {
        var gamenm = $(ADDGAME+"> input")[0].value;
        if (!NAMERE.test(gamenm)) {
            if(gamenm) {
                alert("Your input text is too long!");
            }
            return false;
        }
        $.post('/games', {name: gamenm},

               /**
                * @param data: {obj} contains potential random game name,
                *     e.g. {name: <game name>}
                */
               function(data) {
                   // post was succesful, so clear input
                   $(ADDGAME+"> input").val('');
                   $(LOBBY).hide();
                   $(LOADINGGAME).show();

                   var tries = 0;
                   function loadgame() {
                       $.getJSON("/games", function(games) {
                           for (var i in games) {
                               if (!games.hasOwnProperty(i)) {
                                   continue;
                               }
                               if (data.name === games[i].name) {
                                   // game is ready
                                   $.cookie('game', data.name);
                                   location.reload();
                                   return;
                               }
                           }
                           if (++tries > 3) {
                               return;
                           }
                       });
                       setTimeout(loadgame, 1000);
                   }
                   setTimeout(loadgame, 1000);
               });
    }

    // TODO: figure out why jquery click and keydown functions screw this up?
    $(ADDGAME+"> button")[0].onclick = submit;
    $(ADDGAME+"> input")[0].onkeydown = function(event) {
        if (event.keyCode === 13) {
            submit();
        }
    };
}
761011
def _draw(self, tree, indent=0):
        """"""
        if all([
            isinstance(tree, dict),
            type(tree) != BarDescriptor
        ]):
            for k, v in sorted(tree.items()):
                bar_desc, subdict = v[0], v[1]

                args = [self.cursor.term] + bar_desc.get("args", [])
                kwargs = dict(title_pos="above", indent=indent, title=k)
                kwargs.update(bar_desc.get("kwargs", {}))

                b = Bar(*args, **kwargs)
                b.draw(value=bar_desc["value"].value, flush=False)

                self._draw(subdict, indent=indent + self.indent)
656080
function render() {
  var createNodes = require("./create-nodes");
  var createClusters = require("./create-clusters");
  var createEdgeLabels = require("./create-edge-labels");
  var createEdgePaths = require("./create-edge-paths");
  var positionNodes = require("./position-nodes");
  var positionEdgeLabels = require("./position-edge-labels");
  var positionClusters = require("./position-clusters");
  var shapes = require("./shapes");
  var arrows = require("./arrows");

  var fn = function(svg, g) {
    preProcessGraph(g);

    var outputGroup = createOrSelectGroup(svg, "output");
    var clustersGroup = createOrSelectGroup(outputGroup, "clusters");
    var edgePathsGroup = createOrSelectGroup(outputGroup, "edgePaths");
    var edgeLabels = createEdgeLabels(createOrSelectGroup(outputGroup, "edgeLabels"), g);
    var nodes = createNodes(createOrSelectGroup(outputGroup, "nodes"), g, shapes);

    layout(g);

    positionNodes(nodes, g);
    positionEdgeLabels(edgeLabels, g);
    createEdgePaths(edgePathsGroup, g, arrows);

    var clusters = createClusters(clustersGroup, g);
    positionClusters(clusters, g);

    postProcessGraph(g);
  };

  fn.createNodes = function(value) {
    if (!arguments.length) return createNodes;
    createNodes = value;
    return fn;
  };

  fn.createClusters = function(value) {
    if (!arguments.length) return createClusters;
    createClusters = value;
    return fn;
  };

  fn.createEdgeLabels = function(value) {
    if (!arguments.length) return createEdgeLabels;
    createEdgeLabels = value;
    return fn;
  };

  fn.createEdgePaths = function(value) {
    if (!arguments.length) return createEdgePaths;
    createEdgePaths = value;
    return fn;
  };

  fn.shapes = function(value) {
    if (!arguments.length) return shapes;
    shapes = value;
    return fn;
  };

  fn.arrows = function(value) {
    if (!arguments.length) return arrows;
    arrows = value;
    return fn;
  };

  return fn;
}
579103
function drawBoxes() {
            boxes = svg.select('.chart-group').selectAll('.box').data(data);

            boxes.enter()
              .append('rect')
                .classed('box', true)
                .attr('width', boxSize)
                .attr('height', boxSize)
                .attr('x', ({hour}) => hour * boxSize)
                .attr('y', ({day}) => day * boxSize)
                .style('opacity', boxInitialOpacity)
                .style('fill', boxInitialColor)
                .style('stroke', boxBorderColor)
                .style('stroke-width', boxBorderSize)
                .transition()
                    .duration(animationDuration)
                    .style('fill', ({value}) => colorScale(value))
                    .style('opacity', boxFinalOpacity);

            boxes.exit().remove();
        }
1061471
def draw(self):
        
        devs = normal(size=self._sig.shape[1])
        p = inner(self._sig, devs) + self._mu
        self._set_stochastics(p)
156110
def draw_widget(self, item):
        """"""
        if item:
            self.filter_remove(remember=True)
            selected_id = self.treedata[item]['id']
            item = self.get_toplevel_parent(item)
            widget_id = self.treedata[item]['id']
            wclass = self.treedata[item]['class']
            xmlnode = self.tree_node_to_xml('', item)
            self.previewer.draw(item, widget_id, xmlnode, wclass)
            self.previewer.show_selected(item, selected_id)
            self.filter_restore()
1011024
function drawLines(node, parent) {
      ctx.save();
      var x = node.offset.x;
      var y = node.offset.y;
      ctx.translate(x, y);

      // branch
      if (parent) {
        drawBranch(node, parent);
      }

      // bottom border
      if (!node.isRoot()) {
        ctx.fillStyle = node.branchColor;
        var tm = node.textMetrics;
        ctx.fillRect(0, tm.height + padding, tm.width, node.lineWidth);
      }

      node.forEachChild(function(child) {
        drawLines(child, node);
      });

      ctx.restore();
    }
975748
@Override
    protected void drawWithoutTransforms(final Context2D context, double alpha, final BoundingBox bounds)
    {
        if ((context.isSelection()) && (false == isListening()))
        {
            return;
        }
        alpha = alpha * getAttributes().getAlpha();

        if (alpha <= 0)
        {
            return;
        }
        BoundingBox bbox = getStorageBounds();

        if (null == bbox)
        {
            bbox = bounds;
        }
        final NFastArrayList<M> list = getChildNodes(bbox);

        final int size = list.size();

        final IPathClipper clip = getPathClipper();

        if ((null != clip) && (clip.isActive()))
        {
            context.save();

            clip.clip(context);

            for (int i = 0; i < size; i++)
            {
                list.get(i).drawWithTransforms(context, alpha, bbox);
            }
            context.restore();
        }
        else
        {
            for (int i = 0; i < size; i++)
            {
                list.get(i).drawWithTransforms(context, alpha, bbox);
            }
        }
    }
1287546
def Draw(self, dc):
        '''  '''
        self.hot_map = []
        dc.BeginDrawing()
        brush = wx.Brush( self.BackgroundColour  )
        dc.SetBackground( brush )
        dc.Clear()
        if self.model:
            self.max_depth_seen = 0
            font = self.FontForLabels(dc)
            dc.SetFont(font)
            self._em_size_ = dc.GetFullTextExtent( 'm', font )[0]
            w, h = dc.GetSize()
            self.DrawBox( dc, self.model, 0,0,w,h, hot_map = self.hot_map )
        dc.EndDrawing()