All Projects → naikus → Svg Gauge

naikus / Svg Gauge

Licence: mit
Minimalistic, animated SVG gauge. Zero dependencies

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Svg Gauge

React Svg Buttons
React configurable animated svg buttons
Stars: ✭ 209 (+11.17%)
Mutual labels:  svg, animated
React Native Svg Animated Linear Gradient
A wrap SVG component for animated linear gradient
Stars: ✭ 418 (+122.34%)
Mutual labels:  svg, animated
Jeelizweboji
JavaScript/WebGL real-time face tracking and expression detection library. Build your own emoticons animated in real time in the browser! SVG and THREE.js integration demos are provided.
Stars: ✭ 835 (+344.15%)
Mutual labels:  svg, animated
Lfai Landscape
🌄 Open Source AI Landscape - provides overview of top tier projects in the open source AI ecosystem, shows projects through GitHub data, funding or market cap, first and last commits, contributor count and much other information.
Stars: ✭ 172 (-8.51%)
Mutual labels:  svg
Psvg
Programmable Scalable Vector Graphics -- drawings that draw themselves
Stars: ✭ 177 (-5.85%)
Mutual labels:  svg
Jfreesvg
A fast, lightweight Java library for creating Scalable Vector Graphics (SVG) output.
Stars: ✭ 182 (-3.19%)
Mutual labels:  svg
Visx
🐯 visx | visualization components
Stars: ✭ 14,544 (+7636.17%)
Mutual labels:  svg
File Icon Vectors
A collection of file type icons in SVG format
Stars: ✭ 171 (-9.04%)
Mutual labels:  svg
Weather Underground Icons
Weather Underground Icons ( PNG & SVG )
Stars: ✭ 186 (-1.06%)
Mutual labels:  svg
Alive Progress
A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
Stars: ✭ 2,940 (+1463.83%)
Mutual labels:  animated
Oshmi
SCADA HMI for substations and automation applications.
Stars: ✭ 180 (-4.26%)
Mutual labels:  svg
Portfolio Template
A beautiful minimal and accessible portfolio template for Developers. Give it a star 🌟 if you find it useful.
Stars: ✭ 175 (-6.91%)
Mutual labels:  svg
Akar Icons
A perfectly rounded icon library made for designers, developers, and pretty much everyone.
Stars: ✭ 184 (-2.13%)
Mutual labels:  svg
Picasso.js
A charting library streamlined for building interactive visualizations for the Qlik product suites.
Stars: ✭ 175 (-6.91%)
Mutual labels:  svg
Chartist Js
Simple responsive charts
Stars: ✭ 12,731 (+6671.81%)
Mutual labels:  svg
Svg2vectordrawable
Node.js module and command-line tools for convert SVG to Android vector drawable.
Stars: ✭ 171 (-9.04%)
Mutual labels:  svg
Polymorph
Get Your SVG into Shape!
Stars: ✭ 185 (-1.6%)
Mutual labels:  svg
Komorebi
A beautiful and customizable wallpapers manager for Linux
Stars: ✭ 2,472 (+1214.89%)
Mutual labels:  animated
Feathericon
simply generic vector icon collection - including sketch file, svg files, and font files.
Stars: ✭ 178 (-5.32%)
Mutual labels:  svg
Svgs
svgs is a compatiblity layer between svg and react-native-svg
Stars: ✭ 182 (-3.19%)
Mutual labels:  svg

SVG Gauge

Minmalistic, configurable, animated SVG gauge. Zero dependencies

Buy me a coffee ☕

If you like my work please consider making a small donation

ko-fi

Migration from 1.0.2

The new gauge uses a viewbox of 100x100 as opposed to previous 1000x1000. All the stroke and font values have to be adjusted accordingly in your CSS. Just divide those by 10

Demo

Check out the live demo for various options and styling tips for this gauge

Usage

HTML

<div id="cpuSpeed" class="gauge-container"></div>

CSS

.gauge-container {
  width: 150px;
  height: 150px;
  display: block;
  padding: 10px;
}
.gauge-container > .gauge .dial {
  stroke: #eee;
  stroke-width: 2;
  fill: rgba(0,0,0,0);
}
.gauge-container > .gauge .value {
  stroke: rgb(47, 227, 255);
  stroke-width: 2;
  fill: rgba(0,0,0,0);
}
.gauge-container > .gauge .value-text {
  fill: rgb(47, 227, 255);
  font-family: sans-serif;
  font-weight: bold;
  font-size: 1em;
}

Javascript

// npm install
npm install svg-gauge

// Require JS
var Gauge = require("svg-gauge");

// Standalone
var Gauge = window.Gauge;

// Create a new Gauge
var cpuGauge = Gauge(document.getElementById("cpuSpeed"), {
    max: 100,
    // custom label renderer
    label: function(value) {
      return Math.round(value) + "/" + this.max;
    },
    value: 50,
    // Custom dial colors (Optional)
    color: function(value) {
      if(value < 20) {
        return "#5ee432"; // green
      }else if(value < 40) {
        return "#fffa50"; // yellow
      }else if(value < 60) {
        return "#f7aa38"; // orange
      }else {
        return "#ef4655"; // red
      }
    }
});

// Set gauge value
cpuGauge.setValue(75);

// Set value and animate (value, animation duration in seconds)
cpuGauge.setValueAnimated(90, 1);

Options

Name Description
dialStartAngle The angle in degrees to start the dial (135)
dialEndAngle The angle in degrees to end the dial. This MUST be less than dialStartAngle (45)
radius The radius of the gauge (40)
min The minimum value for the gauge. This can be a negative value (0)
max The maximum value for the gauge (100)
label Optional function that returns a string label that will be rendered in the center. This function will be passed the current value
showValue Whether to show the value at the center of the gauge (true)
gaugeClass The CSS class of the gauge (gauge)
dialClass The CSS class of the gauge's dial (dial)
valueDialClass The CSS class of the gauge's fill (value dial) (value)
valueClass The CSS class of the gauge's text (value-text)
color (new) An optional function that can return a color for current value function(value) {}
viewBox (new) An optional string that specifies the crop region (0 0 100 100)

That's all good, but what about React?

import React, { useEffect, useRef } from "react";
import SvgGauge from "svg-gauge";

const defaultOptions = {
  animDuration: 1,
  showValue: true,
  initialValue: 0,
  max: 100
  // Put any other defaults you want. e.g. dialStartAngle, dialEndAngle, radius, etc.
};

const Gauge = props => {
  const gaugeEl = useRef(null);
  const gaugeRef = useRef(null);
  useEffect(() => {
    if (!gaugeRef.current) {
      const options = { ...defaultOptions, ...props };
      gaugeRef.current = SvgGauge(gaugeEl.current, options);
      gaugeRef.current.setValue(options.initialValue);
    }
    gaugeRef.current.setValueAnimated(props.value, 1);
  }, [props]);

  return <div ref={gaugeEl} className="gauge-container" />;
};

export default Gauge;

// to render:
const renderGauge = () => (
  <Gauge
    value={42}
    // any other options you want
  />
);

And Angular?

Ha! It's already there

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].