Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3: what is the self as in d3.select(self.frameElement).style("height", height + "px");

I have seen statements like below in many D3 examples. However, I can't find out what it means. In particular, I don't know what this self variable refers to. Additionally, does this manifest some sort of D3 magic/convention or is it just an ad-hoc thing? Thank you very much.

d3.select(self.frameElement).style("height", height + "px");

BTW, here is the example where I copied the above statement.

like image 422
JBT Avatar asked Mar 17 '14 06:03

JBT


2 Answers

self: if not redefined (typically as copy of this) than it is window object which always points to window. So they can be used interchangeably.

window.frameElement: Returns the element (such as <iframe> or <object>) in which the window is embedded, or null if the window is top-level.

See Window.frameElement

like image 172
Anto Jurković Avatar answered Sep 21 '22 11:09

Anto Jurković


On this example I found the following comment:

// Hack to make this example display correctly in an iframe on bl.ocks.org
like image 21
rifaco Avatar answered Sep 23 '22 11:09

rifaco