1.1.2 • Published 2 years ago

fluid-meter v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Fluid Meter

Dependency free library to represent progress as the amount of fluid in a container.

Demo

https://aarcoraci.github.io/fluid-meter/

Installation

npm i fluid-meter

Usage

The library is higlhly customizable but it can be easily initialized. It requires a DOM container with a setted width and height (inline or css).

<div id="target" style="width:500px;height:500px"></div>
import { CircularFluidMeter } from 'fluid-meter';

const target = document.querySelector('#target');
new CircularFluidMeter(target, {
  initialProgress: 33
});

Bundled version

A new bundled version has been added. It can be accessed via the IIFE on the global scope.

1 - Add the bundle file to your project (can be found as bundle.js in the /dist directory):

<!-- make sure the path is correct -->
<script src="dist/bundle.js"></script>

2 - Access via the IIFE on the global scope (named cfmModule):

const target = document.querySelector("#target");
new cfmModule.CircularFluidMeter(target, {
  initialProgress: 33,
});

Responsiveness

The library is prepared to work on a responsive scenario if needed via the BreakpointValueConfig:

const config = {
  initialProgress: 75,
  borderWidth: [
    {
      resolution: 0,
      value: 15
    },
    {
      resolution: 1024,
      value: 60
    }
  ],
  fontSize: [
    {
      resolution: 0,
      value: 25
    },
    {
      resolution: 768,
      value: 50
    }
  ]
};

See the supported responsive values on the Configuration table

Configuration

Here are some examples on how to use it. It's with typescript but should be the same with plain javascript. https://github.com/aarcoraci/fluid-meter/blob/main/src/main.ts

optiontypedefaultinfo
initialProgressnumber0initial progress to show
maxProgressnumber100max progress of the meter
borderWidthnumber or BreakpointValueConfig30border width. Can be a number or an array of breakpoint value configs
borderColorstring#75758bcolor of the outer border.
paddingnumber30space between the boundaries of the container and the meter. Usefull if drop shadow is enabled
backgroundColorstring#9f9faemeter background color
showProgressbooleantruedisplays or not the center text
showBubblesbooleantruedisplays or not the bubbles
bubbleColorstring#ffffffcolor of the bubbles
textColorstring#fffffftext color
textDropShadowbooleantruetext has a small shadow. Helps when colors are too similar or on difficult contrasting scenarios
textShadowOpacitynumber1intensity of the shadow between 0 and 1: 0 invisible and 1 fully visible
textShadowColorstring#000000text shadow color
fontFamilystringArialname of the typeface to use
fontSizenumber or BreakpointValueConfig30tex size. Can be a number of an array of breakpoint value configs
use3Dbooleantrueenables details that gives the impresion of depth
dropShadowbooleantruemeter drops shadow. Requires some padding to show correctly
dropShadowColorstring#000000meter shadow color
progressFormatter(value: number) => string(value: number) => Math.round(value).toString()a function that transforms the value shown in the center of the meter
fluidConfigurationFluidLayerConfiguration{color: '#ff0000',waveSpeed: Speed.NORMAL,horizontalSpeed: Speed.NORMAL}values of the fluid being displayed

API and Methods

Example:
import { CircularFluidMeter } from 'fluid-meter';

const target = document.querySelector('#target');
const m = new CircularFluidMeter(target, {
  initialProgress: 50
});

m.targetProgress = 50;
m.dropShadow = false;
m.use3D = false;
List of setters and getters
setter / getterinfo
progressnumber
maxProgress (only getter)number
borderWidthnumber or BreakpointValueConfig[]
borderColorstring
meterPaddingnumber
backgroundColorstring
textColorstring
fontFamilystring
fontSizenumber or BreakpointValueConfig[]
textDropShadowboolean
textShadowOpacitynumber (between 0 and 1)
textShadowColorstring
showProgressboolean
showBubblesboolean
bubbleColorstring
use3Dboolean
dropShadowboolean
dropShadowColorstring
progressFormatter (only getter)(value: number) => string
Performance

If yo are using the library on a context where you will be adding it or removing it dynamically you should call dispose when removing it to correctly clear the animation:

meter.dispose();
1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago