Compile error with SVG tags

82 views
Skip to first unread message

Ronan Michaux

unread,
Jun 14, 2016, 6:17:13 AM6/14/16
to Scalatags
Hello,

I've made a small modification to this SVG example : https://github.com/lihaoyi/scalatags/blob/master/example/src/main/scala/example/ScalaJSExample.scala

I wanted to draw 3 lines :


import org.scalajs.dom
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport
import scalatags.JsDom.all._

import
scalatags.JsDom.implicits._
import scalatags.JsDom.svgAttrs._
import scalatags.JsDom.svgTags._


...
(1 to 3).map(i =>
 
line(
   
x1 := 175 + i, y1 := 100 + i,
   
x2 := 275, y2 := 0,
   
stroke := "rgb(255,0,0)",
   
strokeWidth := i
 
)), // KO ?!?
...

But it doesn't compile :

Error:(34, 19) type mismatch;
 found  
: scala.collection.immutable.IndexedSeq[scalatags.JsDom.TypedTag[org.scalajs.dom.svg.Line]]
   
(which expands to)  scala.collection.immutable.IndexedSeq[scalatags.JsDom.TypedTag[org.scalajs.dom.raw.SVGLineElement]]
 required
: scalatags.JsDom.Modifier
   
(which expands to)  scalatags.generic.Modifier[org.scalajs.dom.raw.Element]
     
(1 to 3).map(i =>
                 
^

What's the problem ?

In an another part of my code I have this code working well :

root.appendChild(
 
div(
   
(1 to 3).map(i =>
     
li(s"$i - Hello SVG !..."))).render) // OK !

Regards,
Ronan.

Ronan Michaux

unread,
Jun 14, 2016, 8:06:13 AM6/14/16
to Scalatags
To make it compile, I had to extract to a typed local val :

val lines: JsDom.svgTags.SeqFrag[TypedTag[Line]] = (1 to 10).map(i =>
 
line(
   
x1 := 100 + 20 * i, y1 := 100,

   
x2 := 275, y2 := 0,

   
stroke := s"rgb(255, ${20 * i}, 0)",
   
strokeWidth := i)
)

It's not very beautiful !

Does it exists an other solution ?

Regards,
Ronan.

Haoyi Li

unread,
Jun 14, 2016, 8:07:08 AM6/14/16
to Ronan Michaux, Scalatags
Try asking on the gitter channel, lots of people there and someone may be able to help you =)

--
You received this message because you are subscribed to the Google Groups "Scalatags" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatags+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ronan Michaux

unread,
Jun 14, 2016, 10:14:41 AM6/14/16
to Scalatags, ronan....@gmail.com
Here is a minimal example :

import scalatags.JsDom.implicits._
import scalatags.JsDom.svgAttrs._
import scalatags.JsDom.svgTags._
import org.scalajs.dom
import org.scalajs.dom.svg.Line

import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport
import scalatags.JsDom
import scalatags.JsDom.TypedTag


object SvgApp extends JSApp {

 
@JSExport
  def main(): Unit = {
   
import scalatags.JsDom.all._
   
val root = dom.document.getElementById("app-placeholder")

    root
.appendChild(
     
div((1 to 3).map(i =>

       
li(s"$i - Hello SVG !..."))).render)


    root
.appendChild(svgExemple.render)
 
}

 
def svgExemple = {


   
val lines: JsDom.svgTags.SeqFrag[TypedTag[Line]] =
     
(1 to 10).map(i =>
       
line(
         
x1 := 100 + 20 * i, y1 := 100,
         
x2 := 275, y2 := 0,
         
stroke := s"rgb(255, ${20 * i}, 0)",
         
strokeWidth := i)
     
)


   
svg(
     
height := "800",
     
width := "500",
      lines
)
 
}
}

I must add type to "lines" to compile the code.

Ronan.

Ronan Michaux

unread,
Jun 15, 2016, 3:37:26 AM6/15/16
to Scalatags, ronan....@gmail.com
Reply all
Reply to author
Forward
0 new messages