svelte-plots-basic 3.1.0 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/2d/Axes.svelte +4 -0
- package/src/methods.js +21 -6
package/package.json
CHANGED
package/src/2d/Axes.svelte
CHANGED
|
@@ -69,18 +69,22 @@
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function handleDown(e) {
|
|
72
|
+
e.preventDefault();
|
|
72
73
|
handleMouse(e, onmousedown)
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
function handleUp(e) {
|
|
77
|
+
e.preventDefault();
|
|
76
78
|
handleMouse(e, onmouseup)
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
function handleMove(e) {
|
|
82
|
+
e.preventDefault();
|
|
80
83
|
handleMouse(e, onmousemove)
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
function handleClick(e) {
|
|
87
|
+
e.preventDefault();
|
|
84
88
|
handleMouse(e, onclick)
|
|
85
89
|
}
|
|
86
90
|
|
package/src/methods.js
CHANGED
|
@@ -154,6 +154,7 @@ export function getTickLabels(ticks) {
|
|
|
154
154
|
if (decNum <= 2) {
|
|
155
155
|
return [0, Array.from(ticks).map(v => v.toFixed(decNum))];
|
|
156
156
|
}
|
|
157
|
+
|
|
157
158
|
tickFactor = decNum - 2;
|
|
158
159
|
decNum = 2;
|
|
159
160
|
|
|
@@ -941,11 +942,14 @@ export function getXAxisParams(limX, limY, scales, tY, axis) {
|
|
|
941
942
|
const tfLabel = getTickFactorLabel(tickFactor);
|
|
942
943
|
|
|
943
944
|
// hide last label if it is too close to tick factor
|
|
944
|
-
const
|
|
945
|
-
const
|
|
945
|
+
const n = tickLabels.length;
|
|
946
|
+
const dtl = Math.abs(limX[1] > limX[0] ? limX[1] - ticksX.v[n - 1] : limX[1] - ticksX.v[0]);
|
|
947
|
+
const dl = Math.abs(limX[1] - limX[0]);
|
|
946
948
|
const dt = Math.abs(ticksX.v[1] - ticksX.v[0]);
|
|
947
|
-
|
|
948
|
-
|
|
949
|
+
|
|
950
|
+
if (tfLabel.length > 0 && dtl < dl * 0.10 && dtl < dt * 0.5) {
|
|
951
|
+
const pos = limX[1] > limX[0] ? n - 1 : 0
|
|
952
|
+
tickLabels[pos] = ' ';
|
|
949
953
|
}
|
|
950
954
|
|
|
951
955
|
return {grid, axisLine, tickCoords, tfCoords, ticks, tickLabels, tickFactor, tfLabel};
|
|
@@ -1020,10 +1024,21 @@ export function getYAxisParams(limX, limY, scales, tX, axis) {
|
|
|
1020
1024
|
const tfLabel = getTickFactorLabel(tickFactor);
|
|
1021
1025
|
|
|
1022
1026
|
// hide last label if it is too close to tick factor
|
|
1023
|
-
|
|
1024
|
-
|
|
1027
|
+
const n = tickLabels.length;
|
|
1028
|
+
const dtl = Math.abs(limY[1] > limY[0] ? limY[1] - ticksY.v[n - 1] : limY[1] - ticksY.v[0]);
|
|
1029
|
+
const dl = Math.abs(limY[1] - limY[0]);
|
|
1030
|
+
const dt = Math.abs(ticksY.v[1] - ticksY.v[0]);
|
|
1031
|
+
|
|
1032
|
+
if (tfLabel.length > 0 && dtl < dl * 0.10 && dtl < dt * 0.5) {
|
|
1033
|
+
const pos = limY[1] > limY[0] ? n - 1 : 0
|
|
1034
|
+
tickLabels[pos] = ' ';
|
|
1025
1035
|
}
|
|
1026
1036
|
|
|
1037
|
+
// old version of the code above - remove after testing
|
|
1038
|
+
// if (tfLabel.length > 0 && (limY[1] - ticksY.v[ticksY.length - 1]) < ((limY[1] - limY[0]) * 0.05)) {
|
|
1039
|
+
// tickLabels[tickLabels.length - 1] = ' ';
|
|
1040
|
+
// }
|
|
1041
|
+
|
|
1027
1042
|
return {grid, axisLine, tickCoords, tfCoords, ticks, tickLabels, tickFactor, tfLabel};
|
|
1028
1043
|
}
|
|
1029
1044
|
|