Skip to content

Commit 74df5af

Browse files
committed
Add yTickFormat property
1 parent d162689 commit 74df5af

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

lib/node_modules/@stdlib/plot/hist/lib/main.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,37 @@ Object.defineProperty( Histogram.prototype, 'yRange', {
11691169
'get': require( './props/y-range/get.js' )
11701170
});
11711171

1172+
/**
1173+
* y-axis tick format.
1174+
*
1175+
* ## Notes
1176+
*
1177+
* - If the value is not `null`, when retrieved, the returned value is a formatting function.
1178+
*
1179+
* @name yTickFormat
1180+
* @memberof Histogram.prototype
1181+
* @type {(string|null)}
1182+
* @throws {TypeError} must be a string primitive or null
1183+
* @default null
1184+
*
1185+
* @example
1186+
* var hist = new Histogram();
1187+
* hist.yTickFormat = '%%';
1188+
*
1189+
* @example
1190+
* var hist = new Histogram({
1191+
* 'yTickFormat': '%%'
1192+
* });
1193+
* var fmt = hist.yTickFormat;
1194+
* // returns '%%'
1195+
*/
1196+
Object.defineProperty( Histogram.prototype, 'yTickFormat', {
1197+
'configurable': false,
1198+
'enumerable': true,
1199+
'set': require( './props/y-tick-format/set.js' ),
1200+
'get': require( './props/y-tick-format/get.js' )
1201+
});
1202+
11721203
/**
11731204
* Generates a histogram view.
11741205
*
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 format = require( 'd3-format' ).format; // TODO: remove
24+
var isNull = require( '@stdlib/assert/is-null' );
25+
26+
27+
// MAIN //
28+
29+
/**
30+
* Returns the y-axis tick format.
31+
*
32+
* @private
33+
* @returns {(Function|null)} format function or null
34+
*/
35+
function get() {
36+
/* eslint-disable no-invalid-this */
37+
if ( isNull( this._yTickFormat ) ) {
38+
return this._yTickFormat;
39+
}
40+
return format( this._yTickFormat );
41+
}
42+
43+
44+
// EXPORTS //
45+
46+
module.exports = get;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 isNull = require( '@stdlib/assert/is-null' );
25+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
27+
28+
// VARIABLES //
29+
30+
var debug = logger( 'hist:set:y-tick-format' );
31+
32+
33+
// MAIN //
34+
35+
/**
36+
* Sets the y-axis tick format.
37+
*
38+
* @private
39+
* @param {(string|null)} fmt - axis tick format
40+
* @throws {TypeError} must be a string primitive or null
41+
*/
42+
function set( fmt ) {
43+
/* eslint-disable no-invalid-this */
44+
if ( !isNull( fmt ) && !isString( fmt ) ) {
45+
throw new TypeError( 'invalid value. `yTickFormat` must be a string or null. Value: `' + fmt + '.`' );
46+
}
47+
if ( fmt !== this._yTickFormat ) {
48+
debug( 'Current value: %s.', this._yTickFormat );
49+
50+
this._yTickFormat = fmt;
51+
debug( 'New value: %s.', this._yTickFormat );
52+
53+
this.emit( 'change' );
54+
}
55+
}
56+
57+
58+
// EXPORTS //
59+
60+
module.exports = set;

0 commit comments

Comments
 (0)