Module: Spoom::Coverage::D3

Extended by:
T::Sig
Defined in:
lib/spoom/coverage/d3.rb,
lib/spoom/coverage/d3/pie.rb,
lib/spoom/coverage/d3/base.rb,
lib/spoom/coverage/d3/timeline.rb,
lib/spoom/coverage/d3/circle_map.rb

Defined Under Namespace

Classes: Base, CircleMap, ColorPalette, Pie, Timeline

Constant Summary collapse

COLOR_IGNORE =
"#999"
COLOR_FALSE =
"#db4437"
COLOR_TRUE =
"#0f9d58"
COLOR_STRICT =
"#0a7340"
COLOR_STRONG =
"#064828"

Class Method Summary collapse

Class Method Details

.header_script(palette) ⇒ Object


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/spoom/coverage/d3.rb', line 60

def self.header_script(palette)
  <<~JS
    var parseDate = d3.timeParse("%s");

    function strictnessColor(strictness) {
      switch(strictness) {
        case "ignore":
          return "#{palette.ignore}";
        case "false":
          return "#{palette.false}";
        case "true":
          return "#{palette.true}";
        case "strict":
          return "#{palette.strict}";
        case "strong":
          return "#{palette.strong}";
      }
      return "#{palette.false}";
    }

    function toPercent(value, sum) {
      return value ? Math.round(value * 100 / sum) : 0;
    }

    var tooltip = d3.select("body")
      .append("div")
        .append("div")
          .attr("class", "tooltip");

    function moveTooltip(d) {
      return tooltip
        .style("left", (d3.event.pageX + 20) + "px")
        .style("top", (d3.event.pageY) + "px")
    }

    #{Pie.header_script}
    #{CircleMap.header_script}
    #{Timeline.header_script}
  JS
end

.header_styleObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/spoom/coverage/d3.rb', line 20

def self.header_style
  <<~CSS
    svg {
      width: 100%;
      height: 100%;
    }

    .tooltip {
      font: 12px Arial, sans-serif;
      color: #fff;
      text-align: center;
      background: rgba(0, 0, 0, 0.6);
      padding: 5px;
      border: 0px;
      border-radius: 4px;
      position: absolute;
      top: 0;
      left: 0;
      opacity: 0;
    }

    .label {
      font: 14px Arial, sans-serif;
      font-weight: bold;
      fill: #fff;
      text-anchor: middle;
      pointer-events: none;
    }

    .label .small {
      font-size: 10px;
    }

    #{Pie.header_style}
    #{CircleMap.header_style}
    #{Timeline.header_style}
  CSS
end