Skip to content

Idiomatic way to add x-axis, y-axis and tooltips #93

@ramnathv

Description

@ramnathv

I am really enjoying converting my d3.js code to d3.chart to make it reusable. I have been working on a d3.scatter component for d3.chart and you can see my work in progress here

http://jsfiddle.net/ramnathv/vtC75/2/

One question I had was regarding the idiomatic way to add x-axis, y-axis and tooltips. In some ways, these can be regarded as layers. Currently, I am sticking the code that creates the x-axis and y-axis directly inside the insert method. However, this is not modular and I have a niggling feeling that there is a cleaner solution to this problem. Any thoughts would be appreciated.

Once I clean this up, I will contribute this to d3.chart as a reusable chart component.

insert: function() {
 // invoke x-axis in context of the visualization
  chart.base.select('g')
   .append('g')
   .classed('x axis', true)
   .attr("transform", "translate(0," + chart.height() + ")")  
   .call(chart.xAxis)

// invoke tooltip in context
 chart.base
   .call(chart.tip)

// invoke y-axis in context
 chart.base.select('g')
   .append('g')
   .classed('y axis', true)
   .call(chart.yAxis)


  return this.append('circle')
    .attr('class', 'circle');
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions