Skip to content
This repository was archived by the owner on Jul 29, 2019. It is now read-only.

Commit 029b6ab

Browse files
axizo-pimojoaxel
authored andcommitted
Consolidated usage of getContext (#2157)
1 parent b136380 commit 029b6ab

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

lib/graph3d/Graph3d.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,17 @@ Graph3d.prototype.redraw = function() {
967967
this._redrawLegend();
968968
};
969969

970+
971+
/**
972+
* Get drawing context without exposing canvas
973+
*/
974+
Graph3d.prototype._getContext = function() {
975+
var canvas = this.frame.canvas;
976+
var ctx = canvas.getContext('2d');
977+
return ctx;
978+
};
979+
980+
970981
/**
971982
* Clear the canvas before redrawing
972983
*/
@@ -1024,8 +1035,7 @@ Graph3d.prototype._redrawLegend = function() {
10241035
var left = right - width;
10251036
var bottom = top + height;
10261037

1027-
var canvas = this.frame.canvas;
1028-
var ctx = canvas.getContext('2d');
1038+
var ctx = this._getContext();
10291039
ctx.lineWidth = 1;
10301040
ctx.font = '14px arial'; // TODO: put in options
10311041

@@ -1157,8 +1167,7 @@ Graph3d.prototype._redrawSlider = function() {
11571167
*/
11581168
Graph3d.prototype._redrawInfo = function() {
11591169
if (this.dataFilter) {
1160-
var canvas = this.frame.canvas;
1161-
var ctx = canvas.getContext('2d');
1170+
var ctx = this._getContext();
11621171

11631172
ctx.font = '14px arial'; // TODO: put in options
11641173
ctx.lineStyle = 'gray';
@@ -1177,8 +1186,7 @@ Graph3d.prototype._redrawInfo = function() {
11771186
* Redraw the axis
11781187
*/
11791188
Graph3d.prototype._redrawAxis = function() {
1180-
var canvas = this.frame.canvas,
1181-
ctx = canvas.getContext('2d'),
1189+
var ctx = this._getContext(),
11821190
from, to, step, prettyStep,
11831191
text, xText, yText, zText,
11841192
offset, xOffset, yOffset,
@@ -1477,8 +1485,7 @@ Graph3d.prototype._hsv2rgb = function(H, S, V) {
14771485
* This function can be used when the style is 'grid'
14781486
*/
14791487
Graph3d.prototype._redrawDataGrid = function() {
1480-
var canvas = this.frame.canvas,
1481-
ctx = canvas.getContext('2d'),
1488+
var ctx = this._getContext(),
14821489
point, right, top, cross,
14831490
i,
14841491
topSideVisible, fillStyle, strokeStyle, lineWidth,
@@ -1624,8 +1631,7 @@ Graph3d.prototype._getStrokeWidth = function(point) {
16241631
* This function can be used when the style is 'dot' or 'dot-line'
16251632
*/
16261633
Graph3d.prototype._redrawDataDot = function() {
1627-
var canvas = this.frame.canvas;
1628-
var ctx = canvas.getContext('2d');
1634+
var ctx = this._getContext();
16291635
var i;
16301636

16311637
if (this.dataPoints === undefined || this.dataPoints.length <= 0)
@@ -1720,8 +1726,7 @@ Graph3d.prototype._redrawDataDot = function() {
17201726
* This function can be used when the style is 'bar', 'bar-color', or 'bar-size'
17211727
*/
17221728
Graph3d.prototype._redrawDataBar = function() {
1723-
var canvas = this.frame.canvas;
1724-
var ctx = canvas.getContext('2d');
1729+
var ctx = this._getContext();
17251730
var i, j, surface, corners;
17261731

17271732
if (this.dataPoints === undefined || this.dataPoints.length <= 0)
@@ -1862,8 +1867,7 @@ Graph3d.prototype._redrawDataBar = function() {
18621867
* This function can be used when the style is 'line'
18631868
*/
18641869
Graph3d.prototype._redrawDataLine = function() {
1865-
var canvas = this.frame.canvas,
1866-
ctx = canvas.getContext('2d'),
1870+
var ctx = this._getContext(),
18671871
point, i;
18681872

18691873
if (this.dataPoints === undefined || this.dataPoints.length <= 0)

0 commit comments

Comments
 (0)