1- import { Chart } from 'chart.js' ;
1+ import { ArcElement , BarElement , defaults , PointElement } from 'chart.js' ;
2+ import {
3+ callback as callbackHelper ,
4+ isNullOrUndef ,
5+ merge ,
6+ resolve ,
7+ toFont ,
8+ toPadding ,
9+ valueOrDefault
10+ } from 'chart.js/helpers' ;
11+
212import utils from './utils' ;
313import positioners from './positioners' ;
414
5- var helpers = Chart . helpers ;
615var rasterize = utils . rasterize ;
716
817function boundingRects ( model ) {
@@ -47,13 +56,13 @@ function getScaleOrigin(el, context) {
4756}
4857
4958function getPositioner ( el ) {
50- if ( el instanceof Chart . elements . ArcElement ) {
59+ if ( el instanceof ArcElement ) {
5160 return positioners . arc ;
5261 }
53- if ( el instanceof Chart . elements . PointElement ) {
62+ if ( el instanceof PointElement ) {
5463 return positioners . point ;
5564 }
56- if ( el instanceof Chart . elements . BarElement ) {
65+ if ( el instanceof BarElement ) {
5766 return positioners . bar ;
5867 }
5968 return positioners . fallback ;
@@ -227,16 +236,15 @@ var Label = function(config, ctx, el, index) {
227236 me . _el = el ;
228237} ;
229238
230- helpers . merge ( Label . prototype , {
239+ merge ( Label . prototype , {
231240 /**
232241 * @private
233242 */
234243 _modelize : function ( display , lines , config , context ) {
235244 var me = this ;
236245 var index = me . _index ;
237- var resolve = helpers . resolve ;
238- var font = helpers . toFont ( resolve ( [ config . font , { } ] , context , index ) ) ;
239- var color = resolve ( [ config . color , Chart . defaults . font . color ] , context , index ) ;
246+ var font = toFont ( resolve ( [ config . font , { } ] , context , index ) ) ;
247+ var color = resolve ( [ config . color , defaults . color ] , context , index ) ;
240248
241249 return {
242250 align : resolve ( [ config . align , 'center' ] , context , index ) ,
@@ -255,7 +263,7 @@ helpers.merge(Label.prototype, {
255263 offset : resolve ( [ config . offset , 0 ] , context , index ) ,
256264 opacity : resolve ( [ config . opacity , 1 ] , context , index ) ,
257265 origin : getScaleOrigin ( me . _el , context ) ,
258- padding : helpers . toPadding ( resolve ( [ config . padding , 0 ] , context , index ) ) ,
266+ padding : toPadding ( resolve ( [ config . padding , 0 ] , context , index ) ) ,
259267 positioner : getPositioner ( me . _el ) ,
260268 rotation : resolve ( [ config . rotation , 0 ] , context , index ) * ( Math . PI / 180 ) ,
261269 size : utils . textSize ( me . _ctx , lines , font ) ,
@@ -277,12 +285,12 @@ helpers.merge(Label.prototype, {
277285
278286 // We first resolve the display option (separately) to avoid computing
279287 // other options in case the label is hidden (i.e. display: false).
280- var display = helpers . resolve ( [ config . display , true ] , context , index ) ;
288+ var display = resolve ( [ config . display , true ] , context , index ) ;
281289
282290 if ( display ) {
283291 value = context . dataset . data [ index ] ;
284- label = helpers . valueOrDefault ( helpers . callback ( config . formatter , [ value , context ] ) , value ) ;
285- lines = helpers . isNullOrUndef ( label ) ? [ ] : utils . toTextLines ( label ) ;
292+ label = valueOrDefault ( callbackHelper ( config . formatter , [ value , context ] ) , value ) ;
293+ lines = isNullOrUndef ( label ) ? [ ] : utils . toTextLines ( label ) ;
286294
287295 if ( lines . length ) {
288296 model = me . _modelize ( display , lines , config , context ) ;
0 commit comments