Skip to content

Commit

Permalink
Trace: Modified so this is used for line/fill properties instead of T…
Browse files Browse the repository at this point in the history
…raceStyle

PointStyle: Moved point spacing properties here from TraceStyle
  • Loading branch information
reportmill committed Nov 20, 2021
1 parent 6445f4e commit 56f2136
Show file tree
Hide file tree
Showing 28 changed files with 492 additions and 646 deletions.
6 changes: 1 addition & 5 deletions src/snapcharts/app/ChartStyler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import snap.util.Undoer;
import snap.view.View;
import snapcharts.model.ChartPart;
import snapcharts.model.Trace;

/**
* ChartStyler.
Expand Down Expand Up @@ -138,10 +137,7 @@ public void setTextColor(Color aColor)
*/
private ChartPart getSelPart()
{
ChartPart chartPart = _editor.getSelChartPart();
if (chartPart instanceof Trace)
chartPart = ((Trace) chartPart).getTraceStyle();
return chartPart;
return _editor.getSelChartPart();
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/snapcharts/appmisc/OpenInPlotly.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ else if (axis.isZeroRequired())
private void writeTrace(Trace aTrace, int anIndex)
{
// Get Trace info
TraceStyle traceStyle = aTrace.getTraceStyle();
int pointCount = aTrace.getPointCount();
DataType dataType = aTrace.getDataType();
int chanCount = dataType.getChannelCount();
Expand Down Expand Up @@ -324,12 +323,12 @@ private void writeTrace(Trace aTrace, int anIndex)
traceJS.addKeyValue("line", lineJS);

// Set the line.color
Color color = traceStyle.getLineColor();
Color color = aTrace.getLineColor();
String colorStr = getPlotlyColorString(color);
lineJS.addKeyValue("color", colorStr);

// Set the line.width
lineJS.addKeyValue("width", traceStyle.getLineWidth());
lineJS.addKeyValue("width", aTrace.getLineWidth());
}
}

Expand Down
34 changes: 25 additions & 9 deletions src/snapcharts/apptools/ContourStyleInsp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import snap.view.ViewEvent;
import snapcharts.app.ChartPane;
import snapcharts.model.ChartPart;
import snapcharts.model.Trace;
import snapcharts.model.TraceStyle;
import snapcharts.modelx.ContourStyle;

Expand All @@ -28,17 +29,34 @@ public ContourStyleInsp(ChartPane aChartPane)
* Returns the ChartPart.
*/
@Override
public ChartPart getChartPart() { return getChart().getTraceStyle(); }
public ChartPart getChartPart() { return getContourStyle(); }

/**
* Returns the Trace.
*/
public Trace getTrace()
{
ChartPart selPart = _chartPane.getSelChartPart();
return selPart instanceof Trace ? (Trace) selPart : null;
}

/**
* Returns the TraceStyle.
*/
public ContourStyle getContourStyle()
{
Trace trace = getTrace();
TraceStyle traceStyle = trace != null ? trace.getTraceStyle() : null;
return traceStyle instanceof ContourStyle ? (ContourStyle) traceStyle : null;
}

/**
* Reset UI.
*/
protected void resetUI()
{
// Get TraceStyle
TraceStyle traceStyle = getChart().getTraceStyle();
ContourStyle contourStyle = traceStyle instanceof ContourStyle ? (ContourStyle) traceStyle : null;
if (contourStyle == null) return;
// Get ContourStyle
ContourStyle contourStyle = getContourStyle(); if (contourStyle == null) return;

// Reset ShowLinesCheckBox, ShowMeshCheckBox
setViewValue("ShowLinesCheckBox", contourStyle.isShowLines());
Expand All @@ -51,10 +69,8 @@ protected void resetUI()
*/
protected void respondUI(ViewEvent anEvent)
{
// Get TraceStyle
TraceStyle traceStyle = getChart().getTraceStyle();
ContourStyle contourStyle = traceStyle instanceof ContourStyle ? (ContourStyle) traceStyle : null;
if (contourStyle == null) return;
// Get ContourStyle
ContourStyle contourStyle = getContourStyle(); if (contourStyle == null) return;

// Handle ShowLinesCheckBox, ShowMeshCheckBox
if (anEvent.equals("ShowLinesCheckBox"))
Expand Down
30 changes: 10 additions & 20 deletions src/snapcharts/apptools/PolarStyleInsp.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package snapcharts.apptools;
import snap.view.ViewEvent;
import snapcharts.app.ChartPane;
import snapcharts.model.Chart;
import snapcharts.model.ChartPart;
import snapcharts.model.Trace;
import snapcharts.model.TraceStyle;
Expand Down Expand Up @@ -33,34 +32,25 @@ public PolarStyleInsp(ChartPane aChartPane)
* Returns the ChartPart.
*/
@Override
public ChartPart getChartPart() { return getChart().getTraceStyle(); }
public ChartPart getChartPart() { return getPolarStyle(); }

/**
* Returns the PolarStyle.
* Returns the Trace.
*/
public PolarStyle getPolarStyle()
public Trace getTrace()
{
ChartPart chartPart = _chartPane.getSelChartPart();
if (chartPart instanceof Trace) {
Trace trace = (Trace) chartPart;
TraceStyle traceStyle = trace.getTraceStyle();
if (traceStyle instanceof PolarStyle)
return (PolarStyle) traceStyle;
}

Chart chart = getChart();
TraceStyle traceStyle = chart.getTraceStyle();
if (traceStyle instanceof PolarStyle)
return (PolarStyle) traceStyle;
return null;
ChartPart selPart = _chartPane.getSelChartPart();
return selPart instanceof Trace ? (Trace) selPart : null;
}

/**
* Initialize UI.
* Returns the PolarStyle.
*/
@Override
protected void initUI()
public PolarStyle getPolarStyle()
{
Trace trace = getTrace();
TraceStyle traceStyle = trace != null ? trace.getTraceStyle() : null;
return traceStyle instanceof PolarStyle ? (PolarStyle) traceStyle : null;
}

/**
Expand Down
38 changes: 12 additions & 26 deletions src/snapcharts/apptools/TraceAreaStyleInsp.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public TraceAreaStyleInsp(ChartPane aChartPane)
@Override
public ChartPart getChartPart()
{
return getTraceStyle();
return getTrace();
}

/**
Expand All @@ -45,27 +45,15 @@ public Trace getTrace()
return selPart instanceof Trace ? (Trace) selPart : null;
}

/**
* Returns the TraceStyle.
*/
public TraceStyle getTraceStyle()
{
Trace trace = getTrace();
if (trace != null)
return trace.getTraceStyle();

return getChart().getTraceStyle();
}

/**
* Initialize UI.
*/
@Override
protected void initUI()
{
// Configure FillModeComboBox to show FillModes
ComboBox<TraceStyle.FillMode> fillModeComboBox = getView("FillModeComboBox", ComboBox.class);
fillModeComboBox.setItems(TraceStyle.FillMode.values());
ComboBox<Trace.FillMode> fillModeComboBox = getView("FillModeComboBox", ComboBox.class);
fillModeComboBox.setItems(Trace.FillMode.values());
fillModeComboBox.setItemTextFunction(item -> StringUtils.fromCamelCase(item.toString()));
}

Expand All @@ -74,30 +62,28 @@ protected void initUI()
*/
protected void resetUI()
{
// Get Trace, TraceStyle
// Get Trace
Trace trace = getTrace(); if (trace == null) return;
TraceStyle traceStyle = getTraceStyle(); if (traceStyle == null) return;

// Reset ShowAreaCheckBox
boolean showArea = trace.isShowArea();
setViewValue("ShowAreaCheckBox", showArea);

// Reset FillColorButton, FillColorResetButton
setViewValue("FillColorButton", traceStyle.getFillColor());
setViewVisible("FillColorResetButton", traceStyle.isFillSet());
setViewValue("FillColorButton", trace.getFillColor());
setViewVisible("FillColorResetButton", trace.isFillSet());

// Reset FillModeComboBox
setViewSelItem("FillModeComboBox", traceStyle.getFillMode());
setViewSelItem("FillModeComboBox", trace.getFillMode());
}

/**
* Respond to UI.
*/
protected void respondUI(ViewEvent anEvent)
{
// Get TraceStyle
// Get Trace
Trace trace = getTrace(); if (trace == null) return;
TraceStyle traceStyle = getTraceStyle(); if (traceStyle == null) return;

// Handle ShowAreaCheckBox, FillModeComboBox
if (anEvent.equals("ShowAreaCheckBox")) {
Expand All @@ -109,15 +95,15 @@ protected void respondUI(ViewEvent anEvent)
if (anEvent.equals("FillColorButton")) {
Color color = (Color) getViewValue("FillColorButton");
color = color.getAlpha() <= .5 ? color : color.copyForAlpha(.5);
traceStyle.setFill(color);
trace.setFill(color);
}
if (anEvent.equals("FillColorResetButton"))
traceStyle.setFill(null);
trace.setFill(null);

// Handle FillModeComboBox
if (anEvent.equals("FillModeComboBox")) {
TraceStyle.FillMode fillMode = (TraceStyle.FillMode) getViewSelItem("FillModeComboBox");
traceStyle.setFillMode(fillMode);
Trace.FillMode fillMode = (Trace.FillMode) getViewSelItem("FillModeComboBox");
trace.setFillMode(fillMode);
}
}
}
48 changes: 17 additions & 31 deletions src/snapcharts/apptools/TraceLineStyleInsp.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public TraceLineStyleInsp(ChartPane aChartPane)
@Override
public ChartPart getChartPart()
{
return getTraceStyle();
return getTrace();
}

/**
Expand All @@ -49,18 +49,6 @@ public Trace getTrace()
return selPart instanceof Trace ? (Trace) selPart : null;
}

/**
* Returns the TraceStyle.
*/
public TraceStyle getTraceStyle()
{
Trace trace = getTrace();
if (trace != null)
return trace.getTraceStyle();

return getChart().getTraceStyle();
}

/**
* Initialize UI.
*/
Expand Down Expand Up @@ -88,42 +76,40 @@ protected void initUI()
*/
protected void resetUI()
{
// Get TraceStyle
// Get Trace
Trace trace = getTrace(); if (trace == null) return;
TraceStyle traceStyle = getTraceStyle(); if (traceStyle == null) return;

// Reset ShowLineCheckBox
boolean showLine = trace.isShowLine();
setViewValue("ShowLineCheckBox", showLine);

// Reset LineColorButton, LineColorResetButton
setViewValue("LineColorButton", traceStyle.getLineColor());
setViewVisible("LineColorResetButton", traceStyle.isLineColorSet());
setViewValue("LineColorButton", trace.getLineColor());
setViewVisible("LineColorResetButton", trace.isLineColorSet());

// Reset LineWidthText, LineWidthResetButton
setViewValue("LineWidthText", traceStyle.getLineWidth());
setViewVisible("LineWidthResetButton", traceStyle.getLineWidth() != TraceStyle.DEFAULT_LINE_WIDTH);
setViewValue("LineWidthText", trace.getLineWidth());
setViewVisible("LineWidthResetButton", trace.getLineWidth() != TraceStyle.DEFAULT_LINE_WIDTH);

// Reset LineDashButton
ToggleButton lineDashButton = getView("LineDashButton", ToggleButton.class);
configureLineDashButton(lineDashButton, traceStyle.getLineDash());
configureLineDashButton(lineDashButton, trace.getLineDash());

// Reset LineDashBox
View lineDashBox = getView("LineDashBox");
ViewAnimUtils.setVisible(lineDashBox, lineDashButton.isSelected(), false, true);

// Reset PointJoinComboBox
setViewSelItem("PointJoinComboBox", traceStyle.getPointJoin());
setViewSelItem("PointJoinComboBox", trace.getPointJoin());
}

/**
* Respond to UI.
*/
protected void respondUI(ViewEvent anEvent)
{
// Get TraceStyle
// Get Trace
Trace trace = getTrace(); if (trace == null) return;
TraceStyle traceStyle = getTraceStyle(); if (traceStyle == null) return;

// Handle ShowLineCheckBox
if (anEvent.equals("ShowLineCheckBox")) {
Expand All @@ -135,33 +121,33 @@ protected void respondUI(ViewEvent anEvent)

// Handle LineWidthText, LineWidthAdd1Button, LineWidthSub1Button, LineWidthResetButton
if (anEvent.equals("LineWidthText"))
traceStyle.setLineWidth(Math.max(anEvent.getIntValue(), 1));
trace.setLineWidth(Math.max(anEvent.getIntValue(), 1));
if (anEvent.equals("LineWidthAdd1Button"))
traceStyle.setLineWidth(traceStyle.getLineWidth() + 1);
trace.setLineWidth(trace.getLineWidth() + 1);
if (anEvent.equals("LineWidthSub1Button"))
traceStyle.setLineWidth(Math.max(traceStyle.getLineWidth() - 1, 1));
trace.setLineWidth(Math.max(trace.getLineWidth() - 1, 1));
if (anEvent.equals("LineWidthResetButton"))
traceStyle.setLineWidth(1);
trace.setLineWidth(1);

// Handle LineColorButton, LineColorResetButton
if (anEvent.equals("LineColorButton")) {
Color color = (Color) getViewValue("LineColorButton");
traceStyle.setLineColor(color);
trace.setLineColor(color);
}
if (anEvent.equals("LineColorResetButton"))
traceStyle.setLineColor(null);
trace.setLineColor(null);

// Handle LineDashButton_X
String eventName = anEvent.getName();
if (eventName.startsWith("LineDashButton_")) {
int id = SnapUtils.intValue(eventName);
double[] dashArray = Stroke.DASHES_ALL[id];
traceStyle.setLineDash(dashArray);
trace.setLineDash(dashArray);
}

// Handle PointJoinComboBox
if (anEvent.equals("PointJoinComboBox"))
traceStyle.setPointJoin((PointJoin) anEvent.getSelItem());
trace.setPointJoin((PointJoin) anEvent.getSelItem());
}

/**
Expand Down
Loading

0 comments on commit 56f2136

Please sign in to comment.