title: How to check Altair chart 's Zoom in/out functionality in a programatic way each time when i Zoom in/out in the front end
body: <p>I have written a streamlit code where I am using altair to display a chart in the front end. The made that chart to have zoom in/out functionality. I used &quot;.interactive()&quot; to get this done like below.</p>
  <pre><code>chart = alt.Chart(embd_1).mark_circle(size=30).encode(
      x = 'dimention1:Q', 
      y = 'dimention2:Q',
      tooltip=['col1'] ,
      color=color).properties(width=600,height=600).add_selection(selected).interactive()
  </code></pre>
  <p>But, I am facing a problem when I do zoom in/out in my app. It's taking lot of time to get updated. once i start scrolling the mouse, it takes literally more than 10 secs to update the zoomed chart in the front end.</p>
  <p>I was just wondering this may be because streamlit is running all the code which is beneath the altairs code as i don't know how to skip or avoid a certain code when i use zoom in/out functionality.</p>
  <p>So, The question is how to programatically define whether the user is zooming in/out ?</p>
  <p>like below :</p>
  <pre><code>if CheckZoom_SomeThingIDnotKnowYet == True:
     logic to execute code1
  else:
     logic to execute code2
  </code></pre>
  <p>Additional Info On data and Altair Code used:</p>
  <pre><code>def altair_graph(embd_1):
      selected = alt.selection_single(on=&quot;click&quot;, empty=&quot;none&quot;)
      dom = ['Other IPs', 'Slected IP','Sel Dims']
      rng_clr = ['lightgrey', 'red','blue']
  
      color_point=alt.Color('color', scale=alt.Scale(domain=dom, range=rng_clr))
  
      color = alt.condition(selected, alt.value('red'), color_point,legend=None)
  
      chart = alt.Chart(embd_1).mark_circle(size=30).encode(
          x = 'dimention1:Q', 
          y = 'dimention2:Q',
          tooltip=['dimention1','dimention2'] ,
          color=color
      ).properties(width=600,height=600).add_selection(selected).interactive()
  
      return chart
  </code></pre>
  <p>And Sample for the above function Can be created like below:</p>
  <pre><code>dimention1=np.random.rand(1,100000).squeeze()
  dimention2=np.random.rand(1,100000).squeeze()
  colr_values = ['Other Ids', 'Slected Id','Sel Dims']
  color = np.random.choice(colr_values, 100000, p=[0.9, 0.05, 0.05])
  sample = pd.DataFrame({'dimention1':dimention1,'dimention2':dimention2,'color':color})
  </code></pre>
  <pre><code>altair_graph(sample)
  </code></pre>
  <p>As shown in the example, My real time data is more than 150k data points.</p>
  <p>Even When I have executed the above code outside streamlit, This is taking significant time to zoom in/out. Could ssomeone please provide a workaround for this problem.</p>