Coder Social home page Coder Social logo

d3-thermometer's Introduction

D3 Thermometer

A simple library for creating an SVG thermometer graphic using D3.js version 4. Apart from D3 there are no other dependencies. Supports IE9 and above.

Demo

https://davidbanksnz.github.io/d3-thermometer/demo.html

Creating a thermometer

To create a thermometer instance, use the Thermometer constructor with optional config. You can specify any subset of available parameters - ones you don't specify will be set to the default value.

var thermometer = new Thermometer({
	mercuryColor: "rgb(220, 150, 0)"
});

The default configuration is as follows.

Thermometer.defaults = {
	
	// SVG width
	width: 80,
	
	// SVG height
	height: 160,
	
	// Color of the mercury
	mercuryColor: "rgb(230, 0, 0)",
	
	// Color of the shine effect on the bulb
	bulbShineColor: "rgb(230, 200, 200)",
	
	// Color of the tube border
	borderColor: "rgb(136, 136, 136)",
	
	// Width of the tube border (pixels)
	borderWidth: 1,
	
	// Color of the empty space between tube border and mercury
	backgroundColor: "rgb(255, 255, 255)",
	
	// Radius of the thermometer bulb (pixes)
	bulbRadius: 18,
	
	// Horizontal width of the tube (pixels)
	tubeWidth: 18.5
	
};

Rendering

To render the thermometer, use the render(container, currentTemp, minTemp, maxTemp) method.

var container = document.getElementById('container');
thermometer.render(container, 15, 10, 20);

Destroying

To destroy the thermometer, use the destroy() method. This simply destroys the rendered SVG. The instance is still functional; you can call render() again if needed.

thermometer.destroy();

Updating

To update the current value, use the setCurrentValue(value) method. This will automatically the min/max values and axis if required.

thermometer.setCurrentValue(14);

To update the maximum value, use the setMaxValue(value) method. This will automatically update the axis.

thermometer.setMaxValue(24);

To update the minimum value, use the setMinValue(value) method. This will automatically update the axis.

thermometer.setMinValue(9);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.