Skip to content

Commit b39fb4e

Browse files
committed
Add render methods
1 parent 01d2148 commit b39fb4e

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

lib/node_modules/@stdlib/plot/base/ctor/lib/main.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,42 @@ Object.defineProperty( Plot.prototype, 'paddingTop', {
676676
'get': require( './props/padding-top/get.js' )
677677
});
678678

679+
/**
680+
* Renders a plot.
681+
*
682+
* @name render
683+
* @memberof Plot.prototype
684+
* @type {Function}
685+
* @param {string} [format] - render format
686+
* @throws {TypeError} must provide a recognized format
687+
* @returns {(VTree|string)} virtual tree or string
688+
*
689+
* @example
690+
* var plot = new Plot();
691+
* var out = plot.render();
692+
*
693+
* @example
694+
* var plot = new Plot();
695+
* var out = plot.render( 'html' );
696+
*/
697+
setReadOnly( Plot.prototype, 'render', require( './render' ) );
698+
699+
/**
700+
* Renders a plot.
701+
*
702+
* ## Notes
703+
*
704+
* - This method **should** be implemented by descendants.
705+
*
706+
* @private
707+
* @name _render
708+
* @memberof Plot.prototype
709+
* @type {Function}
710+
* @param {string} [format] - render format
711+
* @returns {(VTree|string)} rendered plot
712+
*/
713+
setReadOnly( Plot.prototype, '_render', require( './render/stub.js' ) );
714+
679715
/**
680716
* Render format.
681717
*
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var logger = require( 'debug' );
24+
25+
26+
// VARIABLES //
27+
28+
var debug = logger( 'plot:base:render' );
29+
30+
31+
// MAIN //
32+
33+
/**
34+
* Renders a plot.
35+
*
36+
* @private
37+
* @param {string} [format] - render format
38+
* @returns {(VTree|string)} virtual tree or a string
39+
*/
40+
function render( format ) {
41+
/* eslint-disable no-invalid-this, no-underscore-dangle */
42+
var out;
43+
var tmp;
44+
var fmt;
45+
46+
tmp = this.renderFormat;
47+
if ( arguments.length ) {
48+
// Temporarily set the render format:
49+
this.renderFormat = format;
50+
fmt = format;
51+
} else {
52+
fmt = tmp;
53+
}
54+
debug( 'Render format: %s.', this.renderFormat );
55+
56+
debug( 'Rendering...' );
57+
out = this._render( fmt );
58+
this.emit( 'render', out );
59+
60+
if ( arguments.length ) {
61+
// Restore the render format:
62+
this.renderFormat = tmp;
63+
}
64+
return out;
65+
}
66+
67+
68+
// EXPORTS //
69+
70+
module.exports = render;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/**
22+
* Placeholder `render` function.
23+
*
24+
* @private
25+
* @param {string} fmt - render format
26+
* @throws {Error} must be implemented by descendant classes
27+
*/
28+
function render() {
29+
throw new Error( 'method not implemented.' );
30+
}
31+
32+
33+
// EXPORTS //
34+
35+
module.exports = render;

0 commit comments

Comments
 (0)