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

org.datacleaner.visualization.DensityAnalyzerChartScriptHeadElement.scala Maven / Gradle / Ivy

package org.datacleaner.visualization

import org.datacleaner.result.html.HtmlRenderingContext
import org.datacleaner.result.html.HeadElement
import scala.collection.mutable.Map
import scala.collection.mutable.ListBuffer
import java.awt.Color

/**
 * Head element that writes a script specific to the rendering of a single result
 */
class DensityAnalyzerChartScriptHeadElement(result: DensityAnalyzerResult, elementId: String) extends HeadElement {

  val series: Map[String, ListBuffer[(Int, Int)]] = Map[String, ListBuffer[(Int, Int)]]().withDefault(rgbHex => {
    val list: ListBuffer[(Int, Int)] = new ListBuffer[(Int, Int)]()
    series.put(rgbHex, list)
    list
  });

  override def toHtml(context: HtmlRenderingContext): String = {

    val annotations = result.getRowAnnotations

    val maxRowsAnnotation = annotations.values.reduce((a, b) => if (a.getRowCount() > b.getRowCount()) a else b)
    val maxRows = maxRowsAnnotation.getRowCount()

    val paintScale = DensityAnalyzerColors.getPaintScale(maxRows);

    annotations.foreach(entry => {
      val point = entry._1
      val z = entry._2.getRowCount()

      val paint = paintScale.getPaint(z)
      val color = paint.asInstanceOf[Color]
      val rgbHex = DensityAnalyzerColors.toHexString(color)
      val list = series(rgbHex)
      list += point
    })

    return """
"""
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy