- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.9k
 
Bar with non-numeric (x,y) items bug fix #1519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from 2 commits
      Commits
    
    
            Show all changes
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      b62529d
              
                make toBeCloseToArray and toBeCloseToArray2D handle NaN properly
              
              
                etpinard 5279f99
              
                set bar size in main serieslen loop
              
              
                etpinard 0144f06
              
                fill in non-numeric bar items in calcdata
              
              
                etpinard 042cc82
              
                rm bar (now useless) 'placeholder' logic
              
              
                etpinard 6f0a95d
              
                add non-numeric 'x' items test for bar calc.js
              
              
                etpinard File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -283,6 +283,28 @@ describe('Bar.calc', function() { | |
| var cd = gd.calcdata; | ||
| assertPointField(cd, 'b', [[0, 1, 2], [0, 1, 0], [0, 0]]); | ||
| }); | ||
| 
     | 
||
| it('should exclude items with non-numeric x/y from calcdata', function() { | ||
| var gd = mockBarPlot([{ | ||
| x: [5, NaN, 15, 20, null, 21], | ||
| y: [20, NaN, 23, 25, null, 26] | ||
| }]); | ||
| 
     | 
||
| var cd = gd.calcdata; | ||
| assertPointField(cd, 'x', [[5, 15, 20, 21]]); | ||
| assertPointField(cd, 'y', [[20, 23, 25, 26]]); | ||
| }); | ||
| 
     | 
||
| it('should not exclude items with non-numeric y from calcdata (to plots gaps correctly)', function() { | ||
| var gd = mockBarPlot([{ | ||
| x: ['a', 'b', 'c', 'd'], | ||
| y: [1, null, 'nonsense', 15] | ||
| }]); | ||
| 
     | 
||
| var cd = gd.calcdata; | ||
| assertPointField(cd, 'x', [[0, 1, 2, 3]]); | ||
| assertPointField(cd, 'y', [[1, NaN, NaN, 15]]); | ||
| }); | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have a test with a bad  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. Added in 6f0a95d  | 
||
| }); | ||
| 
     | 
||
| describe('Bar.setPositions', function() { | ||
| 
          
            
          
           | 
    @@ -1285,7 +1307,7 @@ function mockBarPlot(dataWithoutTraceType, layout) { | |
| 
     | 
||
| var gd = { | ||
| data: dataWithTraceType, | ||
| layout: layout, | ||
| layout: layout || {}, | ||
| calcdata: [] | ||
| }; | ||
| 
     | 
||
| 
          
            
          
           | 
    ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Do we need to merge in the base loop below too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe? The behavior now is similar to how scatter fills in its
arrayOkattributes. I can double check though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like scatter keeps a 1:1 mapping between calcdata points and the input arrays, filling in non-numerics with
{x: false, y: false}- that's a good point about otherarrayOKattributes, maybe it would be easier to keep that 1:1 mapping for bars too? Should be faster too, as we're not doing repeated.push, can set the size ofcdat the start.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer removing non-numeric items in the calc step, so that we don't have to do that during the plot step (e.g. on zoom).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but then how do you want to solve this for bar color arrays etc? save the original index in each
cdelement?cd.push({p: p, s: s, i: i})or something? That would need to be propagated all the way through toLib.mergeArraywhich seems like a bit of a disaster.Non-numerics should be regarded as an edge case, so the overhead of managing their objects shouldn't be seen as a concern, but you're right to worry about the overhead of checking each valid point. That said, this works for scatter which can have way more points than bars, so I think as long as we make this test super simple it shouldn't be a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexcjohnson ok, you convinced me.
With commit 0144f06 bar calcdata has now a 1-1 correspondence with the bar
(x,y)coordinates. Note that non-numeric bar items are cleaned up inbar/plot.jsandmakeCalcdata(called above theserieslenloop inbar/calc.js) sets non-numeric values toBADNUM.This a pretty big change that might lead to regressions, so this PR will make be part of the next minor release
v1.26.0only.