css tachometer
mouse 320 · person cloud · link
Last update
2023-03-28
2023
03-28
«tachimetro in css»
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- perc, label = local_assigns[:perc].to_f, local_assigns[:label].to_s

- unless (0..1).include?(perc)
  - perc, label = 0, :err

- turns = (perc.to_f / 2).round(2)  # l'unita' di misura "turn" va da 0 a 5

.tachometer
  .gauge-pin
  .gauge-bar.bad
  .gauge-bar.nice
  .gauge-bar.ok
  .gauge-bar.needle{style: "transform: rotate(#{turns}turn)"}
    .pointer
  .gauge-inner
  .gauge-data
    %span= label
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
58
59
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
// https://github.com/JohnrBell/Gauge_CSS
// l'unita' di misura "turn" va da 0 a 5
$tm_base_size: 0.8vw;  // base gauge size

.tachometer {
  position: relative;
  overflow: hidden;
  text-align: center;
  width:  calc(16 * #{$tm_base_size});
  height: calc( 8 * #{$tm_base_size});

  // always print background colors -- https://caniuse.com/css-color-adjust
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;

  .gauge-bar {
    z-index: 2;
    position: absolute;
    background-color: #5664F9;
    width:  calc(16 * #{$tm_base_size});
    height: calc( 8 * #{$tm_base_size});
    top:    calc( 8 * #{$tm_base_size});
    margin-left: auto;
    margin-right: auto;
    border-radius: 0 0 calc(8 * #{$tm_base_size}) calc(8 * #{$tm_base_size});
    transform-origin: center top;
  }
  .gauge-bar.bad {
    z-index: 8;
    background-color: red;
    transform: rotate(.3turn);
  }
  .gauge-bar.nice {
    z-index: 7;
    background-color: yellow;
    transform: rotate(.4turn);
  }
  .gauge-bar.ok {
    z-index: 6;
    background-color: lime;
    transform: rotate(.5turn);
  }
  .gauge-bar.needle {
    z-index: 10;
    background-color: transparent;
    //transform: rotate(.35turn);  // NB: da impostare nel HTML

    .pointer {
      width: 50%;
      margin-top: -0.13rem;
      border-top: 0.26rem solid #888;
    }
  }
  .gauge-pin {
    z-index: 15;
    position: absolute;
    background-color: black;
    width: calc(2 * #{$tm_base_size});
    height: $tm_base_size;
    top: calc(7 * #{$tm_base_size});
    margin-left: calc(7 * #{$tm_base_size});
    margin-right: auto;
    border-radius: calc(10 * #{$tm_base_size}) calc(10 * #{$tm_base_size}) 0 0;
  }
  .gauge-inner {
    z-index: 9;
    position: absolute;
    background-color: white;
    width:  calc(10 * #{$tm_base_size});
    height: calc(5 * #{$tm_base_size});
    top: calc(3 * #{$tm_base_size});
    margin-left: calc(3 * #{$tm_base_size});
    margin-right: auto;
    border-radius: calc(10 * #{$tm_base_size}) calc(10 * #{$tm_base_size}) 0 0;
  }
  .gauge-data {
    z-index: 100;
    font-size: calc(1 * #{$tm_base_size});
    line-height: calc(1 * #{$tm_base_size});
    position: absolute;
    width:  calc(16 * #{$tm_base_size});
    height: calc(8 * #{$tm_base_size});
    top: calc(4 * #{$tm_base_size});
    margin-left: auto;
    margin-right: auto;

    span { font-weight: bold; }
  }
}