Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move width and height to the base renderer class definition. #962

Merged
merged 2 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/canvas/canvasRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var canvasRenderer = function (arg) {
var canvas = m_this.canvas();
if (parseInt(canvas.attr('width'), 10) !== w ||
parseInt(canvas.attr('height'), 10) !== h) {
m_this._setWidthHeight(w, h);
canvas.attr('width', w);
canvas.attr('height', h);
m_this._render();
Expand Down
12 changes: 5 additions & 7 deletions src/d3/d3Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ var d3Renderer = function (arg) {
m_sticky = null,
m_features = {},
m_corners = null,
m_width = null,
m_height = null,
m_diagonal = null,
m_scale = 1,
m_transform = {dx: 0, dy: 0, rx: 0, ry: 0, rotation: 0},
Expand Down Expand Up @@ -209,11 +207,10 @@ var d3Renderer = function (arg) {
width = map.size().width,
height = map.size().height;

m_width = width;
m_height = height;
if (!m_width || !m_height) {
if (!width || !height) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in vglRenderer we use m_this.width() to get width and height, why not we use the same here? instead of getting it from map?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few lines later is where the layer's width and height is set from these values (m_this._setWidthHeight(width, height);), so width and height are the values that will be set.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I was expecting the flow between vgl and d3 renderers would be same and may be they are similar. so sounds like we are getting the width and height from the map and set it to the renderer in both cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

throw new Error('Map layer has size 0');
}
m_this._setWidthHeight(width, height);
m_diagonal = Math.pow(width * width + height * height, 0.5);
m_corners = {
upperLeft: map.displayToGcs({x: 0, y: 0}, null),
Expand Down Expand Up @@ -249,8 +246,8 @@ var d3Renderer = function (arg) {
Math.pow(lowerRight.x - upperLeft.x, 2)) / m_diagonal;
// calculate the translation
rotation = map.rotation();
rx = -m_width / 2;
ry = -m_height / 2;
rx = -m_this.width() / 2;
ry = -m_this.height() / 2;
dx = scale * rx + center.x;
dy = scale * ry + center.y;

Expand Down Expand Up @@ -454,6 +451,7 @@ var d3Renderer = function (arg) {
m_svg.attr('width', w);
m_svg.attr('height', h);
m_this._setTransform();
m_this._setWidthHeight(w, h);
m_this.layer().geoTrigger(d3Rescale, { scale: m_scale }, true);
return m_this;
};
Expand Down
26 changes: 2 additions & 24 deletions src/gl/vglRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,11 @@ var vglRenderer = function (arg) {
var m_this = this,
m_contextRenderer = null,
m_viewer = null,
m_width = 0,
m_height = 0,
m_lastZoom,
m_updateCamera = false,
s_init = this._init,
s_exit = this._exit;

// TODO: Move this API to the base class
/**
* Return width of the renderer.
*
* @returns {number} The width of the current canvas.
*/
this.width = function () {
return m_width;
};

/**
* Return height of the renderer.
*
* @returns {number} The height of the current canvas.
*/
this.height = function () {
return m_height;
};

/**
* Get context specific renderer.
*
Expand Down Expand Up @@ -140,9 +119,8 @@ var vglRenderer = function (arg) {

if (x !== renderWindow.windowPosition[0] ||
y !== renderWindow.windowPosition[1] ||
w !== m_width || h !== m_height) {
m_width = w;
m_height = h;
w !== m_this.width() || h !== m_this.height()) {
m_this._setWidthHeight(w, h);
m_this.canvas().attr('width', w);
m_this.canvas().attr('height', h);
renderWindow.positionAndResize(x, y, w, h);
Expand Down
34 changes: 34 additions & 0 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var renderer = function (arg) {

arg = arg || {};
var m_this = this,
m_width = 0,
m_height = 0,
m_layer = arg.layer === undefined ? null : arg.layer,
m_canvas = arg.canvas === undefined ? null : arg.canvas,
m_initialized = false;
Expand Down Expand Up @@ -94,6 +96,37 @@ var renderer = function (arg) {
throw new Error('Should be implemented by derived classes');
};

/**
* Get the width of the renderer.
*
* @returns {number} The width of the renderer.
*/
this.width = function () {
return m_width;
};

/**
* Get the height of the renderer.
*
* @returns {number} The height of the renderer.
*/
this.height = function () {
return m_height;
};

/**
* Set the width and height of the renderer.
*
* @param {number} width The new width.
* @param {number} height The new height.
* @returns {this}
*/
this._setWidthHeight = function (width, height) {
m_width = width;
m_height = height;
return m_this;
};

/**
* Initialize.
*
Expand All @@ -113,6 +146,7 @@ var renderer = function (arg) {
* @returns {this}
*/
this._resize = function (x, y, w, h) {
m_this._setWidthHeight(w, h);
return m_this;
};

Expand Down
21 changes: 1 addition & 20 deletions src/vtkjs/vtkjsRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ var vtkjsRenderer = function (arg) {
var vtkGenericRenderWindow = vtkjs.Rendering.Misc.vtkGenericRenderWindow;

var m_this = this,
m_width = 0,
m_height = 0,
s_init = this._init;

var vtkRenderer = vtkGenericRenderWindow.newInstance({
Expand All @@ -42,24 +40,6 @@ var vtkjsRenderer = function (arg) {
var vtkjsren = vtkRenderer.getRenderer();
var renderWindow = vtkRenderer.getRenderWindow();

/**
* Return width of the renderer.
*
* @returns {number} The width of the current canvas.
*/
this.width = function () {
return m_width;
};

/**
* Return height of the renderer.
*
* @returns {number} The height of the current canvas.
*/
this.height = function () {
return m_height;
};

/**
* Get context specific renderer.
*
Expand Down Expand Up @@ -110,6 +90,7 @@ var vtkjsRenderer = function (arg) {
* @returns {this}
*/
this._resize = function (x, y, w, h) {
m_this._setWidthHeight(w, h);
vtkRenderer.resize();
m_this._render();
return m_this;
Expand Down