-
Notifications
You must be signed in to change notification settings - Fork 1
/
mapSemiLogX.js
57 lines (51 loc) · 2.05 KB
/
mapSemiLogX.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright (C) 2015 Stefano D'Angelo <zanga.mail@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*** Semi-log coordinate-mapping object with x logarithmic and y linear. ***/
canvasPlot.mapSemiLogX = Object.create(canvasPlot.map);
/* Private members. */
canvasPlot.mapSemiLogX.kx0 = NaN;
canvasPlot.mapSemiLogX.kx1 = NaN;
canvasPlot.mapSemiLogX.kx2 = NaN;
canvasPlot.mapSemiLogX.ky0 = NaN;
canvasPlot.mapSemiLogX.ky1 = NaN;
canvasPlot.mapSemiLogX.update = function (area) {
if (this.xRange.max > this.xRange.min) {
this.kx0 = area.p.x - 0.5;
this.kx1 = area.width
/ Math.log10(this.xRange.max / this.xRange.min);
this.kx2 = 1 / this.xRange.min;
} else {
this.kx0 = area.p2.x + 0.5;
this.kx1 = -area.width
/ Math.log10(this.xRange.min / this.xRange.max);
this.kx2 = 1 / this.xRange.max;
}
this.ky1 = -area.height / (this.yRange.max - this.yRange.min);
this.ky0 = area.p2.y - this.ky1 * this.yRange.min - 0.5;
};
canvasPlot.mapSemiLogX.mapPoint = function (x, y, m) {
m.x = this.kx0 + this.kx1 * Math.log10(this.kx2 * x);
m.y = this.ky0 + this.ky1 * y;
};
canvasPlot.mapSemiLogX.mapPoints = function (x, y, mx, my, xFirst, yFirst,
mxFirst, myFirst, count) {
for (var i = 0; i < count; i++) {
mx[mxFirst + i] = this.kx0
+ this.kx1
* Math.log10(this.kx2 * x[xFirst + i]);
my[myFirst + i] = this.ky0 + this.ky1 * y[yFirst + i];
}
};