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

hotfix/dev-107.30 → develop #2057

Merged
merged 27 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6db80eb
Upgrades sirius-web 🕸️
jakobvogel Nov 18, 2024
9419955
Merge branch 'develop' into feature/jvo/OX-9272-SVG-Charts
jakobvogel Nov 26, 2024
2809faf
Upgrades Sirius ☄️
jakobvogel Nov 26, 2024
0950f8f
Merge branch 'develop' into feature/jvo/OX-9272-SVG-Charts
jakobvogel Nov 27, 2024
b237f2a
Removes dependency on JFreeChart ⚰️
jakobvogel Dec 3, 2024
d9035eb
Adds data container for charts 📊
jakobvogel Dec 5, 2024
57bf5ef
Adds pie and spider charts 📈
jakobvogel Dec 5, 2024
2a5d29f
Adds helper for obtaining a PDF-compatible SCG chart 🖨️
jakobvogel Dec 5, 2024
6971bdc
Bumps Sirius dependencies 🪐
jakobvogel Dec 5, 2024
fbd95d6
Merge pull request #2056 from scireum/ili/HF_107.2.1
jakobvogel Dec 6, 2024
4240299
Merge branch 'hotfix/dev-107.3.0' into feature/jvo/OX-9272-SVG-Charts
jakobvogel Dec 6, 2024
bcf0fbe
Removes blank line 🧹
jakobvogel Dec 11, 2024
9e920ca
Inlines helpers 🥞
jakobvogel Dec 11, 2024
e7aa697
Moves remaining static methods into helper class 🚛
jakobvogel Dec 11, 2024
9b2fad4
Inlines another helper 🫧
jakobvogel Dec 11, 2024
c98cb8f
Renames variables 📛
jakobvogel Dec 11, 2024
49dc88c
Uses `Math.TAU` 🐂
jakobvogel Dec 11, 2024
ffb3112
Renames abstract base class 📇
jakobvogel Dec 11, 2024
abda5ac
Adapts gray colors to design system definitions 🎨
jakobvogel Dec 11, 2024
db3ac87
Renames spider to radar chart 🕷️
jakobvogel Dec 11, 2024
6991f3f
Introduces a doughnut chart 🍩
jakobvogel Dec 11, 2024
5e2cbec
Renamed constants 📛
jakobvogel Dec 11, 2024
5d944a5
Writes numbers differently ✍️
jakobvogel Dec 11, 2024
1cd2fc0
Moves the internal helper back 🎡
jakobvogel Dec 11, 2024
09fccfd
Improves documentation and wording ✍️
jakobvogel Dec 11, 2024
2883f89
Merge pull request #2054 from scireum/feature/jvo/OX-9272-SVG-Charts
jakobvogel Dec 12, 2024
7f36257
Merge branch 'develop' into hotfix/dev-107.3.0
jakobvogel Dec 12, 2024
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
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,12 @@
<artifactId>sevenzipjbinding-all-platforms</artifactId>
<version>16.02-2.01</version>
</dependency>

<!-- Used to render diagrams into SVG -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-all</artifactId>
<version>1.18</version>
</dependency>
</dependencies>
</project>
181 changes: 181 additions & 0 deletions src/main/java/sirius/biz/charts/Chart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - info@scireum.de
*/

package sirius.biz.charts;

import org.apache.batik.anim.dom.SVGDOMImplementation;
import org.w3c.dom.Element;

import java.awt.Dimension;

/**
* Provides an interface for charts that can be rendered as SVG.
*/
public abstract class Chart {

/**
* Contains the tag name for circle elements, {@value}.
*/
protected static final String TAG_CIRCLE = "circle";

/**
* Contains the tag name for group elements, {@value}.
*/
protected static final String TAG_GROUP = "g";

/**
* Contains the tag name for path elements, {@value}.
*/
protected static final String TAG_PATH = "path";

/**
* Contains the tag name for SVG root elements, {@value}.
*/
protected static final String TAG_SVG = "svg";

/**
* Contains the tag name for text elements, {@value}.
*/
protected static final String TAG_TEXT = "text";

/**
* Contains the attribute name for the center x coordinate, {@value}.
*/
protected static final String ATTRIBUTE_CENTER_X = "cx";

/**
* Contains the attribute name for the center y coordinate, {@value}.
*/
protected static final String ATTRIBUTE_CENTER_Y = "cy";

/**
* Contains the attribute name for path definitions, {@value}.
*/
protected static final String ATTRIBUTE_DEFINITION = "d";

/**
* Contains the attribute name for the fill colour, {@value}.
*/
protected static final String ATTRIBUTE_FILL = "fill";

/**
* Contains the attribute name for the fill opacity, {@value}.
*/
protected static final String ATTRIBUTE_FILL_OPACITY = "fill-opacity";

/**
* Contains the attribute name for the font size, {@value}.
*/
protected static final String ATTRIBUTE_FONT_SIZE = "font-size";

/**
* Contains the attribute name for the radius, {@value}.
*/
protected static final String ATTRIBUTE_RADIUS = "r";

/**
* Contains the attribute name for the stroke colour, {@value}.
*/
protected static final String ATTRIBUTE_STROKE = "stroke";

/**
* Contains the attribute name for the stroke width, {@value}.
*/
protected static final String ATTRIBUTE_STROKE_WIDTH = "stroke-width";

/**
* Contains the attribute name for the text anchor, {@value}.
*/
protected static final String ATTRIBUTE_TEXT_ANCHOR = "text-anchor";

/**
* Contains the attribute name for the view box, {@value}.
*/
protected static final String ATTRIBUTE_VIEW_BOX = "viewBox";

/**
* Contains the attribute name for the x coordinate, {@value}.
*/
protected static final String ATTRIBUTE_X = "x";

/**
* Contains the attribute name for the y coordinate, {@value}.
*/
protected static final String ATTRIBUTE_Y = "y";

/**
* Contains the value for the {@linkplain #ATTRIBUTE_FILL fill attribute} to avoid filling, {@value}.
*/
protected static final String VALUE_FILL_NONE = "none";

/**
* Contains the value for the {@linkplain #ATTRIBUTE_TEXT_ANCHOR text anchor attribute} to align text at the start,
* {@value}.
*/
protected static final String VALUE_TEXT_ANCHOR_START = "start";

/**
* Contains the value for the {@linkplain #ATTRIBUTE_TEXT_ANCHOR text anchor attribute} to align text centered,
* {@value}.
*/
protected static final String VALUE_TEXT_ANCHOR_MIDDLE = "middle";

/**
* Contains the value for the {@linkplain #ATTRIBUTE_TEXT_ANCHOR text anchor attribute} to align text at the end,
* {@value}.
*/
protected static final String VALUE_TEXT_ANCHOR_END = "end";

/**
* Contains the black colour as hex-string, {@value}. The value is used as primary colour for charts.
*/
protected static final String COLOR_BLACK = "#000000";

/**
* Contains a dark gray colour as hex-string, {@value}. Its design system equivalent is {@code sirius-gray-dark}.
* <p>
* The value is used as secondary colour for charts.
*/
protected static final String COLOR_GRAY_DARK = "#808080";

/**
* Contains the light gray colour as hex-string, {@value}. Its design system equivalent is {@code sirius-gray-light}.
* <p>
* The value is used as secondary colour for charts.
*/
protected static final String COLOR_GRAY_LIGHT = "#c7c7c7";

/**
* Renders the chart as SVG.
*
* @param bounds the dimensions of the viewport
* @return the SVG representation of the chart
*/
public abstract Element toSvg(Dimension bounds);

/**
* Creates an empty SVG element with the view box centered.
*
* @param bounds the dimensions of the viewport
* @return an empty SVG element with the view box centered
*/
protected Element createSvgElementWithCenteredViewbox(Dimension bounds) {
Element svgElement = SVGDOMImplementation.getDOMImplementation()
.createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI,
Chart.TAG_SVG,
null)
.getDocumentElement();
svgElement.setAttribute(Chart.ATTRIBUTE_VIEW_BOX,
String.format("%f %f %f %f",
-0.5 * bounds.width,
-0.5 * bounds.height,
(double) bounds.width,
(double) bounds.height));
return svgElement;
}
}
46 changes: 46 additions & 0 deletions src/main/java/sirius/biz/charts/Charts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - info@scireum.de
*/

package sirius.biz.charts;

import com.lowagie.text.xml.XmlDomWriter;
import org.w3c.dom.Element;
import sirius.kernel.di.std.Register;
import sirius.web.templates.pdf.TagliatellePDFContentHandler;

import java.awt.Dimension;
import java.io.StringWriter;

/**
* Provides helpers to work with charts.
*/
@Register(classes = Charts.class)
public class Charts {

/**
* Exports a chart as SVG string that is compatible with {@linkplain TagliatellePDFContentHandler PDF rendering}.
*
* @param chart the chart to export
* @param bounds the dimensions of the viewport
* @return the SVG string representing the chart
*/
public String exportChartForPdf(Chart chart, Dimension bounds) {
// we need to clean the SVG code a bit to make it compatible with the PDF renderer
Element element = chart.toSvg(bounds);
element.setAttribute("style",
String.format("display: block; width: 100%%; height: %dmm; page-break-inside: avoid;",
bounds.height));

// note that the string writer uses a string buffer internally; no additional buffering or flushing is required
StringWriter writer = new StringWriter();
XmlDomWriter xmlWriter = new XmlDomWriter();
xmlWriter.setOutput(writer);
xmlWriter.write(element);
return writer.toString();
}
}
Loading
Loading