...

Source file src/gonum.org/v1/plot/plotutil/plotutil.go

Documentation: gonum.org/v1/plot/plotutil

     1  // Copyright ©2015 The Gonum Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package plotutil contains a small number of utilites for creating plots.
     6  //
     7  // This package is under active development so portions of it may change.
     8  package plotutil // import "gonum.org/v1/plot/plotutil"
     9  
    10  import (
    11  	"image/color"
    12  
    13  	"gonum.org/v1/plot/vg"
    14  	"gonum.org/v1/plot/vg/draw"
    15  )
    16  
    17  // DefaultColors is a set of colors used by the Color function.
    18  var DefaultColors = SoftColors
    19  
    20  var DarkColors = []color.Color{
    21  	rgb(238, 46, 47),
    22  	rgb(0, 140, 72),
    23  	rgb(24, 90, 169),
    24  	rgb(244, 125, 35),
    25  	rgb(102, 44, 145),
    26  	rgb(162, 29, 33),
    27  	rgb(180, 56, 148),
    28  }
    29  
    30  var SoftColors = []color.Color{
    31  	rgb(241, 90, 96),
    32  	rgb(122, 195, 106),
    33  	rgb(90, 155, 212),
    34  	rgb(250, 167, 91),
    35  	rgb(158, 103, 171),
    36  	rgb(206, 112, 88),
    37  	rgb(215, 127, 180),
    38  }
    39  
    40  func rgb(r, g, b uint8) color.RGBA {
    41  	return color.RGBA{r, g, b, 255}
    42  }
    43  
    44  // Color returns the ith default color, wrapping
    45  // if i is less than zero or greater than the max
    46  // number of colors in the DefaultColors slice.
    47  func Color(i int) color.Color {
    48  	n := len(DefaultColors)
    49  	if i < 0 {
    50  		return DefaultColors[i%n+n]
    51  	}
    52  	return DefaultColors[i%n]
    53  }
    54  
    55  // DefaultGlyphShapes is a set of GlyphDrawers used by
    56  // the Shape function.
    57  var DefaultGlyphShapes = []draw.GlyphDrawer{
    58  	draw.RingGlyph{},
    59  	draw.SquareGlyph{},
    60  	draw.TriangleGlyph{},
    61  	draw.CrossGlyph{},
    62  	draw.PlusGlyph{},
    63  	draw.CircleGlyph{},
    64  	draw.BoxGlyph{},
    65  	draw.PyramidGlyph{},
    66  }
    67  
    68  // Shape returns the ith default glyph shape,
    69  // wrapping if i is less than zero or greater
    70  // than the max number of GlyphDrawers
    71  // in the DefaultGlyphShapes slice.
    72  func Shape(i int) draw.GlyphDrawer {
    73  	n := len(DefaultGlyphShapes)
    74  	if i < 0 {
    75  		return DefaultGlyphShapes[i%n+n]
    76  	}
    77  	return DefaultGlyphShapes[i%n]
    78  }
    79  
    80  // DefaultDashes is a set of dash patterns used by
    81  // the Dashes function.
    82  var DefaultDashes = [][]vg.Length{
    83  	{},
    84  
    85  	{vg.Points(6), vg.Points(2)},
    86  
    87  	{vg.Points(2), vg.Points(2)},
    88  
    89  	{vg.Points(1), vg.Points(1)},
    90  
    91  	{vg.Points(5), vg.Points(2), vg.Points(1), vg.Points(2)},
    92  
    93  	{vg.Points(10), vg.Points(2), vg.Points(2), vg.Points(2),
    94  		vg.Points(2), vg.Points(2), vg.Points(2), vg.Points(2)},
    95  
    96  	{vg.Points(10), vg.Points(2), vg.Points(2), vg.Points(2)},
    97  
    98  	{vg.Points(5), vg.Points(2), vg.Points(5), vg.Points(2),
    99  		vg.Points(2), vg.Points(2), vg.Points(2), vg.Points(2)},
   100  
   101  	{vg.Points(4), vg.Points(2), vg.Points(4), vg.Points(1),
   102  		vg.Points(1), vg.Points(1), vg.Points(1), vg.Points(1),
   103  		vg.Points(1), vg.Points(1)},
   104  }
   105  
   106  // Dashes returns the ith default dash pattern,
   107  // wrapping if i is less than zero or greater
   108  // than the max number of dash patters
   109  // in the DefaultDashes slice.
   110  func Dashes(i int) []vg.Length {
   111  	n := len(DefaultDashes)
   112  	if i < 0 {
   113  		return DefaultDashes[i%n+n]
   114  	}
   115  	return DefaultDashes[i%n]
   116  }
   117  

View as plain text