styles

package
v1.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package styles defines visual styles for tower rendering.

Overview

Stacktower supports multiple visual styles that control how blocks, edges, text, and interactive elements are rendered. This package provides:

  • Style: The interface that all styles implement
  • Simple: A clean, minimal style with solid colors
  • [handdrawn]: An XKCD-inspired hand-drawn aesthetic (in subpackage)

The Style Interface

All styles implement Style, which provides methods for rendering each visual element:

  • RenderDefs: SVG <defs> section (filters, patterns, gradients)
  • RenderBlock: Individual block shapes
  • RenderEdge: Dependency edges (when enabled)
  • RenderText: Block labels
  • RenderPopup: Hover popup content

Simple Style

Simple provides a clean, professional appearance with:

  • Solid fill colors with subtle gradients
  • Clean rectangular blocks
  • Standard sans-serif fonts

Usage:

svg := sink.RenderSVG(layout, sink.WithStyle(styles.Simple{}))

Hand-Drawn Style

The [handdrawn] subpackage provides the signature XKCD-inspired aesthetic:

  • Wobbly, imperfect lines (via SVG filters)
  • Rough, sketchy fills
  • Comic Sans-style fonts
  • Textured backgrounds
  • "Brittle" visual treatment for at-risk packages

The hand-drawn style uses a seed for reproducible randomness:

style := handdrawn.New(42)  // Seed for consistent wobbly lines
svg := sink.RenderSVG(layout, sink.WithStyle(style))

Block Data

Styles receive Block structs containing all information needed for rendering:

  • ID, Label: Identification and display text
  • X, Y, W, H: Position and dimensions
  • CX, CY: Center coordinates for text placement
  • URL: Optional link target
  • Popup: Metadata for hover popups
  • Brittle: Flag for visual warning treatment

Creating Custom Styles

To create a custom style:

  1. Implement the Style interface
  2. Use the provided Block and Edge data for positioning
  3. Write SVG elements to the provided bytes.Buffer

Example structure:

type MyStyle struct {
    Color string
}

func (s MyStyle) RenderBlock(buf *bytes.Buffer, b Block) {
    fmt.Fprintf(buf, `<rect x="%.1f" y="%.1f" width="%.1f" height="%.1f" fill="%s"/>`,
        b.X, b.Y, b.W, b.H, s.Color)
}

[handdrawn]: github.com/stacktower-io/stacktower/pkg/core/render/tower/styles/handdrawn

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EscapeXML

func EscapeXML(s string) string

func FontSize

func FontSize(b Block) float64

func FontSizeRotated

func FontSizeRotated(b Block) float64

func ShouldRotate

func ShouldRotate(b Block) bool

func TruncateLabel

func TruncateLabel(b Block, rotated bool) string

func WrapURL

func WrapURL(buf *bytes.Buffer, url string, fn func())

Types

type Block

type Block struct {
	ID           string     // Node identifier
	Label        string     // Display text
	X, Y, W, H   float64    // Position and dimensions
	CX, CY       float64    // Center coordinates (for text)
	URL          string     // Optional link target
	Popup        *PopupData // Hover popup content (nil if disabled)
	Brittle      bool       // Whether to apply brittle/warning styling
	VulnSeverity string     // Indicates the maximum vulnerability severity for this package
	License      string     // License name (e.g., "MIT", "GPL-3.0")
	LicenseRisk  string     // License risk classification ("copyleft","weak-copyleft","unknown","")
}

Block contains all data needed to render a single tower block.

type Edge

type Edge struct {
	FromID, ToID   string  // Connected node IDs
	X1, Y1, X2, Y2 float64 // Line coordinates
}

Edge contains positioning data for rendering a dependency edge.

type PopupData

type PopupData struct {
	Description  string // Package description
	Stars        int    // GitHub stars (0 if unknown)
	LastCommit   string // Last commit date
	LastRelease  string // Last release date
	Archived     bool   // Repository archived flag
	Brittle      bool   // Package flagged as brittle
	License      string // License name (e.g., "MIT", "GPL-3.0")
	LicenseRisk  string // License risk classification
	VulnSeverity string // Maximum vulnerability severity (e.g., "critical", "high")
}

PopupData holds metadata displayed in hover popups.

type Simple

type Simple struct{}

func (Simple) RenderBlock

func (Simple) RenderBlock(buf *bytes.Buffer, b Block)

func (Simple) RenderDefs

func (Simple) RenderDefs(*bytes.Buffer)

func (Simple) RenderEdge

func (Simple) RenderEdge(buf *bytes.Buffer, e Edge)

func (Simple) RenderFlags

func (Simple) RenderFlags(buf *bytes.Buffer, b Block)

func (Simple) RenderPopup

func (Simple) RenderPopup(*bytes.Buffer, Block)

func (Simple) RenderText

func (Simple) RenderText(buf *bytes.Buffer, b Block)

type Style

type Style interface {
	// RenderDefs writes SVG <defs> content (filters, patterns, gradients).
	RenderDefs(buf *bytes.Buffer)
	// RenderBlock writes the SVG for a single block shape.
	RenderBlock(buf *bytes.Buffer, b Block)
	// RenderFlags writes the SVG for a block's security flags (license, vuln).
	// Flags are rendered separately so they can be drawn on top of all blocks.
	RenderFlags(buf *bytes.Buffer, b Block)
	// RenderEdge writes the SVG for a dependency edge line.
	RenderEdge(buf *bytes.Buffer, e Edge)
	// RenderText writes the SVG for a block's label text.
	RenderText(buf *bytes.Buffer, b Block)
	// RenderPopup writes the SVG for a block's hover popup.
	RenderPopup(buf *bytes.Buffer, b Block)
}

Style defines the visual appearance for tower rendering. Implementations control how blocks, edges, text, and popups are drawn.

Directories

Path Synopsis
Package handdrawn provides an XKCD-inspired hand-drawn visual style.
Package handdrawn provides an XKCD-inspired hand-drawn visual style.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL