Skip to content

Commit fd156f0

Browse files
committed
Add 'svg/' from commit '08bd432990862bab5b840654dd437fbb2e6176e7'
git-subtree-dir: svg git-subtree-mainline: 582f09d git-subtree-split: 08bd432
2 parents 582f09d + 08bd432 commit fd156f0

File tree

10 files changed

+2635
-0
lines changed

10 files changed

+2635
-0
lines changed

svg/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
elm-stuff

svg/LICENSE

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) 2014-present, Evan Czaplicki
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Evan Czaplicki nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

svg/README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# SVG in Elm
2+
3+
Scalable vector graphics (SVG) is a way to display lines, rectangles, circles, arcs, etc.
4+
5+
The API is a bit wonky, but (1) it is manageable if you look through MDN docs like [these](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/rect) and (2) you can attach event listeners to any shapes and lines you create!
6+
7+
8+
## Example
9+
10+
```elm
11+
import Svg exposing (..)
12+
import Svg.Attributes exposing (..)
13+
14+
main =
15+
svg
16+
[ width "120"
17+
, height "120"
18+
, viewBox "0 0 120 120"
19+
]
20+
[ rect
21+
[ x "10"
22+
, y "10"
23+
, width "100"
24+
, height "100"
25+
, rx "15"
26+
, ry "15"
27+
]
28+
[]
29+
, circle
30+
[ cx "50"
31+
, cy "50"
32+
, r "50"
33+
]
34+
[]
35+
]
36+
```
37+
38+
I highly recommend consulting the MDN docs on SVG to learn how to draw various shapes!
39+
40+
41+
## Make visualizations!
42+
43+
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.
44+
45+
### Make visualization packages?
46+
47+
I think [`terezka/line-charts`](https://terezka.github.io/line-charts/) is a really great effort in this direction. Notice that [the docs](https://package.elm-lang.org/packages/terezka/line-charts/1.0.0/LineChart) 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!
48+
49+
So if you are interested in doing something like this, I recommend:
50+
51+
- Reading [The Visual Display of Quantitative Information](https://www.edwardtufte.com/tufte/books_vdqi) by Edward Tufte.
52+
- Learning about [designing for color blindness](https://www.alanzucconi.com/2015/12/16/color-blindness/)
53+
- Learning about different color spaces, like [CIELUV](https://en.wikipedia.org/wiki/CIELUV) for changing colors without changing the perceived brightness, [cubehelix](https://www.mrao.cam.ac.uk/~dag/CUBEHELIX/) for heatmaps with nice brightness properties, and how to do [color conversions](https://www.cs.rit.edu/~ncs/color/t_convert.html) in general
54+
55+
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!
56+
57+
58+
## Future Plans
59+
60+
This package should only change to account for new SVG tags and attributes.
61+
62+
Just like [`elm/html`](https://package.elm-lang.org/packages/elm/html/latest), 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.

svg/elm.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"type": "package",
3+
"name": "elm/svg",
4+
"summary": "Fast SVG, rendered with virtual DOM diffing",
5+
"license": "BSD-3-Clause",
6+
"version": "1.0.1",
7+
"exposed-modules": {
8+
"SVG": [
9+
"Svg",
10+
"Svg.Attributes",
11+
"Svg.Events"
12+
],
13+
"Optimize": [
14+
"Svg.Keyed",
15+
"Svg.Lazy"
16+
]
17+
},
18+
"elm-version": "0.19.0 <= v < 0.20.0",
19+
"dependencies": {
20+
"elm/core": "1.0.0 <= v < 2.0.0",
21+
"elm/html": "1.0.0 <= v < 2.0.0",
22+
"elm/json": "1.0.0 <= v < 2.0.0",
23+
"elm/virtual-dom": "1.0.0 <= v < 2.0.0"
24+
},
25+
"test-dependencies": {}
26+
}

svg/examples/Logo.elm

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Svg exposing (..)
2+
import Svg.Attributes exposing (..)
3+
4+
main =
5+
svg
6+
[ version "1.1", x "0", y "0", viewBox "0 0 323.141 322.95"
7+
]
8+
[ polygon [ fill "#F0AD00", points "161.649,152.782 231.514,82.916 91.783,82.916" ] []
9+
, polygon [ fill "#7FD13B", points "8.867,0 79.241,70.375 232.213,70.375 161.838,0" ] []
10+
, rect
11+
[ fill "#7FD13B", x "192.99", y "107.392", width "107.676", height "108.167"
12+
, transform "matrix(0.7071 0.7071 -0.7071 0.7071 186.4727 -127.2386)"
13+
]
14+
[]
15+
, polygon [ fill "#60B5CC", points "323.298,143.724 323.298,0 179.573,0" ] []
16+
, polygon [ fill "#5A6378", points "152.781,161.649 0,8.868 0,314.432" ] []
17+
, polygon [ fill "#F0AD00", points "255.522,246.655 323.298,314.432 323.298,178.879" ] []
18+
, polygon [ fill "#60B5CC", points "161.649,170.517 8.869,323.298 314.43,323.298" ] []
19+
]

0 commit comments

Comments
 (0)