chartjs-chart-matrix
Advanced tools
Comparing version 1.0.0-alpha6 to 1.0.0-alpha7
/*! | ||
* chartjs-chart-matrix v1.0.0-alpha6 | ||
* chartjs-chart-matrix v1.0.0-alpha7 | ||
* https://github.com/kurkle/chartjs-chart-matrix#readme | ||
@@ -7,40 +7,107 @@ * (c) 2020 Jukka Kurkela | ||
*/ | ||
import Chart from 'chart.js'; | ||
import { DatasetController, Element } from 'chart.js'; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
class MatrixController extends DatasetController { | ||
return obj; | ||
} | ||
update(mode) { | ||
const me = this; | ||
const meta = me._cachedMeta; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
me.updateElements(meta.data, 0, mode); | ||
} | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
updateElements(rects, start, mode) { | ||
const me = this; | ||
const reset = mode === 'reset'; | ||
const {xScale, yScale} = me._cachedMeta; | ||
const firstOpts = me.resolveDataElementOptions(start, mode); | ||
const sharedOptions = me.getSharedOptions(mode, rects[start], firstOpts); | ||
return target; | ||
}; | ||
for (let i = 0; i < rects.length; i++) { | ||
const index = start + i; | ||
const parsed = !reset && me.getParsed(index); | ||
const x = reset ? xScale.getBasePixel() : xScale.getPixelForValue(parsed.x); | ||
const y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(parsed.y); | ||
const options = me.resolveDataElementOptions(i, mode); | ||
const {width, height, anchorX, anchorY} = options; | ||
const properties = { | ||
x: anchorX === 'left' ? x : x - width / (anchorX === 'right' ? 1 : 2), | ||
y: anchorY === 'top' ? y : y - height / (anchorY === 'bottom' ? 1 : 2), | ||
width, | ||
height, | ||
options | ||
}; | ||
me.updateElement(rects[i], index, properties, mode); | ||
} | ||
return _extends.apply(this, arguments); | ||
me.updateSharedOptions(sharedOptions, mode); | ||
} | ||
draw() { | ||
const me = this; | ||
const data = me.getMeta().data || []; | ||
let i, ilen; | ||
for (i = 0, ilen = data.length; i < ilen; ++i) { | ||
data[i].draw(me._ctx); | ||
} | ||
} | ||
} | ||
MatrixController.id = 'matrix'; | ||
MatrixController.defaults = { | ||
dataElementType: 'matrix', | ||
dataElementOptions: [ | ||
'backgroundColor', | ||
'borderColor', | ||
'borderWidth', | ||
'anchorX', | ||
'anchorY', | ||
'width', | ||
'height' | ||
], | ||
hover: { | ||
mode: 'nearest', | ||
intersect: true | ||
}, | ||
datasets: { | ||
animation: { | ||
numbers: { | ||
type: 'number', | ||
properties: ['x', 'y', 'width', 'height'] | ||
} | ||
}, | ||
anchorX: 'center', | ||
anchorY: 'center' | ||
}, | ||
tooltips: { | ||
mode: 'nearest', | ||
intersect: true | ||
}, | ||
scales: { | ||
x: { | ||
type: 'linear', | ||
offset: true | ||
}, | ||
y: { | ||
type: 'linear', | ||
reverse: true | ||
} | ||
}, | ||
}; | ||
/*! | ||
* Chart.js v3.0.0-alpha.2 | ||
* https://www.chartjs.org | ||
* (c) 2020 Chart.js Contributors | ||
* Released under the MIT License | ||
*/ | ||
function isObject(value) { | ||
return value !== null && Object.prototype.toString.call(value) === '[object Object]'; | ||
} | ||
/** | ||
* Helper function to get the bounds of the rect | ||
* @param {Rectangle} rect the rect | ||
* @param {Matrix} rect the rect | ||
* @param {boolean} [useFinalPosition] | ||
@@ -50,237 +117,135 @@ * @return {object} bounds of the rect | ||
*/ | ||
function getBounds(rect, useFinalPosition) { | ||
var { | ||
x, | ||
y, | ||
width, | ||
height | ||
} = rect.getProps(['x', 'y', 'width', 'height'], useFinalPosition); | ||
return { | ||
left: x, | ||
top: y, | ||
right: x + width, | ||
bottom: y + height | ||
}; | ||
const {x, y, width, height} = rect.getProps(['x', 'y', 'width', 'height'], useFinalPosition); | ||
return {left: x, top: y, right: x + width, bottom: y + height}; | ||
} | ||
function limit(value, min, max) { | ||
return Math.max(Math.min(value, max), min); | ||
return Math.max(Math.min(value, max), min); | ||
} | ||
function parseBorderWidth(rect, maxW, maxH) { | ||
var value = rect.options.borderWidth; | ||
var t, r, b, l; | ||
const value = rect.options.borderWidth; | ||
let t, r, b, l; | ||
if (Chart.helpers.isObject(value)) { | ||
t = +value.top || 0; | ||
r = +value.right || 0; | ||
b = +value.bottom || 0; | ||
l = +value.left || 0; | ||
} else { | ||
t = r = b = l = +value || 0; | ||
} | ||
if (isObject(value)) { | ||
t = +value.top || 0; | ||
r = +value.right || 0; | ||
b = +value.bottom || 0; | ||
l = +value.left || 0; | ||
} else { | ||
t = r = b = l = +value || 0; | ||
} | ||
return { | ||
t: limit(t, 0, maxH), | ||
r: limit(r, 0, maxW), | ||
b: limit(b, 0, maxH), | ||
l: limit(l, 0, maxW) | ||
}; | ||
return { | ||
t: limit(t, 0, maxH), | ||
r: limit(r, 0, maxW), | ||
b: limit(b, 0, maxH), | ||
l: limit(l, 0, maxW) | ||
}; | ||
} | ||
function boundingRects(rect) { | ||
var bounds = getBounds(rect); | ||
var width = bounds.right - bounds.left; | ||
var height = bounds.bottom - bounds.top; | ||
var border = parseBorderWidth(rect, width / 2, height / 2); | ||
return { | ||
outer: { | ||
x: bounds.left, | ||
y: bounds.top, | ||
w: width, | ||
h: height | ||
}, | ||
inner: { | ||
x: bounds.left + border.l, | ||
y: bounds.top + border.t, | ||
w: width - border.l - border.r, | ||
h: height - border.t - border.b | ||
} | ||
}; | ||
const bounds = getBounds(rect); | ||
const width = bounds.right - bounds.left; | ||
const height = bounds.bottom - bounds.top; | ||
const border = parseBorderWidth(rect, width / 2, height / 2); | ||
return { | ||
outer: { | ||
x: bounds.left, | ||
y: bounds.top, | ||
w: width, | ||
h: height | ||
}, | ||
inner: { | ||
x: bounds.left + border.l, | ||
y: bounds.top + border.t, | ||
w: width - border.l - border.r, | ||
h: height - border.t - border.b | ||
} | ||
}; | ||
} | ||
function inRange(rect, x, y, useFinalPosition) { | ||
var skipX = x === null; | ||
var skipY = y === null; | ||
var bounds = !rect || skipX && skipY ? false : getBounds(rect, useFinalPosition); | ||
return bounds && (skipX || x >= bounds.left && x <= bounds.right) && (skipY || y >= bounds.top && y <= bounds.bottom); | ||
const skipX = x === null; | ||
const skipY = y === null; | ||
const bounds = !rect || (skipX && skipY) ? false : getBounds(rect, useFinalPosition); | ||
return bounds | ||
&& (skipX || x >= bounds.left && x <= bounds.right) | ||
&& (skipY || y >= bounds.top && y <= bounds.bottom); | ||
} | ||
class Rectangle extends Chart.Element { | ||
constructor(cfg) { | ||
super(); | ||
this.options = undefined; | ||
this.width = undefined; | ||
this.height = undefined; | ||
class Matrix extends Element { | ||
constructor(cfg) { | ||
super(); | ||
if (cfg) { | ||
_extends(this, cfg); | ||
} | ||
} | ||
this.options = undefined; | ||
this.width = undefined; | ||
this.height = undefined; | ||
draw(ctx) { | ||
var options = this.options; | ||
var { | ||
inner, | ||
outer | ||
} = boundingRects(this); | ||
ctx.save(); | ||
if (cfg) { | ||
Object.assign(this, cfg); | ||
} | ||
} | ||
if (outer.w !== inner.w || outer.h !== inner.h) { | ||
ctx.beginPath(); | ||
ctx.rect(outer.x, outer.y, outer.w, outer.h); | ||
ctx.clip(); | ||
ctx.rect(inner.x, inner.y, inner.w, inner.h); | ||
ctx.fillStyle = options.backgroundColor; | ||
ctx.fill(); | ||
ctx.fillStyle = options.borderColor; | ||
ctx.fill('evenodd'); | ||
} else { | ||
ctx.fillStyle = options.backgroundColor; | ||
ctx.fillRect(inner.x, inner.y, inner.w, inner.h); | ||
} | ||
draw(ctx) { | ||
const options = this.options; | ||
const {inner, outer} = boundingRects(this); | ||
ctx.restore(); | ||
} | ||
ctx.save(); | ||
inRange(mouseX, mouseY, useFinalPosition) { | ||
return inRange(this, mouseX, mouseY, useFinalPosition); | ||
} | ||
if (outer.w !== inner.w || outer.h !== inner.h) { | ||
ctx.beginPath(); | ||
ctx.rect(outer.x, outer.y, outer.w, outer.h); | ||
ctx.clip(); | ||
ctx.rect(inner.x, inner.y, inner.w, inner.h); | ||
ctx.fillStyle = options.backgroundColor; | ||
ctx.fill(); | ||
ctx.fillStyle = options.borderColor; | ||
ctx.fill('evenodd'); | ||
} else { | ||
ctx.fillStyle = options.backgroundColor; | ||
ctx.fillRect(inner.x, inner.y, inner.w, inner.h); | ||
} | ||
inXRange(mouseX, useFinalPosition) { | ||
return inRange(this, mouseX, null, useFinalPosition); | ||
} | ||
ctx.restore(); | ||
} | ||
inYRange(mouseY, useFinalPosition) { | ||
return inRange(this, null, mouseY, useFinalPosition); | ||
} | ||
inRange(mouseX, mouseY, useFinalPosition) { | ||
return inRange(this, mouseX, mouseY, useFinalPosition); | ||
} | ||
getCenterPoint(useFinalPosition) { | ||
var { | ||
x, | ||
y, | ||
width, | ||
height | ||
} = this.getProps(['x', 'y', 'width', 'height'], useFinalPosition); | ||
return { | ||
x: x + width / 2, | ||
y: y + height / 2 | ||
}; | ||
} | ||
inXRange(mouseX, useFinalPosition) { | ||
return inRange(this, mouseX, null, useFinalPosition); | ||
} | ||
tooltipPosition() { | ||
return this.getCenterPoint(); | ||
} | ||
inYRange(mouseY, useFinalPosition) { | ||
return inRange(this, null, mouseY, useFinalPosition); | ||
} | ||
getRange(axis) { | ||
return axis === 'x' ? this.width / 2 : this.height / 2; | ||
} | ||
getCenterPoint(useFinalPosition) { | ||
const {x, y, width, height} = this.getProps(['x', 'y', 'width', 'height'], useFinalPosition); | ||
return { | ||
x: x + width / 2, | ||
y: y + height / 2 | ||
}; | ||
} | ||
} | ||
tooltipPosition() { | ||
return this.getCenterPoint(); | ||
} | ||
_defineProperty(Rectangle, "_type", 'rectangle'); | ||
class MatrixController extends Chart.DatasetController { | ||
update(mode) { | ||
var me = this; | ||
var meta = me._cachedMeta; | ||
me.updateElements(meta.data, 0, mode); | ||
} | ||
updateElements(rects, start, mode) { | ||
var me = this; | ||
var reset = mode === 'reset'; | ||
var { | ||
xScale, | ||
yScale | ||
} = me._cachedMeta; | ||
var firstOpts = me.resolveDataElementOptions(start, mode); | ||
var sharedOptions = me.getSharedOptions(mode, rects[start], firstOpts); | ||
for (var i = 0; i < rects.length; i++) { | ||
var index = start + i; | ||
var parsed = !reset && me.getParsed(index); | ||
var x = reset ? xScale.getBasePixel() : xScale.getPixelForValue(parsed.x); | ||
var y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(parsed.y); | ||
var options = me.resolveDataElementOptions(i, mode); | ||
var { | ||
width, | ||
height, | ||
anchorX, | ||
anchorY | ||
} = options; | ||
var properties = { | ||
x: anchorX === 'left' ? x : x - width / (anchorX === 'right' ? 1 : 2), | ||
y: anchorY === 'top' ? y : y - height / (anchorY === 'bottom' ? 1 : 2), | ||
width, | ||
height, | ||
options | ||
}; | ||
me.updateElement(rects[i], index, properties, mode); | ||
} | ||
me.updateSharedOptions(sharedOptions, mode); | ||
} | ||
draw() { | ||
var me = this; | ||
var data = me.getMeta().data || []; | ||
var i, ilen; | ||
for (i = 0, ilen = data.length; i < ilen; ++i) { | ||
data[i].draw(me._ctx); | ||
} | ||
} | ||
getRange(axis) { | ||
return axis === 'x' ? this.width / 2 : this.height / 2; | ||
} | ||
} | ||
MatrixController.prototype.dataElementType = Rectangle; | ||
MatrixController.prototype.dataElementOptions = ['backgroundColor', 'borderColor', 'borderWidth', 'anchorX', 'anchorY', 'width', 'height']; | ||
Chart.controllers.matrix = MatrixController; | ||
Chart.defaults.matrix = { | ||
hover: { | ||
mode: 'nearest', | ||
intersect: true | ||
}, | ||
datasets: { | ||
animation: { | ||
numbers: { | ||
type: 'number', | ||
properties: ['x', 'y', 'width', 'height'] | ||
} | ||
}, | ||
anchorX: 'center', | ||
anchorY: 'center' | ||
}, | ||
tooltips: { | ||
mode: 'nearest', | ||
intersect: true | ||
}, | ||
scales: { | ||
x: { | ||
type: 'linear', | ||
offset: true | ||
}, | ||
y: { | ||
type: 'linear', | ||
reverse: true | ||
} | ||
}, | ||
elements: { | ||
rectangle: { | ||
width: 20, | ||
height: 20 | ||
} | ||
} | ||
Matrix.id = 'matrix'; | ||
Matrix.defaults = { | ||
width: 20, | ||
height: 20 | ||
}; | ||
export { Matrix, MatrixController }; |
/*! | ||
* chartjs-chart-matrix v1.0.0-alpha6 | ||
* chartjs-chart-matrix v1.0.0-alpha7 | ||
* https://github.com/kurkle/chartjs-chart-matrix#readme | ||
@@ -13,41 +13,4 @@ * (c) 2020 Jukka Kurkela | ||
Chart = Chart && Object.prototype.hasOwnProperty.call(Chart, 'default') ? Chart['default'] : Chart; | ||
var Chart__default = 'default' in Chart ? Chart['default'] : Chart; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _extends() { | ||
@@ -71,46 +34,8 @@ _extends = Object.assign || function (target) { | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
@@ -124,25 +49,104 @@ if (self === void 0) { | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
var MatrixController = /*#__PURE__*/function (_DatasetController) { | ||
_inheritsLoose(MatrixController, _DatasetController); | ||
function MatrixController() { | ||
return _DatasetController.apply(this, arguments) || this; | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
var _proto = MatrixController.prototype; | ||
function _createSuper(Derived) { | ||
return function () { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
_proto.update = function update(mode) { | ||
var me = this; | ||
var meta = me._cachedMeta; | ||
me.updateElements(meta.data, 0, mode); | ||
}; | ||
if (_isNativeReflectConstruct()) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
_proto.updateElements = function updateElements(rects, start, mode) { | ||
var me = this; | ||
var reset = mode === 'reset'; | ||
var _me$_cachedMeta = me._cachedMeta, | ||
xScale = _me$_cachedMeta.xScale, | ||
yScale = _me$_cachedMeta.yScale; | ||
var firstOpts = me.resolveDataElementOptions(start, mode); | ||
var sharedOptions = me.getSharedOptions(mode, rects[start], firstOpts); | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
for (var i = 0; i < rects.length; i++) { | ||
var index = start + i; | ||
var parsed = !reset && me.getParsed(index); | ||
var x = reset ? xScale.getBasePixel() : xScale.getPixelForValue(parsed.x); | ||
var y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(parsed.y); | ||
var options = me.resolveDataElementOptions(i, mode); | ||
var width = options.width, | ||
height = options.height, | ||
anchorX = options.anchorX, | ||
anchorY = options.anchorY; | ||
var properties = { | ||
x: anchorX === 'left' ? x : x - width / (anchorX === 'right' ? 1 : 2), | ||
y: anchorY === 'top' ? y : y - height / (anchorY === 'bottom' ? 1 : 2), | ||
width: width, | ||
height: height, | ||
options: options | ||
}; | ||
me.updateElement(rects[i], index, properties, mode); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
me.updateSharedOptions(sharedOptions, mode); | ||
}; | ||
_proto.draw = function draw() { | ||
var me = this; | ||
var data = me.getMeta().data || []; | ||
var i, ilen; | ||
for (i = 0, ilen = data.length; i < ilen; ++i) { | ||
data[i].draw(me._ctx); | ||
} | ||
}; | ||
return MatrixController; | ||
}(Chart.DatasetController); | ||
MatrixController.id = 'matrix'; | ||
MatrixController.defaults = { | ||
dataElementType: 'matrix', | ||
dataElementOptions: ['backgroundColor', 'borderColor', 'borderWidth', 'anchorX', 'anchorY', 'width', 'height'], | ||
hover: { | ||
mode: 'nearest', | ||
intersect: true | ||
}, | ||
datasets: { | ||
animation: { | ||
numbers: { | ||
type: 'number', | ||
properties: ['x', 'y', 'width', 'height'] | ||
} | ||
}, | ||
anchorX: 'center', | ||
anchorY: 'center' | ||
}, | ||
tooltips: { | ||
mode: 'nearest', | ||
intersect: true | ||
}, | ||
scales: { | ||
x: { | ||
type: 'linear', | ||
offset: true | ||
}, | ||
y: { | ||
type: 'linear', | ||
reverse: true | ||
} | ||
} | ||
}; | ||
/*! | ||
* Chart.js v3.0.0-alpha.2 | ||
* https://www.chartjs.org | ||
* (c) 2020 Chart.js Contributors | ||
* Released under the MIT License | ||
*/ | ||
function isObject(value) { | ||
return value !== null && Object.prototype.toString.call(value) === '[object Object]'; | ||
} | ||
@@ -152,3 +156,3 @@ | ||
* Helper function to get the bounds of the rect | ||
* @param {Rectangle} rect the rect | ||
* @param {Matrix} rect the rect | ||
* @param {boolean} [useFinalPosition] | ||
@@ -182,3 +186,3 @@ * @return {object} bounds of the rect | ||
if (Chart.helpers.isObject(value)) { | ||
if (isObject(value)) { | ||
t = +value.top || 0; | ||
@@ -228,13 +232,9 @@ r = +value.right || 0; | ||
var Rectangle = /*#__PURE__*/function (_Chart$Element) { | ||
_inherits(Rectangle, _Chart$Element); | ||
var Matrix = /*#__PURE__*/function (_Element) { | ||
_inheritsLoose(Matrix, _Element); | ||
var _super = _createSuper(Rectangle); | ||
function Rectangle(cfg) { | ||
function Matrix(cfg) { | ||
var _this; | ||
_classCallCheck(this, Rectangle); | ||
_this = _super.call(this); | ||
_this = _Element.call(this) || this; | ||
_this.options = undefined; | ||
@@ -251,182 +251,73 @@ _this.width = undefined; | ||
_createClass(Rectangle, [{ | ||
key: "draw", | ||
value: function draw(ctx) { | ||
var options = this.options; | ||
var _proto = Matrix.prototype; | ||
var _boundingRects = boundingRects(this), | ||
inner = _boundingRects.inner, | ||
outer = _boundingRects.outer; | ||
_proto.draw = function draw(ctx) { | ||
var options = this.options; | ||
ctx.save(); | ||
var _boundingRects = boundingRects(this), | ||
inner = _boundingRects.inner, | ||
outer = _boundingRects.outer; | ||
if (outer.w !== inner.w || outer.h !== inner.h) { | ||
ctx.beginPath(); | ||
ctx.rect(outer.x, outer.y, outer.w, outer.h); | ||
ctx.clip(); | ||
ctx.rect(inner.x, inner.y, inner.w, inner.h); | ||
ctx.fillStyle = options.backgroundColor; | ||
ctx.fill(); | ||
ctx.fillStyle = options.borderColor; | ||
ctx.fill('evenodd'); | ||
} else { | ||
ctx.fillStyle = options.backgroundColor; | ||
ctx.fillRect(inner.x, inner.y, inner.w, inner.h); | ||
} | ||
ctx.save(); | ||
ctx.restore(); | ||
if (outer.w !== inner.w || outer.h !== inner.h) { | ||
ctx.beginPath(); | ||
ctx.rect(outer.x, outer.y, outer.w, outer.h); | ||
ctx.clip(); | ||
ctx.rect(inner.x, inner.y, inner.w, inner.h); | ||
ctx.fillStyle = options.backgroundColor; | ||
ctx.fill(); | ||
ctx.fillStyle = options.borderColor; | ||
ctx.fill('evenodd'); | ||
} else { | ||
ctx.fillStyle = options.backgroundColor; | ||
ctx.fillRect(inner.x, inner.y, inner.w, inner.h); | ||
} | ||
}, { | ||
key: "inRange", | ||
value: function inRange(mouseX, mouseY, useFinalPosition) { | ||
return _inRange(this, mouseX, mouseY, useFinalPosition); | ||
} | ||
}, { | ||
key: "inXRange", | ||
value: function inXRange(mouseX, useFinalPosition) { | ||
return _inRange(this, mouseX, null, useFinalPosition); | ||
} | ||
}, { | ||
key: "inYRange", | ||
value: function inYRange(mouseY, useFinalPosition) { | ||
return _inRange(this, null, mouseY, useFinalPosition); | ||
} | ||
}, { | ||
key: "getCenterPoint", | ||
value: function getCenterPoint(useFinalPosition) { | ||
var _this$getProps = this.getProps(['x', 'y', 'width', 'height'], useFinalPosition), | ||
x = _this$getProps.x, | ||
y = _this$getProps.y, | ||
width = _this$getProps.width, | ||
height = _this$getProps.height; | ||
return { | ||
x: x + width / 2, | ||
y: y + height / 2 | ||
}; | ||
} | ||
}, { | ||
key: "tooltipPosition", | ||
value: function tooltipPosition() { | ||
return this.getCenterPoint(); | ||
} | ||
}, { | ||
key: "getRange", | ||
value: function getRange(axis) { | ||
return axis === 'x' ? this.width / 2 : this.height / 2; | ||
} | ||
}]); | ||
ctx.restore(); | ||
}; | ||
return Rectangle; | ||
}(Chart.Element); | ||
_proto.inRange = function inRange(mouseX, mouseY, useFinalPosition) { | ||
return _inRange(this, mouseX, mouseY, useFinalPosition); | ||
}; | ||
_defineProperty(Rectangle, "_type", 'rectangle'); | ||
_proto.inXRange = function inXRange(mouseX, useFinalPosition) { | ||
return _inRange(this, mouseX, null, useFinalPosition); | ||
}; | ||
var MatrixController = /*#__PURE__*/function (_Chart$DatasetControl) { | ||
_inherits(MatrixController, _Chart$DatasetControl); | ||
_proto.inYRange = function inYRange(mouseY, useFinalPosition) { | ||
return _inRange(this, null, mouseY, useFinalPosition); | ||
}; | ||
var _super = _createSuper(MatrixController); | ||
_proto.getCenterPoint = function getCenterPoint(useFinalPosition) { | ||
var _this$getProps = this.getProps(['x', 'y', 'width', 'height'], useFinalPosition), | ||
x = _this$getProps.x, | ||
y = _this$getProps.y, | ||
width = _this$getProps.width, | ||
height = _this$getProps.height; | ||
function MatrixController() { | ||
_classCallCheck(this, MatrixController); | ||
return { | ||
x: x + width / 2, | ||
y: y + height / 2 | ||
}; | ||
}; | ||
return _super.apply(this, arguments); | ||
} | ||
_proto.tooltipPosition = function tooltipPosition() { | ||
return this.getCenterPoint(); | ||
}; | ||
_createClass(MatrixController, [{ | ||
key: "update", | ||
value: function update(mode) { | ||
var me = this; | ||
var meta = me._cachedMeta; | ||
me.updateElements(meta.data, 0, mode); | ||
} | ||
}, { | ||
key: "updateElements", | ||
value: function updateElements(rects, start, mode) { | ||
var me = this; | ||
var reset = mode === 'reset'; | ||
var _me$_cachedMeta = me._cachedMeta, | ||
xScale = _me$_cachedMeta.xScale, | ||
yScale = _me$_cachedMeta.yScale; | ||
var firstOpts = me.resolveDataElementOptions(start, mode); | ||
var sharedOptions = me.getSharedOptions(mode, rects[start], firstOpts); | ||
_proto.getRange = function getRange(axis) { | ||
return axis === 'x' ? this.width / 2 : this.height / 2; | ||
}; | ||
for (var i = 0; i < rects.length; i++) { | ||
var index = start + i; | ||
var parsed = !reset && me.getParsed(index); | ||
var x = reset ? xScale.getBasePixel() : xScale.getPixelForValue(parsed.x); | ||
var y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(parsed.y); | ||
var options = me.resolveDataElementOptions(i, mode); | ||
var width = options.width, | ||
height = options.height, | ||
anchorX = options.anchorX, | ||
anchorY = options.anchorY; | ||
var properties = { | ||
x: anchorX === 'left' ? x : x - width / (anchorX === 'right' ? 1 : 2), | ||
y: anchorY === 'top' ? y : y - height / (anchorY === 'bottom' ? 1 : 2), | ||
width: width, | ||
height: height, | ||
options: options | ||
}; | ||
me.updateElement(rects[i], index, properties, mode); | ||
} | ||
return Matrix; | ||
}(Chart.Element); | ||
Matrix.id = 'matrix'; | ||
Matrix.defaults = { | ||
width: 20, | ||
height: 20 | ||
}; | ||
me.updateSharedOptions(sharedOptions, mode); | ||
} | ||
}, { | ||
key: "draw", | ||
value: function draw() { | ||
var me = this; | ||
var data = me.getMeta().data || []; | ||
var i, ilen; | ||
Chart__default.register(MatrixController, Matrix); | ||
for (i = 0, ilen = data.length; i < ilen; ++i) { | ||
data[i].draw(me._ctx); | ||
} | ||
} | ||
}]); | ||
return MatrixController; | ||
}(Chart.DatasetController); | ||
MatrixController.prototype.dataElementType = Rectangle; | ||
MatrixController.prototype.dataElementOptions = ['backgroundColor', 'borderColor', 'borderWidth', 'anchorX', 'anchorY', 'width', 'height']; | ||
Chart.controllers.matrix = MatrixController; | ||
Chart.defaults.matrix = { | ||
hover: { | ||
mode: 'nearest', | ||
intersect: true | ||
}, | ||
datasets: { | ||
animation: { | ||
numbers: { | ||
type: 'number', | ||
properties: ['x', 'y', 'width', 'height'] | ||
} | ||
}, | ||
anchorX: 'center', | ||
anchorY: 'center' | ||
}, | ||
tooltips: { | ||
mode: 'nearest', | ||
intersect: true | ||
}, | ||
scales: { | ||
x: { | ||
type: 'linear', | ||
offset: true | ||
}, | ||
y: { | ||
type: 'linear', | ||
reverse: true | ||
} | ||
}, | ||
elements: { | ||
rectangle: { | ||
width: 20, | ||
height: 20 | ||
} | ||
} | ||
}; | ||
}))); |
/*! | ||
* chartjs-chart-matrix v1.0.0-alpha6 | ||
* chartjs-chart-matrix v1.0.0-alpha7 | ||
* https://github.com/kurkle/chartjs-chart-matrix#readme | ||
@@ -7,2 +7,9 @@ * (c) 2020 Jukka Kurkela | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("chart.js")):"function"==typeof define&&define.amd?define(["chart.js"],e):e((t=t||self).Chart)}(this,(function(t){"use strict";function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function n(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function o(){return(o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&u(t,e)}function a(t){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function u(t,e){return(u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function l(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function c(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function f(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?c(t):e}function h(t){return function(){var e,r=a(t);if(l()){var n=a(this).constructor;e=Reflect.construct(r,arguments,n)}else e=r.apply(this,arguments);return f(this,e)}}function s(t,e){var r=t.getProps(["x","y","width","height"],e),n=r.x,o=r.y;return{left:n,top:o,right:n+r.width,bottom:o+r.height}}function p(t,e,r){return Math.max(Math.min(t,r),e)}function y(e){var r=s(e),n=r.right-r.left,o=r.bottom-r.top,i=function(e,r,n){var o,i,a,u,l=e.options.borderWidth;return t.helpers.isObject(l)?(o=+l.top||0,i=+l.right||0,a=+l.bottom||0,u=+l.left||0):o=i=a=u=+l||0,{t:p(o,0,n),r:p(i,0,r),b:p(a,0,n),l:p(u,0,r)}}(e,n/2,o/2);return{outer:{x:r.left,y:r.top,w:n,h:o},inner:{x:r.left+i.l,y:r.top+i.t,w:n-i.l-i.r,h:o-i.t-i.b}}}function d(t,e,r,n){var o=null===e,i=null===r,a=!(!t||o&&i)&&s(t,n);return a&&(o||e>=a.left&&e<=a.right)&&(i||r>=a.top&&r<=a.bottom)}var g,v,b,w=function(t){i(a,t);var r=h(a);function a(t){var n;return e(this,a),(n=r.call(this)).options=void 0,n.width=void 0,n.height=void 0,t&&o(c(n),t),n}return n(a,[{key:"draw",value:function(t){var e=this.options,r=y(this),n=r.inner,o=r.outer;t.save(),o.w!==n.w||o.h!==n.h?(t.beginPath(),t.rect(o.x,o.y,o.w,o.h),t.clip(),t.rect(n.x,n.y,n.w,n.h),t.fillStyle=e.backgroundColor,t.fill(),t.fillStyle=e.borderColor,t.fill("evenodd")):(t.fillStyle=e.backgroundColor,t.fillRect(n.x,n.y,n.w,n.h)),t.restore()}},{key:"inRange",value:function(t,e,r){return d(this,t,e,r)}},{key:"inXRange",value:function(t,e){return d(this,t,null,e)}},{key:"inYRange",value:function(t,e){return d(this,null,t,e)}},{key:"getCenterPoint",value:function(t){var e=this.getProps(["x","y","width","height"],t),r=e.x,n=e.y;return{x:r+e.width/2,y:n+e.height/2}}},{key:"tooltipPosition",value:function(){return this.getCenterPoint()}},{key:"getRange",value:function(t){return"x"===t?this.width/2:this.height/2}}]),a}((t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t).Element);b="rectangle",(v="_type")in(g=w)?Object.defineProperty(g,v,{value:b,enumerable:!0,configurable:!0,writable:!0}):g[v]=b;var m=function(t){i(o,t);var r=h(o);function o(){return e(this,o),r.apply(this,arguments)}return n(o,[{key:"update",value:function(t){var e=this._cachedMeta;this.updateElements(e.data,0,t)}},{key:"updateElements",value:function(t,e,r){for(var n=this,o="reset"===r,i=n._cachedMeta,a=i.xScale,u=i.yScale,l=n.resolveDataElementOptions(e,r),c=n.getSharedOptions(r,t[e],l),f=0;f<t.length;f++){var h=e+f,s=!o&&n.getParsed(h),p=o?a.getBasePixel():a.getPixelForValue(s.x),y=o?u.getBasePixel():u.getPixelForValue(s.y),d=n.resolveDataElementOptions(f,r),g=d.width,v=d.height,b=d.anchorX,w=d.anchorY,m={x:"left"===b?p:p-g/("right"===b?1:2),y:"top"===w?y:y-v/("bottom"===w?1:2),width:g,height:v,options:d};n.updateElement(t[f],h,m,r)}n.updateSharedOptions(c,r)}},{key:"draw",value:function(){var t,e,r=this.getMeta().data||[];for(t=0,e=r.length;t<e;++t)r[t].draw(this._ctx)}}]),o}(t.DatasetController);m.prototype.dataElementType=w,m.prototype.dataElementOptions=["backgroundColor","borderColor","borderWidth","anchorX","anchorY","width","height"],t.controllers.matrix=m,t.defaults.matrix={hover:{mode:"nearest",intersect:!0},datasets:{animation:{numbers:{type:"number",properties:["x","y","width","height"]}},anchorX:"center",anchorY:"center"},tooltips:{mode:"nearest",intersect:!0},scales:{x:{type:"linear",offset:!0},y:{type:"linear",reverse:!0}},elements:{rectangle:{width:20,height:20}}}})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("chart.js")):"function"==typeof define&&define.amd?define(["chart.js"],e):e((t=t||self).Chart)}(this,(function(t){"use strict";var e="default"in t?t.default:t;function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function n(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}var o=function(t){function e(){return t.apply(this,arguments)||this}n(e,t);var r=e.prototype;return r.update=function(t){var e=this._cachedMeta;this.updateElements(e.data,0,t)},r.updateElements=function(t,e,r){for(var n=this,o="reset"===r,i=n._cachedMeta,a=i.xScale,h=i.yScale,l=n.resolveDataElementOptions(e,r),s=n.getSharedOptions(r,t[e],l),u=0;u<t.length;u++){var c=e+u,d=!o&&n.getParsed(c),f=o?a.getBasePixel():a.getPixelForValue(d.x),p=o?h.getBasePixel():h.getPixelForValue(d.y),g=n.resolveDataElementOptions(u,r),y=g.width,v=g.height,b=g.anchorX,x=g.anchorY,m={x:"left"===b?f:f-y/("right"===b?1:2),y:"top"===x?p:p-v/("bottom"===x?1:2),width:y,height:v,options:g};n.updateElement(t[u],c,m,r)}n.updateSharedOptions(s,r)},r.draw=function(){var t,e,r=this.getMeta().data||[];for(t=0,e=r.length;t<e;++t)r[t].draw(this._ctx)},e}(t.DatasetController);function i(t,e){var r=t.getProps(["x","y","width","height"],e),n=r.x,o=r.y;return{left:n,top:o,right:n+r.width,bottom:o+r.height}}function a(t,e,r){return Math.max(Math.min(t,r),e)}function h(t,e,r){var n,o,i,h,l=t.options.borderWidth;return! | ||
/*! | ||
* Chart.js v3.0.0-alpha.2 | ||
* https://www.chartjs.org | ||
* (c) 2020 Chart.js Contributors | ||
* Released under the MIT License | ||
*/ | ||
function(t){return null!==t&&"[object Object]"===Object.prototype.toString.call(t)}(l)?n=o=i=h=+l||0:(n=+l.top||0,o=+l.right||0,i=+l.bottom||0,h=+l.left||0),{t:a(n,0,r),r:a(o,0,e),b:a(i,0,r),l:a(h,0,e)}}function l(t,e,r,n){var o=null===e,a=null===r,h=!(!t||o&&a)&&i(t,n);return h&&(o||e>=h.left&&e<=h.right)&&(a||r>=h.top&&r<=h.bottom)}o.id="matrix",o.defaults={dataElementType:"matrix",dataElementOptions:["backgroundColor","borderColor","borderWidth","anchorX","anchorY","width","height"],hover:{mode:"nearest",intersect:!0},datasets:{animation:{numbers:{type:"number",properties:["x","y","width","height"]}},anchorX:"center",anchorY:"center"},tooltips:{mode:"nearest",intersect:!0},scales:{x:{type:"linear",offset:!0},y:{type:"linear",reverse:!0}}};var s=function(t){function e(e){var n;return(n=t.call(this)||this).options=void 0,n.width=void 0,n.height=void 0,e&&r(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(n),e),n}n(e,t);var o=e.prototype;return o.draw=function(t){var e,r,n,o,a,l=this.options,s=(r=i(e=this),n=r.right-r.left,o=r.bottom-r.top,a=h(e,n/2,o/2),{outer:{x:r.left,y:r.top,w:n,h:o},inner:{x:r.left+a.l,y:r.top+a.t,w:n-a.l-a.r,h:o-a.t-a.b}}),u=s.inner,c=s.outer;t.save(),c.w!==u.w||c.h!==u.h?(t.beginPath(),t.rect(c.x,c.y,c.w,c.h),t.clip(),t.rect(u.x,u.y,u.w,u.h),t.fillStyle=l.backgroundColor,t.fill(),t.fillStyle=l.borderColor,t.fill("evenodd")):(t.fillStyle=l.backgroundColor,t.fillRect(u.x,u.y,u.w,u.h)),t.restore()},o.inRange=function(t,e,r){return l(this,t,e,r)},o.inXRange=function(t,e){return l(this,t,null,e)},o.inYRange=function(t,e){return l(this,null,t,e)},o.getCenterPoint=function(t){var e=this.getProps(["x","y","width","height"],t),r=e.x,n=e.y;return{x:r+e.width/2,y:n+e.height/2}},o.tooltipPosition=function(){return this.getCenterPoint()},o.getRange=function(t){return"x"===t?this.width/2:this.height/2},e}(t.Element);s.id="matrix",s.defaults={width:20,height:20},e.register(o,s)})); |
{ | ||
"name": "chartjs-chart-matrix", | ||
"version": "1.0.0-alpha6", | ||
"version": "1.0.0-alpha7", | ||
"description": "Chart.js module for creating matrix charts", | ||
@@ -8,3 +8,7 @@ "main": "dist/chartjs-chart-matrix.js", | ||
"scripts": { | ||
"test": "gulp test" | ||
"autobuild": "rollup -c -w", | ||
"build": "rollup -c", | ||
"dev": "karma start karma.config.js --no-signle-run --auto-watch", | ||
"lint": "eslint --ignore-path .gitignore .", | ||
"test": "cross-env NODE_ENV=test karma start karma.config.js --single-run --coverage" | ||
}, | ||
@@ -30,6 +34,5 @@ "repository": { | ||
"devDependencies": { | ||
"@babel/core": "^7.9.0", | ||
"@babel/plugin-proposal-class-properties": "^7.8.3", | ||
"@babel/plugin-transform-object-assign": "^7.8.3", | ||
"@babel/preset-env": "^7.9.5", | ||
"@babel/core": "^7.10.5", | ||
"@babel/plugin-transform-object-assign": "^7.10.4", | ||
"@babel/preset-env": "^7.10.4", | ||
"@rollup/plugin-commonjs": "^11.1.0", | ||
@@ -39,33 +42,27 @@ "@rollup/plugin-node-resolve": "^7.1.3", | ||
"babel-plugin-istanbul": "^6.0.0", | ||
"chart.js": "^3.0.0-alpha", | ||
"chart.js": "^3.0.0-alpha.2", | ||
"chartjs-adapter-date-fns": "^1.1.0-alpha", | ||
"date-fns": "^2.12.0", | ||
"cross-env": "^7.0.2", | ||
"date-fns": "^2.15.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-chartjs": "^0.2.0", | ||
"eslint-config-esnext": "^4.0.0", | ||
"eslint-config-esnext": "^4.1.0", | ||
"eslint-plugin-html": "^6.0.1", | ||
"gulp": "^4.0.2", | ||
"gulp-eslint": "^6.0.0", | ||
"gulp-replace": "^1.0.0", | ||
"gulp-streamify": "^1.0.2", | ||
"gulp-zip": "^4.2.0", | ||
"jasmine-core": "^3.5.0", | ||
"karma": "^5.0.1", | ||
"karma": "^5.1.0", | ||
"karma-coverage": "^1.1.2", | ||
"karma-firefox-launcher": "^1.3.0", | ||
"karma-jasmine": "^2.0.1", | ||
"karma-jasmine-html-reporter": "^1.5.3", | ||
"karma-jasmine-html-reporter": "^1.5.4", | ||
"karma-rollup-preprocessor": "^7.0.5", | ||
"karma-spec-reporter": "0.0.32", | ||
"merge2": "^1.3.0", | ||
"pixelmatch": "^4.0.2", | ||
"rollup": "^2.6.0", | ||
"rollup": "^2.21.0", | ||
"rollup-plugin-babel": "^4.4.0", | ||
"rollup-plugin-terser": "^5.3.0", | ||
"yargs": "^13.3.2" | ||
"rollup-plugin-terser": "^5.3.0" | ||
}, | ||
"peerDependencies": { | ||
"chart.js": "^3.0.0-alpha" | ||
"chart.js": "^3.0.0-alpha.2" | ||
}, | ||
"dependencies": {} | ||
} |
# chartjs-chart-matrix | ||
[Chart.js](https://www.chartjs.org/) **v3.0.0-alpha** module for creating matrix charts | ||
[Chart.js](https://www.chartjs.org/) **v3.0.0-alpha.2** module for creating matrix charts | ||
@@ -66,9 +66,6 @@ ![npm](https://img.shields.io/npm/v/chartjs-chart-matrix.svg) [![release](https://img.shields.io/github/release/kurkle/chartjs-chart-matrix.svg?style=flat-square)](https://github.com/kurkle/chartjs-chart-matrix/releases/latest) [![travis](https://img.shields.io/travis/kurkle/chartjs-chart-matrix.svg?style=flat-square&maxAge=60)](https://travis-ci.org/kurkle/chartjs-chart-matrix) ![npm bundle size](https://img.shields.io/bundlephobia/min/chartjs-chart-matrix.svg) ![GitHub](https://img.shields.io/github/license/kurkle/chartjs-chart-matrix.svg) | ||
```bash | ||
> gulp build // build dist files | ||
> gulp build --watch // build and watch for changes | ||
> gulp test // run all tests | ||
> gulp test --watch // run all tests and watch for changes | ||
> gulp test --coverage // run all tests and generate code coverage | ||
> gulp lint // perform code linting | ||
> gulp package // create an archive with dist files and samples | ||
> npm run build // build dist files | ||
> npm test // run all tests | ||
> npm run lint // perform code linting | ||
> npm package // create an archive with dist files and samples | ||
``` | ||
@@ -75,0 +72,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27
23069
6
507
74
1