@cehlers88/chart 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/ChartEngine.d.ts +26 -0
- package/dist/Factory/DataGroupFactory.d.ts +7 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +146 -0
- package/dist/interface/IChartEngine.d.ts +10 -0
- package/dist/interface/IChartPlugin.d.ts +18 -0
- package/dist/plugin/AbstractChartPlugin.d.ts +23 -0
- package/dist/plugin/BarsPlugin.d.ts +25 -0
- package/dist/plugin/DiagramLine.d.ts +25 -0
- package/dist/plugin/EnrichGroupInfosPlugin.d.ts +12 -0
- package/dist/type/TBRect.d.ts +12 -0
- package/dist/type/TChartEngineCallbacks.d.ts +11 -0
- package/dist/type/TData.d.ts +11 -0
- package/dist/type/TDataGroup.d.ts +16 -0
- package/dist/type/TRect.d.ts +12 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library ChartEngine
|
|
3
|
+
* Created 26.11.22
|
|
4
|
+
*
|
|
5
|
+
* @author Christoph Ehlers
|
|
6
|
+
*/
|
|
7
|
+
import { IChartPlugin } from "./interface/IChartPlugin";
|
|
8
|
+
import { TDataGroup } from "./type/TDataGroup";
|
|
9
|
+
import { IChartEngine } from "./interface/IChartEngine";
|
|
10
|
+
export default class ChartEngine implements IChartEngine {
|
|
11
|
+
private _canvasElement;
|
|
12
|
+
private _ctx;
|
|
13
|
+
private _dataGroups;
|
|
14
|
+
private _plugins;
|
|
15
|
+
constructor(canvasElement: HTMLCanvasElement);
|
|
16
|
+
private getEngineCallbacks;
|
|
17
|
+
addPlugin(plugin: IChartPlugin): ChartEngine;
|
|
18
|
+
getPlugin(pluginName: string): IChartPlugin;
|
|
19
|
+
create(): ChartEngine;
|
|
20
|
+
addDataGroup(dataGroup: TDataGroup): IChartEngine;
|
|
21
|
+
addValue(value: any, groupName?: string): IChartEngine;
|
|
22
|
+
draw(): ChartEngine;
|
|
23
|
+
private drawLegend;
|
|
24
|
+
update(): ChartEngine;
|
|
25
|
+
start(): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TDataGroup } from "../type/TDataGroup";
|
|
2
|
+
export default class DataGroupFactory {
|
|
3
|
+
private static _colors;
|
|
4
|
+
private static _lastColorIndex;
|
|
5
|
+
static buildCounter: number;
|
|
6
|
+
static createDataGroup(values: any[], groupLabel?: string, color?: string): TDataGroup;
|
|
7
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* index.ts
|
|
3
|
+
* Created 05.05.24
|
|
4
|
+
*
|
|
5
|
+
* @author Christoph Ehlers
|
|
6
|
+
*/
|
|
7
|
+
import ChartEngineClass from './ChartEngine';
|
|
8
|
+
import DiagramLine from "./plugin/DiagramLine";
|
|
9
|
+
import BarsPluginClass from "./plugin/BarsPlugin";
|
|
10
|
+
import DataGroupFactoryClass from "./Factory/DataGroupFactory";
|
|
11
|
+
declare const _default: {
|
|
12
|
+
ChartEngine: typeof ChartEngineClass;
|
|
13
|
+
DataGroupFactory: typeof DataGroupFactoryClass;
|
|
14
|
+
plugins: {
|
|
15
|
+
BarsPlugin: typeof BarsPluginClass;
|
|
16
|
+
DiagramLinePlugin: typeof DiagramLine;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export default _default;
|
|
20
|
+
export declare const ChartEngine: typeof ChartEngineClass;
|
|
21
|
+
export declare const DataGroupFactory: typeof DataGroupFactoryClass;
|
|
22
|
+
export declare const BarsPlugin: typeof BarsPluginClass;
|
|
23
|
+
export declare const DiagramLinePlugin: typeof DiagramLine;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
3
|
+
* This devtool is neither made for production nor for readable output files.
|
|
4
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
5
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
6
|
+
* or disable the default devtool with "devtool: false".
|
|
7
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
8
|
+
*/
|
|
9
|
+
/******/ (() => { // webpackBootstrap
|
|
10
|
+
/******/ "use strict";
|
|
11
|
+
/******/ var __webpack_modules__ = ({
|
|
12
|
+
|
|
13
|
+
/***/ "./src/ChartEngine.ts":
|
|
14
|
+
/*!****************************!*\
|
|
15
|
+
!*** ./src/ChartEngine.ts ***!
|
|
16
|
+
\****************************/
|
|
17
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
18
|
+
|
|
19
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _plugin_EnrichGroupInfosPlugin__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./plugin/EnrichGroupInfosPlugin */ \"./src/plugin/EnrichGroupInfosPlugin.ts\");\n/* harmony import */ var _Factory_DataGroupFactory__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Factory/DataGroupFactory */ \"./src/Factory/DataGroupFactory.ts\");\n/**\n * Library ChartEngine\n * Created 26.11.22\n *\n * @author Christoph Ehlers\n */\n\n\nvar ChartEngine = /** @class */ (function () {\n function ChartEngine(canvasElement) {\n this._dataGroups = [\n /*{\n color:'#ff0000',\n data:[\n {label:'zehn',value:10, empty:false},\n {label:'zwanzig',value:20, empty:false},\n {label:'dreißig',value:30, empty:false},\n {label:'vierzig',value:40, empty:false},\n {label:'fünfzig',value:50, empty:false},\n {label:'sechzig',value:60, empty:false},\n {label:'siebzig',value:70, empty:false},\n {label:'achtzig',value:80, empty:false},\n {label:'neunzig',value:90, empty:false},\n {label:'hundert',value:100, empty:false}\n ],\n infos:{},\n label:'Testgruooe 1',\n description:'default'\n },\n {\n color:'#00ff00',\n data:[\n {label:'einundzwanzig',value:201, empty:false},\n {label:'einundzwanzig',value:21, empty:false},\n {label:'achtundvierzig',value:-48, empty:false},\n {label:'achtundvierzig',value:-8, empty:false},\n ],\n infos:{},\n label:'Testgruooe 2',\n description:'default'\n }*/\n ];\n this._plugins = [\n new _plugin_EnrichGroupInfosPlugin__WEBPACK_IMPORTED_MODULE_0__[\"default\"](),\n //new DiagramLine()\n ];\n this._canvasElement = canvasElement;\n this._ctx = canvasElement.getContext('2d');\n }\n ChartEngine.prototype.getEngineCallbacks = function () {\n var _this = this;\n return {\n updateData: function (indexGroup, indexData, newData) {\n console.log('updateData context:', _this);\n _this._dataGroups[indexData].data[indexData] = newData;\n return _this;\n }\n };\n };\n ChartEngine.prototype.addPlugin = function (plugin) {\n this._plugins.push(plugin);\n return this;\n };\n ChartEngine.prototype.getPlugin = function (pluginName) {\n return this._plugins.find(function (plugin) { return plugin.getName() === pluginName; });\n };\n ChartEngine.prototype.create = function () {\n var _this = this;\n this._plugins.map(function (p) { return p.create(_this._canvasElement, _this._dataGroups, _this.getEngineCallbacks()); });\n return this;\n };\n ChartEngine.prototype.addDataGroup = function (dataGroup) {\n this._dataGroups.push(dataGroup);\n return this;\n };\n ChartEngine.prototype.addValue = function (value, groupName) {\n if (groupName === void 0) { groupName = ''; }\n var dataGroup = this._dataGroups.find(function (group) { return group.label === groupName; });\n if (dataGroup) {\n dataGroup.data.push(value);\n }\n else {\n this._dataGroups.push(_Factory_DataGroupFactory__WEBPACK_IMPORTED_MODULE_1__[\"default\"].createDataGroup([value], groupName));\n }\n return this;\n };\n ChartEngine.prototype.draw = function () {\n this._plugins.map(function (p) { return p.draw(); });\n this.drawLegend();\n return this;\n };\n ChartEngine.prototype.drawLegend = function () {\n var _this = this;\n this._dataGroups.map(function (dataGroup, index) {\n _this._ctx.fillStyle = dataGroup.color;\n _this._ctx.fillRect(10, 10 + index * 20, 10, 10);\n _this._ctx.fillStyle = '#000000';\n _this._ctx.fillText(dataGroup.label, 25, 20 + index * 20);\n });\n };\n ChartEngine.prototype.update = function () {\n var _this = this;\n this._plugins.map(function (p) {\n _this._dataGroups = p.update(_this._dataGroups);\n });\n return this;\n };\n ChartEngine.prototype.start = function () {\n var _this = this;\n var run = function () {\n window.requestAnimationFrame(function () {\n _this.update();\n _this.draw();\n run();\n });\n };\n this.create();\n run();\n };\n return ChartEngine;\n}());\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ChartEngine);\n\n\n//# sourceURL=webpack://@cehlers88/chart/./src/ChartEngine.ts?");
|
|
20
|
+
|
|
21
|
+
/***/ }),
|
|
22
|
+
|
|
23
|
+
/***/ "./src/Factory/DataGroupFactory.ts":
|
|
24
|
+
/*!*****************************************!*\
|
|
25
|
+
!*** ./src/Factory/DataGroupFactory.ts ***!
|
|
26
|
+
\*****************************************/
|
|
27
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
28
|
+
|
|
29
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\nvar DataGroupFactory = /** @class */ (function () {\n function DataGroupFactory() {\n }\n DataGroupFactory.createDataGroup = function (values, groupLabel, color) {\n if (groupLabel === void 0) { groupLabel = ''; }\n if (color === void 0) { color = ''; }\n DataGroupFactory.buildCounter++;\n if (color === '') {\n DataGroupFactory._lastColorIndex++;\n if (DataGroupFactory._lastColorIndex >= DataGroupFactory._colors.length) {\n DataGroupFactory._lastColorIndex = 0;\n }\n color = DataGroupFactory._colors[DataGroupFactory._lastColorIndex];\n }\n return {\n color: color,\n label: groupLabel === '' ? 'Group#' + DataGroupFactory.buildCounter : groupLabel,\n description: \"\",\n data: values.map(function (valueDef) {\n var value = (valueDef && valueDef.value) || valueDef;\n var label = (valueDef && valueDef.label) || value;\n return {\n empty: (valueDef === null),\n label: label,\n value: value\n };\n }),\n infos: {}\n };\n };\n DataGroupFactory._colors = [\n '#e84949',\n '#30cb30',\n '#f0a30a',\n '#1d91e3',\n '#ec459e',\n '#9f4ef4',\n '#f4f44e',\n '#4ef4f4',\n '#4ef49f',\n '#f49f4e',\n '#4e9bf4',\n ];\n DataGroupFactory._lastColorIndex = -1;\n DataGroupFactory.buildCounter = 0;\n return DataGroupFactory;\n}());\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (DataGroupFactory);\n\n\n//# sourceURL=webpack://@cehlers88/chart/./src/Factory/DataGroupFactory.ts?");
|
|
30
|
+
|
|
31
|
+
/***/ }),
|
|
32
|
+
|
|
33
|
+
/***/ "./src/index.ts":
|
|
34
|
+
/*!**********************!*\
|
|
35
|
+
!*** ./src/index.ts ***!
|
|
36
|
+
\**********************/
|
|
37
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
38
|
+
|
|
39
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ BarsPlugin: () => (/* binding */ BarsPlugin),\n/* harmony export */ ChartEngine: () => (/* binding */ ChartEngine),\n/* harmony export */ DataGroupFactory: () => (/* binding */ DataGroupFactory),\n/* harmony export */ DiagramLinePlugin: () => (/* binding */ DiagramLinePlugin),\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _ChartEngine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ChartEngine */ \"./src/ChartEngine.ts\");\n/* harmony import */ var _plugin_DiagramLine__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./plugin/DiagramLine */ \"./src/plugin/DiagramLine.ts\");\n/* harmony import */ var _plugin_BarsPlugin__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./plugin/BarsPlugin */ \"./src/plugin/BarsPlugin.ts\");\n/* harmony import */ var _Factory_DataGroupFactory__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Factory/DataGroupFactory */ \"./src/Factory/DataGroupFactory.ts\");\n/**\n * index.ts\n * Created 05.05.24\n *\n * @author Christoph Ehlers\n */\n\n\n\n\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({\n ChartEngine: _ChartEngine__WEBPACK_IMPORTED_MODULE_0__[\"default\"],\n DataGroupFactory: _Factory_DataGroupFactory__WEBPACK_IMPORTED_MODULE_3__[\"default\"],\n plugins: {\n BarsPlugin: _plugin_BarsPlugin__WEBPACK_IMPORTED_MODULE_2__[\"default\"],\n DiagramLinePlugin: _plugin_DiagramLine__WEBPACK_IMPORTED_MODULE_1__[\"default\"],\n }\n});\nvar ChartEngine = _ChartEngine__WEBPACK_IMPORTED_MODULE_0__[\"default\"];\nvar DataGroupFactory = _Factory_DataGroupFactory__WEBPACK_IMPORTED_MODULE_3__[\"default\"];\nvar BarsPlugin = _plugin_BarsPlugin__WEBPACK_IMPORTED_MODULE_2__[\"default\"];\nvar DiagramLinePlugin = _plugin_DiagramLine__WEBPACK_IMPORTED_MODULE_1__[\"default\"];\n\n\n//# sourceURL=webpack://@cehlers88/chart/./src/index.ts?");
|
|
40
|
+
|
|
41
|
+
/***/ }),
|
|
42
|
+
|
|
43
|
+
/***/ "./src/plugin/AbstractChartPlugin.ts":
|
|
44
|
+
/*!*******************************************!*\
|
|
45
|
+
!*** ./src/plugin/AbstractChartPlugin.ts ***!
|
|
46
|
+
\*******************************************/
|
|
47
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
48
|
+
|
|
49
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\nvar AbstractChartPlugin = /** @class */ (function () {\n function AbstractChartPlugin() {\n this._properties = {};\n }\n AbstractChartPlugin.prototype.create = function (canvasElement, dataGroups, engineCallbacks) {\n this.ctx = canvasElement.getContext('2d');\n this._drawAreaRect = {\n x: 0, y: 0,\n h: canvasElement.height,\n w: canvasElement.width\n };\n return this;\n };\n AbstractChartPlugin.prototype.draw = function () {\n return this;\n };\n AbstractChartPlugin.prototype.getDrawAreaRect = function () {\n return this._drawAreaRect;\n };\n AbstractChartPlugin.prototype.getProperty = function (propertyName, defaultResult) {\n return this._properties[propertyName] || defaultResult;\n };\n AbstractChartPlugin.prototype.setProperty = function (propertyName, value) {\n this._properties[propertyName] = value;\n return this;\n };\n AbstractChartPlugin.prototype.init = function () {\n return this;\n };\n return AbstractChartPlugin;\n}());\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (AbstractChartPlugin);\n\n\n//# sourceURL=webpack://@cehlers88/chart/./src/plugin/AbstractChartPlugin.ts?");
|
|
50
|
+
|
|
51
|
+
/***/ }),
|
|
52
|
+
|
|
53
|
+
/***/ "./src/plugin/BarsPlugin.ts":
|
|
54
|
+
/*!**********************************!*\
|
|
55
|
+
!*** ./src/plugin/BarsPlugin.ts ***!
|
|
56
|
+
\**********************************/
|
|
57
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
58
|
+
|
|
59
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ERangeType: () => (/* binding */ ERangeType),\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _AbstractChartPlugin__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./AbstractChartPlugin */ \"./src/plugin/AbstractChartPlugin.ts\");\n/**\n * Library BarsPlugin\n * Created 05.05.24\n *\n * @author Christoph Ehlers\n */\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n};\n\nvar ERangeType;\n(function (ERangeType) {\n ERangeType[\"ZERO_BASED\"] = \"zero_based\";\n ERangeType[\"MIN_MAX\"] = \"min_max\";\n})(ERangeType || (ERangeType = {}));\nvar BarsPlugin = /** @class */ (function (_super) {\n __extends(BarsPlugin, _super);\n function BarsPlugin() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.dataGroups = [];\n _this.rangeType = ERangeType.ZERO_BASED;\n _this.showZeroLine = true;\n _this.syncGroupsPosition = false;\n _this.zeroLineValue = 0;\n _this.zeroLineValuePercentage = 0;\n return _this;\n }\n BarsPlugin.prototype.draw = function () {\n var singlePercentageHeight = this.getDrawAreaRect().h / 100; // 1% height\n this.ctx.clearRect(this.getDrawAreaRect().x, this.getDrawAreaRect().y, this.getDrawAreaRect().w, this.getDrawAreaRect().h);\n this.ctx.fillStyle = '#fff000';\n this.ctx.fillRect(this.getDrawAreaRect().x, this.getDrawAreaRect().y, this.getDrawAreaRect().w, this.getDrawAreaRect().h);\n /*\n this.ctx.fillRect(\n this.getDrawAreaRect().x,\n this.getDrawAreaRect().y,\n this.getDrawAreaRect().w,\n this.getDrawAreaRect().h\n );\n\n if(this.showZeroLine) {\n this.ctx.strokeStyle = '#000000';\n this.ctx.beginPath();\n this.ctx.moveTo(this.getDrawAreaRect().x, this.getDrawAreaRect().y + this.getDrawAreaRect().h - singlePercentageHeight * this.zeroLineValuePercentage);\n this.ctx.lineTo(this.getDrawAreaRect().x + this.getDrawAreaRect().w, this.getDrawAreaRect().y + this.getDrawAreaRect().h - singlePercentageHeight * this.zeroLineValuePercentage);\n this.ctx.stroke();\n }\n\n this.dataGroups.forEach((dataGroup) => {\n const {color, data, infos} = dataGroup;\n const gap = this.calcPointGap(dataGroup);\n const range = this.rangeType === ERangeType.ZERO_BASED ? (infos.max + this.zeroLineValue) : infos.max - infos.min;\n\n this.ctx.strokeStyle = color;\n this.ctx.beginPath();\n\n data.forEach((dataPoint, index) => {\n const x = this.getDrawAreaRect().x + gap * index;\n const y = this.getDrawAreaRect().y + this.getDrawAreaRect().h - singlePercentageHeight * ((dataPoint.value - infos.min) / range * 100);\n if (index === 0) {\n this.ctx.moveTo(x, y);\n } else {\n this.ctx.lineTo(x, y);\n }\n });\n\n this.ctx.stroke();\n });\n*/\n return this;\n };\n BarsPlugin.prototype.calcPointGap = function (dataGroup) {\n return this.getDrawAreaRect().w /\n (this.syncGroupsPosition ? Math.max.apply(Math, this.dataGroups.map(function (group) { return group.data.length - 1; })) : dataGroup.data.length - 1);\n };\n BarsPlugin.prototype.update = function (dataGroups) {\n this.dataGroups = dataGroups;\n this.zeroLineValue = Math.min.apply(Math, __spreadArray([0], dataGroups.map(function (group) { return group.infos.min; }), false)) * -1;\n var maxValue = Math.max.apply(Math, dataGroups.map(function (group) { return group.infos.max; }));\n this.zeroLineValuePercentage = this.zeroLineValue / (maxValue + this.zeroLineValue) * 100;\n return dataGroups;\n };\n BarsPlugin.prototype.getName = function () {\n return \"BarsPlugin\";\n };\n return BarsPlugin;\n}(_AbstractChartPlugin__WEBPACK_IMPORTED_MODULE_0__[\"default\"]));\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (BarsPlugin);\n\n\n//# sourceURL=webpack://@cehlers88/chart/./src/plugin/BarsPlugin.ts?");
|
|
60
|
+
|
|
61
|
+
/***/ }),
|
|
62
|
+
|
|
63
|
+
/***/ "./src/plugin/DiagramLine.ts":
|
|
64
|
+
/*!***********************************!*\
|
|
65
|
+
!*** ./src/plugin/DiagramLine.ts ***!
|
|
66
|
+
\***********************************/
|
|
67
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
68
|
+
|
|
69
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ERangeType: () => (/* binding */ ERangeType),\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _AbstractChartPlugin__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./AbstractChartPlugin */ \"./src/plugin/AbstractChartPlugin.ts\");\n/**\n * Library DiagramLine\n * Created 26.11.22\n *\n * @author Christoph Ehlers\n */\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n};\n\nvar ERangeType;\n(function (ERangeType) {\n ERangeType[\"ZERO_BASED\"] = \"zero_based\";\n ERangeType[\"MIN_MAX\"] = \"min_max\";\n})(ERangeType || (ERangeType = {}));\nvar DiagramLine = /** @class */ (function (_super) {\n __extends(DiagramLine, _super);\n function DiagramLine() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.dataGroups = [];\n _this.rangeType = ERangeType.ZERO_BASED;\n _this.syncGroupsPosition = false;\n _this.zeroLineValue = 0;\n _this.zeroLineValuePercentage = 0;\n return _this;\n }\n DiagramLine.prototype._showZeroLine = function () {\n return this.getProperty('showZeroLine', false);\n };\n DiagramLine.prototype.draw = function () {\n var _this = this;\n var singlePercentageHeight = this.getDrawAreaRect().h / 100; // 1% height\n this.ctx.clearRect(this.getDrawAreaRect().x, this.getDrawAreaRect().y, this.getDrawAreaRect().w, this.getDrawAreaRect().h);\n if (this._showZeroLine()) {\n this.ctx.strokeStyle = '#000000';\n this.ctx.beginPath();\n this.ctx.moveTo(this.getDrawAreaRect().x, this.getDrawAreaRect().y + this.getDrawAreaRect().h - singlePercentageHeight * this.zeroLineValuePercentage);\n this.ctx.lineTo(this.getDrawAreaRect().x + this.getDrawAreaRect().w, this.getDrawAreaRect().y + this.getDrawAreaRect().h - singlePercentageHeight * this.zeroLineValuePercentage);\n this.ctx.stroke();\n }\n this.dataGroups.forEach(function (dataGroup) {\n var color = dataGroup.color, data = dataGroup.data, infos = dataGroup.infos;\n var gap = _this.calcPointGap(dataGroup);\n var range = _this.rangeType === ERangeType.ZERO_BASED ? (infos.max + _this.zeroLineValue) : infos.max - infos.min;\n _this.ctx.strokeStyle = color;\n _this.ctx.beginPath();\n data.forEach(function (dataPoint, index) {\n var x = _this.getDrawAreaRect().x + gap * index;\n var y = _this.getDrawAreaRect().y + _this.getDrawAreaRect().h - singlePercentageHeight * ((dataPoint.value - infos.min) / range * 100);\n if (index === 0) {\n _this.ctx.moveTo(x, y);\n }\n else {\n _this.ctx.lineTo(x, y);\n }\n });\n _this.ctx.stroke();\n });\n return this;\n };\n DiagramLine.prototype.calcPointGap = function (dataGroup) {\n return this.getDrawAreaRect().w /\n (this.syncGroupsPosition ? Math.max.apply(Math, this.dataGroups.map(function (group) { return group.data.length - 1; })) : dataGroup.data.length - 1);\n };\n DiagramLine.prototype.update = function (dataGroups) {\n this.dataGroups = dataGroups;\n this.zeroLineValue = Math.min.apply(Math, __spreadArray([0], dataGroups.map(function (group) { return group.infos.min; }), false)) * -1;\n var maxValue = Math.max.apply(Math, dataGroups.map(function (group) { return group.infos.max; }));\n this.zeroLineValuePercentage = this.zeroLineValue / (maxValue + this.zeroLineValue) * 100;\n return dataGroups;\n };\n DiagramLine.prototype.getName = function () {\n return \"DiagramLine\";\n };\n return DiagramLine;\n}(_AbstractChartPlugin__WEBPACK_IMPORTED_MODULE_0__[\"default\"]));\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (DiagramLine);\n\n\n//# sourceURL=webpack://@cehlers88/chart/./src/plugin/DiagramLine.ts?");
|
|
70
|
+
|
|
71
|
+
/***/ }),
|
|
72
|
+
|
|
73
|
+
/***/ "./src/plugin/EnrichGroupInfosPlugin.ts":
|
|
74
|
+
/*!**********************************************!*\
|
|
75
|
+
!*** ./src/plugin/EnrichGroupInfosPlugin.ts ***!
|
|
76
|
+
\**********************************************/
|
|
77
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
78
|
+
|
|
79
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _AbstractChartPlugin__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./AbstractChartPlugin */ \"./src/plugin/AbstractChartPlugin.ts\");\n/**\n * Library EnrichGroupInfosPlugin\n * Created 05.05,24\n *\n * @author Christoph Ehlers\n */\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __assign = (undefined && undefined.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\n\nvar EnrichGroupInfosPlugin = /** @class */ (function (_super) {\n __extends(EnrichGroupInfosPlugin, _super);\n function EnrichGroupInfosPlugin() {\n return _super !== null && _super.apply(this, arguments) || this;\n }\n EnrichGroupInfosPlugin.prototype.update = function (dataGroups) {\n return dataGroups.map(function (dataGroup) {\n var values = dataGroup.data.map(function (data) { return data.value; });\n return __assign(__assign({}, dataGroup), { infos: __assign(__assign({}, dataGroup.infos), { max: Math.max.apply(Math, values), min: Math.min.apply(Math, values) }) });\n });\n };\n EnrichGroupInfosPlugin.prototype.getName = function () {\n return \"EnrichGroupInfosPlugin\";\n };\n return EnrichGroupInfosPlugin;\n}(_AbstractChartPlugin__WEBPACK_IMPORTED_MODULE_0__[\"default\"]));\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (EnrichGroupInfosPlugin);\n\n\n//# sourceURL=webpack://@cehlers88/chart/./src/plugin/EnrichGroupInfosPlugin.ts?");
|
|
80
|
+
|
|
81
|
+
/***/ })
|
|
82
|
+
|
|
83
|
+
/******/ });
|
|
84
|
+
/************************************************************************/
|
|
85
|
+
/******/ // The module cache
|
|
86
|
+
/******/ var __webpack_module_cache__ = {};
|
|
87
|
+
/******/
|
|
88
|
+
/******/ // The require function
|
|
89
|
+
/******/ function __webpack_require__(moduleId) {
|
|
90
|
+
/******/ // Check if module is in cache
|
|
91
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
92
|
+
/******/ if (cachedModule !== undefined) {
|
|
93
|
+
/******/ return cachedModule.exports;
|
|
94
|
+
/******/ }
|
|
95
|
+
/******/ // Create a new module (and put it into the cache)
|
|
96
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
97
|
+
/******/ // no module.id needed
|
|
98
|
+
/******/ // no module.loaded needed
|
|
99
|
+
/******/ exports: {}
|
|
100
|
+
/******/ };
|
|
101
|
+
/******/
|
|
102
|
+
/******/ // Execute the module function
|
|
103
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
104
|
+
/******/
|
|
105
|
+
/******/ // Return the exports of the module
|
|
106
|
+
/******/ return module.exports;
|
|
107
|
+
/******/ }
|
|
108
|
+
/******/
|
|
109
|
+
/************************************************************************/
|
|
110
|
+
/******/ /* webpack/runtime/define property getters */
|
|
111
|
+
/******/ (() => {
|
|
112
|
+
/******/ // define getter functions for harmony exports
|
|
113
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
114
|
+
/******/ for(var key in definition) {
|
|
115
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
116
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
117
|
+
/******/ }
|
|
118
|
+
/******/ }
|
|
119
|
+
/******/ };
|
|
120
|
+
/******/ })();
|
|
121
|
+
/******/
|
|
122
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
123
|
+
/******/ (() => {
|
|
124
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
125
|
+
/******/ })();
|
|
126
|
+
/******/
|
|
127
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
128
|
+
/******/ (() => {
|
|
129
|
+
/******/ // define __esModule on exports
|
|
130
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
131
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
132
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
133
|
+
/******/ }
|
|
134
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
135
|
+
/******/ };
|
|
136
|
+
/******/ })();
|
|
137
|
+
/******/
|
|
138
|
+
/************************************************************************/
|
|
139
|
+
/******/
|
|
140
|
+
/******/ // startup
|
|
141
|
+
/******/ // Load entry module and return exports
|
|
142
|
+
/******/ // This entry module can't be inlined because the eval devtool is used.
|
|
143
|
+
/******/ var __webpack_exports__ = __webpack_require__("./src/index.ts");
|
|
144
|
+
/******/
|
|
145
|
+
/******/ })()
|
|
146
|
+
;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IChartPlugin } from "./IChartPlugin";
|
|
2
|
+
import { TDataGroup } from "../type/TDataGroup";
|
|
3
|
+
export interface IChartEngine {
|
|
4
|
+
addValue(value: any, groupName?: string): IChartEngine;
|
|
5
|
+
addDataGroup(dataGroup: TDataGroup): IChartEngine;
|
|
6
|
+
addPlugin(plugin: IChartPlugin): IChartEngine;
|
|
7
|
+
getPlugin(pluginName: string): IChartPlugin;
|
|
8
|
+
draw(): IChartEngine;
|
|
9
|
+
update(): IChartEngine;
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface IChartPlugin
|
|
3
|
+
* Created 26.11.22
|
|
4
|
+
*
|
|
5
|
+
* @author Christoph Ehlers
|
|
6
|
+
*/
|
|
7
|
+
import { TDataGroup } from "../type/TDataGroup";
|
|
8
|
+
import { TRect } from "../type/TRect";
|
|
9
|
+
import { TChartEngineCallbacks } from "../type/TChartEngineCallbacks";
|
|
10
|
+
export interface IChartPlugin {
|
|
11
|
+
create(canvasElement: HTMLCanvasElement, dataGroups: TDataGroup[], engineCallbacks: TChartEngineCallbacks): IChartPlugin;
|
|
12
|
+
draw(): IChartPlugin;
|
|
13
|
+
getDrawAreaRect(): TRect;
|
|
14
|
+
getName(): string;
|
|
15
|
+
getProperty(propertyName: string, defaultResult: any): any;
|
|
16
|
+
setProperty(propertyName: string, value: any): IChartPlugin;
|
|
17
|
+
update(dataGroups: TDataGroup[]): TDataGroup[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library AbstractChartPlugin
|
|
3
|
+
* Created 26.11.22
|
|
4
|
+
*
|
|
5
|
+
* @author Christoph Ehlers
|
|
6
|
+
*/
|
|
7
|
+
import { IChartPlugin } from "../interface/IChartPlugin";
|
|
8
|
+
import { TDataGroup } from "../type/TDataGroup";
|
|
9
|
+
import { TRect } from "../type/TRect";
|
|
10
|
+
import { TChartEngineCallbacks } from "../type/TChartEngineCallbacks";
|
|
11
|
+
export default abstract class AbstractChartPlugin implements IChartPlugin {
|
|
12
|
+
private _drawAreaRect;
|
|
13
|
+
private _properties;
|
|
14
|
+
protected ctx: CanvasRenderingContext2D;
|
|
15
|
+
abstract getName(): string;
|
|
16
|
+
abstract update(dataGroups: TDataGroup[]): TDataGroup[];
|
|
17
|
+
create(canvasElement: HTMLCanvasElement, dataGroups: TDataGroup[], engineCallbacks: TChartEngineCallbacks): AbstractChartPlugin;
|
|
18
|
+
draw(): IChartPlugin;
|
|
19
|
+
getDrawAreaRect(): TRect;
|
|
20
|
+
getProperty(propertyName: string, defaultResult: any): any;
|
|
21
|
+
setProperty(propertyName: string, value: any): AbstractChartPlugin;
|
|
22
|
+
init(): AbstractChartPlugin;
|
|
23
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library BarsPlugin
|
|
3
|
+
* Created 05.05.24
|
|
4
|
+
*
|
|
5
|
+
* @author Christoph Ehlers
|
|
6
|
+
*/
|
|
7
|
+
import AbstractChartPlugin from "./AbstractChartPlugin";
|
|
8
|
+
import { TDataGroup } from "../type/TDataGroup";
|
|
9
|
+
import { IChartPlugin } from "../interface/IChartPlugin";
|
|
10
|
+
export declare enum ERangeType {
|
|
11
|
+
ZERO_BASED = "zero_based",
|
|
12
|
+
MIN_MAX = "min_max"
|
|
13
|
+
}
|
|
14
|
+
export default class BarsPlugin extends AbstractChartPlugin {
|
|
15
|
+
private dataGroups;
|
|
16
|
+
private rangeType;
|
|
17
|
+
private showZeroLine;
|
|
18
|
+
private syncGroupsPosition;
|
|
19
|
+
private zeroLineValue;
|
|
20
|
+
private zeroLineValuePercentage;
|
|
21
|
+
draw(): IChartPlugin;
|
|
22
|
+
private calcPointGap;
|
|
23
|
+
update(dataGroups: TDataGroup[]): TDataGroup[];
|
|
24
|
+
getName(): string;
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library DiagramLine
|
|
3
|
+
* Created 26.11.22
|
|
4
|
+
*
|
|
5
|
+
* @author Christoph Ehlers
|
|
6
|
+
*/
|
|
7
|
+
import AbstractChartPlugin from "./AbstractChartPlugin";
|
|
8
|
+
import { TDataGroup } from "../type/TDataGroup";
|
|
9
|
+
import { IChartPlugin } from "../interface/IChartPlugin";
|
|
10
|
+
export declare enum ERangeType {
|
|
11
|
+
ZERO_BASED = "zero_based",
|
|
12
|
+
MIN_MAX = "min_max"
|
|
13
|
+
}
|
|
14
|
+
export default class DiagramLine extends AbstractChartPlugin {
|
|
15
|
+
private dataGroups;
|
|
16
|
+
private rangeType;
|
|
17
|
+
private syncGroupsPosition;
|
|
18
|
+
private zeroLineValue;
|
|
19
|
+
private zeroLineValuePercentage;
|
|
20
|
+
private _showZeroLine;
|
|
21
|
+
draw(): IChartPlugin;
|
|
22
|
+
private calcPointGap;
|
|
23
|
+
update(dataGroups: TDataGroup[]): TDataGroup[];
|
|
24
|
+
getName(): string;
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library EnrichGroupInfosPlugin
|
|
3
|
+
* Created 05.05,24
|
|
4
|
+
*
|
|
5
|
+
* @author Christoph Ehlers
|
|
6
|
+
*/
|
|
7
|
+
import AbstractChartPlugin from "./AbstractChartPlugin";
|
|
8
|
+
import { TDataGroup } from "../type/TDataGroup";
|
|
9
|
+
export default class EnrichGroupInfosPlugin extends AbstractChartPlugin {
|
|
10
|
+
update(dataGroups: TDataGroup[]): TDataGroup[];
|
|
11
|
+
getName(): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library TChartEngineCallbacks
|
|
3
|
+
* Created 27.11.22
|
|
4
|
+
*
|
|
5
|
+
* @author Christoph Ehlers
|
|
6
|
+
*/
|
|
7
|
+
import { TData } from "./TData";
|
|
8
|
+
import ChartEngine from "../ChartEngine";
|
|
9
|
+
export type TChartEngineCallbacks = {
|
|
10
|
+
updateData: (indexGroup: number, indexData: number, newData: TData) => ChartEngine;
|
|
11
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type TDataGroup
|
|
3
|
+
* Created 26.11.22
|
|
4
|
+
*
|
|
5
|
+
* @author Christoph Ehlers
|
|
6
|
+
*/
|
|
7
|
+
import { TData } from "./TData";
|
|
8
|
+
export type TDataGroup = {
|
|
9
|
+
color: string;
|
|
10
|
+
data: TData[];
|
|
11
|
+
label: string;
|
|
12
|
+
description: string;
|
|
13
|
+
infos: {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cehlers88/chart",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A library to create charts using JavaScript and Canvas-Element.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "restricted"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "webpack",
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/cEhlers88/Chart.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"canvas",
|
|
19
|
+
"chart",
|
|
20
|
+
"diagram"
|
|
21
|
+
],
|
|
22
|
+
"author": "Christoph Ehlers",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/cEhlers88/Chart/issues"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"homepage": "https://github.com/cEhlers88/Chart#readme",
|
|
31
|
+
"types": "src/index.d.ts",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"ts-loader": "^9.5.1",
|
|
34
|
+
"typescript": "^5.4.5",
|
|
35
|
+
"webpack": "^5.91.0",
|
|
36
|
+
"webpack-cli": "^5.1.4"
|
|
37
|
+
}
|
|
38
|
+
}
|