44 * (c) 2021 Chart.js Contributors
55 * Released under the MIT License
66 */
7- import { r as requestAnimFrame , a as resolve , e as effects , c as color , i as isObject , b as isArray , d as defaults , v as valueOrDefault , u as unlistenArrayEvents , l as listenArrayEvents , f as resolveObjectKey , g as isNumberFinite , h as defined , s as sign , j as isNullOrUndef , _ as _arrayUnique , t as toRadians , k as toPercentage , m as toDimension , T as TAU , n as formatNumber , o as _angleBetween , H as HALF_PI , P as PI , p as isNumber , q as _limitValue , w as _lookupByKey , x as getRelativePosition$1 , y as _isPointInArea , z as _rlookupByKey , A as toPadding , B as each , C as getMaximumSize , D as _getParentNode , E as readUsedSize , F as throttled , G as supportsEventListenerOptions , I as log10 , J as _factorize , K as finiteOrDefault , L as callback , M as _addGrace , N as toDegrees , O as _measureText , Q as _int16Range , R as _alignPixel , S as clipArea , U as renderText , V as unclipArea , W as toFont , X as _toLeftRightCenter , Y as _alignStartEnd , Z as overrides , $ as merge , a0 as _capitalize , a1 as descriptors , a2 as isFunction , a3 as _attachContext , a4 as _createResolver , a5 as _descriptors , a6 as mergeIf , a7 as uid , a8 as debounce , a9 as retinaScale , aa as clearCanvas , ab as setsEqual , ac as _elementsEqual , ad as getAngleFromPoint , ae as _readValueToProps , af as _updateBezierControlPoints , ag as _computeSegments , ah as _boundSegments , ai as _steppedInterpolation , aj as _bezierInterpolation , ak as _pointInLine , al as _steppedLineTo , am as _bezierCurveTo , an as drawPoint , ao as addRoundedRectPath , ap as toTRBL , aq as toTRBLCorners , ar as _boundSegment , as as _normalizeAngle , at as getRtlAdapter , au as overrideTextDirection , av as _textX , aw as restoreTextDirection , ax as noop , ay as distanceBetweenPoints , az as _setMinAndMaxByKey , aA as niceNum , aB as almostWhole , aC as almostEquals , aD as _decimalPlaces , aE as _longestText , aF as _filterBetween , aG as _lookup } from './chunks/helpers.segment.js' ;
7+ import { r as requestAnimFrame , a as resolve , e as effects , c as color , i as isObject , b as isArray , d as defaults , v as valueOrDefault , u as unlistenArrayEvents , l as listenArrayEvents , f as resolveObjectKey , g as isNumberFinite , h as defined , s as sign , j as isNullOrUndef , _ as _arrayUnique , t as toRadians , k as toPercentage , m as toDimension , T as TAU , n as formatNumber , o as _angleBetween , H as HALF_PI , P as PI , p as isNumber , q as _limitValue , w as _lookupByKey , x as getRelativePosition$1 , y as _isPointInArea , z as _rlookupByKey , A as toPadding , B as each , C as getMaximumSize , D as _getParentNode , E as readUsedSize , F as throttled , G as supportsEventListenerOptions , I as _isDomSupported , J as log10 , K as _factorize , L as finiteOrDefault , M as callback , N as _addGrace , O as toDegrees , Q as _measureText , R as _int16Range , S as _alignPixel , U as clipArea , V as renderText , W as unclipArea , X as toFont , Y as _toLeftRightCenter , Z as _alignStartEnd , $ as overrides , a0 as merge , a1 as _capitalize , a2 as descriptors , a3 as isFunction , a4 as _attachContext , a5 as _createResolver , a6 as _descriptors , a7 as mergeIf , a8 as uid , a9 as debounce , aa as retinaScale , ab as clearCanvas , ac as setsEqual , ad as _elementsEqual , ae as getAngleFromPoint , af as _readValueToProps , ag as _updateBezierControlPoints , ah as _computeSegments , ai as _boundSegments , aj as _steppedInterpolation , ak as _bezierInterpolation , al as _pointInLine , am as _steppedLineTo , an as _bezierCurveTo , ao as drawPoint , ap as addRoundedRectPath , aq as toTRBL , ar as toTRBLCorners , as as _boundSegment , at as _normalizeAngle , au as getRtlAdapter , av as overrideTextDirection , aw as _textX , ax as restoreTextDirection , ay as noop , az as distanceBetweenPoints , aA as _setMinAndMaxByKey , aB as niceNum , aC as almostWhole , aD as almostEquals , aE as _decimalPlaces , aF as _longestText , aG as _filterBetween , aH as _lookup } from './chunks/helpers.segment.js' ;
88export { d as defaults } from './chunks/helpers.segment.js' ;
99
1010class Animator {
@@ -3217,6 +3217,13 @@ class DomPlatform extends BasePlatform {
32173217}
32183218}
32193219
3220+ function _detectPlatform ( canvas ) {
3221+ if ( ! _isDomSupported ( ) || ( typeof OffscreenCanvas !== 'undefined' && canvas instanceof OffscreenCanvas ) ) {
3222+ return BasicPlatform ;
3223+ }
3224+ return DomPlatform ;
3225+ }
3226+
32203227class Element {
32213228constructor ( ) {
32223229this . x = undefined ;
@@ -5040,6 +5047,9 @@ class Config {
50405047this . _scopeCache = new Map ( ) ;
50415048this . _resolverCache = new Map ( ) ;
50425049}
5050+ get platform ( ) {
5051+ return this . _config . platform ;
5052+ }
50435053get type ( ) {
50445054return this . _config . type ;
50455055}
@@ -5227,11 +5237,8 @@ function onAnimationProgress(context) {
52275237const animationOptions = chart . options . animation ;
52285238callback ( animationOptions && animationOptions . onProgress , [ context ] , chart ) ;
52295239}
5230- function isDomSupported ( ) {
5231- return typeof window !== 'undefined' && typeof document !== 'undefined' ;
5232- }
52335240function getCanvas ( item ) {
5234- if ( isDomSupported ( ) && typeof item === 'string' ) {
5241+ if ( _isDomSupported ( ) && typeof item === 'string' ) {
52355242item = document . getElementById ( item ) ;
52365243} else if ( item && item . length ) {
52375244item = item [ 0 ] ;
@@ -5247,9 +5254,9 @@ const getChart = (key) => {
52475254return Object . values ( instances ) . filter ( ( c ) => c . canvas === canvas ) . pop ( ) ;
52485255} ;
52495256class Chart {
5250- constructor ( item , config ) {
5257+ constructor ( item , userConfig ) {
52515258const me = this ;
5252- this . config = config = new Config ( config ) ;
5259+ const config = this . config = new Config ( userConfig ) ;
52535260const initialCanvas = getCanvas ( item ) ;
52545261const existingChart = getChart ( initialCanvas ) ;
52555262if ( existingChart ) {
@@ -5259,7 +5266,7 @@ class Chart {
52595266) ;
52605267}
52615268const options = config . createResolver ( config . chartOptionScopes ( ) , me . getContext ( ) ) ;
5262- this . platform = me . _initializePlatform ( initialCanvas , config ) ;
5269+ this . platform = new ( config . platform || _detectPlatform ( initialCanvas ) ) ( ) ;
52635270const context = me . platform . acquireContext ( initialCanvas , options . aspectRatio ) ;
52645271const canvas = context && context . canvas ;
52655272const height = canvas && canvas . height ;
@@ -5337,14 +5344,6 @@ class Chart {
53375344me . notifyPlugins ( 'afterInit' ) ;
53385345return me ;
53395346}
5340- _initializePlatform ( canvas , config ) {
5341- if ( config . platform ) {
5342- return new config . platform ( ) ;
5343- } else if ( ! isDomSupported ( ) || ( typeof OffscreenCanvas !== 'undefined' && canvas instanceof OffscreenCanvas ) ) {
5344- return new BasicPlatform ( ) ;
5345- }
5346- return new DomPlatform ( ) ;
5347- }
53485347clear ( ) {
53495348clearCanvas ( this . canvas , this . ctx ) ;
53505349return this ;
@@ -10544,4 +10543,4 @@ const registerables = [
1054410543scales ,
1054510544] ;
1054610545
10547- export { Animation , Animations , ArcElement , BarController , BarElement , BasePlatform , BasicPlatform , BubbleController , CategoryScale , Chart , DatasetController , plugin_decimation as Decimation , DomPlatform , DoughnutController , Element , plugin_filler as Filler , Interaction , plugin_legend as Legend , LineController , LineElement , LinearScale , LogarithmicScale , PieController , PointElement , PolarAreaController , RadarController , RadialLinearScale , Scale , ScatterController , plugin_subtitle as SubTitle , Ticks , TimeScale , TimeSeriesScale , plugin_title as Title , plugin_tooltip as Tooltip , adapters as _adapters , animator , controllers , elements , layouts , plugins , registerables , registry , scales } ;
10546+ export { Animation , Animations , ArcElement , BarController , BarElement , BasePlatform , BasicPlatform , BubbleController , CategoryScale , Chart , DatasetController , plugin_decimation as Decimation , DomPlatform , DoughnutController , Element , plugin_filler as Filler , Interaction , plugin_legend as Legend , LineController , LineElement , LinearScale , LogarithmicScale , PieController , PointElement , PolarAreaController , RadarController , RadialLinearScale , Scale , ScatterController , plugin_subtitle as SubTitle , Ticks , TimeScale , TimeSeriesScale , plugin_title as Title , plugin_tooltip as Tooltip , adapters as _adapters , _detectPlatform , animator , controllers , elements , layouts , plugins , registerables , registry , scales } ;