<?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 advanced cross filtering with deneb and vega - brushed area disappearing when doing cross filter in Custom Visuals Development Discussion</title>
    <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4115127#M10383</link>
    <description>&lt;P&gt;My report has a deneb vega line chart and a table.&amp;nbsp; I want to filter the table by brushing the chart and then clicking on the brushed area.&amp;nbsp; The idea is to only apply cross filtering when required.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;A href="https://1drv.ms/u/c/f59494737c32ca2b/Eb677O_H87ZFjHkAeztGI8kBidFKtnwGP41dSdNldk7-iQ?e=fHP7VB" target="_self"&gt;PBIX file&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The filter works partially:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(1) brushing on the area works as expected:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vfx661_1-1724397055444.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1156037i8233F2E147E2ED6F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vfx661_1-1724397055444.png" alt="vfx661_1-1724397055444.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;(2) Then clicking on the brushed area filters the table:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vfx661_2-1724397102488.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1156038i9CDAC139685DE6DC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vfx661_2-1724397102488.png" alt="vfx661_2-1724397102488.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;However the brushed area disappears.&amp;nbsp; I'd like to keep the brushed area after the click.&lt;/P&gt;&lt;P&gt;I've tried different debounce, throttle and consume values for the event - not sure what is causing the brushed area to disappear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;{
  "data": [
    {
      "name": "dataset"
    }
  ],
  "width": 200,
  "height": 200,
  "signals": [
    {
      "name": "colour",
      "value": "blue"
    },
    // brush
    {
      "name": "brush",
      "value": 0,
      "on": [
        {
          "events": "@main:pointerdown",
          "update": "[x(), x()]"
        },
        {
          "events": "[@main:pointerdown, window:pointerup] &amp;gt; window:pointermove!",
          "update": "[brush[0], clamp(round(x()-brush[0])+brush[0], 0, width)]"
        },
        {
          "events": {
            "signal": "delta"
          },
          "update": "clampRange([anchor[0] + delta, anchor[1] + delta], 0, width)"
        }
      ]
    },
    // anchor
    {
      "name": "anchor",
      "value": null,
      "on": [
        {
          "events": "@brush:pointerdown",
          "update": "slice(brush)"
        }
      ]
    },
    // xdown
    {
      "name": "xdown",
      "value": 0,
      "on": [
        {
          "events": "@brush:pointerdown",
          "update": "x()"
        }
      ]
    },
    // delta
    {
      "name": "delta",
      "value": 0,
      "on": [
        {
          "events": "[@brush:pointerdown, window:pointerup] &amp;gt; window:pointermove!",
          "update": "x() - xdown"
        }
      ]
    },
    // main_brush
    {
      "name": "main_brush",
      // "push": "outer",
      "on": [
        {
          "events": {
            "signal": "brush"
          },
          "update": "span(brush) ? invert('x_scale', brush) : null"
        }
      ]
    },
    // cross filter start ------------------------------------------
    {
      "name": "pbiCrossFilterSelection",
      "value": [],
      "on": [
        // when mark is brushed apply cross filter
        {
          "events": {
            "markname": "brush",
            "type": "click",
            "consume": true,
            "debounce": 100,
            "throttle": 100
          },
          "update": "pbiCrossFilterApply(event, \"datum['x'] &amp;gt;= main_brush[0] &amp;amp; datum['x'] &amp;lt;= main_brush[1]\" )"
        }
      ]
    }
    // cross filter end ------------------------------------------
  ],
  "scales": [
    {
      "name": "x_scale",
      "range": "width",
      "padding": 10,
      "domain": {
        "data": "dataset",
        "field": "x"
      }
    },
    {
      "name": "y_scale",
      "range": "height",
      "padding": 10,
      "domain": {
        "data": "dataset",
        "field": "y"
      }
    }
  ],
  "axes": [
    {
      "orient": "bottom",
      "scale": "x_scale"
    },
    {
      "orient": "left",
      "scale": "y_scale"
    }
  ],
  "marks": [
    {
      "name": "main",
      "type": "group",
      "encode": {
        "enter": {
          "x": {
            "value": 0
          },
          "y": {
            "value": 0
          },
          "height": {
            "value": 200
          },
          "width": {
            "value": 200
          },
          "fill": {
            "value": "transparent"
          }
        }
      },
      "marks": [
        // main line chart
        {
          "name": "main_line",
          "type": "line",
          "from": {
            "data": "dataset"
          },
          "encode": {
            "enter": {
              "x": {
                "scale": "x_scale",
                "field": "x"
              },
              "y": {
                "scale": "y_scale",
                "field": "y"
              }
            },
            "update": {
              "stroke": {
                "signal": "colour"
              }
            }
          }
        },
        // brush area mark
        {
          "type": "rect",
          "name": "brush",
          "encode": {
            "enter": {
              "y": {
                "value": 0
              },
              "height": {
                "value": 200
              },
              "fill": {
                "value": "#333"
              },
              "fillOpacity": {
                "value": 0.2
              }
            },
            "update": {
              "x": {
                "signal": "brush[0]"
              },
              "x2": {
                "signal": "brush[1]"
              }
            }
          }
        }
      ]
    }
  ]
}&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Aug 2024 04:38:10 GMT</pubDate>
    <dc:creator>vfx661</dc:creator>
    <dc:date>2024-08-26T04:38:10Z</dc:date>
    <item>
      <title>advanced cross filtering with deneb and vega - brushed area disappearing when doing cross filter</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4115127#M10383</link>
      <description>&lt;P&gt;My report has a deneb vega line chart and a table.&amp;nbsp; I want to filter the table by brushing the chart and then clicking on the brushed area.&amp;nbsp; The idea is to only apply cross filtering when required.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;A href="https://1drv.ms/u/c/f59494737c32ca2b/Eb677O_H87ZFjHkAeztGI8kBidFKtnwGP41dSdNldk7-iQ?e=fHP7VB" target="_self"&gt;PBIX file&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The filter works partially:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(1) brushing on the area works as expected:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vfx661_1-1724397055444.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1156037i8233F2E147E2ED6F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vfx661_1-1724397055444.png" alt="vfx661_1-1724397055444.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;(2) Then clicking on the brushed area filters the table:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vfx661_2-1724397102488.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1156038i9CDAC139685DE6DC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vfx661_2-1724397102488.png" alt="vfx661_2-1724397102488.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;However the brushed area disappears.&amp;nbsp; I'd like to keep the brushed area after the click.&lt;/P&gt;&lt;P&gt;I've tried different debounce, throttle and consume values for the event - not sure what is causing the brushed area to disappear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;{
  "data": [
    {
      "name": "dataset"
    }
  ],
  "width": 200,
  "height": 200,
  "signals": [
    {
      "name": "colour",
      "value": "blue"
    },
    // brush
    {
      "name": "brush",
      "value": 0,
      "on": [
        {
          "events": "@main:pointerdown",
          "update": "[x(), x()]"
        },
        {
          "events": "[@main:pointerdown, window:pointerup] &amp;gt; window:pointermove!",
          "update": "[brush[0], clamp(round(x()-brush[0])+brush[0], 0, width)]"
        },
        {
          "events": {
            "signal": "delta"
          },
          "update": "clampRange([anchor[0] + delta, anchor[1] + delta], 0, width)"
        }
      ]
    },
    // anchor
    {
      "name": "anchor",
      "value": null,
      "on": [
        {
          "events": "@brush:pointerdown",
          "update": "slice(brush)"
        }
      ]
    },
    // xdown
    {
      "name": "xdown",
      "value": 0,
      "on": [
        {
          "events": "@brush:pointerdown",
          "update": "x()"
        }
      ]
    },
    // delta
    {
      "name": "delta",
      "value": 0,
      "on": [
        {
          "events": "[@brush:pointerdown, window:pointerup] &amp;gt; window:pointermove!",
          "update": "x() - xdown"
        }
      ]
    },
    // main_brush
    {
      "name": "main_brush",
      // "push": "outer",
      "on": [
        {
          "events": {
            "signal": "brush"
          },
          "update": "span(brush) ? invert('x_scale', brush) : null"
        }
      ]
    },
    // cross filter start ------------------------------------------
    {
      "name": "pbiCrossFilterSelection",
      "value": [],
      "on": [
        // when mark is brushed apply cross filter
        {
          "events": {
            "markname": "brush",
            "type": "click",
            "consume": true,
            "debounce": 100,
            "throttle": 100
          },
          "update": "pbiCrossFilterApply(event, \"datum['x'] &amp;gt;= main_brush[0] &amp;amp; datum['x'] &amp;lt;= main_brush[1]\" )"
        }
      ]
    }
    // cross filter end ------------------------------------------
  ],
  "scales": [
    {
      "name": "x_scale",
      "range": "width",
      "padding": 10,
      "domain": {
        "data": "dataset",
        "field": "x"
      }
    },
    {
      "name": "y_scale",
      "range": "height",
      "padding": 10,
      "domain": {
        "data": "dataset",
        "field": "y"
      }
    }
  ],
  "axes": [
    {
      "orient": "bottom",
      "scale": "x_scale"
    },
    {
      "orient": "left",
      "scale": "y_scale"
    }
  ],
  "marks": [
    {
      "name": "main",
      "type": "group",
      "encode": {
        "enter": {
          "x": {
            "value": 0
          },
          "y": {
            "value": 0
          },
          "height": {
            "value": 200
          },
          "width": {
            "value": 200
          },
          "fill": {
            "value": "transparent"
          }
        }
      },
      "marks": [
        // main line chart
        {
          "name": "main_line",
          "type": "line",
          "from": {
            "data": "dataset"
          },
          "encode": {
            "enter": {
              "x": {
                "scale": "x_scale",
                "field": "x"
              },
              "y": {
                "scale": "y_scale",
                "field": "y"
              }
            },
            "update": {
              "stroke": {
                "signal": "colour"
              }
            }
          }
        },
        // brush area mark
        {
          "type": "rect",
          "name": "brush",
          "encode": {
            "enter": {
              "y": {
                "value": 0
              },
              "height": {
                "value": 200
              },
              "fill": {
                "value": "#333"
              },
              "fillOpacity": {
                "value": 0.2
              }
            },
            "update": {
              "x": {
                "signal": "brush[0]"
              },
              "x2": {
                "signal": "brush[1]"
              }
            }
          }
        }
      ]
    }
  ]
}&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2024 04:38:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4115127#M10383</guid>
      <dc:creator>vfx661</dc:creator>
      <dc:date>2024-08-26T04:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: advanced cross filtering with deneb and vega - brushed area disappearing when doing cross filter</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4117471#M10387</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/693787"&gt;@vfx661&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you apply cross-filtering, Deneb will currently re-initialize the Vega view. This is partially due to how Power BI updates the canvas to keep the selection state in sync across other visuals. I will be &lt;A href="https://github.com/deneb-viz/deneb/issues/410" target="_self"&gt;working on this&lt;/A&gt; for future versions of Deneb so that the Vega view retains a single lifecycle in line with that of the visual container and patches in updates to data from Power BI rather than re-building. Still, it is a significant change (and will likely materialize as Deneb 2.0, which I don't have an ETA for yet).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For now, though, this means signal values are not preserved between visual update events, so the conventional ways you handle this for a Vega view outside of Power BI will not work as expected. Therefore, you must try to construct the selected area from your dataset's &lt;FONT face="courier new,courier"&gt;__selected__&lt;/FONT&gt; values after it updates. You may be able to do this using &lt;A href="https://vega.github.io/vega/docs/expressions/#pluck" target="_self"&gt;pluck&lt;/A&gt; and &lt;A href="https://vega.github.io/vega/docs/expressions/#extent" target="_self"&gt;extent&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't have the available capacity to fix your specification up completely, but the following may get you closer to where you need to be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Add a dataset that is filtered to selected values, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;{
  "data": [
    ...
    {
      "name": "cross_filter_on",
      "source": "dataset",
      "transform": [
        {
          "type": "filter",
          "expr": "datum.__selected__ == 'on'"
        }
      ]
    }
  ]
  ...
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Add a signal to get the extents from this, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;{
  ...
  "signals": [
    ...
    {
      "name": "cross_filter_extents",
      "update": "extent(pluck(data('cross_filter_on'), 'x'))"
    },
    ...
  ],
  ...
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Modify your brush signal to use the scaled values from this, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;{
  ...
  "signals": [
    ...
    {
      "brush": "cross_filter_extents",
      "init": "[scale('x_scale', cross_filter_extents[0]), scale('x_scale', cross_filter_extents[1])]",
      ... // rest of your signal event logic
    },
    ...
  ],
  ...
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hopefully this may help you on your way. Good luck!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Sun, 25 Aug 2024 23:55:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4117471#M10387</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2024-08-25T23:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: advanced cross filtering with deneb and vega - brushed area disappearing when doing cross filter</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4117472#M10388</link>
      <description>&lt;P&gt;Hopefully this link works to the pbix - I couldn't find a way to share from work so am using another account:&lt;BR /&gt;&lt;A href="https://1drv.ms/u/c/f59494737c32ca2b/Eb677O_H87ZFjHkAeztGI8kBidFKtnwGP41dSdNldk7-iQ?e=fHP7VB" target="_blank"&gt;crossfiltering.pbix&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Aug 2024 23:57:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4117472#M10388</guid>
      <dc:creator>vfridkin</dc:creator>
      <dc:date>2024-08-25T23:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: advanced cross filtering with deneb and vega - brushed area disappearing when doing cross filter</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4117737#M10389</link>
      <description>&lt;P&gt;Thank you - I really appreciate learning about the persistance of _selected_ and your suggested steps.&amp;nbsp; I've gone ahead and implemented and there are two lingering issues - the second one (2) I don't understand.&lt;BR /&gt;&lt;BR /&gt;1) After brushing, if the brushed area is clicked, then it recreates the brushed area according to your idea above:&lt;BR /&gt;&lt;BR /&gt;a) do the brushing&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vfx661_0-1724646381787.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1156870i030ADECE878C2F71/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vfx661_0-1724646381787.png" alt="vfx661_0-1724646381787.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;b) click on the brushed area:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vfx661_1-1724646426421.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1156871iB7455976E24A8E77/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vfx661_1-1724646426421.png" alt="vfx661_1-1724646426421.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I believe the area changes because it is recreated from the x values which are less precise than the original brushed area.&amp;nbsp; I'm guessing this can probably be fixed by 'quantising' the x-scale?&lt;BR /&gt;&lt;BR /&gt;2) However if I click again on this new area, the brush disappears as before - I was expecting nothing to change.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vfx661_2-1724646657462.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1156873iB1BD85284A9EB7D9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vfx661_2-1724646657462.png" alt="vfx661_2-1724646657462.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;*Updated*&lt;BR /&gt;It is working now - seems the brush disappearing has to do with the quantisation of the x-scale which is updated below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;{
  "data": [
    {
      "name": "dataset",
      "transform": [
        {
          "type": "extent",
          "field": "x",
          "signal": "extent_x"
        }
      ]
    },
// get dataset on refresh 
    {
      "name": "selected",
      "source": "dataset",
      "transform": [
        {
          "type": "filter",
          "expr": "datum.__selected__ == 'on'"
        },
        {
          "type": "extent",
          "field": "x",
          "signal": "extent_sel_x"
        }
      ]
    }     
  ],
  "width": 500,
  "height": 500,
  "signals": [
    {
      "name": "colour",
      "value": "blue"
    },
    {
      "name": "c", 
      "update": "(481)/(1+extent_x[1]-extent_x[0])"
    },
    {
      "name": "brush_init",
      "update": "[(extent_sel_x[0]-1)*c, extent_sel_x[1]*c]"
    },
    // brush
    {
      "name": "brush",
      "init": "brush_init",
      "on": [
        {
          "events": "@main:pointerdown",
          "update": "[x(), x()]"
        },
        {
          "events": "[@main:pointerdown, window:pointerup] &amp;gt; window:pointermove!",
          "update": "[round(brush[0]/c)*c, clamp(round(x()/c)*c, 0, width)]"
        },
        {
          "events": {
            "signal": "delta"
          },
          "update": "clampRange([anchor[0] + delta, anchor[1] + delta], 0, width)"
        }
      ]
    },
    // anchor
    {
      "name": "anchor",
      "value": null,
      "on": [
        {
          "events": "@brush:pointerdown",
          "update": "slice(brush)"
        }
      ]
    },
    // xdown
    {
      "name": "xdown",
      "value": 0,
      "on": [
        {
          "events": "@brush:pointerdown",
          "update": "x()"
        }
      ]
    },
    // delta
    {
      "name": "delta",
      "value": 0,
      "on": [
        {
          "events": "[@brush:pointerdown, window:pointerup] &amp;gt; window:pointermove!",
          "update": "round((x() - xdown)/c)*c"
        }
      ]
    },
    // main_brush
    {
      "name": "main_brush",
      // "push": "outer",
      "on": [
        {
          "events": {
            "signal": "brush"
          },
          "update": "span(brush) ? invert('x_scale', brush) : null"
        }
      ]
    },
    // cross filter start ------------------------------------------
    {
      "name": "pbiCrossFilterSelection",
      "value": [],
      "on": [
        // when mark is brushed apply cross filter
        {
          "events": {
            "markname": "brush",
            "type": "click"
          },
          "update": "pbiCrossFilterApply(event, \"datum['x'] &amp;gt;= main_brush[0] &amp;amp; datum['x'] &amp;lt;= main_brush[1]\" )"
        }
      ]
    }
    // cross filter end ------------------------------------------
  ],
  "scales": [
    {
      "name": "x_scale",
      "range": "width",
      "zero": false,
      "padding": {"signal": "c/2"},
      "domain": {
        "data": "dataset",
        "field": "x"
      }
    },
    {
      "name": "y_scale",
      "range": "height",
      "padding": 10,
      "domain": {
        "data": "dataset",
        "field": "y"
      }
    }
  ],
  "axes": [
    {
      "orient": "bottom",
      "scale": "x_scale"
    },
    {
      "orient": "left",
      "scale": "y_scale"
    }
  ],
  "marks": [
    {
      "name": "main",
      "type": "group",
      "encode": {
        "enter": {
          "x": {
            "value": 0
          },
          "y": {
            "value": 0
          },
          "height": {
            "signal": "height"
          },
          "width": {
            "signal": "width"
          },
          "fill": {
            "value": "transparent"
          }
        }
      },
      "marks": [
        // main line chart
        {
          "name": "main_line",
          "type": "line",
          "from": {
            "data": "dataset"
          },
          "encode": {
            "enter": {
              "x": {
                "scale": "x_scale",
                "field": "x"
              },
              "y": {
                "scale": "y_scale",
                "field": "y"
              }
            },
            "update": {
              "stroke": {
                "signal": "colour"
              }
            }
          }
        },
        // brush area mark
        {
          "type": "rect",
          "name": "brush",
          "encode": {
            "enter": {
              "y": {
                "value": 0
              },
              "height": {
                "signal": "height"
              },
              "fill": {
                "value": "#333"
              },
              "fillOpacity": {
                "value": 0.2
              }
            },
            "update": {
              "x": {
                "signal": "brush[0]"
              },
              "x2": {
                "signal": "brush[1]"
              }
            }
          }
        }
      ]
    }
  ]
}&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>Mon, 26 Aug 2024 12:33:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4117737#M10389</guid>
      <dc:creator>vfx661</dc:creator>
      <dc:date>2024-08-26T12:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: advanced cross filtering with deneb and vega - brushed area disappearing when doing cross filter</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4117741#M10390</link>
      <description>&lt;P&gt;Your questions are getting a little more involved than I have the capacity for at present, so tagging&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/124852"&gt;@giammariam&lt;/a&gt;&amp;nbsp;to see if he can offer any insight on this one&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2024 04:38:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4117741#M10390</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2024-08-26T04:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: advanced cross filtering with deneb and vega - brushed area disappearing when doing cross filter</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4118665#M10403</link>
      <description>&lt;P&gt;I've got a brushed time series that cross filters a table when clicking on the brushed area mark.&amp;nbsp; This has a problem that when the brushed area is dragged left or right, it activates the click event and filters the table.&amp;nbsp; I want to be able to drag the area and not activate the filtering.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I've brushed x=3 and then clicked the area to filter the table on the right.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vfx661_0-1724677119317.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1157197i063115C34C796501/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vfx661_0-1724677119317.png" alt="vfx661_0-1724677119317.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Now I drag the brushed area to x=6:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vfx661_1-1724677192437.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1157198i9106E0596A55592E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vfx661_1-1724677192437.png" alt="vfx661_1-1724677192437.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This immediately filters the table for x=6, however the desired behaviour is to stay filtered at x=3 and only update the filter when clicking the brushed area.&amp;nbsp; It seems the act of dragging includes a mouse down and mouse up which trigger the click.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One possible solution is to have a mark set up as a button (e.g. a text mark) and have it trigger the cross filter.&amp;nbsp; The issue with this approach is that it seems the clicked mark needs to include the filtered data.&amp;nbsp; The brushed area has this data.&amp;nbsp; Is there a way to associate the brushed area dataset with a symbol mark that is being used as a button?&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;For example, I've added a text mark in the top left corner with text value 'activate filter' to be used as the filter trigger:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vfx661_2-1724678090866.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1157204iC62138414DDA7889/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vfx661_2-1724678090866.png" alt="vfx661_2-1724678090866.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I want to be able to click on the text mark to activate the filter.&amp;nbsp; How can I associate the data from the brushed area with the event?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code for the last screenshot.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;*Updated&lt;BR /&gt;&lt;SPAN&gt;If I move the group mark down below the button, it partly works when clicking on the button to send the cross filter.&amp;nbsp; To my dismay, when dragging the brushed area left or right after filtering with the button, the brushed area disappears.&amp;nbsp; The idea is to maintain the brushed area so it can be dragged around and used as a cross filter when clicking on the button.&lt;BR /&gt;&lt;BR /&gt;I feel each time it is two steps forward, one step back&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Click on the button now works:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vfx661_2-1724706035377.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1157391i99F2BF27CD31EA6D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vfx661_2-1724706035377.png" alt="vfx661_2-1724706035377.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But then dragging the brushed area with the mouse and releasing clears the brushed area unexpectedly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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="c"&gt;{
  "data": [
    {
      "name": "dataset",
      "transform": [
        {
          "type": "extent",
          "field": "x",
          "signal": "extent_x"
        }
      ]
    },
    // get dataset on refresh 
    {
      "name": "selected",
      "source": "dataset",
      "transform": [
        {
          "type": "filter",
          "expr": "datum.__selected__ == 'on'"
        },
        {
          "type": "extent",
          "field": "x",
          "signal": "extent_sel_x"
        }
      ]
    }
  ],
  "width": 500,
  "height": 500,
  "signals": [
    {
      "name": "colour",
      "value": "blue"
    },
    {
      "name": "c",
      "update": "(481)/(1+extent_x[1]-extent_x[0])"
    },
    {
      "name": "brush_init",
      "update": "[(extent_sel_x[0]-1)*c, extent_sel_x[1]*c]"
    },
    // brush
    {
      "name": "brush",
      "init": "brush_init",
      "on": [
        {
          "events": "@main:pointerdown",
          "update": "[x(), x()]"
        },
        {
          "events": "[@main:pointerdown, window:pointerup] &amp;gt; window:pointermove!",
          "update": "[round(brush[0]/c)*c, clamp(round(x()/c)*c, 0, width)]"
        },
        {
          "events": {
            "signal": "delta"
          },
          "update": "clampRange([anchor[0] + delta, anchor[1] + delta], 0, width)"
        }
      ]
    },
    // anchor
    {
      "name": "anchor",
      "value": null,
      "on": [
        {
          "events": "@brush:pointerdown",
          "update": "slice(brush)"
        }
      ]
    },
    // xdown
    {
      "name": "xdown",
      "value": 0,
      "on": [
        {
          "events": "@brush:pointerdown",
          "update": "x()"
        }
      ]
    },
    // delta
    {
      "name": "delta",
      "value": 0,
      "on": [
        {
          "events": "[@brush:pointerdown, window:pointerup] &amp;gt; window:pointermove!",
          "update": "round((x() - xdown)/c)*c"
        }
      ]
    },
    // main_brush
    {
      "name": "main_brush",
      // "push": "outer",
      "on": [
        {
          "events": {
            "signal": "brush"
          },
          "update": "span(brush) ? invert('x_scale', brush) : null"
        }
      ]
    },
    // cross filter start ------------------------------------------
    {
      "name": "pbiCrossFilterSelection",
      "value": [],
      "on": [
        // when mark is brushed apply cross filter
        {
          "events": {
            "markname": "activate_filter",
            "type": "click"
          },
          "update": "pbiCrossFilterApply(event, \"datum['x'] &amp;gt;= main_brush[0] &amp;amp; datum['x'] &amp;lt;= main_brush[1]\" )"
        }
      ]
    }
    // cross filter end ------------------------------------------
  ],
  "scales": [
    {
      "name": "x_scale",
      "range": "width",
      "zero": false,
      "padding": {
        "signal": "c/2"
      },
      "domain": {
        "data": "dataset",
        "field": "x"
      }
    },
    {
      "name": "y_scale",
      "range": "height",
      "padding": 10,
      "domain": {
        "data": "dataset",
        "field": "y"
      }
    }
  ],
  "marks": [
    {
      "name": "activate_filter",
      "type": "text",
      "encode": {
        "enter": {
          "xc": {
            "value": 10
          },
          "yc": {
            "value": 10
          },
          "text": {
            "value": "activate filter"
          }
        }
      }
    },
    {
      "name": "main",
      "type": "group",
      "encode": {
        "enter": {
          "x": {
            "value": 0
          },
          "y": {
            "value": 20
          },
          "height": {
            "signal": "height"
          },
          "width": {
            "signal": "width"
          },
          "fill": {
            "value": "transparent"
          }
        }
      },
      "axes": [
        {
          "orient": "bottom",
          "scale": "x_scale"
        },
        {
          "orient": "left",
          "scale": "y_scale"
        }
      ],
      "marks": [
        // main line chart
        {
          "name": "main_line",
          "type": "line",
          "from": {
            "data": "dataset"
          },
          "encode": {
            "enter": {
              "x": {
                "scale": "x_scale",
                "field": "x"
              },
              "y": {
                "scale": "y_scale",
                "field": "y"
              }
            },
            "update": {
              "stroke": {
                "signal": "colour"
              }
            }
          }
        },
        // brush area mark
        {
          "type": "rect",
          "name": "brush",
          "encode": {
            "enter": {
              "y": {
                "value": 0
              },
              "height": {
                "signal": "height"
              },
              "fill": {
                "value": "#333"
              },
              "fillOpacity": {
                "value": 0.2
              }
            },
            "update": {
              "x": {
                "signal": "brush[0]"
              },
              "x2": {
                "signal": "brush[1]"
              }
            }
          }
        }
      ]
    }
  ]
}&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2024 21:06:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4118665#M10403</guid>
      <dc:creator>vfx661</dc:creator>
      <dc:date>2024-08-26T21:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: advanced cross filtering with deneb and vega - brushed area disappearing when doing cross filter</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4119403#M10405</link>
      <description>&lt;P&gt;I've found that if the brush area is moved after cross filtering and the mouseup action is performed outside the chart area, then the brushed area remains.&amp;nbsp; Not sure how the mouseup action is causing the brushed area to vanish.&lt;BR /&gt;&lt;BR /&gt;PS: Is there some way to upload a PBIX without having to create a share?&amp;nbsp; I can't create a shared file from work.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 03:24:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4119403#M10405</guid>
      <dc:creator>vfx661</dc:creator>
      <dc:date>2024-08-27T03:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: advanced cross filter with deneb and vega - trigger using a button mark</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4119409#M10406</link>
      <description>&lt;LI-CODE lang="markup"&gt;Is there some way to upload a PBIX without having to create a share?&lt;/LI-CODE&gt;
&lt;P&gt;you need to be a super user to be able to upload some (small) files.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2024 20:57:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/advanced-cross-filtering-with-deneb-and-vega-brushed-area/m-p/4119409#M10406</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-08-26T20:57:58Z</dc:date>
    </item>
  </channel>
</rss>

