    001/*
    002 * Copyright 2025 The Apache Software Foundation.
    003 *
    004 * Licensed under the Apache License, Version 2.0 (the "License");
    005 * you may not use this file except in compliance with the License.
    006 * You may obtain a copy of the License at
    007 *
    008 *      http://www.apache.org/licenses/LICENSE-2.0
    009 *
    010 * Unless required by applicable law or agreed to in writing, software
    011 * distributed under the License is distributed on an "AS IS" BASIS,
    012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    013 * See the License for the specific language governing permissions and
    014 * limitations under the License.
    015 */
    016
    017package org.apache.jspwiki.plugins.chartist;
    018
    019import java.util.Locale;
    020import java.util.Map;
    021import org.apache.wiki.api.core.Context;
    022import org.apache.wiki.api.exceptions.PluginException;
    023import org.apache.wiki.api.plugin.Plugin;
    024
    025/**
    026 * Chartlist-js plugin for JSPWiki.
    027 *
    028 * See readme for deployment and usage guide.
    029 * @since 3.0.0
    030 */
    031public class ChartistPlugin implements Plugin {
    032
    033    @Override
    034    public String execute(Context context, Map<String, String> params) throws PluginException {
    035        StringBuilder sb = new StringBuilder();
    036        sb.append("""
    037                  <style type="text/css">
    038                  .chartist-options,.chartist-table{
    039                      display:none;
    040                  }
    041                  .ct-chart .ct-label,.ct-chart .ct-label.ct-vertical,.ct-chart .ct-label.ct-horizontal{
    042                      font-size:1em;
    043                  }
    044                  .ct-chart-pie .ct-label{
    045                      fill:rgba(255,255,255,.8);
    046                  }
    047
    048                  </style>
    049                  <script>
    050                  const script = document.createElement('script');
    051                  script.src = 'chartist-plugin/index.umd.js';
    052                  document.head.appendChild(script);
    053
    054                  const behavior = document.createElement('script');
    055                behavior.src = 'chartist-plugin/Wiki.Chartist.Behavior.js';
    056                document.head.appendChild(behavior);
    057
    058                  const stylesheet = document.createElement('link');
    059                  stylesheet.rel = 'stylesheet';
    060                  stylesheet.type = 'text/css';
    061                  stylesheet.href = 'chartist-plugin/index.css';
    062                  document.head.appendChild(stylesheet);
    063                  </script>
    064
    065                  """);
    066        //<link rel="stylesheet" href="webjars/chartist/dist/index.css" />
    067        //<script type="text/javascript" src="webjars/chartist/dist/index.umd.js"></script>
    068
    069        return sb.toString();
    070    }
    071
    072    @Override
    073    public String getSnipExample() {
    074        return Plugin.super.getSnipExample();
    075    }
    076
    077    @Override
    078    public String getDisplayName(Locale locale) {
    079        return Plugin.super.getDisplayName(locale);
    080    }
    081}
    082