Skip to content

Commit 168ad9b

Browse files
committed
Do not use global attributes
1 parent f87ff1c commit 168ad9b

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

modules/draw/TPiePainter.mjs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,23 @@ class TPiePainter extends ObjectPainter {
4343
/** @summary start of drag handler
4444
* @private */
4545
moveStart(x, y) {
46+
this.x = x;
47+
this.y = y;
4648
}
4749

4850
/** @summary drag handler
4951
* @private */
5052
moveDrag(dx, dy) {
53+
this.x += dx;
54+
this.y += dy;
5155
}
5256

5357
/** @summary end of drag handler
5458
* @private */
5559
moveEnd(not_changed) {
5660
if (not_changed)
5761
return;
62+
this.x = this.y = 0;
5863
}
5964

6065
/** @summary Draw title
@@ -110,12 +115,13 @@ class TPiePainter extends ObjectPainter {
110115
pie = this.getObject(),
111116
xc = this.axisToSvg('x', pie.fX),
112117
yc = this.axisToSvg('y', pie.fY),
113-
pp = this.getPadPainter();
118+
pp = this.getPadPainter(),
119+
radX = pie.fRadius;
114120

115-
let radX = pie.fRadius, radY = pie.fRadius, pixelHeight = 1;
121+
let radY = radX, pixelHeight = 1;
116122

117123
if (this.#is3d) {
118-
radY *= Math.sin(pie.fAngle3D/180.*Math.PI);
124+
radY *= Math.sin(pie.fAngle3D / 180 * Math.PI);
119125
pixelHeight = this.axisToSvg('y', pie.fY - pie.fHeight) - yc;
120126
}
121127

@@ -125,9 +131,9 @@ class TPiePainter extends ObjectPainter {
125131
ry = this.axisToSvg('y', pie.fY - radY) - yc,
126132
dist_to_15pi = a => {
127133
while (a < 0.5*Math.PI)
128-
a += 2*Math.PI;
129-
while (a >= 2.5*Math.PI)
130-
a -= 2*Math.PI;
134+
a += 2 * Math.PI;
135+
while (a >= 2.5 * Math.PI)
136+
a -= 2 * Math.PI;
131137
return Math.abs(a - 1.5 * Math.PI)
132138
};
133139

@@ -144,15 +150,15 @@ class TPiePainter extends ObjectPainter {
144150
}
145151
// sort in increase/decrease order
146152
if (this.#sort !== 0)
147-
arr.sort((v1,v2) => { return this.#sort*(v1.value - v2.value); });
153+
arr.sort((v1, v2) => { return this.#sort * (v1.value - v2.value); });
148154

149155
// now assign angles for each slice
150156
for (let n = 0; n < arr.length; n++) {
151157
const entry = arr[n];
152158
entry.a2 = af;
153159
af -= entry.value / total * 2 * Math.PI;
154160
entry.a1 = af;
155-
entry.a = dist_to_15pi((entry.a1 + entry.a2)/2);
161+
entry.a = dist_to_15pi((entry.a1 + entry.a2) / 2);
156162
}
157163

158164
// sort for visualization in increasing order from Pi/2 angle
@@ -177,8 +183,8 @@ class TPiePainter extends ObjectPainter {
177183
x2 = Math.round(rx * Math.cos(a2)),
178184
y2 = Math.round(ry * Math.sin(a2));
179185

180-
this.createAttLine({ attr: slice });
181-
this.createAttFill({ attr: slice });
186+
const attline = this.createAttLine({ attr: slice, std: false }),
187+
attfill = this.createAttFill({ attr: slice, std: false });
182188

183189
// paint pseudo-3d object
184190
if (this.#is3d) {
@@ -191,13 +197,13 @@ class TPiePainter extends ObjectPainter {
191197
yy2 = Math.round(ry * Math.sin(aa2));
192198
g.append('svg:path')
193199
.attr('d', `M${xx1},${yy1}a${rx},${ry},0,0,1,${xx2-xx1},${yy2-yy1}v${pixelHeight}a${rx},${ry},0,0,0,${xx1-xx2},${yy1-yy2}z`)
194-
.call(this.lineatt.func)
195-
.call(this.fillatt.func);
200+
.call(attline.func)
201+
.call(attfill.func);
196202
}, add_planar_side = (x,y) => {
197203
g.append('svg:path')
198204
.attr('d', `M0,0v${pixelHeight}l${x},${y}v${-pixelHeight}z`)
199-
.call(this.lineatt.func)
200-
.call(this.fillatt.func);
205+
.call(attline.func)
206+
.call(attfill.func);
201207
}, build_pie = func => {
202208
// use same segments for side and top/bottom curves
203209
let a = a1, border = 0;
@@ -227,8 +233,8 @@ class TPiePainter extends ObjectPainter {
227233
// bottom
228234
g.append('svg:path')
229235
.attr('d', `M0,${pixelHeight}l${x1},${y1}${pie}z`)
230-
.call(this.lineatt.func)
231-
.call(this.fillatt.func);
236+
.call(attline.func)
237+
.call(attfill.func);
232238

233239

234240
// planar
@@ -246,14 +252,13 @@ class TPiePainter extends ObjectPainter {
246252
// upper
247253
g.append('svg:path')
248254
.attr('d', `M0,0l${x1},${y1}${pie}z`)
249-
.call(this.lineatt.func)
250-
.call(this.fillatt.func);
251-
255+
.call(attline.func)
256+
.call(attfill.func);
252257
} else {
253258
g.append('svg:path')
254259
.attr('d', `M0,0l${x1},${y1}a${rx},${ry},0,0,1,${x2-x1},${y2-y1}z`)
255-
.call(this.lineatt.func)
256-
.call(this.fillatt.func);
260+
.call(attline.func)
261+
.call(attfill.func);
257262
}
258263

259264
const frac = total ? slice.fValue / total : 0;

0 commit comments

Comments
 (0)