Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make trend charts theme-aware #287

Merged
merged 7 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<module.name>${project.groupId}.echarts</module.name>

<echarts-build-trends.version>4.3.0</echarts-build-trends.version>
<echarts-build-trends.version>4.4.0</echarts-build-trends.version>

</properties>

Expand Down
20 changes: 20 additions & 0 deletions skip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -e

JENKINS_HOME=../docker/volumes/jenkins-home

mvn -o clean install -Pskip || { echo "Build failed"; exit 1; }

echo "Installing plugin in $JENKINS_HOME"

rm -rf $JENKINS_HOME/plugins/echarts-api-plugin*
cp -fv target/echarts-api.hpi $JENKINS_HOME/plugins/echarts-api.jpi

CURRENT_UID="$(id -u):$(id -g)"
export CURRENT_UID
IS_RUNNING=$(docker-compose ps -q jenkins-controller)
if [[ "$IS_RUNNING" != "" ]]; then
docker-compose restart
echo "Restarting Jenkins (docker compose with user ID ${CURRENT_UID}) ..."
fi
98 changes: 98 additions & 0 deletions src/main/java/io/jenkins/plugins/echarts/JenkinsPalette.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package io.jenkins.plugins.echarts;

import java.util.List;
import java.util.Locale;

import org.apache.commons.lang3.StringUtils;

/**
* Jenkins color palette. Each color is represented as a CSS variable that will be rendered according to the selected
* theme.
*
* @author Ullrich Hafner
* @see "JS method resolveJenkinsColors in file echarts-scope.js"
* @see <a href="https://github.com/jenkinsci/jenkins/blob/master/war/src/main/scss/abstracts/theme.scss">Jenkins
* colors</a>
*/
public enum JenkinsPalette {
BLACK(StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY),
BLUE,
BROWN,
CYAN,
GREY("light-", "medium-", "dark-"),
GREEN,
INDIGO,
ORANGE,
PINK,
PURPLE,
RED,
WHITE(StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY),
YELLOW;

static final List<JenkinsPalette> CHART_COLORS = List.of(JenkinsPalette.RED, JenkinsPalette.BLUE,
JenkinsPalette.YELLOW, JenkinsPalette.GREEN, JenkinsPalette.CYAN, JenkinsPalette.INDIGO,
JenkinsPalette.ORANGE, JenkinsPalette.PINK, JenkinsPalette.PURPLE, JenkinsPalette.BROWN);

/**
* Returns a chart color that can be used to render element {@code n} in a chart. If {@code n} is greater than
* the number of available colors then the color will be selected from the beginning of the list,
* and so on.
*
* @param n
* the n-th element to render
*
* @return a color to be used for rendering the n-th element
*/
public static JenkinsPalette chartColor(final int n) {
return CHART_COLORS.get(n % CHART_COLORS.size());
}

private final String infixLight;
private final String infixNormal;
private final String infixDark;

JenkinsPalette() {
this(LIGHT_INFIX, StringUtils.EMPTY, DARK_INFIX);
}

JenkinsPalette(final String infixLight, final String infixNormal, final String infixDark) {
this.infixLight = infixLight;
this.infixNormal = infixNormal;
this.infixDark = infixDark;
}

private static final String PREFIX = "--";
private static final String DARK_INFIX = "dark-";
private static final String LIGHT_INFIX = "light-";

/**
* Returns the CSS variable name for this color (light variation).
*
* @return the CSS variable name
*/
public String light() {
return compose(infixLight);
}

/**
* Returns the CSS variable name for this color.
*
* @return the CSS variable name
*/
public String normal() {
return compose(infixNormal);
}

/**
* Returns the CSS variable name for this color (dark variation).
*
* @return the CSS variable name
*/
public String dark() {
return compose(infixDark);
}

private String compose(final String infix) {
return PREFIX + infix + name().toLowerCase(Locale.ENGLISH);
}
}
7 changes: 1 addition & 6 deletions src/main/resources/io/jenkins/plugins/echarts-common.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ Use it like <st:adjunct includes="io.jenkins.plugins.echarts-common"/>

<link type="text/css" rel="stylesheet" href="${resURL}/plugin/echarts-api/css/jenkins-style.css"/>

<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/echarts-scope.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/chart-configuration.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/trend-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/zoomable-trend-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/configurable-trend-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/echarts-api.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/pie-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/progress-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/escapeMetaCharacters.js"/>

</j:jelly>
7 changes: 1 addition & 6 deletions src/main/resources/io/jenkins/plugins/echarts-simple.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ Use it like <st:adjunct includes="io.jenkins.plugins.echarts-simple"/>

<link type="text/css" rel="stylesheet" href="${resURL}/plugin/echarts-api/css/jenkins-style.css"/>

<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/echarts-scope.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/chart-configuration.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/trend-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/zoomable-trend-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/configurable-trend-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/echarts-api.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/pie-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/progress-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/escapeMetaCharacters.js"/>

</j:jelly>
7 changes: 1 addition & 6 deletions src/main/resources/io/jenkins/plugins/echarts.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ Use it like <st:adjunct includes="io.jenkins.plugins.echarts"/>

<link type="text/css" rel="stylesheet" href="${resURL}/plugin/echarts-api/css/jenkins-style.css"/>

<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/echarts-scope.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/chart-configuration.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/trend-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/zoomable-trend-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/configurable-trend-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/echarts-api.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/pie-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/progress-chart.js"/>
<script type="text/javascript" src="${resURL}/plugin/echarts-api/js/escapeMetaCharacters.js"/>

</j:jelly>
178 changes: 0 additions & 178 deletions src/main/webapp/js/chart-configuration.js

This file was deleted.

Loading