• Stars
    star
    145
  • Rank 246,653 (Top 5 %)
  • Language
    Elm
  • License
    BSD 3-Clause "New...
  • Created about 8 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fast SVG in Elm

SVG in Elm

Scalable vector graphics (SVG) is a way to display lines, rectangles, circles, arcs, etc.

The API is a bit wonky, but (1) it is manageable if you look through MDN docs like these and (2) you can attach event listeners to any shapes and lines you create!

Example

import Svg exposing (..)
import Svg.Attributes exposing (..)

main =
  svg
    [ width "120"
    , height "120"
    , viewBox "0 0 120 120"
    ]
    [ rect
        [ x "10"
        , y "10"
        , width "100"
        , height "100"
        , rx "15"
        , ry "15"
        ]
        []
    , circle
        [ cx "50"
        , cy "50"
        , r "50"
        ]
        []
    ]

I highly recommend consulting the MDN docs on SVG to learn how to draw various shapes!

Make visualizations!

SVG is great for data visualizations, and I really want people in the Elm community to explore more in that direction! My instinct is that functions like view : data -> Svg msg will be way easier to work with than what is available in other languages. Just give the data! No need to have data and interaction deeply interwoven in complex ways.

Make visualization packages?

I think terezka/line-charts is a really great effort in this direction. Notice that the docs present a really smooth learning path. Getting something on screen is really simple, and then it builds on that basic understanding to give you more capabilities. There are tons of examples as well. I really love seeing work like this!

So if you are interested in doing something like this, I recommend:

In other words, try to learn as much as possible first! Anyone can show dots on a grid, but a great package will build expertise into the API itself, quietly leading people towards better design and accessibility. Ideally it will help people learn the important principles as well, because it is not just about getting data on screen, it is about helping people understand complex information!

Future Plans

This package should only change to account for new SVG tags and attributes.

Just like elm/html, this package is designed to be predictable. Every node takes two arguments (a list of attributes and a list of children) even though in many cases it is possible to do something nicer. So if you want nice helpers for simple shapes (for example) I recommend creating a separate package that builds upon this one.

More Repositories

1

compiler

Compiler for Elm, a functional language for reliable webapps.
Haskell
7,455
star
2

core

Elm's core libraries
Elm
2,785
star
3

elm-lang.org

Server and client code for the Elm website.
Elm
1,985
star
4

projects

Curated collection of projects for folks looking to collaborate within the Elm ecosystem.
424
star
5

html

Use HTML in Elm!
Elm
393
star
6

browser

Create Elm programs that run in browsers!
Elm
310
star
7

package.elm-lang.org

website for browsing packages and exploring documentation
Haskell
294
star
8

parser

A parsing library, focused on simplicity and great error messages
Elm
225
star
9

virtual-dom

The foundation of HTML and SVG in Elm.
JavaScript
206
star
10

error-message-catalog

A catalog of broken Elm programs / data to improve error messages
Elm
173
star
11

http

Make HTTP requests in Elm
Elm
156
star
12

file

Select files. Download files. Work with file content.
Elm
107
star
13

time

A simplified approach to working with dates, times, and time zones.
Elm
91
star
14

json

Work with JSON in Elm
Elm
90
star
15

bytes

Work with bytes and implement network protocols
Elm
80
star
16

url

Build and parse URLs. Useful for HTTP and "routing" in single-page apps (SPAs)
Elm
75
star
17

expectations

Trying to set expectations about @elm processes
53
star
18

editor-plugins

List of editor plugins for Elm.
49
star
19

random

Generate random values in Elm
Elm
45
star
20

regex

If you really need regex in Elm, it is possible.
Elm
33
star
21

color

Standard representation of colors, encouraging sharing between packages.
Elm
24
star
22

foundation.elm-lang.org

Source code for the ESF website
Elm
17
star
23

project-metadata-utils

Work with elm.json and docs.json files in Elm
Elm
16
star
24

forum-rules

Rules for Elm forums
9
star