Coder Social home page Coder Social logo

abdelaz3r / sparkline_svg Goto Github PK

View Code? Open in Web Editor NEW
47.0 2.0 1.0 287 KB

Sparkline SVG is simple, zero-dependency, Elixir library to generate SVG sparkline charts.

License: Apache License 2.0

Elixir 100.00%
elixir elixir-lang elixir-library graph sparkline sparkline-graphs svg

sparkline_svg's People

Contributors

03juan avatar abdelaz3r avatar vhf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

vhf

sparkline_svg's Issues

Vertical padding

Hi, thanks for sharing this awesome library!

Is there a way to use only vertical padding?

When using smoothing (even the default 0.15), the line can be cropped at the top and bottom borders:

Captura de pantalla 2024-02-26 a las 14 46 03

This can be fixed by setting padding, but then I also get horizontal padding, it would be great to have only padding at the top and bottom.

Crash when there are less than 2 values

If the list of values has less than 2, we get this crash:

[error] GenServer #PID<0.1465.0> terminating
** (ArithmeticError) bad argument in arithmetic expression
    (sparkline_svg 0.3.0) lib/sparkline_svg/core.ex:132: SparklineSvg.Core.resize_x/3
    (sparkline_svg 0.3.0) lib/sparkline_svg/core.ex:62: anonymous fn/4 in SparklineSvg.Core.resize_datapoints/4
    (elixir 1.14.5) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
    (sparkline_svg 0.3.0) lib/sparkline_svg/core.ex:35: SparklineSvg.Core.compute/1
    (sparkline_svg 0.3.0) lib/sparkline_svg.ex:688: SparklineSvg.compute/1
    (sparkline_svg 0.3.0) lib/sparkline_svg.ex:605: SparklineSvg.to_svg/1
    (sparkline_svg 0.3.0) lib/sparkline_svg.ex:635: SparklineSvg.to_svg!/1

Maybe this could be handled by the library and return a better error?

If there are 0 values, I just don't show the sparkline, but I have a case where I can have 1 value:

In my stats I have a date selector that can display the last 7, 30 or 365 days, but the user can also choose to show a single day. In this case the library will crash, so a workaround might be showing 2 points when we have only 1, by repeating it:

Captura de pantalla 2024-02-29 a las 8 54 53

However this feels a bit weird, it might be preferable to just show a single dot and no line?

Change API; add annotation

Proposal of change:

SimpleCharts.new(datapoints, options2)
|> SimpleCharts.show_dots(options3)
|> SimpleCharts.show_line(options4)
|> SimpleCharts.show_area(options5)
|> SimpleCharts.add_dot(p1, options)
|> SimpleCharts.add_line(p2, options)
# or
|> SimpleCharts.add_annotation(:line, p1, options)
# or
|> SimpleCharts.add_line_annotation(p1, options)
|> SimpleCharts.to_svg()
  1. Options are passed according to what we want (dots options are different than line options)
  2. We add annotations for reporting incident (eg.)

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.