### Picture Configuration Example Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Example of configuring picture rendering settings. ```go Config{ Fit: picture.FitCover, Anchor: picture.AnchorCenter, KittyID: 42, CellPixelWidth: 8, CellPixelHeight: 16, KittyResolutionFactor: 0.75, } ``` -------------------------------- ### Run Picture Grid Example Source: https://github.com/nimblemarkets/ntcharts/blob/v2/examples/picture/grid/README.md Execute the example to see the picture grid functionality in action. ```sh go run ./examples/picture/grid ``` -------------------------------- ### Sparkline Initialization and Data Push Example Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/sparkline.md Demonstrates how to create a sparkline, push initial data, and render it to the console. ```go sl := sparkline.New(40, 5) s := sparkline.New(40, 5) sl.PushAll([]float64{7.81, 3.82, 8.39, 2.06, 4.19, 4.34, 6.83, 2.51, 9.21, 1.3}) sl.Draw() fmt.Println(sl.View()) ``` -------------------------------- ### Sparkline Rendering Examples Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/sparkline.md Demonstrates rendering sparklines using columns and braille patterns, showing how to view the output. ```go sl := sparkline.New(50, 10) // Add some data for i := 0; i < 50; i++ { sl.Push(math.Sin(float64(i)/10) * 50 + 50) } // Render with columns sl.Draw() fmt.Println(sl.View()) // Or render with braille sl.DrawBraille() fmt.Println(sl.View()) ``` -------------------------------- ### Line Chart Options Example Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/linechart.md Demonstrates how to construct a line chart with custom Y-axis step and line styling using lipgloss. This example sets the Y-axis tick frequency to 10 and applies a specific foreground color to the line. ```go lc := linechart.New(60, 25, 0, 100, 0, 100, linechart.WithYStep(10), linechart.WithStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("11"))), ) ``` -------------------------------- ### Line Chart Constructor and Plotting Example Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/linechart.md Demonstrates how to create a new line chart, plot data points, and render the chart. Ensure the chart dimensions and value ranges are set appropriately. ```go lc := linechart.New(50, 20, 0, 10, 0, 100) // Add data points lc.Plot(canvas.Float64Point{X: 0, Y: 10}) lc.Plot(canvas.Float64Point{X: 5, Y: 50}) lc.Plot(canvas.Float64Point{X: 10, Y: 90}) lc.Draw() fmt.Println(lc.View()) ``` -------------------------------- ### Run ntcharts-lorem-picsum CLI Source: https://github.com/nimblemarkets/ntcharts/blob/v2/cmd/ntcharts-lorem-picsum/README.md Execute the ntcharts-lorem-picsum command-line tool to start the image browser. Ensure the binary is available in your PATH. ```bash ./bin/ntcharts-lorem-picsum ``` -------------------------------- ### Basic lipgloss Styling Example Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/README.md Demonstrates how to create and apply basic styling using lipgloss.NewStyle. This is fundamental for styling all ntcharts elements. ```go import "charm.land/lipgloss/v2" style := lipgloss.NewStyle(). Foreground(lipgloss.Color("11")). // Bright cyan Bold() ``` -------------------------------- ### Heat Map Data Population and Drawing Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/README.md Example of initializing a heatmap, setting the X and Y ranges, pushing data points with calculated values, and drawing the map. ```go package main import ( "fmt" "math" "github.com/NimbleMarkets/ntcharts/v2/heatmap" ) func main() { hm := heatmap.New(30, 25) hm.SetXYRange(-math.Pi, math.Pi, -math.Pi, math.Pi) for x := -math.Pi; x < math.Pi; x += 0.2 { for y := -math.Pi; y < math.Pi; y += 0.2 { val := math.Sin(math.Sqrt(x*x + y*y)) hm.Push(heatmap.NewHeatPoint(x, y, val)) } } hm.Draw() fmt.Println(hm.View()) } ``` -------------------------------- ### 256-Color Palette Specification Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Examples of specifying colors using the 256-color palette. ```go lipgloss.Color("196") // Bright red lipgloss.Color("226") // Bright yellow ``` -------------------------------- ### Lip Gloss Color Styling Example Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/types.md Demonstrates how to apply foreground and background colors to text using lipgloss.Color, specifying colors by index or hex code. ```go style := lipgloss.NewStyle(). Foreground(lipgloss.Color("11")). // Bright cyan Background(lipgloss.Color("#000000")) // Black ``` -------------------------------- ### Simple Bar Chart Creation and Drawing Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/README.md Example of creating a new bar chart, defining data with labels and values, and rendering it. Uses lipgloss for value styling. ```go package main import ( "fmt" "github.com/NimbleMarkets/ntcharts/v2/barchart" "charm.land/lipgloss/v2" ) func main() { bc := barchart.New(40, 20) d := barchart.BarData{ Label: "Series A", Values: []barchart.BarValue{ {"Q1", 21.5, lipgloss.NewStyle().Foreground(lipgloss.Color("10"))}, {"Q2", 18.2, lipgloss.NewStyle().Foreground(lipgloss.Color("10"))}, }, } bc.Push(d) bc.Draw() fmt.Println(bc.View()) } ``` -------------------------------- ### ANSI 16-Color Specification Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Examples of specifying colors using the standard ANSI 16-color format. ```go lipgloss.Color("0") // Black lipgloss.Color("7") // White lipgloss.Color("11") // Bright cyan ``` -------------------------------- ### Import Libraries for ntcharts Source: https://github.com/nimblemarkets/ntcharts/blob/v2/examples/quickstart/README.md Imports necessary libraries for ntcharts, Bubble Tea, Lip Gloss, and BubbleZone. Ensure these are installed before running. ```go package main import ( "fmt" "os" "time" tslc "github.com/NimbleMarkets/ntcharts/v2/linechart/timeserieslinechart" tea "charm.land/bubbletea/v2" "charm.land/lipgloss/v2" zone "github.com/lrstanley/bubblezone/v2" ) ``` -------------------------------- ### Hex RGB Color Specification Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Examples of specifying colors using Hex RGB format. ```go lipgloss.Color("#FF0000") // Red lipgloss.Color("#00FF00") // Green lipgloss.Color("#0000FF") // Blue ``` -------------------------------- ### Custom Color Scale Example Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/heatmap.md Demonstrates how to provide a custom color gradient to the heat map using a slice of lipgloss.Color. This scale is used for mapping data values to colors. ```go colorGrad := []color.Color{ lipgloss.Color("#0000FF"), // blue lipgloss.Color("#00FF00"), // green lipgloss.Color("#FFFF00"), // yellow lipgloss.Color("#FF0000"), // red } hm := heatmap.New(50, 30, heatmap.WithColorScale(colorGrad)) ``` -------------------------------- ### Dimensions Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/heatmap.md Methods to get and set the dimensions of the heat map grid. ```APIDOC ## Dimensions ### Methods - `Width() int`: Returns the current width of the heat map in cells. - `Height() int`: Returns the current height of the heat map in cells. - `Resize(w, h int)`: Resizes the heat map to the specified width and height. This action updates all internal scales. ``` -------------------------------- ### Model Methods - Dimensions Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-index.md Provides methods to get and set the dimensions of the chart model. ```APIDOC ## Model Methods - Dimensions ### Description Methods to retrieve and modify the width and height properties of the chart model, including graph-specific dimensions and resizing capabilities. ### Methods - `Width()`: Returns the width of the chart model. - `Height()`: Returns the height of the chart model. - `GraphWidth()`: Returns the width of the graph area within the chart. - `GraphHeight()`: Returns the height of the graph area within the chart. - `Resize(w, h int)`: Resizes the chart model to the specified width (w) and height (h). ``` -------------------------------- ### Initialize Canvas with Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/configuration.md Create a new canvas with specified dimensions and custom configurations. Use variadic arguments for options like styling, focus, and viewport dimensions. ```go import ( "github.com/NimbleMarkets/ntcharts/v2/canvas" "charm.land/lipgloss/v2" ) c := canvas.New(80, 24, canvas.WithStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("6"))), canvas.WithFocus(), canvas.WithViewWidth(80), canvas.WithViewHeight(24), ) ``` -------------------------------- ### Canvas Dimensions Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/canvas.md Provides methods to get the current width and height of the canvas, and to resize it. ```APIDOC ## Canvas Dimensions ### Description Get canvas dimensions or resize the canvas. `Resize` truncates content if shrinking and clamps negative dimensions to 0. ### Methods - `Width() int` - Returns the current width of the canvas. - `Height() int` - Returns the current height of the canvas. - `Resize(w, h int)` - Resizes the canvas to the specified width and height. ``` -------------------------------- ### Canvas Construction with Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/canvas.md Demonstrates how to create a new canvas instance with custom options. Options like styling, key mapping, update handlers, mouse support, cursor position, focus, initial content, and viewport dimensions can be configured during construction. ```go c := canvas.New(80, 24, canvas.WithStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("6"))), canvas.WithFocus(), ) ``` -------------------------------- ### Bar Chart Constructor with Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/barchart.md Demonstrates initializing a bar chart with custom options for orientation, bar gap, and axis styling. ```go bc := barchart.New(50, 25, barchart.WithHorizontal(true), barchart.WithBarGap(2), barchart.WithAxisStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("240"))), ) ``` -------------------------------- ### Initialize Heatmap with Custom Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/heatmap.md Demonstrates how to create a new heatmap instance with custom value range, XY range, and color scale options. Ensure `colorGradient` is defined and appropriate for your data. ```go hm := heatmap.New(50, 40, heatmap.WithValueRange(-1, 1), heatmap.WithXYRange(-math.Pi, math.Pi, -math.Pi, math.Pi), heatmap.WithColorScale(colorGradient), ) ``` -------------------------------- ### Initialize Picture with Partial Config Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/configuration.md Create a picture model with a subset of configuration options, allowing defaults to be used for unspecified fields. ```go cfg := picture.Config{ Fit: picture.FitFill, KittyID: 42, CellPixelWidth: 10, CellPixelHeight: 20, } pm := picture.NewWithConfig(cfg) ``` -------------------------------- ### Initialize Line Chart with Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/configuration.md Create a line chart with specified dimensions and data ranges, applying custom configurations. Options control axis steps, label formatting, styling, and auto-ranging. ```go import "github.com/NimbleMarkets/ntcharts/v2/linechart" lc := linechart.New(60, 25, 0, 100, 0, 100, linechart.WithYStep(10), linechart.WithStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("11"))), linechart.WithAutoXYRange(), linechart.WithYLabelFormatter(func(i int, v float64) string { return fmt.Sprintf("%.1f", v) }), ) ``` -------------------------------- ### Basic Bar Chart Initialization and Usage Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/barchart.md Demonstrates creating a bar chart, adding data, and rendering it. Assumes default options for auto-scaling and vertical orientation. ```go bc := barchart.New(40, 20) // Add data d1 := barchart.BarData{ Label: "Series A", Values: []barchart.BarValue{ {Name: "Jan", Value: 21.5, Style: lipgloss.NewStyle().Foreground(lipgloss.Color("10"))}, {Name: "Feb", Value: 18.2, Style: lipgloss.NewStyle().Foreground(lipgloss.Color("10"))}, }, } bc.Push(d1) bc.Draw() fmt.Println(bc.View()) ``` -------------------------------- ### Cell Operations Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/canvas.md Allows direct manipulation of individual cells on the canvas, including getting and setting cells, runes, and styles. ```APIDOC ## Cell Operations ### Description Get and set individual cells or cell properties at coordinates (X, Y). Cell operations return `bool` indicating whether coordinates were in bounds. ### Methods - `SetCell(p Point, c Cell) bool` - Sets a cell at the specified point. - `Cell(p Point) Cell` - Gets the cell at the specified point. - `SetRune(p Point, r rune) bool` - Sets a rune at the specified point. - `SetRuneWithStyle(p Point, r rune, style lipgloss.Style) bool` - Sets a rune with a specific style at the specified point. - `SetCellStyle(p Point, s lipgloss.Style) bool` - Sets the style of the cell at the specified point. - `GetCellStyle(p Point) *lipgloss.Style` - Gets the style of the cell at the specified point. ``` -------------------------------- ### Bar Chart Dimension and Scaling Methods Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/barchart.md Allows getting chart dimensions, resizing the chart, and managing value scaling. ```go func (m *Model) Width() int func (m *Model) Height() int func (m *Model) Resize(w, h int) func (m *Model) MaxValue() float64 func (m *Model) Scale() float64 func (m *Model) SetMaxValue(f float64) ``` -------------------------------- ### Initialize Bar Chart with Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/configuration.md Instantiate a bar chart with custom width, height, and configuration options. Options include auto-scaling, bar spacing, orientation, and axis styling. ```go import "github.com/NimbleMarkets/ntcharts/v2/barchart" bc := barchart.New(50, 25, barchart.WithHorizontal(true), barchart.WithBarGap(2), barchart.WithAutoBarWidth(true), barchart.WithAxisStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("240"))), ) ``` -------------------------------- ### Basic Image Display Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/picture.md Demonstrates how to create a new Picture model, set an image, and return commands in the Update method for rendering. ```go pm := picture.New() // When you have an image.Image cmd := pm.SetImage(decodedImage) // In your Update method if cmd != nil { return m, cmd } // Render return m, nil ``` -------------------------------- ### Get Cell Style Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/canvas.md Retrieves a pointer to the Lip Gloss style of the cell at the specified coordinates. Returns nil if coordinates are out of bounds. ```go style := m.GetCellStyle(canvas.Point{X: 2, Y: 2}) ``` -------------------------------- ### Get Cell Content Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/canvas.md Retrieves the Cell (rune and style) at the specified coordinates. The returned Cell will have default values if coordinates are out of bounds. ```go cell := m.Cell(canvas.Point{X: 1, Y: 1}) ``` -------------------------------- ### Create and Render a Canvas Source: https://github.com/nimblemarkets/ntcharts/blob/v2/README.md Demonstrates creating a canvas of a specified size and setting lines with a Lip Gloss style. Use this for basic text rendering in a grid. ```go package main import ( "fmt" "github.com/NimbleMarkets/ntcharts/v2/canvas" "charm.land/lipgloss/v2" ) func main() { c := canvas.New(5, 2) c.SetLinesWithStyle( []string{"hello", "world"}, lipgloss.NewStyle().Foreground(lipgloss.Color("6"))) // cyan fmt.Println(c.View()) } ``` -------------------------------- ### Default Color Scale Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/heatmap.md Functions to get and set the default color scale used by new heat maps. The default is a 16-step grayscale. ```APIDOC ## Default Color Scale ### Functions - `GetDefaultColorScale() []color.Color`: Retrieves the current default color scale. - `SetDefaultColorScale(cs []color.Color) []color.Color`: Sets a new default color scale for all subsequent heat maps. Returns the previously set scale. ``` -------------------------------- ### Bubble Tea Init Method Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/canvas.md Implements the Bubble Tea `Init` interface method. Returns a command to be executed on initialization. ```go func (m Model) Init() tea.Cmd { return nil } ``` -------------------------------- ### Get and Resize Dimensions Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/heatmap.md Retrieves the current width and height of the heat map canvas or resizes it to new dimensions. Resizing updates internal scales. ```go func (m *Model) Width() int func (m *Model) Height() int func (m *Model) Resize(w, h int) ``` -------------------------------- ### Initialize Picture with Config Struct Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/configuration.md Construct a picture model using a Config struct, specifying parameters like KittyID, Fit mode, and cell dimensions. ```go cfg := picture.Config{ KittyID: 42, Background: nil, Fit: picture.FitContain, Anchor: picture.AnchorCenter, CellPixelWidth: 8, CellPixelHeight: 16, KittyResolutionFactor: 0.75, } pm := picture.NewWithConfig(cfg) ``` -------------------------------- ### Sparkline Constructor with Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/sparkline.md Shows how to create a sparkline with custom options like a fixed maximum value and a specific rendering style. ```go sl := sparkline.New(60, 8, sparkline.WithMaxValue(100), sparkline.WithStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("11"))), ) ``` -------------------------------- ### Initialize Heat Map with Custom Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/configuration.md Create a new heatmap instance with specified dimensions and custom configuration options such as color scale, value range, and coordinate ranges. ```go import "github.com/NimbleMarkets/ntcharts/v2/heatmap" import "math" colors := []color.Color{ lipgloss.Color("#0000FF"), // blue lipgloss.Color("#00FF00"), // green lipgloss.Color("#FFFF00"), // yellow lipgloss.Color("#FF0000"), // red } hm := heatmap.New(50, 40, heatmap.WithColorScale(colors), heatmap.WithValueRange(-1, 1), heatmap.WithXYRange(-math.Pi, math.Pi, -math.Pi, math.Pi), ) ``` -------------------------------- ### Create Bar Chart with Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/INDEX.md Instantiate a new bar chart with specified dimensions and configuration options. Use options like WithStyle and WithHorizontal to customize its appearance and orientation. ```go bc := barchart.New(width, height, barchart.WithStyle(style), barchart.WithHorizontal(true), ) ``` -------------------------------- ### Default Color Scale Management Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/heatmap.md Provides functions to get the default grayscale color scale or set a custom default for all new heat maps. Returns the previous scale upon setting. ```go func GetDefaultColorScale() []color.Color func SetDefaultColorScale(cs []color.Color) []color.Color ``` -------------------------------- ### Create and Draw on Canvas Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Initializes a new canvas with specified dimensions and style, sets a cell, and prints the canvas view. Requires the canvas package. ```go c := canvas.New(80, 24, canvas.WithStyle(myStyle)) c.SetCell(canvas.Point{X: 5, Y: 5}, canvas.NewCell('*')) fmt.Println(c.View()) ``` -------------------------------- ### Responsive Sizing with Window Resize Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/picture.md Shows how to handle terminal window resize events by updating the Picture model's geometry. ```go pm := picture.New() // Handle terminal resize case tea.WindowSizeMsg: cmd := pm.SetGeometry(msg.Width, msg.Height) return m, cmd ``` -------------------------------- ### Create and Push Data to Heat Map Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Initializes a new heat map and pushes data points with values. Requires the heatmap package. ```go hm := heatmap.New(40, 30) for x := 0.0; x < 10; x += 0.5 { for y := 0.0; y < 10; y += 0.5 { hm.Push(heatmap.NewHeatPoint(x, y, value)) } } hm.Draw() ``` -------------------------------- ### Create and Plot Wave Line Chart Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Initializes a new wave line chart and plots a data point. Requires the wavelinechart package. ```go wlc := wavelinechart.New(50, 20) wlc.Plot(canvas.Float64Point{X: 1, Y: 10}) ``` -------------------------------- ### Initialize Heat Picture with Sampler Function Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/configuration.md Create a high-resolution heatmap using the heatpicture package, providing a custom sampler function and configuration options. ```go sampler := func(x, y float64) float64 { return math.Sin(math.Sqrt(x*x + y*y)) } hp := heatpicture.New(width, height, sampler, opts...) ``` -------------------------------- ### Initialize Sparkline with Custom Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/configuration.md Create a new sparkline instance with specified dimensions and custom options like maximum value and rendering style. ```go import "github.com/NimbleMarkets/ntcharts/v2/sparkline" sl := sparkline.New(60, 8, sparkline.WithMaxValue(100), sparkline.WithStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("11"))), ) ``` -------------------------------- ### Create and Plot Line Chart Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Initializes a new line chart with specified dimensions and axis ranges, then plots a data point. Requires the linechart package. ```go lc := linechart.New(60, 25, 0, 100, 0, 100) lc.Plot(canvas.Float64Point{X: 50, Y: 75}) lc.Draw() ``` -------------------------------- ### Constructor: New Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/barchart.md Creates a new bar chart instance with specified dimensions and optional configurations. ```APIDOC ## New ```go func New(w, h int, opts ...Option) Model ``` ### Description Creates a new bar chart with specified dimensions. ### Parameters #### Path Parameters - **w** (int) - Required - Chart width in cells - **h** (int) - Required - Chart height in cells - **opts** (...Option) - Optional - Variadic options ### Returns - **Model** - Initialized bar chart ### Defaults - `AutoMaxValue`: true - `AutoBarWidth`: true - Bars oriented vertically - Axis displayed with labels ### Example ```go bc := barchart.New(40, 20) // Add data d1 := barchart.BarData{ Label: "Series A", Values: []barchart.BarValue{ {Name: "Jan", Value: 21.5, Style: lipgloss.NewStyle().Foreground(lipgloss.Color("10"))}, {Name: "Feb", Value: 18.2, Style: lipgloss.NewStyle().Foreground(lipgloss.Color("10"))}, }, } bc.Push(d1) bc.Draw() fmt.Println(bc.View()) ``` ``` -------------------------------- ### Create and Draw Sparkline Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Initializes a new sparkline, pushes all data values, and draws it. Requires the sparkline package. ```go sl := sparkline.New(50, 5) sl.PushAll(dataValues) sl.Draw() // or sl.DrawBraille() for smooth lines ``` -------------------------------- ### Set Image for Picture Renderer Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Creates a new picture model and sets an image to it. Returns the model and a command. Requires the picture package. ```go pm := picture.New() cmd := pm.SetImage(decodedImage) return m, cmd ``` -------------------------------- ### Create and Render a Streamline Chart Source: https://github.com/nimblemarkets/ntcharts/blob/v2/README.md Demonstrates creating a streamline chart by pushing individual float64 values. Ideal for visualizing time-series data with a continuous flow. ```go package main import ( "fmt" "github.com/NimbleMarkets/ntcharts/v2/linechart/streamlinechart" ) func main() { slc := streamlinechart.New(13, 10) for _, v := range []float64{4, 6, 8, 10, 8, 6, 4, 2, 0, 2, 4} { slc.Push(v) } slc.Draw() fmt.Println(slc.View()) } ``` -------------------------------- ### New Picture Model Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/picture.md Creates a new picture model with default configuration. Use this for basic image rendering. ```go pm := picture.New() ``` -------------------------------- ### Create and Draw Bar Chart Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Initializes a new bar chart and pushes data to it. Requires the barchart package. ```go bc := barchart.New(50, 25) bc.Push(barchart.BarData{ Label: "Q1", Values: []barchart.BarValue{{Name: "Sales", Value: 100, Style: style}}, }) bc.Draw() ``` -------------------------------- ### New Picture Model with Custom Config Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/picture.md Creates a new picture model with custom configuration. Use this to specify fitting, anchoring, or Kitty graphics settings. ```go cfg := picture.Config{ Fit: picture.FitCover, Anchor: picture.AnchorTop, KittyID: 42, } pm := picture.NewWithConfig(cfg) ``` -------------------------------- ### New Constructor Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/heatmap.md Creates a new heat map with specified dimensions and optional configuration. Defaults are set for ranges and color scale. ```APIDOC ## New ### Description Creates a new heat map with specified dimensions. ### Parameters #### Path Parameters - **w** (int) - Required - Chart width in cells - **h** (int) - Required - Chart height in cells - **opts** (...Option) - Optional - Variadic options ### Returns - **Model** - Initialized heat map ### Defaults - X range: 0 to 1 - Y range: 0 to 1 - Auto-adjustment enabled for all ranges and value ranges - Uses default color scale (black to white gradient) ### Example ```go hm := heatmap.New(40, 30) hm.SetXYRange(0, 10, 0, 10) for x := 0.0; x < 10; x += 0.5 { for y := 0.0; y < 10; y += 0.5 { val := math.Sin(math.Sqrt(x*x + y*y)) hm.Push(heatmap.NewHeatPoint(x, y, val)) } } hm.Draw() fmt.Println(hm.View()) ``` ``` -------------------------------- ### Create and Render a Bar Chart Source: https://github.com/nimblemarkets/ntcharts/blob/v2/README.md Shows how to create a bar chart with multiple data sets, each having labeled values with specific styles. Suitable for comparing categorical data. ```go package main import ( "fmt" "github.com/NimbleMarkets/ntcharts/v2/barchart" "charm.land/lipgloss/v2" ) func main() { d1 := barchart.BarData{ Label: "A", Values: []barchart.BarValue{ {"Item1", 21.2, lipgloss.NewStyle().Foreground(lipgloss.Color("10"))}}, // green } d2 := barchart.BarData{ Label: "B", Values: []barchart.BarValue{ {"Item1", 15.2, lipgloss.NewStyle().Foreground(lipgloss.Color("9"))}}, // red } bc := barchart.New(11, 10) bc.PushAll([]barchart.BarData{d1, d2}) bc.Draw() fmt.Println(bc.View()) } ``` -------------------------------- ### Render Chart with BubbleZone and Styling Source: https://github.com/nimblemarkets/ntcharts/blob/v2/examples/quickstart/README.md The `View()` method renders the chart and wraps its output with `zoneManager.Scan()` for mouse event handling. A Lip Gloss style is applied to add a purple border around the chart. ```go func (m model) View() string { // call bubblezone Manager.Scan() at root model return m.zoneManager.Scan( lipgloss.NewStyle(). BorderStyle(lipgloss.NormalBorder()). BorderForeground(lipgloss.Color("63")). // purple Render(m.chart.View()), ) } ``` -------------------------------- ### Wave Line Chart Constructor Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/linechart.md Use this constructor to create a line chart with wave pattern connections between data points. It requires width and height, and accepts optional configuration settings. ```go import "github.com/NimbleMarkets/ntcharts/v2/linechart/wavelinechart" func New(w, h int, opts ...Option) Model ``` -------------------------------- ### Bar Chart Configuration Methods Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/barchart.md Methods to configure the width and gap between bars. ```go func (m *Model) SetBarWidth(w int) func (m *Model) SetBarGap(g int) func (m *Model) BarWidth() int func (m *Model) BarGap() int ``` -------------------------------- ### Canvas Constructor Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/canvas.md Creates a new canvas with specified width and height. Supports variadic options for further configuration. ```go c := canvas.New(80, 24) ``` -------------------------------- ### Config Struct Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/picture.md Configuration for the Picture Model, including Kitty graphics ID, background color, fit mode, anchor, cell dimensions, and Kitty resolution factor. ```go type Config struct { KittyID int Background color.Color Fit FitMode Anchor FitAnchor CellPixelWidth int CellPixelHeight int KittyResolutionFactor float64 } ``` -------------------------------- ### Run Bubble Tea Program Source: https://github.com/nimblemarkets/ntcharts/blob/v2/examples/quickstart/README.md Initializes and runs the Bubble Tea program with mouse cell motion enabled. This is the final step to launch the interactive chart application. ```go func main() { // [...] // start new Bubble Tea program with mouse support enabled m := model{chart, zoneManager} if _, err := tea.NewProgram(m, tea.WithAltScreen(), tea.WithMouseCellMotion()).Run(); err != nil { fmt.Println("Error running program:", err) os.Exit(1) } } ``` -------------------------------- ### New Picture Model Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/picture.md Creates a new picture model with default configuration. This is the simplest way to initialize the picture rendering model. ```APIDOC ## New ```go func New() Model ``` ### Description Creates a new picture model with default configuration. ### Returns - `Model` - Initialized picture ### Example ```go pm := picture.New() ``` ``` -------------------------------- ### Update Chart Configuration at Runtime Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/configuration.md Demonstrates how to modify chart properties like bar width, ranges, styles, and dimensions after the chart has been created. ```go // Change bar width at runtime bc.SetBarWidth(5) // Change line chart ranges lc.SetYRange(0, 200) // Change style sl.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("12")) // Resize lc.Resize(newWidth, newHeight) ``` -------------------------------- ### New Picture Model with Configuration Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/picture.md Creates a new picture model with custom configuration, allowing fine-grained control over rendering behavior like aspect ratio handling and Kitty graphics ID. ```APIDOC ## NewWithConfig ```go func NewWithConfig(cfg Config) Model ``` ### Description Creates a new picture model with custom configuration. ### Parameters #### Request Body - **cfg** (Config) - Required - Configuration structure ### Returns - `Model` - Initialized picture ### Example ```go cfg := picture.Config{ Fit: picture.FitCover, Anchor: picture.AnchorTop, KittyID: 42, } pm := picture.NewWithConfig(cfg) ``` ``` -------------------------------- ### Line Chart Configuration Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Options for line charts, controlling step sizes, label formatting, axis ranges, and interpolation. ```go linechart.WithStyle(s) ``` ```go linechart.WithXStep(n) ``` ```go linechart.WithYStep(n) ``` ```go linechart.WithXLabelFormatter(f) ``` ```go linechart.WithYLabelFormatter(f) ``` ```go linechart.WithAutoXYRange() ``` ```go linechart.WithMaxInterpolationPoints(n) ``` -------------------------------- ### Canvas Configuration Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Options for configuring the canvas, such as style, focus, cursor, and dimensions. ```go canvas.WithStyle(s) ``` ```go canvas.WithFocus() ``` ```go canvas.WithCursor(p) ``` ```go canvas.WithZoneManager(zm) ``` ```go canvas.WithViewWidth(w) ``` ```go canvas.WithViewHeight(h) ``` -------------------------------- ### Create and Push Data to Streamline Chart Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Initializes a new streamline chart and pushes a value, causing it to scroll. Requires the streamlinechart package. ```go slc := streamlinechart.New(50, 15) slc.Push(value) // Scrolls from right to left ``` -------------------------------- ### Define and Apply Themes Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/configuration.md Defines functions to create dark and light themes using lipgloss styles and applies them to a barchart. ```go func darkTheme() (axis, label lipgloss.Style) { return lipgloss.NewStyle().Foreground(lipgloss.Color("8")), lipgloss.NewStyle().Foreground(lipgloss.Color("7")) } func lightTheme() (axis, label lipgloss.Style) { return lipgloss.NewStyle().Foreground(lipgloss.Color("240")), lipgloss.NewStyle().Foreground(lipgloss.Color("0")) } // Switch themes axis, label := darkTheme() bc := barchart.New(50, 25, barchart.WithAxisStyle(axis), barchart.WithLabelStyle(label), ) ``` -------------------------------- ### Create and Draw a Waveline Chart Source: https://github.com/nimblemarkets/ntcharts/blob/v2/README.md Generates a waveline chart with a specified Y-axis range. It plots individual points and then draws the chart. ```go package main import ( "fmt" "github.com/NimbleMarkets/ntcharts/v2/canvas" "github.com/NimbleMarkets/ntcharts/v2/linechart/wavelinechart" ) func main() { wlc := wavelinechart.New(12, 10, wavelinechart.WithYRange(-3, 3)) wlc.Plot(canvas.Float64Point{1.0, 2.0}) wlc.Plot(canvas.Float64Point{3.0, -2.0}) wlc.Plot(canvas.Float64Point{5.0, 2.0}) wlc.Plot(canvas.Float64Point{7.0, -2.0}) wlc.Plot(canvas.Float64Point{9.0, 2.0}) wlc.Draw() fmt.Println(wlc.View()) } ``` -------------------------------- ### Bubble Tea Mouse Support Integration Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/README.md Shows how to integrate mouse event support into a chart using BubbleZone. Ensure the zone.Manager is set on the chart and its output is scanned in the View method. ```go zm := zone.NewManager() // Enable on chart bc.SetZoneManager(zm) // In View method, wrap output return zm.Scan(bc.View()) ``` -------------------------------- ### Heatmap Configuration Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Options for heatmaps, including color scale, value range, and axis ranges. ```go heatmap.WithColorScale(cs) ``` ```go heatmap.WithValueRange(min, max) ``` ```go heatmap.WithXYRange(minX, maxX, minY, maxY) ``` ```go heatmap.WithAutoXYRange() ``` -------------------------------- ### Bubble Tea Interface - Init Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/picture.md The standard Bubble Tea initialization method for the picture model. It returns an initial command, typically nil. ```APIDOC ## Init ```go func (m Model) Init() tea.Cmd ``` ### Description Standard Bubble Tea interface method for initialization. ### Returns - `tea.Cmd` - Initial command ``` -------------------------------- ### Create and Draw a Heat Map Source: https://github.com/nimblemarkets/ntcharts/blob/v2/README.md Generates a heatmap by calculating values for a 2D grid based on a mathematical function. It sets value and XY ranges before pushing points and drawing. ```go package main import ( "fmt" "math" "github.com/NimbleMarkets/ntcharts/v2/heatmap" ) func main() { hm := heatmap.New(20, 20, heatmap.WithValueRange(0, 1)) hm.SetXYRange(-1, 1, -1, 1) for x := float64(-1); x < 1.0; x += 1.0 / float64(hm.GraphWidth()) { for y := float64(-1); y < 1.0; y += 1.0 / float64(hm.GraphHeight()) { val := math.Sin(math.Sqrt(x*x + y*y)) hm.Push(heatmap.NewHeatPoint(x, y, val)) } } hm.Draw() fmt.Println(hm.View()) } ``` -------------------------------- ### Create and Draw a Sparkline Source: https://github.com/nimblemarkets/ntcharts/blob/v2/README.md Generates a sparkline by pushing multiple data points at once. The sparkline is then drawn to the console. ```go package main import ( "fmt" "github.com/NimbleMarkets/ntcharts/v2/sparkline" ) func main() { sl := sparkline.New(10, 5) sl.PushAll([]float64{7.81, 3.82, 8.39, 2.06, 4.19, 4.34, 6.83, 2.51, 9.21, 1.3}) sl.Draw() fmt.Println(sl.View()) } ``` -------------------------------- ### New Heat Map Constructor Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/heatmap.md Creates a new heat map with specified dimensions. Defaults are set for ranges and color scale. Use SetXYRange to adjust coordinate ranges and Push to add data points. ```go func New(w, h int, opts ...Option) Model ``` ```go hm := heatmap.New(40, 30) hm.SetXYRange(0, 10, 0, 10) for x := 0.0; x < 10; x += 0.5 { for y := 0.0; y < 10; y += 0.5 { val := math.Sin(math.Sqrt(x*x + y*y)) hm.Push(heatmap.NewHeatPoint(x, y, val)) } } hm.Draw() fmt.Println(hm.View()) ``` -------------------------------- ### Options Functions Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-index.md Provides functions to configure chart options during initialization. ```APIDOC ## Options Functions ### Description Functions used to configure chart options when creating a new chart instance. ### Options - `WithAutoMaxValue(b bool) Option`: Enables or disables automatic calculation of the maximum value. - `WithAutoBarWidth(b bool) Option`: Enables or disables automatic calculation of bar width. - `WithBarWidth(w int) Option`: Sets the width of the bars. - `WithBarGap(g int) Option`: Sets the gap between the bars. - `WithHorizontal(h bool) Option`: Sets the chart orientation to horizontal. - `WithShowAxis(show bool) Option`: Toggles the visibility of the chart axis. - `WithAxisStyle(s lipgloss.Style) Option`: Sets the style for the chart axis. - `WithLabelStyle(s lipgloss.Style) Option`: Sets the style for the chart labels. - `WithZoneManager(zm *zone.Manager) Option`: Sets the zone manager for interaction. ``` -------------------------------- ### Canvas Construction Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/canvas.md Details the available options for configuring a new canvas instance, such as styling, key mapping, event handling, and viewport dimensions. ```APIDOC ## Canvas Options ### Description Options that can be passed during canvas construction to customize its behavior and appearance. ### Available Options - `WithStyle(s lipgloss.Style)`: Sets the default cell style. - `WithKeyMap(k KeyMap)`: Sets the keyboard event map. - `WithUpdateHandler(h UpdateHandler)`: Sets a custom event handler. - `WithZoneManager(zm *zone.Manager)`: Enables mouse support. - `WithCursor(p Point)`: Sets the viewport cursor position. - `WithFocus()`: Initializes the canvas with focus enabled. - `WithContent(lines []string)`: Sets the initial content of the canvas. - `WithViewWidth(w int)`: Sets the viewport width. - `WithViewHeight(h int)`: Sets the viewport height. ### Example ```go c := canvas.New(80, 24, canvas.WithStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("6"))), canvas.WithFocus(), ) ``` ``` -------------------------------- ### Enable Mouse Support with BubbleZone Source: https://github.com/nimblemarkets/ntcharts/blob/v2/examples/quickstart/README.md Integrates BubbleZone for mouse support by creating a `zone.Manager` and assigning it to the chart. `chart.Focus()` is called to ensure the chart processes mouse and keyboard events. ```go // mouse support is enabled with BubbleZone zoneManager := zone.New() chart.SetZoneManager(zoneManager) chart.Focus() // set focus to process keyboard and mouse messages ``` -------------------------------- ### Kitty Mode with Resolution Control Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/picture.md Illustrates configuring the Picture model for Kitty graphics mode with custom ID, fit mode, and resolution factor. ```go cfg := picture.Config{ KittyID: 42, Fit: picture.FitFill, KittyResolutionFactor: 0.5, // half resolution, faster } pm := picture.NewWithConfig(cfg) cmd := pm.SetImage(img) ``` -------------------------------- ### Bar Chart Mouse Support Methods Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/barchart.md Methods for enabling and managing mouse event support using BubbleZone. ```go func (m *Model) SetZoneManager(zm *zone.Manager) func (m *Model) ZoneManager() *zone.Manager func (m *Model) ZoneID() string ``` -------------------------------- ### Create and Push Time Series Data Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Initializes a new time series line chart and pushes a time-based data point. Requires the timeserieslinechart package. ```go tslc := timeserieslinechart.New(50, 20) tslc.Push(timeserieslinechart.TimePoint{Time: time.Now(), Value: 42}) ``` -------------------------------- ### Sparkline Rendering Methods Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/sparkline.md Lists methods for rendering sparklines, including column-only and braille pattern options, and retrieving the rendered view. ```go func (m *Model) Draw() func (m *Model) DrawColumnsOnly() func (m *Model) DrawBraille() func (m *Model) View() string ``` -------------------------------- ### Picture Package Constructors and Methods Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-index.md Documentation for the Picture package, including its types, constants, constructors, and model methods for rendering images. ```APIDOC ## Picture Package ### Types - `PictureMode`: Rendering backend (Glyph or Kitty). - `FitMode`: Aspect ratio handling. - `FitAnchor`: Crop anchor for FitCover. - `Config`: Model configuration struct. - `Model`: Main picture model. ### Constants - `PictureGlyph` (0): Half-block ANSI mode. - `PictureKitty` (1): Kitty graphics mode. - `FitContain` (0): Letterbox (default). - `FitFill` (1): Stretch to fill. - `FitCover` (2): Crop to fill. - `AnchorCenter` (0): Center crop (default). - `AnchorTop` (1): Preserve top. - `AnchorBottom` (2): Preserve bottom. - `AnchorLeft` (3): Preserve left. - `AnchorRight` (4): Preserve right. - `DefaultKittyID` (43): Default Kitty layer ID. ### New ### Description Creates a new Picture model with default configuration. ### Signature `New() Model` ### Returns - `Model` - The new picture model. ### NewWithConfig ### Description Creates a new Picture model with a custom configuration. ### Signature `NewWithConfig(cfg Config) Model` ### Parameters - `cfg` (Config) - The configuration for the picture model. ### Returns - `Model` - The new picture model. ### SetImage ### Description Sets the image to be rendered by the Picture model. ### Method `SetImage(img image.Image) tea.Cmd` ### Parameters - `img` (image.Image) - The image to set. ### Returns - `tea.Cmd` - The command to execute. ### SetMode ### Description Sets the rendering mode for the Picture model (Glyph or Kitty). ### Method `SetMode(mode PictureMode) tea.Cmd` ### Parameters - `mode` (PictureMode) - The rendering mode to set. ### Returns - `tea.Cmd` - The command to execute. ### SetGeometry ### Description Sets the geometry (columns and rows) for the Picture model. ### Method `SetGeometry(cols, rows int) tea.Cmd` ### Parameters - `cols` (int) - The number of columns. - `rows` (int) - The number of rows. ### Returns - `tea.Cmd` - The command to execute. ### SetCellPixelSize ### Description Sets the pixel size of each cell in the Picture model. ### Method `SetCellPixelSize(w, h int) tea.Cmd` ### Parameters - `w` (int) - The width of a cell in pixels. - `h` (int) - The height of a cell in pixels. ### Returns - `tea.Cmd` - The command to execute. ### Init ### Description Initializes the Picture model for Bubble Tea. ### Method `Init() tea.Cmd` ### Returns - `tea.Cmd` - The command to execute. ### Update ### Description Updates the Picture model based on a Bubble Tea message. ### Method `Update(msg tea.Msg) (Model, tea.Cmd)` ### Parameters - `msg` (tea.Msg) - The incoming message. ### Returns - `(Model, tea.Cmd)` - The updated model and a command to execute. ### View ### Description Returns the string representation of the Picture model view. ### Method `View() string` ### Returns - `string` - The picture view as a string. ``` -------------------------------- ### Sparkline Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/api-reference/sparkline.md Lists available options for customizing sparkline behavior and appearance during construction. ```go WithAutoMaxValue(b bool) WithMaxValue(f float64) WithStyle(s lipgloss.Style) WithMaxInterpolationPoints(n int) ``` -------------------------------- ### Picture Fit Mode Options Source: https://github.com/nimblemarkets/ntcharts/blob/v2/_autodocs/REFERENCE.md Specifies how images should be scaled within their container. ```go FitContain, FitFill, FitCover ``` -------------------------------- ### Import ntcharts v1 Source: https://github.com/nimblemarkets/ntcharts/blob/v2/README.md Import the ntcharts library when using Bubble Tea v1. ```go import "github.com/NimbleMarkets/ntcharts" ```