add playground for testing stuff, add https://github.com/sathomas/material-gauge as gauge meter

This commit is contained in:
Marcus 2024-05-02 15:54:10 +02:00
parent 9116336b05
commit 7c072735ad
7 changed files with 388 additions and 0 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
KiCad/CanGrow/CanGrow-backups
KiCad/CanGrow/CanGrow.kicad_sch-bak
KiCad/CanGrow/fp-info-cache

View File

@ -0,0 +1,7 @@
Copyright (c) 2015 Stephen Thomas
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,69 @@
A simple [Material Design](https://www.google.com/design/spec/material-design/introduction.html) gauge control implemented in pure CSS/HTML. Includes a JavaScript implementation to change the gauge value dynamically.
Origin: https://github.com/sathomas/material-gauge
![](example.png)
Check out the [live example](http://sathomas.me/material-gauge/).
The basic markup for the gauge is as follows:
```
<div class="gauge" id="myGauge">
<div class="gauge__container">
<div class="gauge__marker"></div>
<div class="gauge__background"></div>
<div class="gauge__center"></div>
<div class="gauge__data"></div>
<div class="gauge__needle"></div>
</div>
<div class="gauge__labels mdl-typography__headline">
<span class="gauge__label--low">No</span>
<span class="gauge__label--spacer"></span>
<span class="gauge__label--high">Yes</span>
</div>
</div>
```
The gauge value is specified by `transform:` property on both the `.gauge__data` and `.gauge__needle` elements. The value for the rotation is
`0.5 × X - 0.5` turns, where `X` ranges from 0 (left-most position) to 1 (right-most position). For example, to set the gauge at "3/4 full", you can specify the `transform` as
```
.gauge__data {
-webkit-transform: rotate(-0.125turn);
-moz-transform: rotate(-0.125turn);
-ms-transform: rotate(-0.125turn);
-o-transform: rotate(-0.125turn);
transform: rotate(-0.125turn);
}
.gauge__needle {
-webkit-transform: rotate(-0.125turn);
-moz-transform: rotate(-0.125turn);
-ms-transform: rotate(-0.125turn);
-o-transform: rotate(-0.125turn);
transform: rotate(-0.125turn);
}
```
As the example indicates, you probably want to use vendor prefixes for maximum compatibility.
If you wish, you can use the included JavaScript component to set and update the gauge value. The component API is quite simple. First, create a new object:
var gauge = new Gauge();
You can optionally pass a DOM element (constructed as above) to the constructor:
var gauge = new Gauge(document.getElementById("myGauge"));
If you don't pass the DOM element as a constructor parameter, you can initialize it later using the `element()` method:
gauge.element(document.getElementById("myGauge"));
> Note that the component will not construct the DOM element itself. You must supply a pre-constructed element with the sub-elements indicated above.
Once you have an initialized constructor, set the value (between 0 and 1) using the `value()` method:
gauge.value(0.75);
As a final enhancement, if you're going to update the gauge live on the page, you can add the `gauge--liveupdate` class to the parent element. This will enable a nice CSS-based animation for value updates.

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -0,0 +1,51 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Material Design Gauge</title>
<meta name="description"
content="Simple Material Design gauge control implemented in pure CSS/HTML">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="material-gauge.css">
<style>
body {
background-color: #1d211e;
color: #cae0d0;
font-family: Roboto, Helvetica, Arial, sans-serif;
font-size: 24px;
font-weight: normal;
height: 32px;
letter-spacing: normal;
line-height: 32px;
padding-top: 100px;
}
</style>
</head>
<body>
<div class="gauge gauge--liveupdate" id="gauge">
<div class="gauge__container">
<div class="gauge__marker"></div>
<div class="gauge__background"></div>
<div class="gauge__center"></div>
<div class="gauge__data"></div>
<div class="gauge__needle"></div>
</div>
<div class="gauge__labels mdl-typography__headline">
<span class="gauge__label--low">No</span>
<span class="gauge__label--spacer"></span>
<span class="gauge__label--high">Yes</span>
</div>
</div>
<script src="material-gauge.js"></script>
<script>
var gauge = new Gauge(document.getElementById("gauge"));
gauge.value(0.75);
</script>
</body>
</html>

View File

@ -0,0 +1,192 @@
/*
* #### Gauge Component
*
* The standard markup for the component is:
*
* <div class="gauge">
* <div class="gauge__container">
* <div class="gauge__marker"></div>
* <div class="gauge__background"></div>
* <div class="gauge__center"></div>
* <div class="gauge__data"></div>
* <div class="gauge__needle"></div>
* </div>
* <div class="gauge__labels">
* <span class="gauge__label--low">No</span>
* <span class="gauge__label--spacer"></span>
* <span class="gauge__label--high">Yes</span>
* </div>
* </div>
*/
/*
* First define all of the relevant rules that aren't dependent
* on the size of the gauge. We want to collect the size-depenent
* rules in one place to make it easier to adjust the size.
*/
.gauge {
position: relative;
}
.gauge__container {
margin: 0;
padding: 0;
position: absolute;
left: 50%;
overflow: hidden;
text-align: center;
-webkit-transform: translateX(-50%);
-moz-transform: translateX(-50%);
-ms-transform: translateX(-50%);
-o-transform: translateX(-50%);
transform: translateX(-50%);
}
.gauge__background {
z-index: 0;
position: absolute;
background-color: #C5CAE9;
top: 0;
border-radius: 300px 300px 0 0;
}
.gauge__data {
z-index: 1;
position: absolute;
background-color: #3F51B5;
margin-left: auto;
margin-right: auto;
border-radius: 300px 300px 0 0;
-webkit-transform-origin: center bottom;
-moz-transform-origin: center bottom;
-ms-transform-origin: center bottom;
-o-transform-origin: center bottom;
transform-origin: center bottom;
}
.gauge__center {
z-index: 2;
position: absolute;
background-color: #1d211e;
margin-right: auto;
border-radius: 300px 300px 0 0;
}
.gauge__marker {
z-index: 3;
background-color: #fff;
position: absolute;
width: 1px;
}
.gauge__needle {
z-index: 4;
background-color: #E91E63;
height: 3px;
position: absolute;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-ms-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
.gauge__labels {
display: table;
margin: 0 auto;
position: relative;
}
.gauge__label--low {
display: table-cell;
text-align: center;
}
.gauge__label--spacer {
display: table-cell;
}
.gauge__label--high {
display: table-cell;
text-align: center;
}
/*
* Now define the rules that depend on the size of
* the gauge. We start with sizing for a small mobile
* device.
*/
.gauge { height: calc(120px + 3em); }
.gauge__container { width: 240px; height: 120px; }
.gauge__marker { height: 120px; left: 119.5px; }
.gauge__background { width: 240px; height: 120px; }
.gauge__center { width: 144px; height: 72px; top: 48px; margin-left: 48px; }
.gauge__data { width: 240px; height: 120px; }
.gauge__needle { left: 120px; top: 117px; width: 120px; }
.gauge__labels { top: 120px; width: 240px; }
.gauge__label--low { width: 48px; }
.gauge__label--spacer { width: 144px; }
.gauge__label--high { width: 48px; }
/*
* Increase the gauge size slightly on larger viewports.
*/
@media only screen and (min-width: 400px) {
.gauge { height: calc(150px + 3em); }
.gauge__container { width: 300px; height: 150px; }
.gauge__marker { height: 150px; left: 149.5px; }
.gauge__background { width: 300px; height: 150px; }
.gauge__center { width: 180px; height: 90px; top: 60px; margin-left: 60px; }
.gauge__data { width: 300px; height: 150px; }
.gauge__needle { left: 150px; top: 147px; width: 150px; }
.gauge__labels { top: 150px; width: 300px; }
.gauge__label--low { width: 60px; }
.gauge__label--spacer { width: 180px; }
.gauge__label--high { width: 60px; }
}
/*
* As an option, the `gauge--liveupdate` class can be added
* to the main gauge element. When this class is present,
* we add a transition that animates any changes to the gauge
* value. Currently, the app does not use this option because
* all the inputs that can change gauge values are present
* on tab panels that are different from the gauge itself.
* Therefore, users won't be able to see any gauge changes
* when they make input changes. The code is available, though,
* should this change.
*/
.gauge--liveupdate .gauge__data,
.gauge--liveupdate .gauge__needle {
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}
/*
* For a given gauge value, x, ranging from 0.0 to 1.0, set
* the `transform: rotate()` property according to the
* following equation: `-0.5 + 0.5x turns` The default
* properties below represent an x value of 0.
*/
.gauge__data {
-webkit-transform: rotate(-.50turn);
-moz-transform: rotate(-.50turn);
-ms-transform: rotate(-.50turn);
-o-transform: rotate(-.50turn);
transform: rotate(-.50turn);
}
.gauge__needle {
-webkit-transform: rotate(-.50turn);
-moz-transform: rotate(-.50turn);
-ms-transform: rotate(-.50turn);
-o-transform: rotate(-.50turn);
transform: rotate(-.50turn);
}

View File

@ -0,0 +1,67 @@
// #### Gauge
// The Gauge object encapsulates the behavior
// of simple gauge. Most of the implementation
// is in the CSS rules, but we do have a bit
// of JavaScript to set or read the gauge value
function Gauge(el) {
// ##### Private Properties and Attributes
var element, // Containing element for the info component
data, // `.gauge__data` element
needle, // `.gauge__needle` element
value = 0.0, // Current gauge value from 0 to 1
prop; // Style for transform
// ##### Private Methods and Functions
var setElement = function(el) {
// Keep a reference to the various elements and sub-elements
element = el;
data = element.querySelector(".gauge__data");
needle = element.querySelector(".gauge__needle");
};
var setValue = function(x) {
value = x;
var turns = -0.5 + (x * 0.5);
data.style[prop] = "rotate(" + turns + "turn)";
needle.style[prop] = "rotate(" + turns + "turn)";
};
// ##### Object to be Returned
function exports() { };
// ##### Public API Methods
exports.element = function(el) {
if (!arguments.length) { return element; }
setElement(el);
return this;
};
exports.value = function(x) {
if (!arguments.length) { return value; }
setValue(x);
return this;
};
// ##### Initialization
var body = document.getElementsByTagName("body")[0];
["webkitTransform", "mozTransform", "msTransform", "oTransform", "transform"].
forEach(function(p) {
if (typeof body.style[p] !== "undefined") { prop = p; }
}
);
if (arguments.length) {
setElement(el);
}
return exports;
};