I am working on a visualization that includes updating a text element that appears inside a circle. Sort of:
<g> <circle></circle> <text>My text that needs updating</text> </g>
Along with this small visual is the d3 brush, used as a slider. In the / brushend brush, I need <text>Update the text here</text> based on data related to the time scale along the x axis of the slider.
I have two Angular directives. One that contains a circle, the other is a slider. In my slider directive, I call:
$rootScope.$emit('brushing'); and setting the rootScope variable according to my data, $rootScope.myNewValue = newValue; when the slip occurs
Then I listen to this in my other directive and update text.attr as rootScope var:
$rootScope.$on('brushing', function () { myText.text($rootScope.myNewValue); });
Where:
var myText = svg.append('text') .text('I'm trying to update this text..');
... in the d3 part of the code
Performing such actions seems to work, but I'm wondering if there is a way to bind data directly when initializing myText:
var myText = svg.append('text) .text($rootScope.myNewValue);
Thus, the value is automatically updated without the need for generation and listening. I tried scope.$apply in the directive, but it seems to have no effect.
Has anyone come across a similar scenario when using d3 with Angular?