Skip to content

Commit 5052dcc

Browse files
Fixed #5 - "How to plot vector of all zeros?"
1 parent 24aab1e commit 5052dcc

File tree

16 files changed

+475
-41
lines changed

16 files changed

+475
-41
lines changed

C/pbPlots.c

+11
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,17 @@ _Bool DrawScatterPlotFromSettings(RGBABitmapImageReference *canvasReference, Sca
636636
xMax = boundaries->x2;
637637
yMax = boundaries->y2;
638638

639+
// If zero, set to defaults.
640+
if(xMin - xMax == 0){
641+
xMin = 0;
642+
xMax = 10;
643+
}
644+
645+
if(yMin - yMax == 0){
646+
yMin = 0;
647+
yMax = 10;
648+
}
649+
639650
xLength = xMax - xMin;
640651
yLength = yMax - yMin;
641652

CS/pbPlots.cs

+11
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,17 @@ public static bool DrawScatterPlotFromSettings(RGBABitmapImageReference canvasRe
818818
xMax = boundaries.x2;
819819
yMax = boundaries.y2;
820820

821+
// If zero, set to defaults.
822+
if(xMin - xMax == 0){
823+
xMin = 0;
824+
xMax = 10;
825+
}
826+
827+
if(yMin - yMax == 0){
828+
yMin = 0;
829+
yMax = 10;
830+
}
831+
821832
xLength = xMax - xMin;
822833
yLength = yMax - yMin;
823834

Cpp/pbPlots.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,17 @@ bool DrawScatterPlotFromSettings(RGBABitmapImageReference *canvasReference, Scat
606606
xMax = boundaries->x2;
607607
yMax = boundaries->y2;
608608

609+
// If zero, set to defaults.
610+
if(xMin - xMax == 0){
611+
xMin = 0;
612+
xMax = 10;
613+
}
614+
615+
if(yMin - yMax == 0){
616+
yMin = 0;
617+
yMax = 10;
618+
}
619+
609620
xLength = xMax - xMin;
610621
yLength = yMax - yMin;
611622

Java/pbPlots/pbPlots.java

+11
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,17 @@ public static boolean DrawScatterPlotFromSettings(RGBABitmapImageReference canva
696696
xMax = boundaries.x2;
697697
yMax = boundaries.y2;
698698

699+
// If zero, set to defaults.
700+
if(xMin - xMax == 0){
701+
xMin = 0;
702+
xMax = 10;
703+
}
704+
705+
if(yMin - yMax == 0){
706+
yMin = 0;
707+
yMax = 10;
708+
}
709+
699710
xLength = xMax - xMin;
700711
yLength = yMax - yMin;
701712

JavaScript/pbPlots.js

+11
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,17 @@ function DrawScatterPlotFromSettings(canvasReference, settings){
607607
xMax = boundaries.x2;
608608
yMax = boundaries.y2;
609609

610+
// If zero, set to defaults.
611+
if(xMin - xMax == 0){
612+
xMin = 0;
613+
xMax = 10;
614+
}
615+
616+
if(yMin - yMax == 0){
617+
yMin = 0;
618+
yMax = 10;
619+
}
620+
610621
xLength = xMax - xMin;
611622
yLength = yMax - yMin;
612623

PHP/pbPlots.php

+11
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,17 @@ function DrawScatterPlotFromSettings($canvasReference, $settings){
560560
$xMax = $boundaries->x2;
561561
$yMax = $boundaries->y2;
562562

563+
// If zero, set to defaults.
564+
if($xMin - $xMax == 0){
565+
$xMin = 0;
566+
$xMax = 10;
567+
}
568+
569+
if($yMin - $yMax == 0){
570+
$yMin = 0;
571+
$yMax = 10;
572+
}
573+
563574
$xLength = $xMax - $xMin;
564575
$yLength = $yMax - $yMin;
565576

Python/pbPlots.py

+9
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,15 @@ def DrawScatterPlotFromSettings(canvasReference, settings):
601601
xMax = boundaries.x2
602602
yMax = boundaries.y2
603603

604+
# If zero, set to defaults.
605+
if(xMin - xMax == 0):
606+
xMin = 0
607+
xMax = 10
608+
609+
if(yMin - yMax == 0):
610+
yMin = 0
611+
yMax = 10
612+
604613
xLength = xMax - xMin
605614
yLength = yMax - yMin
606615

Ruby/pbPlots.rb

+11
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,17 @@ def DrawScatterPlotFromSettings(canvasReference, settings)
785785
xMax = boundaries.x2
786786
yMax = boundaries.y2
787787

788+
# If zero, set to defaults.
789+
if xMin - xMax == 0
790+
xMin = 0
791+
xMax = 10
792+
end
793+
794+
if yMin - yMax == 0
795+
yMin = 0
796+
yMax = 10
797+
end
798+
788799
xLength = xMax - xMin
789800
yLength = yMax - yMin
790801

TypeScript/pbPlots.ts

+11
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,17 @@ export function DrawScatterPlotFromSettings(canvasReference : RGBABitmapImageRef
816816
xMax = boundaries.x2;
817817
yMax = boundaries.y2;
818818

819+
// If zero, set to defaults.
820+
if(xMin - xMax == 0){
821+
xMin = 0;
822+
xMax = 10;
823+
}
824+
825+
if(yMin - yMax == 0){
826+
yMin = 0;
827+
yMax = 10;
828+
}
829+
819830
xLength = xMax - xMin;
820831
yLength = yMax - yMin;
821832

VisualBasic/pbPlots.vb

+11
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,17 @@ Module Plots
862862
xMax = boundaries.x2
863863
yMax = boundaries.y2
864864

865+
' If zero, set to defaults.
866+
If xMin - xMax = 0
867+
xMin = 0
868+
xMax = 10
869+
End If
870+
871+
If yMin - yMax = 0
872+
yMin = 0
873+
yMax = 10
874+
End If
875+
865876
xLength = xMax - xMin
866877
yLength = yMax - yMin
867878

src/info.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Plots",
3-
"version": "0.1.7",
3+
"version": "0.1.9-SNAPSHOT",
44
"organization namespace": "no.inductive.libraries",
55
"scientific namespace": "mathematics.dataanalysis.plots",
66
"imports": [

src/main/Plots/BarPlot/BarPlot.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static boolean DrawBarPlotFromSettings(RGBABitmapImageReference canvasRef
9898
double s, n, y, x, w, h, yMin, yMax, b, i, py, yValue;
9999
RGBA [] colors;
100100
double [] ys, yGridPositions;
101-
double yTop, yBottom, ss, bs, yLength;
101+
double yTop, yBottom, ss, bs;
102102
double groupSeparation, barSeparation, barWidth, textwidth;
103103
StringArrayReference yLabels;
104104
NumberArrayReference yLabelPriorities;
@@ -149,7 +149,6 @@ public static boolean DrawBarPlotFromSettings(RGBABitmapImageReference canvasRef
149149
yMin = settings.yMin;
150150
yMax = settings.yMax;
151151
}
152-
yLength = yMax - yMin;
153152

154153
// boundaries
155154
xPixelMin = xPadding;

src/main/Plots/Common/Common.java

+44-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static Graphics2D.Graphics2D.Graphics2D.*;
99
import static Plots.Arrays.Arrays.*;
1010
import static Plots.Math.Math.*;
11+
import static Plots.Plots.Plots.ComputeBoundariesBasedOnSettings;
1112
import static Plots.Rectangles.Rectangles.*;
1213
import static Plots.TextDrawing.TextDrawing.*;
1314
import static java.lang.Math.*;
@@ -285,13 +286,55 @@ public static double MapXCoordinate(double x, double xMin, double xMax, double x
285286
}
286287

287288
public static double MapXCoordinateAutoSettings(double x, RGBABitmapImage image, double[] xs) {
288-
return MapXCoordinate(x, GetMinimum(xs), GetMaximum(xs) - GetMinimum(xs), GetDefaultPaddingPercentage() * ImageWidth(image), (1d - GetDefaultPaddingPercentage()) * ImageWidth(image));
289+
return MapXCoordinate(x, GetMinimum(xs), GetMaximum(xs), GetDefaultPaddingPercentage() * ImageWidth(image), (1d - GetDefaultPaddingPercentage()) * ImageWidth(image));
289290
}
290291

291292
public static double MapYCoordinateAutoSettings(double y, RGBABitmapImage image, double[] ys) {
292293
return MapYCoordinate(y, GetMinimum(ys), GetMaximum(ys), GetDefaultPaddingPercentage() * ImageHeight(image), (1d - GetDefaultPaddingPercentage())*ImageHeight(image));
293294
}
294295

296+
public static double MapXCoordinateBasedOnSettings(double x, ScatterPlotSettings settings) {
297+
double xMin, xMax, xPadding, xPixelMin, xPixelMax;
298+
Rectangle boundaries;
299+
300+
boundaries = new Rectangle();
301+
ComputeBoundariesBasedOnSettings(settings, boundaries);
302+
xMin = boundaries.x1;
303+
xMax = boundaries.x2;
304+
305+
if(settings.autoPadding) {
306+
xPadding = floor(GetDefaultPaddingPercentage() * settings.width);
307+
}else{
308+
xPadding = settings.xPadding;
309+
}
310+
311+
xPixelMin = xPadding;
312+
xPixelMax = settings.width - xPadding;
313+
314+
return MapXCoordinate(x, xMin, xMax, xPixelMin, xPixelMax);
315+
}
316+
317+
public static double MapYCoordinateBasedOnSettings(double y, ScatterPlotSettings settings) {
318+
double yMin, yMax, yPadding, yPixelMin, yPixelMax;
319+
Rectangle boundaries;
320+
321+
boundaries = new Rectangle();
322+
ComputeBoundariesBasedOnSettings(settings, boundaries);
323+
yMin = boundaries.y1;
324+
yMax = boundaries.y2;
325+
326+
if(settings.autoPadding) {
327+
yPadding = floor(GetDefaultPaddingPercentage() * settings.height);
328+
}else{
329+
yPadding = settings.yPadding;
330+
}
331+
332+
yPixelMin = yPadding;
333+
yPixelMax = settings.height - yPadding;
334+
335+
return MapYCoordinate(y, yMin, yMax, yPixelMin, yPixelMax);
336+
}
337+
295338
public static double GetDefaultPaddingPercentage() {
296339
return 0.10d;
297340
}

0 commit comments

Comments
 (0)