inkplot 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.codespellignore +0 -0
  3. data/.yamllint +16 -0
  4. data/CHANGELOG.md +16 -1
  5. data/LICENSE.txt +1 -1
  6. data/README.md +43 -67
  7. data/bench/inkplot.rb +12 -3
  8. data/docs/index.html +31 -0
  9. data/examples/gallery/01-line.svg +1 -1
  10. data/examples/gallery/02-line-gaps.svg +1 -1
  11. data/examples/gallery/03-series.svg +1 -1
  12. data/examples/gallery/09-histogram.svg +1 -0
  13. data/examples/gallery/12-time.svg +1 -0
  14. data/examples/gallery/13-annotations.svg +1 -0
  15. data/examples/gallery/14-dark-theme.svg +1 -0
  16. data/examples/gallery/15-category-labels.svg +1 -0
  17. data/examples/gallery/16-custom-bins.svg +1 -0
  18. data/examples/gallery/17-connected-gaps.svg +1 -0
  19. data/examples/gallery/18-step-series.svg +1 -0
  20. data/examples/gallery/19-combined-marks.svg +1 -0
  21. data/examples/gallery/20-scatter-sizes.svg +1 -0
  22. data/examples/gallery/README.md +7 -7
  23. data/examples/gallery.rb +26 -44
  24. data/lib/inkplot/core.rb +351 -146
  25. data/lib/inkplot/renderers/png.rb +390 -0
  26. data/lib/inkplot/renderers/svg.rb +3 -1
  27. data/lib/inkplot/version.rb +1 -1
  28. data/lib/inkplot.rb +3 -3
  29. data/sig/inkplot.rbs +7 -6
  30. data/test/snapshots/inkplot/01-line.png +0 -0
  31. data/test/snapshots/inkplot/02-line-gaps.png +0 -0
  32. data/test/snapshots/inkplot/03-series.png +0 -0
  33. data/test/snapshots/inkplot/04-scatter.png +0 -0
  34. data/test/snapshots/inkplot/05-bars.png +0 -0
  35. data/test/snapshots/inkplot/06-horizontal-bars.png +0 -0
  36. data/test/snapshots/inkplot/07-grouped-bars.png +0 -0
  37. data/test/snapshots/inkplot/08-stacked-bars.png +0 -0
  38. data/test/snapshots/inkplot/09-histogram.png +0 -0
  39. data/test/snapshots/inkplot/10-area.png +0 -0
  40. data/test/snapshots/inkplot/11-step.png +0 -0
  41. data/test/snapshots/inkplot/12-time.png +0 -0
  42. data/test/snapshots/inkplot/13-annotations.png +0 -0
  43. data/test/snapshots/inkplot/14-dark-theme.png +0 -0
  44. data/test/snapshots/inkplot/15-category-labels.png +0 -0
  45. data/test/snapshots/inkplot/16-custom-bins.png +0 -0
  46. data/test/snapshots/inkplot/17-connected-gaps.png +0 -0
  47. data/test/snapshots/inkplot/18-step-series.png +0 -0
  48. data/test/snapshots/inkplot/19-combined-marks.png +0 -0
  49. data/test/snapshots/inkplot/20-scatter-sizes.png +0 -0
  50. metadata +41 -18
  51. data/examples/gallery/09-signed-stack.svg +0 -1
  52. data/examples/gallery/12-histogram.svg +0 -1
  53. data/examples/gallery/13-log-scale.svg +0 -1
  54. data/examples/gallery/14-time-axis.svg +0 -1
  55. data/examples/gallery/15-category-order.svg +0 -1
  56. data/examples/gallery/16-dark-theme.svg +0 -1
  57. data/examples/gallery/17-annotations.svg +0 -1
  58. data/examples/gallery/18-combo.svg +0 -1
  59. data/examples/gallery/19-legend-position.svg +0 -1
  60. data/examples/gallery/20-long-categories.svg +0 -1
  61. data/lib/inkplot/renderers/raster.rb +0 -322
data/examples/gallery.rb CHANGED
@@ -31,69 +31,51 @@ module InkplotGallery
31
31
  p.bar(%w[Mon Tue Wed Thu Fri], [12, 16, 11, 19, 22], label: "Direct", stacked: true)
32
32
  p.bar(%w[Mon Tue Wed Thu Fri], [8, 9, 13, 10, 14], label: "Search", stacked: true)
33
33
  end],
34
- ["09-signed-stack", Inkplot.plot(title: "Daily net change") do |p|
35
- p.bar(%w[Mon Tue Wed Thu Fri], [8, -4, 5, -2, 9], label: "New", stacked: true)
36
- p.bar(%w[Mon Tue Wed Thu Fri], [3, -6, 2, -5, 4], label: "Removed", stacked: true)
37
- end],
34
+ ["09-histogram", Inkplot.histogram([12, 14, 15, 15, 16, 18, 19, 20, 22, 24, 25, 31, 35, 42], title: "Request latency", bins: :auto, x_label: "ms")],
38
35
  ["10-area", Inkplot.plot(title: "Build time over a release") { |p| p.area((1..8).to_a, [25, 29, 27, 38, 36, 44, 40, 51], label: "Seconds") }],
39
36
  ["11-step", Inkplot.plot(title: "Queue depth") { |p| p.step((0..7).to_a, [3, 3, 5, 5, 4, 8, 8, 2], label: "Jobs") }],
40
- ["12-histogram", Inkplot.histogram([8, 9, 10, 10, 11, 12, 12, 13, 14, 15, 17, 18, 22, 25, 31, 33], bins: :auto, title: "Response time", x_label: "Milliseconds")],
41
- ["13-log-scale", Inkplot.plot(title: "Growth on a log scale") do |p|
42
- p.y_axis(scale: :log, min: 1)
43
- p.line((0..5).to_a, [1, 3, 9, 27, 81, 243])
44
- end],
45
- ["14-time-axis", Inkplot.plot(title: "Hourly requests") do |p|
46
- p.x_axis(label: "UTC", type: :time)
47
- p.line((0..6).map do |hour|
48
- Time.utc(2026, 9, 24, hour * 4)
49
- end, [12, 17, 15, 24, 31, 27, 38])
37
+ ["12-time", Inkplot.plot(title: "Monthly active users") do |p|
38
+ p.x_axis(label: "Month", type: :time)
39
+ p.line((0..11).map { |month| Time.utc(2026, month + 1, 1) }, [34, 37, 36, 42, 48, 51, 49, 57, 62, 66, 72, 79], label: "Users")
50
40
  end],
51
- ["15-category-order", Inkplot.plot(title: "Deployment health") do |p|
52
- p.x_axis(order: %w[dev staging production])
53
- p.line(%w[production dev staging], [98, 100, 99], label: "Success %")
41
+ ["13-annotations", Inkplot.plot(title: "Release performance") do |p|
42
+ p.line(%w[v1.0 v1.1 v1.2 v1.3], [34, 42, 39, 55], label: "Requests/s")
43
+ p.hline(45, label: "Target", color: "#D55E00")
44
+ p.vline("v1.2", label: "Cache enabled", color: "#0072B2")
45
+ p.annotate("v1.3", 55, "peak", anchor: :end)
54
46
  end],
55
- ["16-dark-theme", Inkplot.plot(title: "Dark dashboard", theme: :dark) do |p|
56
- p.line((1..7).to_a, [12, 18, 16, 24, 22, 30, 35], label: "Throughput")
57
- p.hline(20, label: "Target", color: :orange)
47
+ ["14-dark-theme", Inkplot.plot(title: "Dark theme", theme: :dark) do |p|
48
+ p.line(%w[Mon Tue Wed Thu Fri], [12, 16, 14, 22, 19], label: "Deploys")
49
+ p.line(%w[Mon Tue Wed Thu Fri], [8, 9, 13, 12, 18], label: "Rollbacks")
58
50
  end],
59
- ["17-annotations", Inkplot.plot(title: "Service level objective") do |p|
60
- p.line((1..7).to_a, [32, 28, 41, 36, 30, 24, 27])
61
- p.hline(35, label: "SLO", color: :red)
62
- p.vline(4, color: :blue)
63
- p.text(4.1, 42, "deploy")
51
+ ["15-category-labels", Inkplot.bar((1..18).to_h { |index| ["Region #{index} very long", ((index * 7) % 31) + 4] }, title: "Regional volume")],
52
+ ["16-custom-bins", Inkplot.histogram([2, 4, 5, 7, 9, 11, 14, 18, 21, 24, 28, 35], bins: [0, 10, 20, 30, 40], title: "Custom latency ranges")],
53
+ ["17-connected-gaps", Inkplot.plot(title: "Bridge short gaps") do |p|
54
+ p.line((0..8).to_a, [2, 3, nil, 5, 6, nil, 4, 7, 8], label: "Estimated", gaps: :connect)
64
55
  end],
65
- ["18-combo", Inkplot.plot(title: "Sales and conversion") do |p|
66
- p.bar(%w[Jan Feb Mar Apr], [24, 30, 27, 42], label: "Orders")
67
- p.line(%w[Jan Feb Mar Apr], [2.8, 3.1, 3.0, 3.8], label: "Conversion %", color: :red)
56
+ ["18-step-series", Inkplot.plot(title: "Rate limit changes") do |p|
57
+ p.step((0..6).to_a, [50, 50, 75, 75, 100, 100, 125], label: "Requests/min")
58
+ p.hline(100, label: "Current limit")
68
59
  end],
69
- ["19-legend-position", Inkplot.plot(title: "Legend below", width: 640, height: 380) do |p|
70
- p.line((1..5).to_a, [3, 5, 4, 7, 6], label: "Actual")
71
- p.line((1..5).to_a, [2, 3, 4, 5, 6], label: "Plan")
72
- p.legend(position: :bottom_left)
60
+ ["19-combined-marks", Inkplot.plot(title: "Quarterly sales") do |p|
61
+ p.bar(%w[Q1 Q2 Q3 Q4], [16, 20, 18, 27], label: "Previous")
62
+ p.line(%w[Q1 Q2 Q3 Q4], [19, 25, 24, 34], label: "Current")
73
63
  end],
74
- ["20-long-categories", Inkplot.plot(title: "Labels rotate when needed") do |p|
75
- p.x_axis(order: ["North America", "South America", "Europe", "Asia Pacific"])
76
- p.bar(["North America", "South America", "Europe", "Asia Pacific"], [22, 14, 31, 27])
64
+ ["20-scatter-sizes", Inkplot.plot(title: "Session length vs. pages") do |p|
65
+ p.scatter([12, 18, 21, 27, 32, 38, 44], [2, 3, 5, 4, 7, 8, 10], size: [1, 2, 3, 2, 5, 6, 8], label: "Sessions")
66
+ p.annotate(38, 8, "engaged")
77
67
  end]
78
68
  ]
79
69
  end
80
70
  end
81
71
 
82
72
  if $PROGRAM_NAME == __FILE__
83
- update_snapshots = ARGV.delete("--update-snapshots")
84
- raise ArgumentError, "usage: ruby examples/gallery.rb [--update-snapshots]" unless ARGV.empty?
73
+ raise ArgumentError, "usage: ruby examples/gallery.rb" unless ARGV.empty?
85
74
 
86
75
  svg_dir = File.expand_path("gallery", __dir__)
87
76
  FileUtils.mkdir_p(svg_dir)
88
77
 
89
78
  InkplotGallery.charts.each do |name, chart|
90
79
  File.write(File.join(svg_dir, "#{name}.svg"), chart.to_svg)
91
- next unless update_snapshots
92
-
93
- require "tessel"
94
- require "glyphic"
95
- png_dir = File.expand_path("../spec/snapshots", __dir__)
96
- FileUtils.mkdir_p(png_dir)
97
- File.binwrite(File.join(png_dir, "#{name}.png"), Tessel::PNG.encode(chart.to_image))
98
80
  end
99
81
  end