11import { getHoverColor } from '../helpers/helpers.color' ;
22import { isObject , merge , valueOrDefault } from '../helpers/helpers.core' ;
33
4+ const privateSymbol = Symbol ( 'private' ) ;
5+
46/**
57 * @param {object } node
68 * @param {string } key
@@ -23,9 +25,7 @@ function getScope(node, key) {
2325 * Note: class is exported for typedoc
2426 */
2527export class Defaults {
26- constructor ( ) {
27- this . _scriptable = ( name ) => name !== 'onClick' && name !== 'onHover' ;
28- this . _indexable = ( name ) => name !== 'events' ;
28+ constructor ( descriptors ) {
2929 this . animation = undefined ;
3030 this . backgroundColor = 'rgba(0,0,0,0.1)' ;
3131 this . borderColor = 'rgba(0,0,0,0.1)' ;
@@ -48,16 +48,13 @@ export class Defaults {
4848 weight : null
4949 } ;
5050 this . hover = {
51- _fallback : 'interaction' ,
5251 onHover : null
5352 } ;
5453 this . hoverBackgroundColor = ( ctx , options ) => getHoverColor ( options . backgroundColor ) ;
5554 this . hoverBorderColor = ( ctx , options ) => getHoverColor ( options . borderColor ) ;
5655 this . hoverColor = ( ctx , options ) => getHoverColor ( options . color ) ;
5756 this . indexAxis = null ;
5857 this . interaction = {
59- _scroptable : false ,
60- _indexable : false ,
6158 mode : 'nearest' ,
6259 intersect : true
6360 } ;
@@ -70,6 +67,13 @@ export class Defaults {
7067 this . scale = undefined ;
7168 this . scales = { } ;
7269 this . showLine = true ;
70+
71+ Object . defineProperty ( this , privateSymbol , {
72+ value : Object . create ( null ) ,
73+ writable : false
74+ } ) ;
75+
76+ this . describe ( descriptors ) ;
7377 }
7478
7579 /**
@@ -90,6 +94,22 @@ export class Defaults {
9094 return getScope ( this , scope ) ;
9195 }
9296
97+ /**
98+ * @param {string|object } scope
99+ * @param {object } [values]
100+ */
101+ describe ( scope , values ) {
102+ const root = this [ privateSymbol ] ;
103+ if ( typeof scope === 'string' ) {
104+ return merge ( getScope ( root , scope ) , values ) ;
105+ }
106+ return merge ( getScope ( root , '' ) , scope ) ;
107+ }
108+
109+ get descriptors ( ) {
110+ return this [ privateSymbol ] ;
111+ }
112+
93113 /**
94114 * Routes the named defaults to fallback to another scope/name.
95115 * This routing is useful when those target values, like defaults.color, are changed runtime.
@@ -138,4 +158,14 @@ export class Defaults {
138158}
139159
140160// singleton instance
141- export default new Defaults ( ) ;
161+ export default new Defaults ( {
162+ _scriptable : ( name ) => name !== 'onClick' && name !== 'onHover' ,
163+ _indexable : ( name ) => name !== 'events' ,
164+ hover : {
165+ _fallback : 'interaction'
166+ } ,
167+ interaction : {
168+ _scroptable : false ,
169+ _indexable : false ,
170+ }
171+ } ) ;
0 commit comments