|
| 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 | +var Annotations = require( '@stdlib/plot/components/svg/annotations' ); |
| 25 | +var ClipPath = require( '@stdlib/plot/components/svg/clip-path' ); |
| 26 | +var Canvas = require( '@stdlib/plot/components/svg/canvas' ); |
| 27 | +var Graph = require( '@stdlib/plot/components/svg/graph' ); |
| 28 | +var Title = require( '@stdlib/plot/components/svg/title' ); |
| 29 | +var Marks = require( '@stdlib/plot/components/svg/marks' ); |
| 30 | +var Bkgd = require( '@stdlib/plot/components/svg/background' ); |
| 31 | +var Defs = require( '@stdlib/plot/components/svg/defs' ); |
| 32 | +var Axis = require( '@stdlib/plot/components/svg/axis' ); |
| 33 | +var Columns = require( '@stdlib/plot/components/svg/columns' ); |
| 34 | + |
| 35 | + |
| 36 | +// VARIABLES // |
| 37 | + |
| 38 | +var debug = logger( 'hist:render:svg:init' ); |
| 39 | + |
| 40 | + |
| 41 | +// MAIN // |
| 42 | + |
| 43 | +/** |
| 44 | +* Initializes SVG components. |
| 45 | +* |
| 46 | +* @private |
| 47 | +* @param {Object} state - state |
| 48 | +*/ |
| 49 | +function init( state ) { |
| 50 | + var svg = state.$.svg; |
| 51 | + |
| 52 | + debug( 'Initializing components...' ); |
| 53 | + |
| 54 | + debug( 'Initializing canvas component...' ); |
| 55 | + Object.defineProperty( svg, 'canvas', { |
| 56 | + 'configurable': false, |
| 57 | + 'enumerable': false, |
| 58 | + 'writable': false, |
| 59 | + 'value': new Canvas({ |
| 60 | + 'autoRender': false |
| 61 | + }) |
| 62 | + }); |
| 63 | + |
| 64 | + debug( 'Initializing definitions component...' ); |
| 65 | + Object.defineProperty( svg, 'defs', { |
| 66 | + 'configurable': false, |
| 67 | + 'enumerable': false, |
| 68 | + 'writable': false, |
| 69 | + 'value': new Defs({ |
| 70 | + 'autoRender': false |
| 71 | + }) |
| 72 | + }); |
| 73 | + |
| 74 | + debug( 'Initializing clipping path component...' ); |
| 75 | + Object.defineProperty( svg, 'clipPath', { |
| 76 | + 'configurable': false, |
| 77 | + 'enumerable': false, |
| 78 | + 'writable': false, |
| 79 | + 'value': new ClipPath({ |
| 80 | + 'autoRender': false, |
| 81 | + 'id': state._clipPathId // eslint-disable-line no-underscore-dangle |
| 82 | + }) |
| 83 | + }); |
| 84 | + |
| 85 | + debug( 'Initializing graph component...' ); |
| 86 | + Object.defineProperty( svg, 'graph', { |
| 87 | + 'configurable': false, |
| 88 | + 'enumerable': false, |
| 89 | + 'writable': false, |
| 90 | + 'value': new Graph({ |
| 91 | + 'autoRender': false |
| 92 | + }) |
| 93 | + }); |
| 94 | + |
| 95 | + debug( 'Initializing annotations component...' ); |
| 96 | + Object.defineProperty( svg, 'annotations', { |
| 97 | + 'configurable': false, |
| 98 | + 'enumerable': false, |
| 99 | + 'writable': false, |
| 100 | + 'value': new Annotations({ |
| 101 | + 'autoRender': false |
| 102 | + }) |
| 103 | + }); |
| 104 | + |
| 105 | + debug( 'Initializing title component...' ); |
| 106 | + Object.defineProperty( svg, 'title', { |
| 107 | + 'configurable': false, |
| 108 | + 'enumerable': false, |
| 109 | + 'writable': false, |
| 110 | + 'value': new Title({ |
| 111 | + 'autoRender': false |
| 112 | + }) |
| 113 | + }); |
| 114 | + |
| 115 | + debug( 'Initializing background component...' ); |
| 116 | + Object.defineProperty( svg, 'bkgd', { |
| 117 | + 'configurable': false, |
| 118 | + 'enumerable': false, |
| 119 | + 'writable': false, |
| 120 | + 'value': new Bkgd({ |
| 121 | + 'autoRender': false |
| 122 | + }) |
| 123 | + }); |
| 124 | + |
| 125 | + debug( 'Initializing marks component...' ); |
| 126 | + Object.defineProperty( svg, 'marks', { |
| 127 | + 'configurable': false, |
| 128 | + 'enumerable': false, |
| 129 | + 'writable': false, |
| 130 | + 'value': new Marks({ |
| 131 | + 'autoRender': false, |
| 132 | + 'clipPathId': state._clipPathId // eslint-disable-line no-underscore-dangle |
| 133 | + }) |
| 134 | + }); |
| 135 | + |
| 136 | + debug( 'Initializing columns component...' ); |
| 137 | + Object.defineProperty( svg, 'columns', { |
| 138 | + 'configurable': false, |
| 139 | + 'enumerable': false, |
| 140 | + 'writable': false, |
| 141 | + 'value': new Columns({ |
| 142 | + 'autoRender': false |
| 143 | + }) |
| 144 | + }); |
| 145 | + |
| 146 | + debug( 'Initializing x-axis component...' ); |
| 147 | + Object.defineProperty( svg, 'xAxis', { |
| 148 | + 'configurable': false, |
| 149 | + 'enumerable': false, |
| 150 | + 'writable': false, |
| 151 | + 'value': new Axis({ |
| 152 | + 'autoRender': false |
| 153 | + }) |
| 154 | + }); |
| 155 | + |
| 156 | + debug( 'Initializing y-axis component...' ); |
| 157 | + Object.defineProperty( svg, 'yAxis', { |
| 158 | + 'configurable': false, |
| 159 | + 'enumerable': false, |
| 160 | + 'writable': false, |
| 161 | + 'value': new Axis({ |
| 162 | + 'autoRender': false |
| 163 | + }) |
| 164 | + }); |
| 165 | + |
| 166 | + debug( 'All components initialized.' ); |
| 167 | +} |
| 168 | + |
| 169 | + |
| 170 | +// EXPORTS // |
| 171 | + |
| 172 | +module.exports = init; |
0 commit comments