Sha256: e14278290e1828078a69247ff91f9ec91352fd28ca1405f22fdd943f53962d50

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

root = exports ? window
root.Swagr = if root.Swagr then root.Swagr else {}

# Assumes d3graph.coffee has been required before this one...
class root.Swagr.UpdatingTextGraph extends root.Swagr.D3Graph
  _transform_string: -> "translate(16," + (@opts.height / 2) + ")"

  _join_data: (data) -> 
    @svg.selectAll("text").data(data, (d) -> d.value)

  _update_existing_elements: (text) ->
    @elems.attr("class", "update")
        .text(@textmapper(@elems, @data))
        .transition()
        .duration(@opts.transition_time)
        .attr("x", @xmapper(@elems, @data))

  _enter_new_elements: (text) ->
    @elems.enter().append("text")
        .attr("class", "enter")
        .attr("dy", ".35em")
        .attr("y", -@opts.transition_y)
        .attr("x", @xmapper(@elems, @data))
        .style("fill-opacity", 1e-6)
        .text(@textmapper(@elems, @data))
        .transition()
        .duration(@opts.transition_time)
        .attr("y", 0)
        .style("fill-opacity", 1)

  _remove_exiting_elements: (text) ->
    @elems.exit()
        .attr("class", "exit")
        .transition()
        .duration(@opts.transition_time)
        .attr("y", @opts.transition_y)
        .style("fill-opacity", 1e-6)
        .remove()

  xmapper: (elems, data) => (d,i) => i * @opts.x_per_element

  textmapper: (elems, data) -> (d,i) -> 
    d.value + ( if (i+1 isnt data.length) then "," else "" )

Version data entries

6 entries across 3 versions & 1 rubygems

Version Path
swagr-0.0.10 examples/examples01/coffee/updating_text_graph.coffee
swagr-0.0.10 templates/coffee/updating_text_graph.coffee
swagr-0.0.8 examples/examples01/coffee/updating_text_graph.coffee
swagr-0.0.8 templates/coffee/updating_text_graph.coffee
swagr-0.0.7 examples/examples01/coffee/updating_text_graph.coffee
swagr-0.0.7 templates/coffee/updating_text_graph.coffee