def _build_js(self): # build scales scales = """ scales = { x : get_scales(['%s'], 'horizontal'), y : get_scales(['%s'], 'vertical') } """ % (self.x, self.y) # add the line x_fxn = Function(None, "d", "return scales.x(d.%s)" % self.x) y_fxn = Function(None, "d", "return scales.y(d.%s)" % self.y) draw = Function("draw", ("data", )) draw += scales draw += "var line = " + Selection("d3.svg").add_attribute("line") \ .add_attribute("x", x_fxn) \ .add_attribute("y", y_fxn) draw += Selection("g").append("'svg:path'") \ .attr("'d'", "line(data)") \ .attr("'class'", "'geom_line'") \ .attr("'id'", "'line_%s_%s'"%(self.x, self.y)) self.js = JavaScript(draw) return self.js
def _build_js(self): scales = """ scales = { x: get_scales(['%s'], 'horizontal'), y: get_scales(['%s','%s'], 'vertical') } """ % (self.x, self.ylower, self.yupper) x_fxn = Function(None, "d", "return scales.x(d.%s)" % self.x) y1_fxn = Function(None, "d", "return scales.y(d.%s)" % self.yupper) y0_fxn = Function(None, "d", "return scales.y(d.%s)" % self.ylower) draw = Function("draw", ("data", )) draw += scales draw += "var area = " + Selection("d3.svg").add_attribute("area") \ .add_attribute("x", x_fxn) \ .add_attribute("y0", y0_fxn) \ .add_attribute("y1", y1_fxn) draw += "console.log(data)" draw += "console.log(area(data))" draw += "console.log(scales.y(data[0].y))" draw += Selection("g").append("'svg:path'") \ .attr("'d'", "area(data)") \ .attr("'class'", "'geom_area'") \ .attr("'id'", "'area_%s_%s_%s'"%(self.x, self.yupper, self.ylower)) self.js = JavaScript(draw) return self.js
def _build_js(self): # build scales scales = """ scales = { x : get_scales(['%s'], 'horizontal'), y : get_scales(['%s'], 'vertical') } """ % (self.x, self.y) xfxn = Function(None, "d", "return scales.x(d.%s);" % self.x) yfxn = Function(None, "d", "return scales.y(d.%s)" % self.y) heightfxn = Function(None, "d", "return height - scales.y(d.%s)" % self.y) draw = Function("draw", ("data", ), [scales]) draw += scales draw += Selection("g").selectAll("'.bars'") \ .data("data") \ .enter() \ .append("'rect'") \ .attr("'class'", "'geom_bar'") \ .attr("'id'", "'%s'"%self._id) \ .attr("'x'", xfxn) \ .attr("'y'", yfxn) \ .attr("'width'", "scales.x.rangeBand()")\ .attr("'height'", heightfxn) # TODO: rangeBand above breaks for histogram type bar-plots... fix! self.js = JavaScript() + draw self.js += (Function("init", autocall=True) + "console.debug('Hi');") return self.js
def build_js(self): xfxn = Function(None, "d", "return scales.%s_x(d.%s);" % (self.x, self.x)) yfxn = Function(None, "d", "return scales.%(y)s_y(d.%(y)s)" % {"y": self.y}) heightfxn = Function( None, "d", "return height - scales.%(y)s_y(d.%(y)s)" % {"y": self.y}) draw = Function("draw", ("data", ), []) draw += Object("g").selectAll("'.bars'") \ .data("data") \ .enter() \ .append("'rect'") \ .attr("'class'", "'geom_bar'") \ .attr("'id'", "'%s'"%self._id) \ .attr("'x'", xfxn) \ .attr("'y'", yfxn) \ .attr("'width'", "scales.%s_x.rangeBand()"%self.x)\ .attr("'height'", heightfxn) # TODO: rangeBand above breaks for histogram type bar-plots... fix! self.js = JavaScript() + draw self.js += (Function("init", autocall=True) + "console.debug('Hi');") return self.js
def _build_js(self): scales = """ scales = { x : get_scales(['%s'], 'horizontal'), y : get_scales(['%s'], 'vertical') } """ % (self.x, self.y) draw = Function("draw", ("data", )) draw += scales js_cx = Function(None, "d", "return scales.x(d.%s);" % self.x) js_cy = Function(None, "d", "return scales.y(d.%s);" % self.y) obj = Selection("g").selectAll("'.geom_point'") \ .data("data") \ .enter() \ .append("'svg:circle'") \ .attr("'cx'", js_cx) \ .attr("'cy'", js_cy) \ .attr("'r'", 4) \ .attr("'class'", "'geom_point'") \ .attr("'id'", "'%s'"%self._id) if self.c: fill = Function(None, "return d.%s;" % self.c) obj.add_attribute("style", "fill", fill) draw += obj self.js = JavaScript(draw) return self.js
def _build_js(self): draw = Function("draw", ("data",), []) draw += Selection("g") \ .selectAll("'circle.node'") \ .data("data.nodes") \ .enter() \ .append("'circle'") \ .attr("'class'","'node'") \ .attr("'r'", 12) draw += Selection("g") \ .selectAll("'line.link'") \ .data("data.links") \ .enter() \ .append("'line'") \ .attr("'class'", "'link'") code = [ "var force = d3.layout.force()", ".charge(-120)", '.linkDistance(30)', '.size([width, height])', '.nodes(data.nodes)', '.links(data.links);' 'force.on("tick", function() {', 'g.selectAll("line.link").attr("x1", function(d) { return d.source.x; })', '.attr("y1", function(d) { return d.source.y; })', '.attr("x2", function(d) { return d.target.x; })', '.attr("y2", function(d) { return d.target.y; });', 'g.selectAll("circle.node").attr("cx", function(d) { return d.x; })', '.attr("cy", function(d) { return d.y; });', '});', 'g.selectAll("circle.node").call(force.drag);', 'force.start();', ] # TODO the order of the next two lines seems inappropriately important draw += JavaScript(code) self.js = JavaScript() + draw self.js += (Function("init", autocall=True) + "console.debug('Hi');") return self.js
def build_js(self): # add the line draw = Function("draw", ("data", )) x_fxn = Function(None, "d", "return scales.%s_x(d.%s)"%(self.x, self.x)) y_fxn = Function(None, "d", "return scales.%s_y(d.%s)"%(self.y, self.y)) draw += "var line = " + Object("d3.svg").add_attribute("line") \ .add_attribute("x", x_fxn) \ .add_attribute("y", y_fxn) draw += Object("g").append("'svg:path'") \ .attr("'d'", "line(data)") \ .attr("'class'", "'geom_line'") \ .attr("'id'", "'line_%s_%s'"%(self.x, self.y)) self.js = JavaScript(draw) return self.js
def build_js(self): draw = Function("draw", ("data",)) js_cx = Function(None, "d", "return scales.%s_x(d.%s);"%(self.x,self.x)) js_cy = Function(None, "d", "return scales.%s_y(d.%s);"%(self.y,self.y)) obj = Object("g").selectAll("'.geom_point'") \ .data("data") \ .enter() \ .append("'svg:circle'") \ .attr("'cx'", js_cx) \ .attr("'cy'", js_cy) \ .attr("'r'", 4) \ .attr("'class'", "'geom_point'") \ .attr("'id'", "'%s'"%self._id) if self.c: fill = Function(None, "return d.%s;"%self.c) obj.add_attribute("style", "fill", fill) draw += obj self.js = JavaScript(draw) return self.js
def build_js(self): draw = Function("draw", ("data", ), []) scale = "scales.%s_%s" % (self.var, self.var) draw += "%s = d3.svg.axis().scale(%s)%s" % ( self.name, scale, ".orient('%s')" % self.orient if self.orient else "") axis_group = Object("g").append('"g"') \ .attr('"class"','"%s"'%self.name) \ .attr('"transform"', '"translate(" + margin + ",0)"') \ .call(self.name) draw += axis_group self.js = JavaScript() + draw return self.js
def _build_js(self): draw = Function("draw", ("data",), []) scale = "scales.y" draw += "yAxis = d3.svg.axis().scale(%s).orient('left')"%scale yaxis_group = Selection("g").append('"g"') \ .attr('"class"','"yaxis"') \ .call("yAxis") draw += yaxis_group if self.label: # TODO: Have the transform on this label be less hacky label_group = Selection("g").append('"text"') \ .add_attribute("text", '"%s"'%self.label) \ .attr('"y"', '- margin.left + 15') \ .attr('"x"', '- height / 2.0') \ .attr('"text-anchor"', '"middle"') \ .attr('"transform"', '"rotate(-90, 0, 0)"') draw += label_group self.js = JavaScript() + draw return self.js
def _build_js(self): draw = Function("draw", ("data", ), []) scale = "scales.x" draw += "xAxis = d3.svg.axis().scale(%s)" % scale xaxis_group = Selection("g").append('"g"') \ .attr('"class"','"xaxis"') \ .attr('"transform"', '"translate(0," + height + ")"') \ .call("xAxis") draw += xaxis_group if self.label: # TODO: Have the transform on this label be less hacky label_group = Selection("g").append('"text"') \ .add_attribute("text", '"%s"'%self.label) \ .attr('"text-anchor"', '"middle"') \ .attr('"x"', "width/2") \ .attr('"y"', "height+45") draw += label_group self.js = JavaScript() + draw return self.js