I found a million guides on how to make responsive d3 graphs but none seem to address the problem I'm having. I have a d3 graph being created from a angularjs controller that is a coffeescript class. All of the functions in this class use @width, @height, @margin, @x, @y etc. I need to write a resize function that can access these variables. However, the @ (this) in the resize function points to window, and not the object. I can't seem to figure out a way to have resize act in the same scope as everything else. Any ideas?
EDIT: relevant example code
class Graph
init: () ->
@width = 100
$(window).resize ->
console.log(@width) #returns undefined
Not sure this is what you need, but you can pass in the reference as the first arg in the "resize" method.