Skip to content

Commit db5c62a

Browse files
committed
WIP
1 parent 00af98f commit db5c62a

File tree

6 files changed

+128
-56
lines changed

6 files changed

+128
-56
lines changed

src/plots/smith/set_convert.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,41 @@ module.exports = function setConvert(ax, polarLayout, fullLayout) {
4949
case 'angularaxis':
5050
setConvertAngular(ax, polarLayout);
5151
break;
52+
case 'realaxis':
53+
setConvertReal(ax, polarLayout);
54+
break;
5255
}
5356
};
5457

58+
function setConvertReal(ax, polarLayout) {
59+
var subplot = polarLayout._subplot;
60+
var radius = subplot.radius;
61+
62+
ax.setGeometry = function () {
63+
ax.c2g = function(v) {
64+
var sq = function (x) { return x * x; };
65+
var gammaX = function(re) {
66+
var denom = sq(re + 1.0);
67+
var result = (sq(re) - 1.0) / denom;
68+
return result;
69+
}
70+
// console.log(v, gammaX(v));
71+
72+
return gammaX(v);
73+
};
74+
75+
ax.g2c = function(v) {
76+
return (v + 1.0) / (1.0 - v);
77+
};
78+
79+
ax.g2p = function(v) {
80+
return v * radius;
81+
};
82+
83+
ax.c2p = function(v) { return ax.g2p(ax.c2g(v)); };
84+
};
85+
}
86+
5587
function setConvertRadial(ax, polarLayout) {
5688
var subplot = polarLayout._subplot;
5789

src/plots/smith/smith.js

Lines changed: 69 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,30 @@ proto.updateLayout = function(fullLayout, polarLayout) {
240240
var cyy = _this.cyy = cy - yOffset2;
241241

242242
_this.radialAxis = _this.mockAxis(fullLayout, polarLayout, radialLayout, {
243-
// make this an 'x' axis to make positioning (especially rotation) easier
244-
_id: 'x',
245-
// convert to 'x' axis equivalent
243+
_id: 'realaxis',
246244
side: {
247245
counterclockwise: 'top',
248246
clockwise: 'bottom'
249247
}[radialLayout.side],
250248
// keep track of real side
251249
_realSide: radialLayout.side,
252-
// spans length 1 radius
253-
domain: [innerRadius / gs.w, radius / gs.w]
250+
domain: [0, 100]
254251
});
255252

253+
// _this.radialAxis = _this.mockAxis(fullLayout, polarLayout, radialLayout, {
254+
// // make this an 'x' axis to make positioning (especially rotation) easier
255+
// _id: 'x',
256+
// // convert to 'x' axis equivalent
257+
// side: {
258+
// counterclockwise: 'top',
259+
// clockwise: 'bottom'
260+
// }[radialLayout.side],
261+
// // keep track of real side
262+
// _realSide: radialLayout.side,
263+
// // spans length 1 radius
264+
// domain: [innerRadius / gs.w, radius / gs.w]
265+
// });
266+
256267
_this.angularAxis = _this.mockAxis(fullLayout, polarLayout, angularLayout, {
257268
side: 'right',
258269
// to get auto nticks right
@@ -380,16 +391,20 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
380391

381392
// set special grid path function
382393
var gridPathFn = function(d) {
383-
var sq = function (x) { return x * x; };
384-
var gammaX = function(re) {
385-
var denom = sq(re + 1.0);
386-
var result = (sq(re) - 1.0) / denom;
387-
return result;
388-
}
389-
var gamma_x = gammaX(d.x);
394+
// var sq = function (x) { return x * x; };
395+
// var gammaX = function(re) {
396+
// var denom = sq(re + 1.0);
397+
// var result = (sq(re) - 1.0) / denom;
398+
// return result;
399+
// }
400+
// var gamma_x = gammaX(d.x);
401+
402+
// console.log(d);
390403

391-
var gridRadius = 0.5 * (_this.radius - ax.r2p(gamma_x));
392-
var gridCenter = gridRadius + ax.r2p(gamma_x);
404+
var value = 5 * d.x
405+
406+
var gridRadius = 0.5 * (_this.radius - ax.c2p(value));
407+
var gridCenter = gridRadius + ax.c2p(value);
393408
return Lib.pathArc(gridRadius, 0, 2 * Math.PI, gridCenter, 0);
394409
};
395410

@@ -399,6 +414,39 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
399414
_this.radialTickLayout = newTickLayout;
400415
}
401416

417+
var out = Axes.makeLabelFns(ax, 0);
418+
var labelStandoff = out.labelStandoff;
419+
var labelFns = {};
420+
421+
labelFns.xFn = function(d) {
422+
// var rad = t2g(d);
423+
// return Math.cos(rad) * labelStandoff;
424+
return ax.c2g(d);
425+
};
426+
427+
labelFns.yFn = function(d) {
428+
// var rad = t2g(d);
429+
// var ff = Math.sin(rad) > 0 ? 0.2 : 1;
430+
// return -Math.sin(rad) * (labelStandoff + d.fontSize * ff) +
431+
// Math.abs(Math.cos(rad)) * (d.fontSize * MID_SHIFT);
432+
return 0;
433+
};
434+
435+
labelFns.anchorFn = function(d) {
436+
// var rad = t2g(d);
437+
// var cos = Math.cos(rad);
438+
// return Math.abs(cos) < 0.1 ?
439+
// 'middle' :
440+
// (cos > 0 ? 'start' : 'end');
441+
return 'middle';
442+
};
443+
444+
labelFns.heightFn = function(d, a, h) {
445+
// var rad = t2g(d);
446+
// return -0.5 * (1 + Math.sin(rad)) * h;
447+
return 0;
448+
};
449+
402450
if(hasRoomForIt) {
403451
ax.setScale();
404452

@@ -426,7 +474,8 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
426474
vals: vals,
427475
layer: layers['radial-axis'],
428476
transFn: transFn,
429-
labelFns: Axes.makeLabelFns(ax, 0)
477+
// labelFns: Axes.makeLabelFns(ax, 0)
478+
labelFns: labelFns
430479
});
431480
}
432481

@@ -657,6 +706,9 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
657706
var sinRad = Math.sin(rad);
658707
return 'M' + [cx + innerRadius * cosRad, cy - innerRadius * sinRad] +
659708
'L' + [cx + radius * cosRad, cy - radius * sinRad];
709+
710+
// var h = 2.0 / d.y;
711+
// var radius = h;
660712
};
661713

662714
var out = Axes.makeLabelFns(ax, 0);
@@ -1431,15 +1483,8 @@ proto.updateAngularDrag = function(fullLayout) {
14311483
};
14321484

14331485
proto.isPtInside = function(d) {
1434-
var sectorInRad = this.sectorInRad;
1435-
var vangles = this.vangles;
1436-
var thetag = this.angularAxis.c2g(d.im);
1437-
var radialAxis = this.radialAxis;
1438-
var r = radialAxis.c2l(d.re);
1439-
var rl = radialAxis._rl;
1440-
1441-
var fn = vangles ? helpers.isPtInsidePolygon : Lib.isPtInsideSector;
1442-
return fn(r, thetag, rl, sectorInRad, vangles);
1486+
// return d.re >= 0;
1487+
return true;
14431488
};
14441489

14451490
proto.pathArc = function(r) {

src/traces/scattersmith/calc.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,6 @@ function sq(x) {
1414
return x * x;
1515
}
1616

17-
function gammaTransformReal(re, im) {
18-
var denom = sq(re + 1.0) + sq(im);
19-
var result = (sq(re) + sq(im) - 1.0) / denom;
20-
return result;
21-
}
22-
23-
function gammaTransformImaginary(re, im) {
24-
var denom = sq(re + 1.0) + sq(im);
25-
var result = (2 * im) / denom;
26-
return result;
27-
}
28-
29-
function cart2pol(re, im) {
30-
var r = Math.sqrt(sq(re) + sq(im));
31-
var theta = Math.atan2(im, re);
32-
33-
return {
34-
r: r,
35-
theta: theta,
36-
};
37-
}
38-
3917
module.exports = function calc(gd, trace) {
4018
var fullLayout = gd._fullLayout;
4119
var subplotId = trace.subplot;
@@ -52,10 +30,8 @@ module.exports = function calc(gd, trace) {
5230
var cdi = cd[i] = {};
5331

5432
if(isNumeric(re) && isNumeric(im)) {
55-
var pol = cart2pol(gammaTransformReal(re, im), gammaTransformImaginary(re, im));
56-
57-
cdi.re = pol.r;
58-
cdi.im = pol.theta;
33+
cdi.re = re;
34+
cdi.im = im;
5935
} else {
6036
cdi.re = BADNUM;
6137
}

src/traces/scattersmith/format_labels.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@ module.exports = function formatLabels(cdi, trace, fullLayout) {
2828
var thetaVal = angularAxis.thetaunit === 'degrees' ? Lib.rad2deg(cdi.im) : cdi.im;
2929
labels.thetaLabel = Axes.tickText(angularAxis, thetaVal, true).text;
3030

31+
// labels.reLabel = Axes.tickText(radialAxis, cdi.re, true).text;
32+
// labels.imLabel = Axes.tickText(radialAxis, cdi.im, true).text;
33+
3134
return labels;
3235
};

src/traces/scattersmith/hover.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ function hoverPoints(pointData, xval, yval, hovermode) {
2929
function makeHoverPointText(cdi, trace, subplot, pointData) {
3030
var radialAxis = subplot.radialAxis;
3131
var angularAxis = subplot.angularAxis;
32-
radialAxis._hovertitle = 'r';
33-
angularAxis._hovertitle = 'θ';
32+
radialAxis._hovertitle = 're';
33+
angularAxis._hovertitle = 'im';
3434

3535
var fullLayout = {};
3636
fullLayout[trace.subplot] = {_subplot: subplot};

src/traces/scattersmith/plot.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
var scatterPlot = require('../scatter/plot');
44
var BADNUM = require('../../constants/numerical').BADNUM;
55

6+
function sq(x) {
7+
return x * x;
8+
}
9+
10+
function gammaTransformReal(re, im) {
11+
var denom = sq(re + 1.0) + sq(im);
12+
var result = (sq(re) + sq(im) - 1.0) / denom;
13+
return result;
14+
}
15+
16+
function gammaTransformImaginary(re, im) {
17+
var denom = sq(re + 1.0) + sq(im);
18+
var result = (2 * im) / denom;
19+
return result;
20+
}
21+
622
module.exports = function plot(gd, subplot, moduleCalcData) {
723
var mlayer = subplot.layers.frontplot.select('g.scatterlayer');
824

@@ -29,10 +45,10 @@ module.exports = function plot(gd, subplot, moduleCalcData) {
2945
if(re === BADNUM) {
3046
cd.x = cd.y = BADNUM;
3147
} else {
32-
var rg = radialAxis.c2g(re);
33-
var thetag = angularAxis.c2g(im);
34-
cd.x = rg * Math.cos(thetag);
35-
cd.y = rg * Math.sin(thetag);
48+
cd.x = gammaTransformReal(re, im);
49+
cd.y = gammaTransformImaginary(re, im);
50+
51+
console.log(cd.im, cd.y, 2.0 / cd.im);
3652
}
3753
}
3854
}

0 commit comments

Comments
 (0)