Skip to content

Commit

Permalink
Exclude infinite x or y points for charts
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Sep 6, 2024
1 parent 0200a44 commit 049b195
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
70 changes: 70 additions & 0 deletions src/studio/kdb/K.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ public double toDouble() {
return value;
}

@Override
public boolean isPositiveInfinity() {
return false;
}

@Override
public boolean isNegativeInfinity() {
return false;
}

@Override
protected void serialiseData(OutputStream o) throws IOException {
write(o, value);
Expand Down Expand Up @@ -153,6 +163,16 @@ public boolean isNull() {
return value == Integer.MIN_VALUE;
}

@Override
public boolean isPositiveInfinity() {
return value == Integer.MAX_VALUE;
}

@Override
public boolean isNegativeInfinity() {
return value == -Integer.MAX_VALUE;
}

public double toDouble() {
return value;
}
Expand Down Expand Up @@ -204,6 +224,16 @@ public double toDouble() {
return value;
}

@Override
public boolean isPositiveInfinity() {
return value == Long.MAX_VALUE;
}

@Override
public boolean isNegativeInfinity() {
return value == -Long.MAX_VALUE;
}

public long toLong() {
return value;
}
Expand Down Expand Up @@ -247,6 +277,16 @@ public double toDouble() {
return value;
}

@Override
public boolean isPositiveInfinity() {
return value == Double.POSITIVE_INFINITY;
}

@Override
public boolean isNegativeInfinity() {
return value == Double.NEGATIVE_INFINITY;
}

@Override
public void serialiseData(OutputStream o) throws IOException {
long j = Double.doubleToLongBits(value);
Expand Down Expand Up @@ -575,6 +615,16 @@ public double toDouble() {
return b ? 1.0 : 0.0;
}

@Override
public boolean isPositiveInfinity() {
return false;
}

@Override
public boolean isNegativeInfinity() {
return false;
}

public boolean toBoolean() {
return b;
}
Expand Down Expand Up @@ -634,6 +684,16 @@ public double toDouble() {
return s;
}

@Override
public boolean isPositiveInfinity() {
return s == Short.MAX_VALUE;
}

@Override
public boolean isNegativeInfinity() {
return s == -Short.MAX_VALUE;
}

public KShort(short s) {
super(-5);
this.s = s;
Expand Down Expand Up @@ -826,6 +886,16 @@ public double toDouble() {
return f;
}

@Override
public boolean isPositiveInfinity() {
return f == Float.POSITIVE_INFINITY;
}

@Override
public boolean isNegativeInfinity() {
return f == Float.NEGATIVE_INFINITY;
}

public KFloat(float f) {
super(-8);
this.f = f;
Expand Down
9 changes: 8 additions & 1 deletion src/studio/kdb/ToDouble.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package studio.kdb;

public interface ToDouble {
public double toDouble();

double toDouble();
boolean isPositiveInfinity();
boolean isNegativeInfinity();

default boolean isInfinity() {
return isPositiveInfinity() || isNegativeInfinity();
}
}
8 changes: 5 additions & 3 deletions src/studio/ui/chart/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,11 @@ private IntervalXYDataset getDateset(int col) {
K.KBase yValue = (K.KBase)table.getValueAt(row, col);
if (xValue.isNull() || yValue.isNull()) continue;

double x = ((ToDouble)xValue).toDouble();
double y = ((ToDouble)yValue).toDouble();
series.add(x, y);
ToDouble x = (ToDouble)xValue;
ToDouble y = (ToDouble)yValue;
if (x.isInfinity() || y.isInfinity()) continue;

series.add(x.toDouble(), y.toDouble());
}
collection.addSeries(series);
return collection;
Expand Down

0 comments on commit 049b195

Please sign in to comment.