def _build_js(self): draw = JS.Function("draw", ("data",)) draw += "var margin = %s;"%json.dumps(self.margins).replace('""','') draw += " width = %s - margin.left - margin.right"%self.margins["width"] draw += " height = %s - margin.top - margin.bottom;"%self.margins["height"] # this approach to laying out the graph is from Bostock: http://bl.ocks.org/1624660 draw += "var g = " + JS.Selection("d3").select("'#chart'") \ .append("'svg'") \ .attr("'width'", 'width + margin.left + margin.right + 25') \ .attr("'height'", 'height + margin.top + margin.bottom + 25') \ .append("'g'") \ .attr("'transform'", "'translate(' + margin.left + ',' + margin.top + ')'") self.js = JS.JavaScript() + draw + JS.Function("init")
def setUp(self): self.g = javascript.Selection("g").attr("color", "red") self.j = javascript.JavaScript() + self.g self.f = javascript.Function("test", None, "return 5")