Giter VIP home page Giter VIP logo

esparklines's Introduction

ESParklines

Nice sparklines for ESP8266, ESP32, Arduino

Sparklines are small, high resolution graphics embedded in a context of words, numbers or images". Edward Tufte describes sparklines as "data-intense, design-simple, word-sized graphics".

Read more about Sparklines here.

Help wanted โ€“ I appreciate PRs with

  • examples for other architectures
  • examples for different display libraries

Description

This library is very simple, it

  • holds a buffer of any numeric data type of speficied size
  • renders sparklines using a passed-in function to draw lines
  • uses the line drawing function of your preferred graphics library (u8g2, Adafruit, ...)

Showcase

Click picture to watch video (35sec) on YouTube Example App: Geiger Counter
DemoVideo AppExample

Example Usage

Create Sparkline with a buffer for 25 items of uint16_t and pass in your existing line drawing function. I use u8g2's drawLine():

SparkLine<uint16_t> MySparkLine(25, [&](const uint16_t x0, const uint16_t y0, const uint16_t x1, const uint16_t y1) { 
  u8g2.drawLine(x0, y0, x1, y1);
});

This example uses a lambda expression (aka. 'closure' or anonymous / unnamed function: [] ( <parameters> ) { <code> }) to match the function signature of u8g2's drawLine(). For the AdafruitGFX library, change to tft.drawLine(x0, y0, x1, y1, myColor);, if myColor holds your line color in the current function scope. The ampersand [&] captures scope, so your outside variables are available inside { }.

Next, add data regularly, e.g. every minute upon sensor read, or analogRead(), etc. The data will be automatically scaled and automatically rotated (FIFO), once the buffer exceeds the specified number of items.

MySparkLine.add(42);

Then, periodically display sparkline at 0x10, 50 pixel wide, 20 pixel high, e.g. from loop() like so:

static esp8266::polledTimeout::periodicMs periodicSecond(1000);

if (periodicSecond) {
  MySparkLine.draw(0, 10, 50, 20);
}

Dependency Information

This library depends on FixedPointsArduino. It will be automatically installed via PlatformIO.

To remove this dependency, redefine num_t to float or double and remove all occurences of .getInteger() in SparkLine.h.

License

MIT License

Copyright (c) 2020 [email protected]

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.

esparklines's People

Contributors

0xpit avatar

Watchers

James Cloos avatar

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.