<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic d3.mouse in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/d3-mouse/m-p/922017#M22214</link>
    <description>&lt;P&gt;Hi&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I am trying to get X,Y coordinates of mouse position using d3.mouse function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;export class Visual implements IVisual {
    private host: IVisualHost;
    private svg: Selection&amp;lt;SVGElement&amp;gt;;
    private container: Selection&amp;lt;SVGElement&amp;gt;;

  constructor(options: VisualConstructorOptions) {     
        this.svg = d3.select(options.element)
            .append('svg')
        this.container = this.svg.append("g")
            .classed('container', true)  


this.container
        .on("mousemove", function () {
            d3.select(".tooltip").remove()
                var mouse = d3.mouse(this.container)
//I get following error with d3.mouse(parameter). I tried d3.mouse(this) as well
//Argument of type 'SVGElement' is not assignable to parameter of type 'ContainerElement'.
  //Type 'SVGElement' is missing the following properties from type 'SVGGElement': transform, //getBBox, getCTM, getScreenCTM, and 2 more.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Feb 2020 05:39:33 GMT</pubDate>
    <dc:creator>Husain</dc:creator>
    <dc:date>2020-02-05T05:39:33Z</dc:date>
    <item>
      <title>d3.mouse</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/d3-mouse/m-p/922017#M22214</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I am trying to get X,Y coordinates of mouse position using d3.mouse function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;export class Visual implements IVisual {
    private host: IVisualHost;
    private svg: Selection&amp;lt;SVGElement&amp;gt;;
    private container: Selection&amp;lt;SVGElement&amp;gt;;

  constructor(options: VisualConstructorOptions) {     
        this.svg = d3.select(options.element)
            .append('svg')
        this.container = this.svg.append("g")
            .classed('container', true)  


this.container
        .on("mousemove", function () {
            d3.select(".tooltip").remove()
                var mouse = d3.mouse(this.container)
//I get following error with d3.mouse(parameter). I tried d3.mouse(this) as well
//Argument of type 'SVGElement' is not assignable to parameter of type 'ContainerElement'.
  //Type 'SVGElement' is missing the following properties from type 'SVGGElement': transform, //getBBox, getCTM, getScreenCTM, and 2 more.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 05:39:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/d3-mouse/m-p/922017#M22214</guid>
      <dc:creator>Husain</dc:creator>
      <dc:date>2020-02-05T05:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: d3.mouse</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/d3-mouse/m-p/922124#M22215</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/133382"&gt;@Husain&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;This is where the problem starts:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;private container: Selection&amp;lt;SVGElement&amp;gt;;&lt;/LI-CODE&gt;&lt;P&gt;In your constructor, you're correctly assigning the '&lt;FONT face="courier new,courier"&gt;g&lt;/FONT&gt;' element, but TypeScript thinks it's a &lt;FONT face="courier new,courier"&gt;SVGElement&lt;/FONT&gt; due to your property declaration and gets upset when you try to call &lt;FONT face="courier new,courier"&gt;d3.mouse&lt;/FONT&gt; on it. This needs to be declared as a &lt;FONT face="courier new,courier"&gt;ContainerElement&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;To make the code in your post work to that point, change the container declaration as follows:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;private container: Selection&amp;lt;ContainerElement&amp;gt;;&lt;/LI-CODE&gt;&lt;P&gt;Then, your &lt;FONT face="courier new,courier"&gt;d3.mouse&lt;/FONT&gt; function can work on &lt;FONT face="courier new,courier"&gt;this&lt;/FONT&gt;, which is scoped as the element you're calling the event function on. This line should now read as follows:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;.on("mousemove", function () {
    d3.select(".tooltip").remove()
        var mouse = d3.mouse(this)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Your partial listing would now look as follows if you just want to copy/paste the whole thing:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;export class Visual implements IVisual {
    private host: IVisualHost;
    private svg: Selection&amp;lt;SVGElement&amp;gt;;
    private container: Selection&amp;lt;ContainerElement&amp;gt;; /** Now has correct type */

  constructor(options: VisualConstructorOptions) {     
        this.svg = d3.select(options.element)
            .append('svg')
        this.container = this.svg.append("g")
            .classed('container', true)  


this.container
        .on("mousemove", function () {
            d3.select(".tooltip").remove()
                var mouse = d3.mouse(this) /** `this` is declared as the element (this.container) in the listener function */&lt;/LI-CODE&gt;&lt;P&gt;This block of code will now compile correctly.&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;FONT size="2"&gt;If my post solves your challenge, then please consider accepting as a solution to help other forum members find the answer more quickly &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 07:24:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/d3-mouse/m-p/922124#M22215</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2020-02-05T07:24:51Z</dc:date>
    </item>
  </channel>
</rss>

