GemSunburstChart
Sunburst charts look like pie charts with multiple layers. Each of them refines the information of the previous layer and gives information about the distribution of the parent layer in percent. The sunburst chart can also be represented by a tree-like structure with parent nodes and subnodes which contain the refined information about the parent nodes. Unlike a GemPieChart, which only shows a single layer of categories, a sunburst chart is useful when the data has a hierarchical structure with multiple nested levels that should be shown at once. For example, it can be used to visualize the folder structure of a file system, or the breakdown of a company's revenue by region and then by product line.
Usage Example
/* (c) https://github.com/MontiCore/monticore */
package example_charts;
import Domain.Person;
import mc.fenix.arrange.GemColumn;
import mc.fenix.arrange.GemRow;
import mc.fenix.charts.GemSunburstChart;
import common.ExamplePage;
page GemSunburstChartExample(List<Person> persons) {
@ExamplePage(
component = @GemRow(width = "513px", height = "620px", components = [
@GemColumn(rowGap = "10px", width = "100%", components = [
@GemSunburstChart(
data = getData(),
ignoreError = true,
showConfig = true
)
])
]),
basePath = "example_charts",
componentName = "GemSunburstChartExample"
);
}
TypeScript implementation:
/* (c) https://github.com/MontiCore/monticore */
package example_charts;
import com.google.common.collect.Lists;
import domain.Person;
import mc.fenix.charts.gemsunburstcharttypes.GemSunburstData;
import mc.fenix.charts.gemsunburstcharttypes.GemSunburstDataBuilder;
import mc.fenix.charts.gemsunburstcharttypes.GemSunburstEntry;
import umlp.jsweet.extension.annotation.Component;
import java.util.ArrayList;
@Component
public class GemSunburstChartExample extends GemSunburstChartExampleTOP {
@Override
public GemSunburstData getData() {
if (this.getPersons() == null) {
return null;
}
GemSunburstData data = new GemSunburstDataBuilder().entry(new GemSunburstEntry("People separated in age groups", this.getPersons().size()))
.subEntries(Lists.newArrayList(
new GemSunburstDataBuilder().entry(new GemSunburstEntry("Number of people born before 1993", 0))
.subEntries(Lists.newArrayList(
new GemSunburstDataBuilder().entry(new GemSunburstEntry("Number of people born before 1987", 0))
.subEntries(new ArrayList<>()).build().get(),
new GemSunburstDataBuilder().entry(new GemSunburstEntry("Number of people born between 1987 and 1991", 0))
.subEntries(new ArrayList<>()).build().get(),
new GemSunburstDataBuilder().entry(new GemSunburstEntry("Number of people after 1991", 0))
.subEntries(new ArrayList<>()).build().get()
)).build().get(),
new GemSunburstDataBuilder().entry(new GemSunburstEntry("People born between 1993 and 1998", 0))
.subEntries(Lists.newArrayList(
new GemSunburstDataBuilder().entry(new GemSunburstEntry("Number of people born before 1995", 0))
.subEntries(new ArrayList<>()).build().get(),
new GemSunburstDataBuilder().entry(new GemSunburstEntry("Number of people born between 1995 and 1997", 0))
.subEntries(new ArrayList<>()).build().get(),
new GemSunburstDataBuilder().entry(new GemSunburstEntry("Number of people after 1997", 0))
.subEntries(new ArrayList<>()).build().get()
)).build().get(),
new GemSunburstDataBuilder().entry(new GemSunburstEntry("Number of people born after 1998", 0))
.subEntries(Lists.newArrayList(
new GemSunburstDataBuilder().entry(new GemSunburstEntry("Number of people born before 2001", 0))
.subEntries(new ArrayList<>()).build().get(),
new GemSunburstDataBuilder().entry(new GemSunburstEntry("Number of people born between 2001 and 2002", 0))
.subEntries(new ArrayList<>()).build().get(),
new GemSunburstDataBuilder().entry(new GemSunburstEntry("Number of people after 2002\"", 0))
.subEntries(new ArrayList<>()).build().get()
)).build().get())
).build().get();
for (Person person : this.getPersons()) {
int birthday = person.getBirthday().getYear();
if (birthday < 1993) {
data.getSubEntries(0).getEntry().setValue(data.getSubEntries(0).getEntry().getValue() + 1);
if (birthday < 1987) {
data.getSubEntries(0).getSubEntries(0).getEntry().setValue(data.getSubEntries(0).getSubEntries(0).getEntry().getValue() + 1);
}
else if (birthday < 1992) {
data.getSubEntries(0).getSubEntries(1).getEntry().setValue(data.getSubEntries(0).getSubEntries(1).getEntry().getValue() + 1);
}
else {
data.getSubEntries(0).getSubEntries(2).getEntry().setValue(data.getSubEntries(0).getSubEntries(2).getEntry().getValue() + 1);
}
}
else if (birthday <= 1998) {
data.getSubEntries(1).getEntry().setValue(data.getSubEntries(1).getEntry().getValue() + 1);
if (birthday < 1995) {
data.getSubEntries(1).getSubEntries(0).getEntry().setValue(data.getSubEntries(1).getSubEntries(0).getEntry().getValue() + 1);
}
else if (birthday < 1998) {
data.getSubEntries(1).getSubEntries(1).getEntry().setValue(data.getSubEntries(1).getSubEntries(1).getEntry().getValue() + 1);
}
else {
data.getSubEntries(1).getSubEntries(2).getEntry().setValue(data.getSubEntries(1).getSubEntries(2).getEntry().getValue() + 1);
}
}
else {
data.getSubEntries(2).getEntry().setValue(data.getSubEntries(2).getEntry().getValue() + 1);
if (birthday < 2001) {
data.getSubEntries(2).getSubEntries(0).getEntry().setValue(data.getSubEntries(2).getSubEntries(0).getEntry().getValue() + 1);
}
else if (birthday < 2003) {
data.getSubEntries(2).getSubEntries(1).getEntry().setValue(data.getSubEntries(2).getSubEntries(1).getEntry().getValue() + 1);
}
else {
data.getSubEntries(2).getSubEntries(2).getEntry().setValue(data.getSubEntries(2).getSubEntries(2).getEntry().getValue() + 1);
}
}
}
return data;
}
}
GUI Model
package mc.fenix.charts;
import mc.fenix.charts.GemSunburstChartTypes.GemSunburstData;
import mc.fenix.charts.GemSunburstChartTypes.GemSDNshort;
component GemSunburstChart (
GemSunburstData data,
GemSDNshort dataShort,
List<String> colors,
Boolean ignoreError,
boolean showConfig = false
)
| Name |
Type |
Description |
Default value |
data |
GemSunburstData |
The hierarchical data to be displayed in the chart. |
|
dataShort |
GemSDNshort |
Deprecated. Legacy, short data format kept for backwards compatibility. |
|
colors |
List<String> |
Colors used for the layers/segments of the chart. |
|
ignoreError |
Boolean |
Whether errors in the input data are ignored instead of raised. |
|
showConfig |
boolean |
Whether the chart's configuration panel is shown. |
false |
Types
GemSunburstChartTypes
package mc.fenix.charts;
import java.util.List;
<<pojoCD>>
classdiagram GemSunburstChartTypes {
public class GemSunburstData {
GemSunburstEntry entry;
List<GemSunburstData> subEntries;
}
public class GemSunburstDataHelper {
GemSunburstEntry entry;
List<GemSunburstData> subEntries;
String color;
}
public class GemSunburstEntry {
String label;
Integer value;
}
// Deprecated
public class GemSDNshort {
List<String> c; // In the hwc typescript it was any[]
List<GemSDNshort> sN;
}
}
GemSunburstData
| Name |
Type |
Description |
Default value |
entry |
GemSunburstEntry |
|
|
subEntries |
List<GemSunburstData> |
|
|
GemSunburstDataHelper
| Name |
Type |
Description |
Default value |
entry |
GemSunburstEntry |
|
|
subEntries |
List<GemSunburstData> |
|
|
color |
String |
|
|
GemSunburstEntry
| Name |
Type |
Description |
Default value |
label |
String |
|
|
value |
Integer |
|
|
GemSDNshort
| Name |
Type |
Description |
Default value |
c |
List<String> |
|
|
sN |
List<GemSDNshort> |
|
|