Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svg support #25

Merged
merged 18 commits into from
Apr 9, 2018
Merged

Svg support #25

merged 18 commits into from
Apr 9, 2018

Conversation

doofin
Copy link
Sponsor Contributor

@doofin doofin commented Feb 24, 2018

Seems that we should move every svg thing here,which is idiom github workflow..

For reference:

Scalatags impl:

fixes #20

README.md Outdated
## Community & Contributing

### updating:
Currently we are working to add support for svg at svg branch ,help very welcomed!
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed given what's in master and in #26

@@ -86,6 +86,10 @@ package object defs {
type EmbedTags[T[_ <: dom.Element]] = generic.defs.tags.EmbedTags[T, dom.Element, dom.html.Image, dom.html.IFrame, dom.html.Embed, dom.html.Object, dom.html.Param, dom.html.Video, dom.html.Audio, dom.html.Source, dom.html.Track, dom.html.Canvas, dom.html.Map, dom.html.Area]
type TableTags[T[_ <: dom.Element]] = generic.defs.tags.TableTags[T, dom.Element, dom.html.Table, dom.html.TableCaption, dom.html.TableCol, dom.html.TableSection, dom.html.TableRow, dom.html.TableCell, dom.html.TableHeaderCell]
type MiscTags[T[_ <: dom.Element]] = generic.defs.tags.MiscTags[T, dom.Element, dom.html.Title, dom.html.Style, dom.html.Element, dom.html.Quote, dom.html.Progress, dom.html.Menu]
import org.scalajs.dom._
import svg._
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't use those extra imports – instead, spell out dom.svg.Type everywhere instead of just Type – yes, even in this huge list. It's just much easier to text search, and matches the style in the rest of the definitions here.

@@ -86,6 +86,10 @@ package object defs {
type EmbedTags[T[_ <: dom.Element]] = generic.defs.tags.EmbedTags[T, dom.Element, dom.html.Image, dom.html.IFrame, dom.html.Embed, dom.html.Object, dom.html.Param, dom.html.Video, dom.html.Audio, dom.html.Source, dom.html.Track, dom.html.Canvas, dom.html.Map, dom.html.Area]
type TableTags[T[_ <: dom.Element]] = generic.defs.tags.TableTags[T, dom.Element, dom.html.Table, dom.html.TableCaption, dom.html.TableCol, dom.html.TableSection, dom.html.TableRow, dom.html.TableCell, dom.html.TableHeaderCell]
type MiscTags[T[_ <: dom.Element]] = generic.defs.tags.MiscTags[T, dom.Element, dom.html.Title, dom.html.Style, dom.html.Element, dom.html.Quote, dom.html.Progress, dom.html.Menu]
import org.scalajs.dom._
import svg._
type svgTags[T[_ <: dom.Element]]=generic.defs.tags.SvgTags[T,dom.Element,svg.Element,Circle,ClipPath,Defs,Desc,Ellipse,FEBlend,FEColorMatrix,ComponentTransferFunction,FEComposite,FEConvolveMatrix,FEDiffuseLighting,FEDisplacementMap,FEDiffuseLighting,FEFlood,FEFuncA,FEFuncB,FEFuncG,FEFuncR,FEGaussianBlur,FEImage,FEMerge,FEMergeNode,FEMorphology,FEOffset,FEPointLight,FESpecularLighting,FESpecularLighting,FETile,FETurbulence,Filter,G,Image,Line,LinearGradient,Marker,Mask,Metadata,Path,Pattern,Polygon,Polyline,RadialGradient,RectElement,SVG,Stop,SVG,Switch,Symbol,svg.Text,TextPath,TSpan,Use,View]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls capitalize the first S so that this type's name is consistent with other type names above

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting: add spaces around =, and put each type param on a new line

SvgRectElement <: SvgElement,
Svg <: SvgElement,
SvgStop <: SvgElement,
SvgSVG <: SvgElement,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type param seems to be unused? There's another Svg two lines above this


import com.raquo.domtypes.generic.builders.TagBuilder

trait SvgTags[T[_ <: DomElement], DomElement, SvgElement <: DomElement,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T[_ <: DomElement] should be T[_ <: SvgElement], I think, and it doesn't seem like we need the DomElement type param at all.

*
* MDN
*/
lazy val altGlyph:T[SvgElement] = tag("altGlyph")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting: Pls add a space between : and T in all these lazy vals to be consistent with other traits like this

*
* MDN
*/
lazy val `missing-glyph`:T[SvgElement] = tag("missing-glyph")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not be using backticks. Tags with dashed should be camelCased instead. (same for other tags)

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true,gonna do that later with regex after initial test

import com.raquo.domtypes.generic.codecs.Codec

/**
* This class represents an HTML Element Attribute. Meaning the key that can be set, not the whole a key-value pair.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update "HTML" to "SVG"

import com.raquo.domtypes.generic.builders.AttrBuilder
import com.raquo.domtypes.generic.codecs.{BooleanAsOnOffStringCodec, BooleanAsTrueFalseStringCodec}

/** @tparam A svg Attribute, canonically [[com.raquo.domtypes.generic.keys.SvgAttr]] */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatiing: svg should be capitalized ("SVG") in the comment

@raquo raquo mentioned this pull request Feb 24, 2018
@doofin
Copy link
Sponsor Contributor Author

doofin commented Mar 1, 2018

CI gives error due to that some attr name is the same as element name ..

[error] /home/travis/build/raquo/scala-dom-types/js/src/test/scala/com/raquo/domtypes/CompileTest.scala:76: object svg inherits conflicting members:
[error] lazy value clipPath in trait SvgAttrs of type com.raquo.domtypes.generic.keys.SvgAttr[String] and
[error] lazy value clipPath in trait SvgTags of type com.raquo.domtypes.generic.builders.Tag[org.scalajs.dom.svg.ClipPath]
[error] (Note: this can be resolved by declaring an override in object svg.);
[error] other members with override errors are: cursor, filter, mask
[error] object svg
[error] ^
[error] one error found
[error] (domtypesJS/test:compileIncremental) Compilation failed
[error] Total time: 19 s, completed Mar 1, 2018 4:29:50 AM

    /**
      * The clip-path attribute bind the element is applied to with a given <clipPath> element
      * As a presentation attribute, it also can be used as a property directly inside a CSS stylesheet
      *
      * Value 	<FuncIRI> | none | inherit
      *
      * MDN
      */
    lazy val clipPath = stringAttr("clip-path")

Should we namespace them ? Or provide alternative name?
BTW , the seemly simple and innocent compileTest actually find problems! Gonna remember this nice trick

@raquo
Copy link
Owner

raquo commented Mar 1, 2018

Yep, that's exactly what CompileTest is for, nice.

Unless we know that the clipPath attr is much more popular (more often used) than the clipPath tag (or the other way around), we should disambiguate them by renaming them clipPathAttr and clipPathTag respectively.

BTW you don't need to wait for CI, you can run the tests locally with sbt test.

@doofin
Copy link
Sponsor Contributor Author

doofin commented Mar 1, 2018

I have added postfix "Attr" for the attrs and now it passed.Thank for the advice!

Maybe it's time to use dom builder to test svg rendering?
raquo/scala-dom-builder#3

@raquo
Copy link
Owner

raquo commented Mar 2, 2018

For DOM Builder work, we'll need a sample SVG file I described in this comment: #20 (comment)

@doofin
Copy link
Sponsor Contributor Author

doofin commented Mar 2, 2018

Do you mean something like svg(circle(rx:=5,ry:=5)) ? But this syntax seems only available at dom builder which is yet to be finished..

@raquo
Copy link
Owner

raquo commented Mar 2, 2018 via email

@doofin
Copy link
Sponsor Contributor Author

doofin commented Mar 2, 2018

So you want to make dom builder render to string and test their equality,right? Where should i put these svg file?

@doofin
Copy link
Sponsor Contributor Author

doofin commented Mar 2, 2018

Plenty of thanks to lihaoyi (http://www.lihaoyi.com/scalatags/#scalatags.TextSVG)
<svg height="800" width="500"><polyline points="20,20 40,25 60,40 80,120 120,140 200,180" fill="none" stroke="black" stroke-width="3"></polyline><line x1="175" y1="100" x2="275" y2="0" stroke="rgb(255,0,0)" stroke-width="10"></line><rect x="300" y="10" rx="20" ry="20" width="100" height="100" fill="rgb(0,0,255)" stroke-width="3" stroke="rgb(0,0,0)" fill-opacity="0.1" stroke-opacity="0.5"></rect><circle cx="30" cy="250" r="10" stroke="black" stroke-width="3" fill="red"></circle><ellipse cx="150" cy="250" rx="100" ry="50" fill="yellow" stroke="purple" stroke-width="4"></ellipse><polygon points="300,110 350,290 260,310" fill="line" stroke="purple" stroke-width="10"></polygon><path d="M100 300 L25 500 L175 500 Z"></path><text x="350" y="250" fill="red" transform="rotate(30 20, 40)">I love SVG!</text><text x="350" y="350" fill="green">Several lines<tspan x="350" y="380">First line.</tspan><tspan x="350" y="410">Second line.</tspan></text><defs><linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" stop-color="rgb(255,255,0)"></stop><stop offset="100%" stop-color="rgb(255,0,0)"></stop></linearGradient></defs><ellipse cx="100" cy="590" rx="85" ry="55" fill="url(#grad1)"></ellipse></svg>

@raquo
Copy link
Owner

raquo commented Mar 6, 2018

Cool, looks like it should work. I'll try to get something going on DOM Builder side on the weekend. Sorry for the delay, very busy days now between work and various chores.

@doofin
Copy link
Sponsor Contributor Author

doofin commented Mar 6, 2018

No worry,after all we are doing this for fun.I would also become very busy soon due to that I got a great scala job about big data . Scala is quite popular these days in China,which is unimaginable!

Also:
- Give more specific types to SVG attrs
- Various renamings for consistency
- Formatting fixes for consistency
- Address other minor code review comments
@raquo
Copy link
Owner

raquo commented Apr 8, 2018

@doofin I almost finished integrating SVG into DOM Builder and Laminar. While I'm wrapping that up, could you please copy over ScalaTags/MDN comments to remaining SVG attrs? I should have my SDB / Laminar changes ready some time next week.

Make sure to first pull the latest changes from this branch to avoid merge conflicts, as I changed the SvgAttrs file among others.

@raquo raquo merged commit 211d92c into master Apr 9, 2018
@raquo raquo deleted the svg branch April 9, 2018 05:57
@doofin
Copy link
Sponsor Contributor Author

doofin commented Apr 10, 2018

@raquo
Copy link
Owner

raquo commented Apr 10, 2018

@doofin it's not the attributes themselves that are missing, but the MDN comments for them, starting with d: https://github.com/raquo/scala-dom-types/blob/master/shared/src/main/scala/com/raquo/domtypes/generic/defs/attrs/SvgAttrs.scala#L414

@doofin
Copy link
Sponsor Contributor Author

doofin commented Apr 10, 2018

The comments are not present in scalaTags either..so I would have to get them from MDN site myself.I would be happy to write a parser to get them from web automatically but currently I am too busy to do that @raquo

For reference : https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute

@raquo
Copy link
Owner

raquo commented Apr 10, 2018 via email

@fdietze
Copy link
Contributor

fdietze commented Apr 10, 2018

Thank you all for working on this PR!

@doofin
Copy link
Sponsor Contributor Author

doofin commented Apr 10, 2018

Cheers and thank everyone ! Finally we can do some very complex stuff with svg and reactive programming!

@raquo raquo restored the svg branch March 2, 2020 08:02
@raquo raquo deleted the svg branch March 2, 2020 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SVG support
3 participants