trackplot 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1640bf80db9c399eac8aeb2df85355ad008dec2b91c3b7e3a8c87fa1dfaaddc
4
- data.tar.gz: 88a4e3de4b79d903085690c6dd7bcd9795f9f574fc083d1b68b03e0eba7a19bc
3
+ metadata.gz: dd81256294542897c6d23b5f3f1e6a44ec163ddcfb2e342299b8ece69267b0f7
4
+ data.tar.gz: 8ffb1cb2f0d060a460a4f2e16b547ba6a495d6f1d756f043e28b2e01e5a178ca
5
5
  SHA512:
6
- metadata.gz: 90143b3d120b726acf7fe579314636d8e7526de86d34d384f053663ddee6eb41497176aa6d670c28c8b2d1c52a7a6e6b516d3fd5d9d433287597b7c1360746a1
7
- data.tar.gz: 58cb42158c1d86bf600e93a1c7ae0792e4cbb270e1d9177d6d96da84d90ae41070c686a72a0fbcad98ff026fb3d4673d61d0977095807bb6b3ee59e6f9ec433a
6
+ metadata.gz: a200da76cac37a0676045c46335fb3639f9f132d8bda06c0fa93f2d4cc3aa6eb29ea29b63e9581a6bb9831e4b935b58c8f1714bca49fbbcae076b9380bc31f1e
7
+ data.tar.gz: 7515dbf870e6174984ea2a5f8ca4fa348a2727ed0694817e9e05e98a34ac773131face3e50141e1c95dd3edf6904423f93967fb76b506e248dce22629507bf06
@@ -17,6 +17,7 @@ export interface ThemeConfig {
17
17
  export interface LineConfig {
18
18
  type: "line";
19
19
  data_key: string;
20
+ name?: string;
20
21
  color?: string;
21
22
  stroke_width?: number;
22
23
  curve?: boolean;
@@ -29,6 +30,7 @@ export interface LineConfig {
29
30
  export interface BarConfig {
30
31
  type: "bar";
31
32
  data_key: string;
33
+ name?: string;
32
34
  color?: string;
33
35
  opacity?: number;
34
36
  radius?: number;
@@ -39,6 +41,7 @@ export interface BarConfig {
39
41
  export interface AreaConfig {
40
42
  type: "area";
41
43
  data_key: string;
44
+ name?: string;
42
45
  color?: string;
43
46
  opacity?: number;
44
47
  stroke_width?: number;
@@ -50,6 +53,7 @@ export interface AreaConfig {
50
53
  export interface ScatterConfig {
51
54
  type: "scatter";
52
55
  data_key: string;
56
+ name?: string;
53
57
  x_key?: string;
54
58
  color?: string;
55
59
  opacity?: number;
@@ -68,6 +72,7 @@ export interface PieConfig {
68
72
  export interface RadarConfig {
69
73
  type: "radar";
70
74
  data_key: string;
75
+ name?: string;
71
76
  color?: string;
72
77
  opacity?: number;
73
78
  stroke_width?: number;
@@ -78,6 +83,7 @@ export interface RadarConfig {
78
83
  export interface HorizontalBarConfig {
79
84
  type: "horizontal_bar";
80
85
  data_key: string;
86
+ name?: string;
81
87
  color?: string;
82
88
  opacity?: number;
83
89
  radius?: number;
@@ -60,6 +60,10 @@ function sanitizeClass(str) {
60
60
  return String(str).replace(/[^a-zA-Z0-9_-]/g, "_")
61
61
  }
62
62
 
63
+ function seriesLabel(s) {
64
+ return s.name || s.data_key
65
+ }
66
+
63
67
  function getXKey(components) {
64
68
  const xAxis = components.find(c => c.type === "axis" && c.direction === "x")
65
69
  return xAxis ? xAxis.data_key : null
@@ -510,7 +514,7 @@ function renderLine(g, data, xScale, yScale, xKey, series, animate, chartElement
510
514
  .attr("stroke", series.color)
511
515
  .attr("stroke-width", 2)
512
516
  .style("cursor", "pointer")
513
- .attr("aria-label", d => `${series.data_key}: ${d[series.data_key]}`)
517
+ .attr("aria-label", d => `${seriesLabel(series)}: ${d[series.data_key]}`)
514
518
 
515
519
  if (animate) {
516
520
  dots.attr("r", 0).transition().delay(DURATION).duration(300).attr("r", dotR)
@@ -582,7 +586,7 @@ function renderBars(g, data, xScale, yScale, xKey, barSeries, animate, chartElem
582
586
  .attr("opacity", series.opacity ?? 1)
583
587
  .attr("y", animate ? yScale(0) : d => yScale(+d[series.data_key] || 0))
584
588
  .attr("height", animate ? 0 : d => Math.max(0, yScale(0) - yScale(+d[series.data_key] || 0)))
585
- .attr("aria-label", d => `${series.data_key}: ${d[series.data_key]}`)
589
+ .attr("aria-label", d => `${seriesLabel(series)}: ${d[series.data_key]}`)
586
590
  .style("cursor", "pointer")
587
591
  .transition().duration(animate ? DURATION : 0).ease(EASE)
588
592
  .delay((_, i) => animate ? i * 40 : 0)
@@ -637,7 +641,7 @@ function renderStackedBars(g, data, xScale, yScale, xKey, stackedSeries, animate
637
641
  .attr("opacity", series.opacity ?? 1)
638
642
  .attr("y", animate ? yScale(0) : d => yScale(d[1]))
639
643
  .attr("height", animate ? 0 : d => Math.max(0, yScale(d[0]) - yScale(d[1])))
640
- .attr("aria-label", (d, i) => `${series.data_key}: ${data[i][series.data_key]}`)
644
+ .attr("aria-label", (d, i) => `${seriesLabel(series)}: ${data[i][series.data_key]}`)
641
645
  .style("cursor", "pointer")
642
646
  .transition().duration(animate ? DURATION : 0).ease(EASE)
643
647
  .delay((_, i) => animate ? i * 40 : 0)
@@ -771,7 +775,7 @@ function renderScatter(g, data, xScale, yScale, xKey, series, animate, chartElem
771
775
  .attr("fill-opacity", series.opacity || 0.7)
772
776
  .attr("stroke", "white")
773
777
  .attr("stroke-width", 1.5)
774
- .attr("aria-label", d => `${series.data_key}: ${d[series.data_key]}`)
778
+ .attr("aria-label", d => `${seriesLabel(series)}: ${d[series.data_key]}`)
775
779
  .style("cursor", "pointer")
776
780
 
777
781
  if (animate) {
@@ -829,7 +833,7 @@ function renderHorizontalBars(g, data, xScale, yScale, yKey, barSeries, animate,
829
833
  .attr("ry", radius)
830
834
  .attr("fill", series.color)
831
835
  .attr("opacity", series.opacity ?? 1)
832
- .attr("aria-label", d => `${series.data_key}: ${d[series.data_key]}`)
836
+ .attr("aria-label", d => `${seriesLabel(series)}: ${d[series.data_key]}`)
833
837
  .style("cursor", "pointer")
834
838
  .attr("width", animate ? 0 : d => Math.max(0, xScale(+d[series.data_key] || 0)))
835
839
  .transition().duration(animate ? DURATION : 0).ease(EASE)
@@ -1468,7 +1472,7 @@ function setupCartesianTooltip(element, g, data, xScale, yScale, xKey, series, c
1468
1472
  const formatted = isNaN(+val) ? val : fmtValue(+val)
1469
1473
  html += `<div style="display:flex;align-items:center;gap:8px">`
1470
1474
  html += `<span style="width:8px;height:8px;border-radius:50%;background:${s.color};flex-shrink:0"></span>`
1471
- html += `<span style="color:${t.text_color}">${s.data_key}</span>`
1475
+ html += `<span style="color:${t.text_color}">${seriesLabel(s)}</span>`
1472
1476
  html += `<span style="font-weight:500;color:${t.tooltip_text};margin-left:auto;padding-left:12px">${formatted}</span>`
1473
1477
  html += `</div>`
1474
1478
  }
@@ -1554,7 +1558,7 @@ function setupRadarTooltip(element, g, data, radarSeries, labelKey, config, them
1554
1558
  let html = `<div style="font-weight:600;color:${t.tooltip_text};margin-bottom:2px">${cat}</div>`
1555
1559
  html += `<div style="display:flex;align-items:center;gap:8px">`
1556
1560
  html += `<span style="width:8px;height:8px;border-radius:50%;background:${series.color};flex-shrink:0"></span>`
1557
- html += `<span style="color:${t.text_color}">${series.data_key}</span>`
1561
+ html += `<span style="color:${t.text_color}">${seriesLabel(series)}</span>`
1558
1562
  html += `<span style="font-weight:500;color:${t.tooltip_text};margin-left:auto;padding-left:12px">${d[series.data_key]}</span>`
1559
1563
  html += `</div>`
1560
1564
  tooltip.innerHTML = html
@@ -1685,7 +1689,7 @@ function renderLegend(element, items, config, theme) {
1685
1689
  background: item.color, flexShrink: "0"
1686
1690
  })
1687
1691
  const label = document.createElement("span")
1688
- label.textContent = item.data_key
1692
+ label.textContent = seriesLabel(item)
1689
1693
  label.style.color = t.text_color
1690
1694
 
1691
1695
  el.appendChild(dot)
@@ -2000,7 +2004,7 @@ class Chart {
2000
2004
  const formatted = isNaN(+val) ? val : fmtValue(+val)
2001
2005
  html += `<div style="display:flex;align-items:center;gap:8px">`
2002
2006
  html += `<span style="width:8px;height:8px;border-radius:50%;background:${s.color};flex-shrink:0"></span>`
2003
- html += `<span style="color:${t.text_color}">${s.data_key}</span>`
2007
+ html += `<span style="color:${t.text_color}">${seriesLabel(s)}</span>`
2004
2008
  html += `<span style="font-weight:500;color:${t.tooltip_text};margin-left:auto;padding-left:12px">${formatted}</span>`
2005
2009
  html += `</div>`
2006
2010
  }
@@ -17,7 +17,8 @@ module Trackplot
17
17
  opacity: options[:opacity] || 0.3,
18
18
  stroke_width: options[:stroke_width] || 2,
19
19
  stack: options[:stack],
20
- y_axis: options[:y_axis]&.to_s
20
+ y_axis: options[:y_axis]&.to_s,
21
+ name: options[:name] || data_key
21
22
  }.compact
22
23
  end
23
24
  end
@@ -16,7 +16,8 @@ module Trackplot
16
16
  opacity: options[:opacity],
17
17
  radius: options[:radius] || 4,
18
18
  stack: options[:stack],
19
- y_axis: options[:y_axis]&.to_s
19
+ y_axis: options[:y_axis]&.to_s,
20
+ name: options[:name] || data_key
20
21
  }.compact
21
22
  end
22
23
  end
@@ -14,7 +14,8 @@ module Trackplot
14
14
  data_key: data_key,
15
15
  color: options[:color],
16
16
  opacity: options[:opacity],
17
- radius: options[:radius] || 4
17
+ radius: options[:radius] || 4,
18
+ name: options[:name] || data_key
18
19
  }.compact
19
20
  end
20
21
  end
@@ -18,7 +18,8 @@ module Trackplot
18
18
  stroke_width: options[:stroke_width] || 2,
19
19
  dot: options.fetch(:dot, true),
20
20
  dot_size: options[:dot_size] || 4,
21
- y_axis: options[:y_axis]&.to_s
21
+ y_axis: options[:y_axis]&.to_s,
22
+ name: options[:name] || data_key
22
23
  }.compact
23
24
  end
24
25
  end
@@ -16,7 +16,8 @@ module Trackplot
16
16
  opacity: options[:opacity] || 0.15,
17
17
  stroke_width: options[:stroke_width] || 2,
18
18
  dot: options.fetch(:dot, true),
19
- dot_size: options[:dot_size] || 4
19
+ dot_size: options[:dot_size] || 4,
20
+ name: options[:name] || data_key
20
21
  }.compact
21
22
  end
22
23
  end
@@ -17,7 +17,8 @@ module Trackplot
17
17
  dot_size: options[:dot_size] || 5,
18
18
  opacity: options[:opacity] || 0.7,
19
19
  shape: options[:shape] || "circle",
20
- y_axis: options[:y_axis]&.to_s
20
+ y_axis: options[:y_axis]&.to_s,
21
+ name: options[:name] || data_key
21
22
  }.compact
22
23
  end
23
24
  end
@@ -1,3 +1,3 @@
1
1
  module Trackplot
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trackplot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eagerworks