- 
                Notifications
    You must be signed in to change notification settings 
- Fork 305
Advanced Flexbox Layout #259
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
          
     Open
      
      
            siefkenj
  wants to merge
  14
  commits into
  plotters-rs:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
siefkenj:layout
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            14 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      821a655
              
                Initial work on flexbox layout
              
              
                siefkenj a9a477c
              
                Merge remote-tracking branch 'upstream/master' into layout
              
              
                siefkenj 5c0f3a5
              
                Switch to concrete error type
              
              
                siefkenj b403db3
              
                Added ability to set labels and margins
              
              
                siefkenj 353c6a6
              
                Add accessor for chart_area drawing area
              
              
                siefkenj 9938d7b
              
                Fix incorrect calculation of drawing area pixels
              
              
                siefkenj 79ec8f3
              
                Spelling fixes
              
              
                siefkenj 45cb820
              
                Added auto-sizing axes
              
              
                siefkenj 6d81f7c
              
                Added ticks module
              
              
                siefkenj 6f23207
              
                Merge remote-tracking branch 'upstream/master' into layout
              
              
                siefkenj 6514ed9
              
                Put ChartLayout under a features flag
              
              
                siefkenj 1b85ad0
              
                Call `present` at the end of example to make sure an error is thrown for
              
              
                siefkenj a9e7037
              
                Autosizing of labels
              
              
                siefkenj 8cc45ea
              
                Merge remote-tracking branch 'upstream/master' into layout
              
              
                siefkenj 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| use plotters::prelude::*; | ||
|  | ||
| const OUT_FILE_NAME: &'static str = "plotters-doc-data/layout2.png"; | ||
|  | ||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| const W: u32 = 600; | ||
| const H: u32 = 400; | ||
| let root = BitMapBackend::new(OUT_FILE_NAME, (W, H)).into_drawing_area(); | ||
| root.fill(&full_palette::WHITE)?; | ||
|  | ||
| let x_spec = -3.1..3.01f32; | ||
| let y_spec = -1.1..1.1f32; | ||
|  | ||
| let mut chart = ChartLayout::new(&root); | ||
| chart | ||
| .set_chart_title_text("Chart Title")? | ||
| .set_chart_title_style(("serif", 60.).into_font().with_color(&RED))? | ||
| .set_left_label_text("Ratio of Sides")? | ||
| .set_bottom_label_text("Radians")? | ||
| .set_bottom_label_margin(10.)? | ||
| .set_left_label_margin((0., -5., 0., 10.))? | ||
| .build_cartesian_2d(x_spec.clone(), y_spec.clone())? | ||
| .draw()?; | ||
|  | ||
| // If we extract a drawing area corresponding to a chart area, we can | ||
| // use the usual chart API to draw. | ||
| let da_chart = chart.get_chart_drawing_area()?; | ||
| let x_axis = x_spec.clone().step(0.1); | ||
| let mut cc = ChartBuilder::on(&da_chart) | ||
| //.margin(5) | ||
| //.set_all_label_area_size(15) | ||
| .build_cartesian_2d(x_spec.clone(), y_spec.clone())?; | ||
|  | ||
| cc.draw_series(LineSeries::new(x_axis.values().map(|x| (x, x.sin())), &RED))? | ||
| .label("Sine") | ||
| .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &RED)); | ||
|  | ||
| cc.configure_series_labels().border_style(&BLACK).draw()?; | ||
| root.present()?; | ||
|  | ||
|         
                  siefkenj marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| Ok(()) | ||
| } | ||
| #[test] | ||
| fn entry_point() { | ||
| main().unwrap() | ||
| } | ||
  
    
      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
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  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.
Also, this seems odd as we also have https://docs.rs/plotters/0.3.1/plotters/chart/struct.MeshStyle.html#method.x_desc which have the similar effect.
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 guess this should be a broader discussion about how charts should be configured and what belongs to the chart vs. the coordinate system.
The way plotters seems to do it now is to attach labels to the coordinate system and then adjust whether the axes are printed to the left right/etc. Since
ChartLayoutdoesn't handle coordinate systems right now, I just went an API that labels things based on position.I think that maybe the best solution would be to have both. If you set via the coordinate system, it would automatically call the
set_XXX_label_text. However if a person wanted to set the text without a coordinate system or to override it, they would be free to.What do you think?