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

com.knockdata.spark.highcharts.Init.scala Maven / Gradle / Ivy

There is a newer version: 0.6.6
Show newest version
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.knockdata.spark.highcharts

object Init {

  val allHighchartUrls = List(
    "http://code.highcharts.com/highcharts.js",
    "http://code.highcharts.com/highcharts-more.js",
    "http://code.highcharts.com/highcharts-3d.js",
    "http://code.highcharts.com/adapters/standalone-framework.js",
    "http://code.highcharts.com/modules/annotations.js",
    "http://code.highcharts.com/modules/boost.js",
    "http://code.highcharts.com/modules/broken-axis.js",
    "http://code.highcharts.com/modules/canvas-tools.js",
    "http://code.highcharts.com/modules/data.js",
    "http://code.highcharts.com/modules/exporting.js",
    "http://code.highcharts.com/modules/drilldown.js",
    "http://code.highcharts.com/modules/funnel.js",
    "http://code.highcharts.com/modules/heatmap.js",
    "http://code.highcharts.com/modules/no-data-to-display.js",
    "http://code.highcharts.com/modules/offline-exporting.js",
    "http://code.highcharts.com/modules/solid-gauge.js",
    "http://code.highcharts.com/modules/treemap.js",
    "http://code.highcharts.com/maps/modules/map.js",
    "http://code.highcharts.com/mapdata/countries/us/us-all.js")

  // from name to url, name like "map", "us-all"
  val highchartName2Url = allHighchartUrls.map {
    url =>
      val name = url.stripSuffix(".js").split("/").last
      name -> url
  }.toMap


  /**
    * add one or few Highchart modules to the Zeppelin notebook
    *
    * if no parameters provided, then add all modules
    */
  def init(highcharts: String*): Unit = {

    val highchartUrls =
      if (highcharts.isEmpty)
        allHighchartUrls
      else {
        highcharts.map(name => highchartName2Url(name))
      }

    val jq = "$"

    // load js modules
    val loaders = highchartUrls.map {
      url =>
        s"""
           |$jq.getScript("$url")
           |  .done(function( script, textStatus ) {
           |    console.log( "load $url " + textStatus );
           |  })
           |  .fail(function(jqxhr, settings, exception ) {
           |     console.log("load $url " + exception);
           |  });
           | """.stripMargin
    }

    // wrap everything in %angular
    val template =
      s"""
        |%angular
        |
      """.stripMargin

    println(template)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy