code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
last() { const segments = this.segments; const points = this.points; const count = segments.length; return count && points[segments[count - 1].end]; }
Last non-skipped point on this line @returns {PointElement|undefined}
last
javascript
chartjs/Chart.js
src/elements/element.line.js
https://github.com/chartjs/Chart.js/blob/master/src/elements/element.line.js
MIT
interpolate(point, property) { const options = this.options; const value = point[property]; const points = this.points; const segments = _boundSegments(this, {property, start: value, end: value}); if (!segments.length) { return; } const result = []; const _interpolate = _getInter...
Interpolate a point in this line at the same value on `property` as the reference `point` provided @param {PointElement} point - the reference point @param {string} property - the property to match on @returns {PointElement|undefined}
interpolate
javascript
chartjs/Chart.js
src/elements/element.line.js
https://github.com/chartjs/Chart.js/blob/master/src/elements/element.line.js
MIT
path(ctx, start, count) { const segments = this.segments; const segmentMethod = _getSegmentMethod(this); let loop = this._loop; start = start || 0; count = count || (this.points.length - start); for (const segment of segments) { loop &= segmentMethod(ctx, this, segment, {start, end: star...
Append all segments of this line to current path. @param {CanvasRenderingContext2D|Path2D} ctx @param {number} [start] @param {number} [count] @returns {undefined|boolean} - true if line is a full loop (path should be closed)
path
javascript
chartjs/Chart.js
src/elements/element.line.js
https://github.com/chartjs/Chart.js/blob/master/src/elements/element.line.js
MIT
draw(ctx, chartArea, start, count) { const options = this.options || {}; const points = this.points || []; if (points.length && options.borderWidth) { ctx.save(); draw(ctx, this, start, count); ctx.restore(); } if (this.animated) { // When line is animated, the control po...
Draw @param {CanvasRenderingContext2D} ctx @param {object} chartArea @param {number} [start] @param {number} [count]
draw
javascript
chartjs/Chart.js
src/elements/element.line.js
https://github.com/chartjs/Chart.js/blob/master/src/elements/element.line.js
MIT
function propertyFn(property) { if (property === 'angle') { return { between: _angleBetween, compare: _angleDiff, normalize: _normalizeAngle, }; } return { between: _isBetween, compare: (a, b) => a - b, normalize: x => x }; }
@typedef { import('../elements/element.line.js').default } LineElement @typedef { import('../elements/element.point.js').default } PointElement @typedef {{start: number, end: number, loop: boolean, style?: any}} Segment
propertyFn
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
function normalizeSegment({start, end, count, loop, style}) { return { start: start % count, end: end % count, loop: loop && (end - start + 1) % count === 0, style }; }
@typedef { import('../elements/element.line.js').default } LineElement @typedef { import('../elements/element.point.js').default } PointElement @typedef {{start: number, end: number, loop: boolean, style?: any}} Segment
normalizeSegment
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
function getSegment(segment, points, bounds) { const {property, start: startBound, end: endBound} = bounds; const {between, normalize} = propertyFn(property); const count = points.length; // eslint-disable-next-line prefer-const let {start, end, loop} = segment; let i, ilen; if (loop) { start += coun...
@typedef { import('../elements/element.line.js').default } LineElement @typedef { import('../elements/element.point.js').default } PointElement @typedef {{start: number, end: number, loop: boolean, style?: any}} Segment
getSegment
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
function _boundSegment(segment, points, bounds) { if (!bounds) { return [segment]; } const {property, start: startBound, end: endBound} = bounds; const count = points.length; const {compare, between, normalize} = propertyFn(property); const {start, end, loop, style} = getSegment(segment, points, bounds...
Returns the sub-segment(s) of a line segment that fall in the given bounds @param {object} segment @param {number} segment.start - start index of the segment, referring the points array @param {number} segment.end - end index of the segment, referring the points array @param {boolean} segment.loop - indicates that the ...
_boundSegment
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
function _boundSegments(line, bounds) { const result = []; const segments = line.segments; for (let i = 0; i < segments.length; i++) { const sub = _boundSegment(segments[i], line.points, bounds); if (sub.length) { result.push(...sub); } } return result; }
Returns the segments of the line that are inside given bounds @param {LineElement} line @param {object} [bounds] @param {string} bounds.property - the property we are bounding with. `x`, `y` or `angle`. @param {number} bounds.start - start value of the `property` @param {number} bounds.end - end value of the `property`...
_boundSegments
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
function findStartAndEnd(points, count, loop, spanGaps) { let start = 0; let end = count - 1; if (loop && !spanGaps) { // loop and not spanning gaps, first find a gap to start from while (start < count && !points[start].skip) { start++; } } // find first non skipped point (after the first ...
Find start and end index of a line.
findStartAndEnd
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
function solidSegments(points, start, max, loop) { const count = points.length; const result = []; let last = start; let prev = points[start]; let end; for (end = start + 1; end <= max; ++end) { const cur = points[end % count]; if (cur.skip || cur.stop) { if (!prev.skip) { loop = fals...
Compute solid segments from Points, when spanGaps === false @param {PointElement[]} points - the points @param {number} start - start index @param {number} max - max index (can go past count on a loop) @param {boolean} loop - boolean indicating that this would be a loop if no gaps are found
solidSegments
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
function _computeSegments(line, segmentOptions) { const points = line.points; const spanGaps = line.options.spanGaps; const count = points.length; if (!count) { return []; } const loop = !!line._loop; const {start, end} = findStartAndEnd(points, count, loop, spanGaps); if (spanGaps === true) { ...
Compute the continuous segments that define the whole line There can be skipped points within a segment, if spanGaps is true. @param {LineElement} line @param {object} [segmentOptions] @return {Segment[]} @private
_computeSegments
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
function splitByStyles(line, segments, points, segmentOptions) { if (!segmentOptions || !segmentOptions.setContext || !points) { return segments; } return doSplitByStyles(line, segments, points, segmentOptions); }
@param {Segment[]} segments @param {PointElement[]} points @param {object} [segmentOptions] @return {Segment[]}
splitByStyles
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
function doSplitByStyles(line, segments, points, segmentOptions) { const chartContext = line._chart.getContext(); const baseStyle = readStyle(line.options); const {_datasetIndex: datasetIndex, options: {spanGaps}} = line; const count = points.length; const result = []; let prevStyle = baseStyle; let start...
@param {LineElement} line @param {Segment[]} segments @param {PointElement[]} points @param {object} [segmentOptions] @return {Segment[]}
doSplitByStyles
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
function addStyle(s, e, l, st) { const dir = spanGaps ? -1 : 1; if (s === e) { return; } // Style can not start/end on a skipped point, adjust indices accordingly s += count; while (points[s % count].skip) { s -= dir; } while (points[e % count].skip) { e += dir; } ...
@param {LineElement} line @param {Segment[]} segments @param {PointElement[]} points @param {object} [segmentOptions] @return {Segment[]}
addStyle
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
function readStyle(options) { return { backgroundColor: options.backgroundColor, borderCapStyle: options.borderCapStyle, borderDash: options.borderDash, borderDashOffset: options.borderDashOffset, borderJoinStyle: options.borderJoinStyle, borderWidth: options.borderWidth, borderColor: opti...
@param {LineElement} line @param {Segment[]} segments @param {PointElement[]} points @param {object} [segmentOptions] @return {Segment[]}
readStyle
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
function styleChanged(style, prevStyle) { if (!prevStyle) { return false; } const cache = []; const replacer = function(key, value) { if (!isPatternOrGradient(value)) { return value; } if (!cache.includes(value)) { cache.push(value); } return cache.indexOf(value); }; retu...
@param {LineElement} line @param {Segment[]} segments @param {PointElement[]} points @param {object} [segmentOptions] @return {Segment[]}
styleChanged
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
replacer = function(key, value) { if (!isPatternOrGradient(value)) { return value; } if (!cache.includes(value)) { cache.push(value); } return cache.indexOf(value); }
@param {LineElement} line @param {Segment[]} segments @param {PointElement[]} points @param {object} [segmentOptions] @return {Segment[]}
replacer
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
replacer = function(key, value) { if (!isPatternOrGradient(value)) { return value; } if (!cache.includes(value)) { cache.push(value); } return cache.indexOf(value); }
@param {LineElement} line @param {Segment[]} segments @param {PointElement[]} points @param {object} [segmentOptions] @return {Segment[]}
replacer
javascript
chartjs/Chart.js
src/helpers/helpers.segment.js
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.segment.js
MIT
releaseContext(context) { // eslint-disable-line no-unused-vars return false; }
Called at chart destruction time, releases any resources associated to the context previously returned by the acquireContext() method. @param {CanvasRenderingContext2D} context - The context2d instance @returns {boolean} true if the method succeeded, else false
releaseContext
javascript
chartjs/Chart.js
src/platform/platform.base.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.base.js
MIT
getDevicePixelRatio() { return 1; }
@returns {number} the current devicePixelRatio of the device this platform is connected to.
getDevicePixelRatio
javascript
chartjs/Chart.js
src/platform/platform.base.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.base.js
MIT
getMaximumSize(element, width, height, aspectRatio) { width = Math.max(0, width || element.width); height = height || element.height; return { width, height: Math.max(0, aspectRatio ? Math.floor(width / aspectRatio) : height) }; }
Returns the maximum size in pixels of given canvas element. @param {HTMLCanvasElement} element @param {number} [width] - content width of parent element @param {number} [height] - content height of parent element @param {number} [aspectRatio] - aspect ratio to maintain
getMaximumSize
javascript
chartjs/Chart.js
src/platform/platform.base.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.base.js
MIT
isAttached(canvas) { // eslint-disable-line no-unused-vars return true; }
@param {HTMLCanvasElement} canvas @returns {boolean} true if the canvas is attached to the platform, false if not.
isAttached
javascript
chartjs/Chart.js
src/platform/platform.base.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.base.js
MIT
updateConfig(config) { // eslint-disable-line no-unused-vars // no-op }
Updates config with platform specific requirements @param {import('../core/core.config.js').default} config
updateConfig
javascript
chartjs/Chart.js
src/platform/platform.base.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.base.js
MIT
acquireContext(item) { // To prevent canvas fingerprinting, some add-ons undefine the getContext // method, for example: https://github.com/kkapsner/CanvasBlocker // https://github.com/chartjs/Chart.js/issues/2807 return item && item.getContext && item.getContext('2d') || null; }
Platform class for charts without access to the DOM or to many element properties This platform is used by default for any chart passed an OffscreenCanvas. @extends BasePlatform
acquireContext
javascript
chartjs/Chart.js
src/platform/platform.basic.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.basic.js
MIT
updateConfig(config) { config.options.animation = false; }
Platform class for charts without access to the DOM or to many element properties This platform is used by default for any chart passed an OffscreenCanvas. @extends BasePlatform
updateConfig
javascript
chartjs/Chart.js
src/platform/platform.basic.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.basic.js
MIT
function initCanvas(canvas, aspectRatio) { const style = canvas.style; // NOTE(SB) canvas.getAttribute('width') !== canvas.width: in the first case it // returns null or '' if no explicit value has been set to the canvas attribute. const renderHeight = canvas.getAttribute('height'); const renderWidth = canva...
Initializes the canvas style and render size without modifying the canvas display size, since responsiveness is handled by the controller.resize() method. The config is used to determine the aspect ratio to apply in case no explicit height has been specified. @param {HTMLCanvasElement} canvas @param {number} [aspectRat...
initCanvas
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
function addListener(node, type, listener) { if (node) { node.addEventListener(type, listener, eventListenerOptions); } }
Initializes the canvas style and render size without modifying the canvas display size, since responsiveness is handled by the controller.resize() method. The config is used to determine the aspect ratio to apply in case no explicit height has been specified. @param {HTMLCanvasElement} canvas @param {number} [aspectRat...
addListener
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
function removeListener(chart, type, listener) { if (chart && chart.canvas) { chart.canvas.removeEventListener(type, listener, eventListenerOptions); } }
Initializes the canvas style and render size without modifying the canvas display size, since responsiveness is handled by the controller.resize() method. The config is used to determine the aspect ratio to apply in case no explicit height has been specified. @param {HTMLCanvasElement} canvas @param {number} [aspectRat...
removeListener
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
function fromNativeEvent(event, chart) { const type = EVENT_TYPES[event.type] || event.type; const {x, y} = getRelativePosition(event, chart); return { type, chart, native: event, x: x !== undefined ? x : null, y: y !== undefined ? y : null, }; }
Initializes the canvas style and render size without modifying the canvas display size, since responsiveness is handled by the controller.resize() method. The config is used to determine the aspect ratio to apply in case no explicit height has been specified. @param {HTMLCanvasElement} canvas @param {number} [aspectRat...
fromNativeEvent
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
function nodeListContains(nodeList, canvas) { for (const node of nodeList) { if (node === canvas || node.contains(canvas)) { return true; } } }
Initializes the canvas style and render size without modifying the canvas display size, since responsiveness is handled by the controller.resize() method. The config is used to determine the aspect ratio to apply in case no explicit height has been specified. @param {HTMLCanvasElement} canvas @param {number} [aspectRat...
nodeListContains
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
function createAttachObserver(chart, type, listener) { const canvas = chart.canvas; const observer = new MutationObserver(entries => { let trigger = false; for (const entry of entries) { trigger = trigger || nodeListContains(entry.addedNodes, canvas); trigger = trigger && !nodeListContains(entry...
Initializes the canvas style and render size without modifying the canvas display size, since responsiveness is handled by the controller.resize() method. The config is used to determine the aspect ratio to apply in case no explicit height has been specified. @param {HTMLCanvasElement} canvas @param {number} [aspectRat...
createAttachObserver
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
function createDetachObserver(chart, type, listener) { const canvas = chart.canvas; const observer = new MutationObserver(entries => { let trigger = false; for (const entry of entries) { trigger = trigger || nodeListContains(entry.removedNodes, canvas); trigger = trigger && !nodeListContains(ent...
Initializes the canvas style and render size without modifying the canvas display size, since responsiveness is handled by the controller.resize() method. The config is used to determine the aspect ratio to apply in case no explicit height has been specified. @param {HTMLCanvasElement} canvas @param {number} [aspectRat...
createDetachObserver
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
function onWindowResize() { const dpr = window.devicePixelRatio; if (dpr === oldDevicePixelRatio) { return; } oldDevicePixelRatio = dpr; drpListeningCharts.forEach((resize, chart) => { if (chart.currentDevicePixelRatio !== dpr) { resize(); } }); }
Initializes the canvas style and render size without modifying the canvas display size, since responsiveness is handled by the controller.resize() method. The config is used to determine the aspect ratio to apply in case no explicit height has been specified. @param {HTMLCanvasElement} canvas @param {number} [aspectRat...
onWindowResize
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
function listenDevicePixelRatioChanges(chart, resize) { if (!drpListeningCharts.size) { window.addEventListener('resize', onWindowResize); } drpListeningCharts.set(chart, resize); }
Initializes the canvas style and render size without modifying the canvas display size, since responsiveness is handled by the controller.resize() method. The config is used to determine the aspect ratio to apply in case no explicit height has been specified. @param {HTMLCanvasElement} canvas @param {number} [aspectRat...
listenDevicePixelRatioChanges
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
function unlistenDevicePixelRatioChanges(chart) { drpListeningCharts.delete(chart); if (!drpListeningCharts.size) { window.removeEventListener('resize', onWindowResize); } }
Initializes the canvas style and render size without modifying the canvas display size, since responsiveness is handled by the controller.resize() method. The config is used to determine the aspect ratio to apply in case no explicit height has been specified. @param {HTMLCanvasElement} canvas @param {number} [aspectRat...
unlistenDevicePixelRatioChanges
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
function createResizeObserver(chart, type, listener) { const canvas = chart.canvas; const container = canvas && _getParentNode(canvas); if (!container) { return; } const resize = throttled((width, height) => { const w = container.clientWidth; listener(width, height); if (w < container.clientWi...
Initializes the canvas style and render size without modifying the canvas display size, since responsiveness is handled by the controller.resize() method. The config is used to determine the aspect ratio to apply in case no explicit height has been specified. @param {HTMLCanvasElement} canvas @param {number} [aspectRat...
createResizeObserver
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
function releaseObserver(chart, type, observer) { if (observer) { observer.disconnect(); } if (type === 'resize') { unlistenDevicePixelRatioChanges(chart); } }
Initializes the canvas style and render size without modifying the canvas display size, since responsiveness is handled by the controller.resize() method. The config is used to determine the aspect ratio to apply in case no explicit height has been specified. @param {HTMLCanvasElement} canvas @param {number} [aspectRat...
releaseObserver
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
function createProxyAndListen(chart, type, listener) { const canvas = chart.canvas; const proxy = throttled((event) => { // This case can occur if the chart is destroyed while waiting // for the throttled function to occur. We prevent crashes by checking // for a destroyed chart if (chart.ctx !== nu...
Initializes the canvas style and render size without modifying the canvas display size, since responsiveness is handled by the controller.resize() method. The config is used to determine the aspect ratio to apply in case no explicit height has been specified. @param {HTMLCanvasElement} canvas @param {number} [aspectRat...
createProxyAndListen
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
acquireContext(canvas, aspectRatio) { // To prevent canvas fingerprinting, some add-ons undefine the getContext // method, for example: https://github.com/kkapsner/CanvasBlocker // https://github.com/chartjs/Chart.js/issues/2807 const context = canvas && canvas.getContext && canvas.getContext('2d'); ...
@param {HTMLCanvasElement} canvas @param {number} [aspectRatio] @return {CanvasRenderingContext2D|null}
acquireContext
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
addEventListener(chart, type, listener) { // Can have only one listener per type, so make sure previous is removed this.removeEventListener(chart, type); const proxies = chart.$proxies || (chart.$proxies = {}); const handlers = { attach: createAttachObserver, detach: createDetachObserver, ...
@param {Chart} chart @param {string} type @param {function} listener
addEventListener
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
removeEventListener(chart, type) { const proxies = chart.$proxies || (chart.$proxies = {}); const proxy = proxies[type]; if (!proxy) { return; } const handlers = { attach: releaseObserver, detach: releaseObserver, resize: releaseObserver }; const handler = handlers[...
@param {Chart} chart @param {string} type
removeEventListener
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
getDevicePixelRatio() { return window.devicePixelRatio; }
@param {Chart} chart @param {string} type
getDevicePixelRatio
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
getMaximumSize(canvas, width, height, aspectRatio) { return getMaximumSize(canvas, width, height, aspectRatio); }
@param {HTMLCanvasElement} canvas @param {number} [width] - content width of parent element @param {number} [height] - content height of parent element @param {number} [aspectRatio] - aspect ratio to maintain
getMaximumSize
javascript
chartjs/Chart.js
src/platform/platform.dom.js
https://github.com/chartjs/Chart.js/blob/master/src/platform/platform.dom.js
MIT
getBoxSize = (labelOpts, fontSize) => { let {boxHeight = fontSize, boxWidth = fontSize} = labelOpts; if (labelOpts.usePointStyle) { boxHeight = Math.min(boxHeight, fontSize); boxWidth = labelOpts.pointStyleWidth || Math.min(boxWidth, fontSize); } return { boxWidth, boxHeight, itemHeight: M...
@typedef { import('../types/index.js').ChartEvent } ChartEvent
getBoxSize
javascript
chartjs/Chart.js
src/plugins/plugin.legend.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.legend.js
MIT
getBoxSize = (labelOpts, fontSize) => { let {boxHeight = fontSize, boxWidth = fontSize} = labelOpts; if (labelOpts.usePointStyle) { boxHeight = Math.min(boxHeight, fontSize); boxWidth = labelOpts.pointStyleWidth || Math.min(boxWidth, fontSize); } return { boxWidth, boxHeight, itemHeight: M...
@typedef { import('../types/index.js').ChartEvent } ChartEvent
getBoxSize
javascript
chartjs/Chart.js
src/plugins/plugin.legend.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.legend.js
MIT
constructor(config) { super(); this._added = false; // Contains hit boxes for each dataset (in dataset order) this.legendHitBoxes = []; /** * @private */ this._hoveredItem = null; // Are we in doughnut mode which has a different data type this.doughnutMode = false; this....
@param {{ ctx: any; options: any; chart: any; }} config
constructor
javascript
chartjs/Chart.js
src/plugins/plugin.legend.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.legend.js
MIT
handleEvent(e) { const opts = this.options; if (!isListened(e.type, opts)) { return; } // Chart event already has relative position in it const hoveredItem = this._getLegendItemAt(e.x, e.y); if (e.type === 'mousemove' || e.type === 'mouseout') { const previous = this._hoveredItem; ...
Handle an event @param {ChartEvent} e - The event to handle
handleEvent
javascript
chartjs/Chart.js
src/plugins/plugin.legend.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.legend.js
MIT
function calculateItemSize(boxWidth, labelFont, ctx, legendItem, _itemHeight) { const itemWidth = calculateItemWidth(legendItem, boxWidth, labelFont, ctx); const itemHeight = calculateItemHeight(_itemHeight, legendItem, labelFont.lineHeight); return {itemWidth, itemHeight}; }
Handle an event @param {ChartEvent} e - The event to handle
calculateItemSize
javascript
chartjs/Chart.js
src/plugins/plugin.legend.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.legend.js
MIT
function calculateItemWidth(legendItem, boxWidth, labelFont, ctx) { let legendItemText = legendItem.text; if (legendItemText && typeof legendItemText !== 'string') { legendItemText = legendItemText.reduce((a, b) => a.length > b.length ? a : b); } return boxWidth + (labelFont.size / 2) + ctx.measureText(lege...
Handle an event @param {ChartEvent} e - The event to handle
calculateItemWidth
javascript
chartjs/Chart.js
src/plugins/plugin.legend.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.legend.js
MIT
function calculateItemHeight(_itemHeight, legendItem, fontLineHeight) { let itemHeight = _itemHeight; if (typeof legendItem.text !== 'string') { itemHeight = calculateLegendItemHeight(legendItem, fontLineHeight); } return itemHeight; }
Handle an event @param {ChartEvent} e - The event to handle
calculateItemHeight
javascript
chartjs/Chart.js
src/plugins/plugin.legend.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.legend.js
MIT
function calculateLegendItemHeight(legendItem, fontLineHeight) { const labelHeight = legendItem.text ? legendItem.text.length : 0; return fontLineHeight * labelHeight; }
Handle an event @param {ChartEvent} e - The event to handle
calculateLegendItemHeight
javascript
chartjs/Chart.js
src/plugins/plugin.legend.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.legend.js
MIT
function isListened(type, opts) { if ((type === 'mousemove' || type === 'mouseout') && (opts.onHover || opts.onLeave)) { return true; } if (opts.onClick && (type === 'click' || type === 'mouseup')) { return true; } return false; }
Handle an event @param {ChartEvent} e - The event to handle
isListened
javascript
chartjs/Chart.js
src/plugins/plugin.legend.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.legend.js
MIT
constructor(config) { super(); this.chart = config.chart; this.options = config.options; this.ctx = config.ctx; this._padding = undefined; this.top = undefined; this.bottom = undefined; this.left = undefined; this.right = undefined; this.width = undefined; this.height = unde...
@param {{ ctx: any; options: any; chart: any; }} config
constructor
javascript
chartjs/Chart.js
src/plugins/plugin.title.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.title.js
MIT
update(maxWidth, maxHeight) { const opts = this.options; this.left = 0; this.top = 0; if (!opts.display) { this.width = this.height = this.right = this.bottom = 0; return; } this.width = this.right = maxWidth; this.height = this.bottom = maxHeight; const lineCount = isArr...
@param {{ ctx: any; options: any; chart: any; }} config
update
javascript
chartjs/Chart.js
src/plugins/plugin.title.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.title.js
MIT
isHorizontal() { const pos = this.options.position; return pos === 'top' || pos === 'bottom'; }
@param {{ ctx: any; options: any; chart: any; }} config
isHorizontal
javascript
chartjs/Chart.js
src/plugins/plugin.title.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.title.js
MIT
_drawArgs(offset) { const {top, left, bottom, right, options} = this; const align = options.align; let rotation = 0; let maxWidth, titleX, titleY; if (this.isHorizontal()) { titleX = _alignStartEnd(align, left, right); titleY = top + offset; maxWidth = right - left; } else { ...
@param {{ ctx: any; options: any; chart: any; }} config
_drawArgs
javascript
chartjs/Chart.js
src/plugins/plugin.title.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.title.js
MIT
draw() { const ctx = this.ctx; const opts = this.options; if (!opts.display) { return; } const fontOpts = toFont(opts.font); const lineHeight = fontOpts.lineHeight; const offset = lineHeight / 2 + this._padding.top; const {titleX, titleY, maxWidth, rotation} = this._drawArgs(offs...
@param {{ ctx: any; options: any; chart: any; }} config
draw
javascript
chartjs/Chart.js
src/plugins/plugin.title.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.title.js
MIT
function createTitle(chart, titleOpts) { const title = new Title({ ctx: chart.ctx, options: titleOpts, chart }); layouts.configure(chart, title, titleOpts); layouts.addBox(chart, title); chart.titleBlock = title; }
@param {{ ctx: any; options: any; chart: any; }} config
createTitle
javascript
chartjs/Chart.js
src/plugins/plugin.title.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.title.js
MIT
average(items) { if (!items.length) { return false; } let i, len; let xSet = new Set(); let y = 0; let count = 0; for (i = 0, len = items.length; i < len; ++i) { const el = items[i].element; if (el && el.hasValue()) { const pos = el.tooltipPosition(); xSet...
Average mode places the tooltip at the average position of the elements shown
average
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
nearest(items, eventPosition) { if (!items.length) { return false; } let x = eventPosition.x; let y = eventPosition.y; let minDistance = Number.POSITIVE_INFINITY; let i, len, nearestElement; for (i = 0, len = items.length; i < len; ++i) { const el = items[i].element; if (...
Gets the tooltip position nearest of the item nearest to the event position
nearest
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function pushOrConcat(base, toPush) { if (toPush) { if (isArray(toPush)) { // base = base.concat(toPush); Array.prototype.push.apply(base, toPush); } else { base.push(toPush); } } return base; }
Gets the tooltip position nearest of the item nearest to the event position
pushOrConcat
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function splitNewlines(str) { if ((typeof str === 'string' || str instanceof String) && str.indexOf('\n') > -1) { return str.split('\n'); } return str; }
Returns array of strings split by newline @param {*} str - The value to split by newline. @returns {string|string[]} value if newline present - Returned from String split() method @function
splitNewlines
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function createTooltipItem(chart, item) { const {element, datasetIndex, index} = item; const controller = chart.getDatasetMeta(datasetIndex).controller; const {label, value} = controller.getLabelAndValue(index); return { chart, label, parsed: controller.getParsed(index), raw: chart.data.dataset...
Private helper to create a tooltip item model @param {Chart} chart @param {ActiveElement} item - {element, index, datasetIndex} to create the tooltip item for @return new tooltip item
createTooltipItem
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function getTooltipSize(tooltip, options) { const ctx = tooltip.chart.ctx; const {body, footer, title} = tooltip; const {boxWidth, boxHeight} = options; const bodyFont = toFont(options.bodyFont); const titleFont = toFont(options.titleFont); const footerFont = toFont(options.footerFont); const titleLineCou...
Get the size of the tooltip
getTooltipSize
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
maxLineWidth = function(line) { width = Math.max(width, ctx.measureText(line).width + widthPadding); }
Get the size of the tooltip
maxLineWidth
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
maxLineWidth = function(line) { width = Math.max(width, ctx.measureText(line).width + widthPadding); }
Get the size of the tooltip
maxLineWidth
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function determineYAlign(chart, size) { const {y, height} = size; if (y < height / 2) { return 'top'; } else if (y > (chart.height - height / 2)) { return 'bottom'; } return 'center'; }
Get the size of the tooltip
determineYAlign
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function doesNotFitWithAlign(xAlign, chart, options, size) { const {x, width} = size; const caret = options.caretSize + options.caretPadding; if (xAlign === 'left' && x + width + caret > chart.width) { return true; } if (xAlign === 'right' && x - width - caret < 0) { return true; } }
Get the size of the tooltip
doesNotFitWithAlign
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function determineXAlign(chart, options, size, yAlign) { const {x, width} = size; const {width: chartWidth, chartArea: {left, right}} = chart; let xAlign = 'center'; if (yAlign === 'center') { xAlign = x <= (left + right) / 2 ? 'left' : 'right'; } else if (x <= width / 2) { xAlign = 'left'; } else ...
Get the size of the tooltip
determineXAlign
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function determineAlignment(chart, options, size) { const yAlign = size.yAlign || options.yAlign || determineYAlign(chart, size); return { xAlign: size.xAlign || options.xAlign || determineXAlign(chart, options, size, yAlign), yAlign }; }
Helper to get the alignment of a tooltip given the size
determineAlignment
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function alignX(size, xAlign) { let {x, width} = size; if (xAlign === 'right') { x -= width; } else if (xAlign === 'center') { x -= (width / 2); } return x; }
Helper to get the alignment of a tooltip given the size
alignX
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function alignY(size, yAlign, paddingAndSize) { // eslint-disable-next-line prefer-const let {y, height} = size; if (yAlign === 'top') { y += paddingAndSize; } else if (yAlign === 'bottom') { y -= height + paddingAndSize; } else { y -= (height / 2); } return y; }
Helper to get the alignment of a tooltip given the size
alignY
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function getBackgroundPoint(options, size, alignment, chart) { const {caretSize, caretPadding, cornerRadius} = options; const {xAlign, yAlign} = alignment; const paddingAndSize = caretSize + caretPadding; const {topLeft, topRight, bottomLeft, bottomRight} = toTRBLCorners(cornerRadius); let x = alignX(size, x...
Helper to get the location a tooltip needs to be placed at given the initial position (via the vm) and the size and alignment
getBackgroundPoint
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function getAlignedX(tooltip, align, options) { const padding = toPadding(options.padding); return align === 'center' ? tooltip.x + tooltip.width / 2 : align === 'right' ? tooltip.x + tooltip.width - padding.right : tooltip.x + padding.left; }
Helper to get the location a tooltip needs to be placed at given the initial position (via the vm) and the size and alignment
getAlignedX
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function getBeforeAfterBodyLines(callback) { return pushOrConcat([], splitNewlines(callback)); }
Helper to build before and after body lines
getBeforeAfterBodyLines
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function createTooltipContext(parent, tooltip, tooltipItems) { return createContext(parent, { tooltip, tooltipItems, type: 'tooltip' }); }
Helper to build before and after body lines
createTooltipContext
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function overrideCallbacks(callbacks, context) { const override = context && context.dataset && context.dataset.tooltip && context.dataset.tooltip.callbacks; return override ? callbacks.override(override) : callbacks; }
Helper to build before and after body lines
overrideCallbacks
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
title(tooltipItems) { if (tooltipItems.length > 0) { const item = tooltipItems[0]; const labels = item.chart.data.labels; const labelCount = labels ? labels.length : 0; if (this && this.options && this.options.mode === 'dataset') { return item.dataset.label || ''; } else if (i...
Helper to build before and after body lines
title
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
label(tooltipItem) { if (this && this.options && this.options.mode === 'dataset') { return tooltipItem.label + ': ' + tooltipItem.formattedValue || tooltipItem.formattedValue; } let label = tooltipItem.dataset.label || ''; if (label) { label += ': '; } const value = tooltipItem.for...
Helper to build before and after body lines
label
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
labelColor(tooltipItem) { const meta = tooltipItem.chart.getDatasetMeta(tooltipItem.datasetIndex); const options = meta.controller.getStyle(tooltipItem.dataIndex); return { borderColor: options.borderColor, backgroundColor: options.backgroundColor, borderWidth: options.borderWidth, b...
Helper to build before and after body lines
labelColor
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
labelTextColor() { return this.options.bodyColor; }
Helper to build before and after body lines
labelTextColor
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
labelPointStyle(tooltipItem) { const meta = tooltipItem.chart.getDatasetMeta(tooltipItem.datasetIndex); const options = meta.controller.getStyle(tooltipItem.dataIndex); return { pointStyle: options.pointStyle, rotation: options.rotation, }; }
Helper to build before and after body lines
labelPointStyle
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function invokeCallbackWithFallback(callbacks, name, ctx, arg) { const result = callbacks[name].call(ctx, arg); if (typeof result === 'undefined') { return defaultCallbacks[name].call(ctx, arg); } return result; }
Invoke callback from object with context and arguments. If callback returns `undefined`, then will be invoked default callback. @param {Record<keyof typeof defaultCallbacks, Function>} callbacks @param {keyof typeof defaultCallbacks} name @param {*} ctx @param {*} arg @returns {any}
invokeCallbackWithFallback
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
_updateAnimationTarget(options) { const chart = this.chart; const anims = this.$animations; const animX = anims && anims.x; const animY = anims && anims.y; if (animX || animY) { const position = positioners[options.position].call(this, this._active, this._eventPosition); if (!position) {...
Update x/y animation targets when _active elements are animating too @private
_updateAnimationTarget
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
_willRender() { return !!this.opacity; }
Determine if the tooltip will draw anything @returns {boolean} True if the tooltip will render
_willRender
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
draw(ctx) { const options = this.options.setContext(this.getContext()); let opacity = this.opacity; if (!opacity) { return; } this._updateAnimationTarget(options); const tooltipSize = { width: this.width, height: this.height }; const pt = { x: this.x, y: ...
Determine if the tooltip will draw anything @returns {boolean} True if the tooltip will render
draw
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
getActiveElements() { return this._active || []; }
Get active elements in the tooltip @returns {Array} Array of elements that are active in the tooltip
getActiveElements
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
setActiveElements(activeElements, eventPosition) { const lastActive = this._active; const active = activeElements.map(({datasetIndex, index}) => { const meta = this.chart.getDatasetMeta(datasetIndex); if (!meta) { throw new Error('Cannot find a dataset at index ' + datasetIndex); } ...
Set active elements in the tooltip @param {array} activeElements Array of active datasetIndex/index pairs. @param {object} eventPosition Synthetic event position used in positioning
setActiveElements
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
handleEvent(e, replay, inChartArea = true) { if (replay && this._ignoreReplayEvents) { return false; } this._ignoreReplayEvents = false; const options = this.options; const lastActive = this._active || []; const active = this._getActiveElements(e, lastActive, replay, inChartArea); //...
Handle an event @param {ChartEvent} e - The event to handle @param {boolean} [replay] - This is a replayed event (from update) @param {boolean} [inChartArea] - The event is inside chartArea @returns {boolean} true if the tooltip changed
handleEvent
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
_getActiveElements(e, lastActive, replay, inChartArea) { const options = this.options; if (e.type === 'mouseout') { return []; } if (!inChartArea) { // Let user control the active elements outside chartArea. Eg. using Legend. // But make sure that active elements are still valid. ...
Helper for determining the active elements for event @param {ChartEvent} e - The event to handle @param {InteractionItem[]} lastActive - Previously active elements @param {boolean} [replay] - This is a replayed event (from update) @param {boolean} [inChartArea] - The event is inside chartArea @returns {InteractionItem[...
_getActiveElements
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
_positionChanged(active, e) { const {caretX, caretY, options} = this; const position = positioners[options.position].call(this, active, e); return position !== false && (caretX !== position.x || caretY !== position.y); }
Determine if the active elements + event combination changes the tooltip position @param {array} active - Active elements @param {ChartEvent} e - Event that triggered the position change @returns {boolean} True if the position has changed
_positionChanged
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
afterInit(chart, _args, options) { if (options) { chart.tooltip = new Tooltip({chart, options}); } }
Determine if the active elements + event combination changes the tooltip position @param {array} active - Active elements @param {ChartEvent} e - Event that triggered the position change @returns {boolean} True if the position has changed
afterInit
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
beforeUpdate(chart, _args, options) { if (chart.tooltip) { chart.tooltip.initialize(options); } }
Determine if the active elements + event combination changes the tooltip position @param {array} active - Active elements @param {ChartEvent} e - Event that triggered the position change @returns {boolean} True if the position has changed
beforeUpdate
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
reset(chart, _args, options) { if (chart.tooltip) { chart.tooltip.initialize(options); } }
Determine if the active elements + event combination changes the tooltip position @param {array} active - Active elements @param {ChartEvent} e - Event that triggered the position change @returns {boolean} True if the position has changed
reset
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
afterDraw(chart) { const tooltip = chart.tooltip; if (tooltip && tooltip._willRender()) { const args = { tooltip }; if (chart.notifyPlugins('beforeTooltipDraw', {...args, cancelable: true}) === false) { return; } tooltip.draw(chart.ctx); chart.notifyPlugin...
Determine if the active elements + event combination changes the tooltip position @param {array} active - Active elements @param {ChartEvent} e - Event that triggered the position change @returns {boolean} True if the position has changed
afterDraw
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
afterEvent(chart, args) { if (chart.tooltip) { // If the event is replayed from `update`, we should evaluate with the final positions. const useFinalPosition = args.replay; if (chart.tooltip.handleEvent(args.event, useFinalPosition, args.inChartArea)) { // notify chart about the change, so...
Determine if the active elements + event combination changes the tooltip position @param {array} active - Active elements @param {ChartEvent} e - Event that triggered the position change @returns {boolean} True if the position has changed
afterEvent
javascript
chartjs/Chart.js
src/plugins/plugin.tooltip.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js
MIT
function _createBoundaryLine(boundary, line) { let points = []; let _loop = false; if (isArray(boundary)) { _loop = true; // @ts-ignore points = boundary; } else { points = _pointsFromSegments(boundary, line); } return points.length ? new LineElement({ points, options: {tension: 0}...
@param {PointElement[] | { x: number; y: number; }} boundary @param {LineElement} line @return {LineElement?}
_createBoundaryLine
javascript
chartjs/Chart.js
src/plugins/plugin.filler/filler.helper.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.filler/filler.helper.js
MIT
function _shouldApplyFill(source) { return source && source.fill !== false; }
@param {PointElement[] | { x: number; y: number; }} boundary @param {LineElement} line @return {LineElement?}
_shouldApplyFill
javascript
chartjs/Chart.js
src/plugins/plugin.filler/filler.helper.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.filler/filler.helper.js
MIT
function _resolveTarget(sources, index, propagate) { const source = sources[index]; let fill = source.fill; const visited = [index]; let target; if (!propagate) { return fill; } while (fill !== false && visited.indexOf(fill) === -1) { if (!isFinite(fill)) { return fill; } target =...
@typedef { import('../../core/core.scale.js').default } Scale @typedef { import('../../elements/element.line.js').default } LineElement @typedef { import('../../types/index.js').FillTarget } FillTarget @typedef { import('../../types/index.js').ComplexFillTarget } ComplexFillTarget
_resolveTarget
javascript
chartjs/Chart.js
src/plugins/plugin.filler/filler.options.js
https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.filler/filler.options.js
MIT