# HG changeset patch # User Tomas Zeman # Date 1459432560 -7200 # Node ID 147153d571330b633b74ec5c3696917cd43a18d5 # Parent caab42578564bd0842bc15bf5782d27984a0c890 Modularized RadarChart. diff -r caab42578564 -r 147153d57133 build.sbt --- a/build.sbt Thu Mar 31 15:02:45 2016 +0200 +++ b/build.sbt Thu Mar 31 15:56:00 2016 +0200 @@ -1,18 +1,23 @@ +import sbt.Project.project + lazy val root = project.in(file(".")). - aggregate(ngtagsJS, ngtagsJVM). + aggregate(ngtagsJS, ngtagsJVM, radarChart). settings( publish := {}, publishLocal := {} ) -lazy val ngtags = crossProject.in(file(".")). -enablePlugins(BuildInfoPlugin). -settings( +lazy val buildSettings = Seq( organization := "net.tz", name := "ngTags", scalaVersion := "2.11.8", - licenses += ("Apache-2.0", url("http://opensource.org/licenses/Apache-2.0")), + licenses += ("Apache-2.0", url("http://opensource.org/licenses/Apache-2.0")) +) +lazy val ngtags = crossProject.in(file(".")). +enablePlugins(BuildInfoPlugin). +settings(buildSettings:_*). +settings( libraryDependencies ++= Seq( "com.lihaoyi" %%% "scalatags" % "0.5.3" //"com.github.japgolly.scalacss" %%% "ext-scalatags" % "0.1.0" @@ -27,11 +32,17 @@ buildInfoPackage := "ngtags", buildInfoOptions ++= Seq(BuildInfoOption.ToMap, BuildInfoOption.ToJson) -).jvmSettings().jsSettings( - jsDependencies += ProvidedJS / "RadarChart.js" -) +).jvmSettings().jsSettings() lazy val ngtagsJS = ngtags.js lazy val ngtagsJVM = ngtags.jvm +lazy val radarChart = project.in(file("radar-chart")). + enablePlugins(ScalaJSPlugin). + settings(buildSettings: _*). + settings(moduleName := "ngtags-radarchart"). + settings( + jsDependencies += ProvidedJS / "RadarChart.js" + ) + // vim: et ts=2 sw=2 syn=scala diff -r caab42578564 -r 147153d57133 js/src/main/resources/RadarChart.js --- a/js/src/main/resources/RadarChart.js Thu Mar 31 15:02:45 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,245 +0,0 @@ -/* - * Cloned from https://gist.github.com/nbremer/6506614 - */ - -//Practically all this code comes from https://github.com/alangrafu/radar-chart-d3 -//I only made some additions and aesthetic adjustments to make the chart look better -//(of course, that is only my point of view) -//Such as a better placement of the titles at each line end, -//adding numbers that reflect what each circular level stands for -//Not placing the last level and slight differences in color -// -//For a bit of extra information check the blog about it: -//http://nbremer.blogspot.nl/2013/09/making-d3-radar-chart-look-bit-better.html - -var RadarChart = { - draw: function(id, d, options){ - var cfg = { - radius: 5, - w: 600, - h: 600, - factor: 1, - factorLegend: .85, - levels: 3, - maxValue: 0, - radians: 2 * Math.PI, - opacityArea: 0.5, - ToRight: 5, - TranslateX: 80, - TranslateY: 30, - ExtraWidthX: 100, - ExtraWidthY: 100, - color: d3.scale.category10(), - offset: 0.0, - formatAxis: d3.format('%'), - formatValue: d3.format('%'), - drawMaxLevel: false - }; - - if (d.length == 0) - return; - - if('undefined' !== typeof options){ - for(var i in options){ - if('undefined' !== typeof options[i]){ - cfg[i] = options[i]; - } - } - } - cfg.maxValue = Math.max(cfg.maxValue, d3.max(d, function(i){return d3.max(i.map(function(o){return o.value;}))})) + cfg.offset; - var allAxis = (d[0].map(function(i, j){return i})); - var total = allAxis.length; - var radius = cfg.factor*Math.min(cfg.w/2, cfg.h/2); - d3.select(id).select("svg").remove(); - - var g = d3.select(id) - .append("svg") - .attr("width", cfg.w+cfg.ExtraWidthX) - .attr("height", cfg.h+cfg.ExtraWidthY) - .append("g") - .attr("transform", "translate(" + cfg.TranslateX + "," + cfg.TranslateY + ")"); - ; - - var tooltip; - - //Circular segments - var maxLevel = cfg.drawMaxLevel ? cfg.levels : cfg.levels - 1; - for(var j=0; j