Code Monkey home page Code Monkey logo

lumean / svg-graph2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from clbustos/svg-graph

50.0 50.0 20.0 1.1 MB

SVG:::Graph is a pure Ruby library for generating charts, which are a type of graph where the values of one axis are not scalar. SVG::Graph has a verry similar API to the Perl library SVG::TT::Graph, and the resulting charts also look the same. This isn't surprising, because SVG::Graph started as a loose port of SVG::TT::Graph.

License: Other

Ruby 100.00%

svg-graph2's People

Contributors

adamalbrecht avatar akostadinov avatar ashleydavies avatar boutil avatar cameron2920 avatar chrismedrdz avatar clbustos avatar clofresh avatar dansbits avatar erullmann avatar liehann avatar lilacstella avatar lumean avatar marnen avatar mondhs avatar olegsfinest avatar pbosetti avatar sonota88 avatar thinkingbox avatar tiwi avatar trimble 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  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

svg-graph2's Issues

Add a Histogram

I think a histogram would be a valuable addition to the available charts. I got started on a prototype yesterday but wanted to gather feedback before putting more work in. Does a histogram sound like a good idea? It can technically be accomplished with the existing bar chart but requires you to calculate the bin count and size yourself.

Here is a link to my fork with my start on a histogram. It's pretty functional at this point but doesn't handle all of the options that other charts do. Let me know what you think.
https://github.com/dansbits/svg-graph2/tree/histogram-chart

Legend inline at bottom

key_position: :right

image

key_position: :bottom

image

Feels like when using :bottom, the legend should be inline rather than in block.

2 Y Axis

is it possible to create charts with 2 y axis?

Color data

I searched in the code and saw no way to choose color without providing a CSS stylesheet.

Knockouts don't align with labels

This is from the bar_horizontal.svg file written by svg-graph2's own test suite (viewed in Chrome 80, Mac OS 10.14 [Mojave]). This isn't desired behavior, right?

image

Formatting issue with years as labels

After I updated to the latest, I noticed that the years along the x axis in one of my graphs were now displaying as 2015.00, 2016.00, etc even though I was passing them in as strings ("2015", "2016", etc).

I think the issue is this line of code:
https://github.com/lumean/svg-graph2/blob/master/lib/SVG/Graph/Graph.rb#L592

which is formatting anything that can be parsed as a float as a number with decimal places, including strings. I fixed it by setting the number_format option to "%g", but I could see other people getting tripped up by this as the default behavior. I think this is a perfectly fine default for numeric data types, but strings should probably be displayed as-is.

Thanks!

Automatically show charts in jupyter

I think this is a great library for plotting. One of the better plotting libraries for ruby.

I think it would be a good addition if graphs would display automatically in Jupyter and iRuby. I believe this would be a simple addition of a to_iruby method to the SVG::Graph::Graph class. I'm happy to put up a PR for this but wanted to get feedback on the idea first. Any thoughts?

dataPointLabel styling issues

It looks like Graph#make_datapoint_text writes each datapoint's text twice, once on top of the other, to provide a background and help the text stand out. Unfortunately, one text object uses the class .dataPointLabel, while the other uses .dataPointLabel plus some inline styling to make the background. This is a problem for those of us who use our own CSS to style the SVG graphs, because the inline styling (which, BTW, has the background hard-coded to white) means that it's difficult or impossible to customize the backgrounds to do the right thing.

What I propose, then, is the following (and I'll make a pull request for it hopefully in the next day or so): keep .dataPointLabel on the foreground element, but create a new class called something like .dataPointLabelBackground for the background element, and put the styling there instead of inline. This should keep the graph's current behavior with the default CSS, but make custom CSS easier to apply. Sound good?

Centering x-axis on 0 of y-axis

Is it possible to place the x-axis on the 0 of the y-axis? Attached is the issue I'm running into.

Right now, the y-axis is placed on the least value of the x-axis.
example

In Plot.rb min/max_x/y_value are not respected

The assumption so far was, that the divisions of the axis are exactly aligned with the graph borders. Probably it would make sense to decouple this, especially for integer divisions. i.e. to allow some padding before the first or after last division if needed.

graph border should align with min/max_x/y_value when given or else depend on the datapoints and align with the min max values of those.

See also #35

Unable to create donut pie chart

Is there any option to create donut pie chart like this https://image-charts.com/chart?cht=pd&chtt=Blend&chs=978x300&chd=t:20,20,30,400,50&chl=20%C2%B0|20%C2%B0|30%C2%B0|40%C2%B0|50%C2%B0&chli=95K&chdl=Expansion|Payroll|Equipment ?

looking for maintainer

Due to a shift in my priorities, I'm no longer able to invest enough time to thoroughly review and test PRs, not even speaking of active development of this library.

Please reach out if you're interested in continuing to maintain this small and hopefully still useful library project. I'm happy to share repo and gem publish rights.

Dead links to www.germane-software/repositories

The following links are now dead:

$ git grep -n germane-software/repositories/
lib/SVG/Graph/Line.rb:45:    # http://www.germane-software/repositories/public/SVG/test/single.rb
lib/SVG/Graph/Pie.rb:39:    # http://www.germane-software/repositories/public/SVG/test/single.rb
lib/SVG/Graph/Plot.rb:58:    # http://www.germane-software/repositories/public/SVG/test/plot.rb
lib/SVG/Graph/Schedule.rb:50:    # http://www.germane-software/repositories/public/SVG/test/schedule.rb
lib/SVG/Graph/TimeSeries.rb:63:    # http://www.germane-software/repositories/public/SVG/test/timeseries.rb

These URLs are dead as well:

http://www.germane-software.com/repositories/...  
https://www.germane-software.com/repositories/...  

Pie graph often covers key / legend

First of all, I just wanted to say thanks to @lumean for putting some effort into this gem recently. This is really the only decent ruby graphing library I have found, but it could still use some work. And I'm happy to contribute, as well, because I've been depending on it lately.

Anyway, here is my issue: Often, when I use a key and the labels are somewhat long, they get covered by the pie graph. For example:

pie_graph_example

There are a few ways this could be fixed or partially fixed:

  1. Move the pie graph left depending on the width of the key (hardest but best option, I would think)
  2. Add an option for x_offset or something similar to specify the distance from the left so that the pie could be left-aligned
  3. Add an option to add a maximum width on the key and line break any labels that are longer
  4. Add an option to right-align the key

Let me know what you think and I'm happy to contribute a pull request. Thanks!

Data point popups aren't at highest Z index

Data point popups are rendered in the SVG document just after the data point that they're associated with, but before the next data point. Unfortunately, unlike HTML, SVG 1.1 has no z-index attribute, but rather paints elements declared later in the document on top of elements declared earlier. This means that in a closely spaced graph, a popup can appear obscured by the following data point or its label:
image

So what I propose (and will hopefully submit a PR for soon) is a slightly different rendering process, where the nodes for the data point popups aren't put into the SVG document till after all the data point nodes are written. Does that sound reasonable, or would that cause problems somewhere else?

BTW, I do really appreciate this gem quite a lot. It's making my life much easier on http://covid-tracking-charts.herokuapp.com. @lumean Thanks for maintaining it!

Refactor for maintenance and testability

As mentioned in #24, the code in this gem is really hard to work with. I'm planning to refactor the gem to made the code more tractable, probably moving tests to RSpec in the process.

  • Translate tests to RSpec
  • Make a first refactoring pass to make better use of RSpec features
  • Write better tests (many of the existing ones are just smoketests without really checking the functionality)
  • Refactor as necessary

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.