phetsims/vector-addition

sum vector is labeled when it should not be in Lab screen

Closed this issue · 5 comments

This was caused by the change in #238 (Click anywhere in the graph to clear the selected vector), and was discovered by @arouinfar.

To reproduce:

  1. Go to Lab screen.
  2. Check both Sum checkboxes
  3. Drag one 'blue' and one 'orange' vector to the graph.
  4. Click on the graph to clear the selection. Note that both sum vectors become labeled with 's', see screenshot below.

screenshot_1601

Another similar problem, steps to reproduce:

  1. Got to Lab screen.
  2. Check blue 'Sum' checkbox.
  3. Drag a 'blue' vector to the graph.
  4. Click anywhere on the graph to deselect. Note that that the blue sum 's' continues to be labeled, see screenshot below. A sum vector should be labeled only if it, or one of its associated vectors, is selected.

screenshot_1602

The code of interest is in SumVector:

      // @private {function} isSymbolDisplayed - function to check if the sum vector should display its symbol.
      // The sum vector only displays its symbol when a vector in its vector set is active, or the sum is active.
      this.isSymbolDisplayed = () => {
        return vectorSet.vectors.some( vector => vector === graph.activeVectorProperty.value )
               || graph.activeVectorProperty.value === this
               || graph.activeVectorProperty.value === null;

Fixed in the above commit, master and 1.0.0-dev.43. I'm not particularly pleased with the solution - it feels like a hack - but I was painted into a corner. This bit of code has caused me repeated problems, and there's no good/easy way to fix it. I've documented it, and its working, so... onward.

@arouinfar please verify.

@pixelzoom the behavior is looking good in dev.43. Thanks for making this change and patching things up.

Sorry to do this to you @arouinfar. But I dreamed up (literally:) a better way to address this that should mitigate future maintenance problems. Please verify in master or 1.0.0-dev.45.

Sounds like it was a productive night of dreaming, dev.45 looks good to me.