All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.flowtick.graphs.graphml.GraphMLRenderer.scala Maven / Gradle / Ivy

The newest version!
package com.flowtick.graphs.graphml

import com.flowtick.graphs.layout.{ DefaultGeometry, GraphLayout, ShapeDefinition }
import com.flowtick.graphs.{ EdgeType, Graph, Identifiable, Labeled }

import scala.xml.{ Elem, Text }

class GraphMLRenderer {
  def render[G[_, _, _], E[_, _], V, N, M](
    g: G[E[V, N], N, M],
    layouter: GraphLayout,
    shapeDefinition: N => Option[ShapeDefinition] = (_: N) => None)(implicit graph: Graph[G, E], edgeType: EdgeType[E], identifiable: Identifiable[N], edgeLabel: Labeled[E[V, N], String]): Elem = {
    val layout = layouter.layout[G, E, V, N, M](g, shapeDefinition)

    def nodeProperties(aNode: N): Map[String, GraphMLProperty] = (aNode match {
      case GraphMLNode(_, _, properties) => properties
      case _ => Map.empty[String, GraphMLProperty]
    }) + ("graphics" -> nodeGraphicsProperty(aNode, identifiable.id(aNode), shapeDefinition(aNode)))

    def dataKeys: Iterable[Elem] = graph.nodes(g).flatMap(nodeProperties(_).values).map { property: GraphMLProperty =>
      
    }

    def dataValues(node: N) = nodeProperties(node).map {
      case (key, property) => { property.value }
    }

    def nodeGraphicsProperty(
      node: N,
      label: String,
      shape: Option[ShapeDefinition]): GraphMLProperty = {
      val geometry = layout(node).map(_.geometry).getOrElse(DefaultGeometry(0, 0, 30, 30))

      val shapeNodeElem =
        // format: OFF
        
          
          
          
          {label}
            
              
            
          
           "roundrectangle"
          case other@_ => other
        }.getOrElse("rectangle")}/>
        
      // format: ON

      GraphMLProperty(
        key = GraphMLKey(id = "graphics", targetHint = Some("node"), yfilesType = Some("nodegraphics")),
        value = shapeNodeElem)
    }

    def edgesXml = {
      graph.edges(g).flatMap { edge =>
        val source = edgeType.head(edge)
        val target = edgeType.tail(edge)
        
      }
    }

    def nodesXml =
      graph.nodes(g).map { node =>
        
          { dataValues(node) }
        
      }

    // format: OFF
    
      
      { dataKeys }
      
        { nodesXml }
        { edgesXml }
      
    
    // format: ON
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy