Skip to content

Commit

Permalink
ChartInsp, ChartUtils: Added new StackedArea pseudo chart type
Browse files Browse the repository at this point in the history
  • Loading branch information
reportmill committed Oct 1, 2021
1 parent 7245681 commit 7457878
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
6 changes: 4 additions & 2 deletions src/snapcharts/apptools/ChartInsp.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ protected void respondUI(ViewEvent anEvent)
// Handle BarChartButton, LineChartButton, PieChartButton
if (anEvent.equals("LineChartButton"))
ChartUtils.setScatterType(chart, ChartUtils.ScatterType.LINE);
if (anEvent.equals("AreaChartButton"))
ChartUtils.setScatterType(chart, ChartUtils.ScatterType.AREA);
if (anEvent.equals("ScatterChartButton"))
ChartUtils.setScatterType(chart, ChartUtils.ScatterType.SCATTER);
if (anEvent.equals("AreaChartButton"))
ChartUtils.setScatterType(chart, ChartUtils.ScatterType.AREA);
if (anEvent.equals("StackedAreaChartButton"))
ChartUtils.setScatterType(chart, ChartUtils.ScatterType.STACKED_AREA);
if (anEvent.equals("BarChartButton"))
chart.setType(ChartType.BAR);
if (anEvent.equals("PieChartButton"))
Expand Down
33 changes: 16 additions & 17 deletions src/snapcharts/apptools/ChartInsp.snp
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<ColView Padding="4,10,4,10" Spacing="4" FillWidth="true">
<RowView Padding="4" Spacing="4">
<Label text="Name:" />
<Label Spacing="4" text="Name:" />
<TextField Name="NameText" GrowWidth="true" />
</RowView>
<TitleView MinWidth="120" MinHeight="60" GrowWidth="true" Text="Chart Type">
<RowView Padding="4,10,5,10" GrowWidth="true" FillHeight="true">
<ColView Spacing="4">
<RadioButton Name="LineChartButton" PrefWidth="80" PrefHeight="22" text="Line" Selected="true" Group="bg0" />
<RadioButton Name="AreaChartButton" PrefWidth="80" PrefHeight="22" text="Area" Group="bg0" />
<RadioButton Name="ScatterChartButton" PrefWidth="80" PrefHeight="22" text="Scatter" Group="bg0" />
<RadioButton Name="ContourChartButton" PrefWidth="80" PrefHeight="22" text="Contour" Group="bg0" />
<RowView Padding="6,10,5,15" GrowWidth="true" FillHeight="true">
<ColView MinWidth="120" Spacing="4">
<RadioButton Name="LineChartButton" PrefHeight="22" Spacing="5" text="Line" Selected="true" Group="bg0" />
<RadioButton Name="AreaChartButton" PrefHeight="22" Spacing="5" text="Area" Group="bg0" />
<RadioButton Name="BarChartButton" PrefWidth="80" PrefHeight="22" Spacing="5" text="Bar" Group="bg0" />
<RadioButton Name="PieChartButton" PrefHeight="22" Spacing="5" text="Pie" Group="bg0" />
<RadioButton Name="PolarChartButton" PrefHeight="22" Spacing="5" text="Polar" Group="bg0" />
<RadioButton Name="ContourChartButton" PrefHeight="22" Spacing="5" text="Contour" Group="bg0" />
</ColView>
<ColView Spacing="4">
<RadioButton Name="BarChartButton" PrefWidth="80" PrefHeight="22" text="Bar" Group="bg0" />
<RadioButton Name="PieChartButton" PrefWidth="80" PrefHeight="22" text="Pie" Group="bg0" />
<RadioButton Name="PolarChartButton" PrefWidth="80" PrefHeight="22" text="Polar" Group="bg0" />
<RadioButton Name="PolarContourChartButton" PrefWidth="90" PrefHeight="22" text="Polar Contour" Group="bg0" />
</ColView>
<ColView Spacing="4">
<RadioButton Name="Bar3DChartButton" PrefWidth="90" PrefHeight="22" text="Bar 3D" Group="bg0" />
<RadioButton Name="Pie3DChartButton" PrefWidth="80" PrefHeight="22" text="Pie 3D" Group="bg0" />
<RadioButton Name="Line3DChartButton" PrefWidth="80" PrefHeight="22" text="Line 3D" Group="bg0" />
<ColView MinWidth="100" Spacing="4">
<RadioButton Name="ScatterChartButton" PrefHeight="22" Spacing="5" text="Scatter" Group="bg0" />
<RadioButton Name="StackedAreaChartButton" PrefHeight="22" Spacing="5" text="Stacked Area" Group="bg0" />
<RadioButton Name="Bar3DChartButton" PrefHeight="22" Spacing="5" text="Bar 3D" Group="bg0" />
<RadioButton Name="Pie3DChartButton" PrefHeight="22" Spacing="5" text="Pie 3D" Group="bg0" />
<RadioButton Name="PolarContourChartButton" PrefHeight="22" Spacing="5" text="Polar Contour" Group="bg0" />
<RadioButton Name="Line3DChartButton" PrefHeight="22" Spacing="5" text="Line 3D" Group="bg0" />
</ColView>
</RowView>
</TitleView>
Expand Down
32 changes: 26 additions & 6 deletions src/snapcharts/util/ChartUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,32 @@
public class ChartUtils {

// Constants for Scatter type
public enum ScatterType { LINE, AREA, SCATTER }
public enum ScatterType { LINE, AREA, SCATTER, STACKED_AREA }

/**
* Returns the ScatterType for a Chart.
*/
public static ScatterType getScatterType(Chart aChart)
{
// Get DataSets (if none, just return LINE)
DataSet[] dataSets = aChart.getDataSetList().getDataSets();
if (dataSets.length == 0)
return ScatterType.SCATTER;
return ScatterType.LINE;

// If all DataSets ShowArea, return AREA
boolean showArea = true;
for (DataSet dataSet : dataSets) {
if (!dataSet.getDataStyle().isShowArea()) {
showArea = false;
break;
}
if (dataSet.isStacked())
return ScatterType.STACKED_AREA;
}
if (showArea)
return ScatterType.AREA;

// If all DataSets ShowLine, return LINE
boolean showLine = true;
for (DataSet dataSet : dataSets) {
if (!dataSet.getDataStyle().isShowLine()) {
Expand All @@ -38,6 +45,8 @@ public static ScatterType getScatterType(Chart aChart)
}
if (showLine)
return ScatterType.LINE;

// Return SCATTER
return ScatterType.SCATTER;
}

Expand All @@ -46,13 +55,22 @@ public static ScatterType getScatterType(Chart aChart)
*/
public static void setScatterType(Chart aChart, ScatterType scatterType)
{
// Get booleans
boolean isLine = scatterType == ScatterType.LINE;
boolean isScatter = scatterType == ScatterType.SCATTER;
boolean isArea = scatterType == ScatterType.AREA;
boolean isStackedArea = scatterType == ScatterType.STACKED_AREA;

aChart.setType(ChartType.SCATTER);

// Configure DataSets
DataSet[] dataSets = aChart.getDataSetList().getDataSets();
for (DataSet dataSet : dataSets) {
DataStyle dataStyle = dataSet.getDataStyle();
dataStyle.setShowLine(scatterType == ScatterType.LINE || scatterType == ScatterType.AREA);
dataStyle.setShowSymbols(scatterType == ScatterType.LINE || scatterType == ScatterType.SCATTER);
dataStyle.setShowArea(scatterType == ScatterType.AREA);
dataStyle.setShowLine(isLine || isArea || isStackedArea);
dataStyle.setShowSymbols(isLine || isScatter);
dataStyle.setShowArea(isArea || isStackedArea);
dataSet.setStacked(isStackedArea);
}
}

Expand All @@ -61,9 +79,11 @@ public static void setScatterType(Chart aChart, ScatterType scatterType)
*/
public static String getScatterTypeString(Chart aChart)
{
switch (getScatterType(aChart)) {
ScatterType scatterType = getScatterType(aChart);
switch (scatterType) {
case LINE: return "Line";
case AREA: return "Area";
case STACKED_AREA: return "StackedArea";
default: return "Scatter";
}
}
Expand Down

0 comments on commit 7457878

Please sign in to comment.