# Plotting: select point on click?

**URL:** <https://discourse.slicer.org/t/plotting-select-point-on-click/3568>\
**Category:** Development\
**Created:** [July 24, 2018, 4:34pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568 "2018-07-24T16:34:41Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [July 24, 2018, 4:34pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/1 "2018-07-24T16:34:41Z")

</div>

Is there a plot mode allowing click-to-select a point, rather than dragging the selection box? I only want to select one point at a time. Thanks.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 24, 2018, 5:00pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/2 "2018-07-24T17:00:43Z")

</div>

Currently, single point selection on click is not available in plot view. It would not be difficult to add a new interaction mode, in [qMRMLPlotView](https://github.com/Slicer/Slicer/blob/badd435e439d3435444f27acaa2dd9fe4aa5a7d0/Libs/MRML/Widgets/qMRMLPlotView.cxx#L690-L712) that would map vtkChart::NOTIFY to LEFT\_BUTTON event and then add an event handler for the notification that would select the clicked point. @Davide_Punzo or I would be happy to help/review if you decide to implement it.

What would you like to use this for? Note that you can define a custom label for each point that is displayed in the tooltip when you hover over a point with the mouse (labels are defined in the “Labels Column” table column that you set in Plots module / Series).

---

<div class="post-metadata">

**Author:** ![mschumaker](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschumaker/32/1395_2.png) [@mschumaker](https://discourse.slicer.org/u/mschumaker)\
**Post date:** [July 24, 2018, 5:19pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/3 "2018-07-24T17:19:52Z")

</div>

That’s a feature I’d also be interested in. I’d use it to allow a user to click on a point in a chart, which would then take them back to another workflow step where they set the value of that point.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 24, 2018, 5:26pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/4 "2018-07-24T17:26:47Z")

</div>

> [@mschumaker](#):
>
> take them back to another workflow step where they set the value of that point

Note that you can change the value of any point by directly dragging in the plot (if you switch interaction mode to “move points”). Of course this may not be optimal for all use cases, as you may want to use a different GUI or apply some constraints - I just wanted to make sure that you are aware of this feature.

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [July 24, 2018, 5:29pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/5 "2018-07-24T17:29:24Z")

</div>

> [@lassoan](#):
>
> What would you like to use this for?

We are porting a matlab GUI in which we plot a slice-wise quantity, and one of the interaction modes provides a vertical slider on the plot to control which slice is displayed. Plotting a point per slice with a callback on click-to-select seems like the simplest approximation for now.

---

<div class="post-metadata">

**Author:** ![Davide\_Punzo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/davide_punzo/32/66104_2.png) [@Davide\_Punzo](https://discourse.slicer.org/u/Davide_Punzo)\
**Post date:** [July 24, 2018, 6:04pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/6 "2018-07-24T18:04:29Z")

</div>

> [@lassoan](#):
>
> Currently, single point selection on click is not available in plot view. It would not be difficult to add a new interaction mode, in [qMRMLPlotView](https://github.com/Slicer/Slicer/blob/badd435e439d3435444f27acaa2dd9fe4aa5a7d0/Libs/MRML/Widgets/qMRMLPlotView.cxx#L690-L712) that would map vtkChart::NOTIFY to LEFT\_BUTTON event and then add an event handler for the notification that would select the clicked point. @Davide_Punzo or I would be happy to help/review if you decide to implement it.

Hi @ihnorton. Unfortunately it is not straightforward to implement, because there is no single selection click at VTK level. The Andras suggestion is good, but even better will be to implement it at VTK level and expose it in Slicer as a new interaction mode (such as the click and move).

---

<div class="post-metadata">

**Author:** ![Davide\_Punzo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/davide_punzo/32/66104_2.png) [@Davide\_Punzo](https://discourse.slicer.org/u/Davide_Punzo)\
**Post date:** [July 24, 2018, 6:06pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/7 "2018-07-24T18:06:39Z")

</div>

Rethink about it, the click and drag can be constrained both on X and Y. The result will be that you select the point. However, at the moment it is not possible to select multiple points (one selection after another, let’s say) which had few bugs (and we have to force the selection to be on after the release of the click). In principle this can be implemented (at VTK level) and it should not be too difficult. At the moment, I haven’t the time to implement it, but I’ll be glad to review any PR. I may do it in future when I’ll have some free time (: .

---

<div class="post-metadata">

**Author:** ![Davide\_Punzo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/davide_punzo/32/66104_2.png) [@Davide\_Punzo](https://discourse.slicer.org/u/Davide_Punzo)\
**Post date:** [July 26, 2018, 11:43am UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/8 "2018-07-26T11:43:29Z")

</div>

Done!

here VTK PR: [https://gitlab.kitware.com/vtk/vtk/merge\_requests/4531](https://gitlab.kitware.com/vtk/vtk/merge_requests/4531)  
here Slicer PR: [https://github.com/Slicer/Slicer/pull/994](https://github.com/Slicer/Slicer/pull/994)

this selects (left click) one point in the plot view if using the pan, selection points and free-hand select point interaction modes (so if you click a point, the left click will do the single point selection, otherwise it will do still the interaction chosen in the plotView controller). In addition pressing the key U removes the current selection. Still, there can be only one selection at time: a subsequent selection will delete the previous one.

Video: [https://www.dropbox.com/s/vzue6tmchm3vltq/SinglePointSelection.webm?dl=0](https://www.dropbox.com/s/vzue6tmchm3vltq/SinglePointSelection.webm?dl=0)

Remember that there is an high level Slicer API method for connecting the VTK selection to your modules:

> <https://github.com/Slicer/Slicer/blob/50774a8691293659f2867e5e92ef0e285de00f0e/Libs/MRML/Widgets/qMRMLPlotView.cxx#L622-L669>

> <https://github.com/Punzo/SlicerAstro/blob/8387dcdf49b206899c85c8422013b94a61f1972d/AstroModeling/qSlicerAstroModelingModuleWidget.cxx#L833-L852>

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [July 26, 2018, 2:11pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/9 "2018-07-26T14:11:13Z")

</div>

> [@Davide\_Punzo](#):
>
> here VTK PR

Thanks!

> [@Davide\_Punzo](#):
>
> so if you click a point, the left click will do the single point selection, otherwise it will do still the interaction chosen in the plotView controller

Is it possible to make this selection mode exclusive?

---

<div class="post-metadata">

**Author:** ![Davide\_Punzo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/davide_punzo/32/66104_2.png) [@Davide\_Punzo](https://discourse.slicer.org/u/Davide_Punzo)\
**Post date:** [July 26, 2018, 2:15pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/10 "2018-07-26T14:15:38Z")

</div>

you are welcome.

> Is it possible to make this selection mode exclusive?

do you mean to have a new interaction mode in the plot view controller combo box? If it is this it can be done, I didn’t want to add an another interaction mode, however for me it is fine. @lassoan what do you think about it?

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [July 26, 2018, 2:29pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/11 "2018-07-26T14:29:19Z")

</div>

> [@Davide\_Punzo](#):
>
> do you mean to have a new interaction mode in the plot view controller combo box?

I couldn’t tell for sure from the code/your comment: does click-to-select with this PR require also enabling one of the other selection modes – box/freehand? (I would like to allow only click-to-select)

---

<div class="post-metadata">

**Author:** ![Davide\_Punzo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/davide_punzo/32/66104_2.png) [@Davide\_Punzo](https://discourse.slicer.org/u/Davide_Punzo)\
**Post date:** [July 26, 2018, 2:33pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/12 "2018-07-26T14:33:39Z")

</div>

> does click-to-select with this PR require also enabling one of the other selection modes – box/freehand?

with the current PR, you will be able to use the click one point selection also with the pan interaction mode. Will that work for you?

in the [video](https://www.dropbox.com/s/vzue6tmchm3vltq/SinglePointSelection.webm?dl=0) I show how does work both with the pan view and the select points interaction

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [July 26, 2018, 2:41pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/13 "2018-07-26T14:41:16Z")

</div>

Ok, I see. Eventually we may want to be able to select with pan disabled, but not critical for now – this is great and sufficient to port the GUI.

---

<div class="post-metadata">

**Author:** ![Davide\_Punzo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/davide_punzo/32/66104_2.png) [@Davide\_Punzo](https://discourse.slicer.org/u/Davide_Punzo)\
**Post date:** [July 26, 2018, 2:55pm UTC](https://discourse.slicer.org/t/plotting-select-point-on-click/3568/14 "2018-07-26T14:55:13Z")

</div>

> Ok, I see. Eventually we may want to be able to select with pan disabled, but not critical for now – this is great and sufficient to port the GUI.

In the case, for allowing only the clickSelectPoint interaction, it will be needed to change the following if condition in the VTK chartXY method:

> **[Charts/Core/vtkChartXY.cxx · SingleClickSelection · Davide Punzo / VTK · GitLab](https://gitlab.kitware.com/Punzo/vtk/blob/SingleClickSelection/Charts/Core/vtkChartXY.cxx#L1911-1915)**
>
> Visualization Toolkit

and add the clickSelectPoint interaction in combobox in the GUI of the plot controller and set the (click)ActionToButton of the chart for the specific interaction mode here:  
[https://github.com/Punzo/Slicer/blob/SingleClickSelection/Libs/MRML/Widgets/qMRMLPlotView.cxx#L697-L720](https://github.com/Punzo/Slicer/blob/SingleClickSelection/Libs/MRML/Widgets/qMRMLPlotView.cxx#L697-L720)
