Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I use an Angularjs filter within the html element of a d3 tooltip?
    primarykey
    data
    text
    <p>I have a web app that combines Angularjs and d3js. One of my directives called <code>dailyView</code> sets up a tooltip using a function <code>drawtooltip()</code> defined in a service called <code>cfg</code>. The directive code is similar to the following:</p> <pre><code>app.directive('dailyView', ['cfg', function (cfg) { return { restrict: 'E', link: function(scope, element, attrs) { scope.$watch('daily', function(newVal, oldVal) { if (!newVal) return; cfg.drawDaily(scope.daily[attrs.bus], element, attrs.bus); $('#sortable2').sortable({ start: scope.dragStart, update: scope.dragEnd }); cfg.drawTooltip(); }); } }; }]); </code></pre> <p>On the other hand, the <code>drawTooltip()</code> function is defined like:</p> <pre><code>app.factory('cfg', ['$window', '$rootScope', '$cookieStore', function($window, $rootScope, $cookieStore){ function drawTooltip(){ var tooltip = d3.select(".tooltip"); d3.selectAll(".myImage") .on("mousemove", function(d){ tooltip.transition().duration(100) .style("opacity", .9); tooltip.html('&lt;p&gt;{{"' + d.measure + '"|myLocationFilter}}&lt;/p&gt;') .style("left", (d3.event.pageX + 20) + "px") .style("top", (d3.event.pageY - 110) + "px"); }) .on("mouseout", function(d) { tooltip.transition().duration(200) .style("opacity", 0); }); } </code></pre> <p>My angular filter should transform the <code>d.measure</code> string into a descriptive text that changes based on the browser language. The problem is that my the filter is not recognized and my tooltip simply shows the following text (e.g. when the measure data bound to the element is the string "plug": {{"plug"|myLocationFilter}}.</p> <p>How can I inject my angular filter into the d3js html element?</p> <blockquote> <p>Note: <a href="https://stackoverflow.com/questions/20399336/how-do-i-use-angularjs-directives-in-generated-d3-html">This</a> is a fairly similar question that has not been answered yet.</p> <p>Edit 1: I've tried using $compile()(scope) in the directive, right after calling <code>cfg.drawtooltip()</code> but the angular filter did not work.</p> <p>Edit 2: After testing the multiple suggestions offered in the comments, it is clear that the problem lies in the use of the <code>html()</code> method of a d3 selection. Would it be possible to somehow wait until <code>$compile()</code> is processed and then use the outerHTML value of the resulting object?</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload