Skip to content

Commit

Permalink
renamed folders, unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Patric Gutersohn committed Apr 6, 2020
1 parent 0e0cd9e commit ae3c434
Show file tree
Hide file tree
Showing 40 changed files with 7,675 additions and 3,768 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ npm run build
| docs | md documentation files |
| public | content-base for webpack dev server, contains some circliful examples |
| src | all code for the library |
| styles | scss styling files for circles |
| tests | unit and dom tests, coming soon... |
| style | scss styling files for circles |
| test | unit and dom tests, coming soon... |

#### src folder ####

| Folder | Description |
| ------------- |-------------|
| base-classes | basic classes to centralize main features |
| base-class | basic classes to centralize main features |
| circle-type | some default circles, you can add there your own |
| helpers | svg and object helper |
| interfaces | typescript interfaces for validation |
| helper | svg and object helper |
| interface | typescript interfaces for validation |


7 changes: 7 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// for jest (unit testing)
module.exports = {
presets: [
["@babel/preset-env", {targets: {node: "current"}}],
"@babel/preset-typescript",
],
};
4 changes: 2 additions & 2 deletions dist/circliful.js

Large diffs are not rendered by default.

11,052 changes: 7,373 additions & 3,679 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"scripts": {
"start:dev": "webpack-dev-server --config webpack.dev.config.js --content-base public/",
"build": "webpack --config webpack.dev.config.js",
"lint": "tslint -c tslint.json -p tsconfig.json --fix"
"lint": "tslint -c tslint.json -p tsconfig.json --fix",
"test": "jest --collectCoverage",
"test:watch": "jest --watch"
},
"keywords": [
"circliful",
Expand All @@ -34,6 +36,7 @@
"@babel/core": "^7.9.0",
"@babel/plugin-transform-modules-umd": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@babel/preset-typescript": "^7.9.0",
"@types/node": "^13.9.4",
"babel-loader": "^8.1.0",
"babel-plugin-syntax-async-functions": "^6.13.0",
Expand All @@ -43,6 +46,7 @@
"es6-promise-promise": "^1.0.0",
"events": "^3.1.0",
"html-webpack-plugin": "^4.0.2",
"jest": "^25.2.7",
"mini-css-extract-plugin": "^0.9.0",
"node-sass": "^4.13.1",
"optimize-css-assets-webpack-plugin": "^5.0.3",
Expand All @@ -56,5 +60,8 @@
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
},
"dependencies": {
"@types/jest": "^25.2.1"
}
}
26 changes: 19 additions & 7 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Circle from "./base-classes/circle";
import {IAvailableOptions} from "./interfaces/iavailable-options";
import {IType} from "./interfaces/itype";
import Circle from "./base-class/circle";
import ObjectHelper from "./helper/object-helper";
import {IAvailableOptions} from "./interface/iavailable-options";
import {IType} from "./interface/itype";

export class Api {
public readonly options: IAvailableOptions;
Expand All @@ -9,6 +10,10 @@ export class Api {
this.options = options;
}

/**
* @description Update options and rerender circle
* @param parameter
*/
public update(parameter: IType | IType[]) {
const element = document.getElementById(`svg-${this.options.id}`);

Expand All @@ -22,6 +27,11 @@ export class Api {
Circle.initializeCircleType(this.options);
}

/**
* @description Update options by given type
* @param type
* @param value
*/
private updateType(type: string, value: IType["value"]): void {
switch (type) {
case "percent":
Expand Down Expand Up @@ -70,9 +80,11 @@ export class Api {
}
}

public get(type: string): void {
if (this.options.hasOwnProperty(type)) {
return this.options[type];
}
/**
* @description Get property from object
* @param type
*/
public get(type: string) {
return ObjectHelper.extractPropertyFromObject(this.options, type);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {IAvailableOptions} from "../interfaces/iavailable-options";
import {ISize} from "../interfaces/isize";
import {ITag} from "../interfaces/itag";
import {IViewBoxAttributes} from "../interfaces/iview-box-attributes";
import {IAvailableOptions} from "../interface/iavailable-options";
import {ISize} from "../interface/isize";
import {ITag} from "../interface/itag";
import {IViewBoxAttributes} from "../interface/iview-box-attributes";
import SvgTags from "./svg-tags";

/**
Expand Down Expand Up @@ -74,10 +74,10 @@ export abstract class BaseCircle {
* @description Draws the svg tag
* @param additionalAttributes
*/
public drawContainer(additionalAttributes?: object) {
const {minX, minY, width, height} = this.getViewBoxParams();
public drawContainer(additionalAttributes?: object) {console.log(additionalAttributes);
const {minX, minY, width, height} = this.getViewBoxParams();

const container = SvgTags.addSvg({
const container = SvgTags.addSvg({
width: "100%",
height: "100%",
viewBox: `${minX} ${minY} ${width} ${height}`,
Expand All @@ -86,7 +86,7 @@ export abstract class BaseCircle {
...additionalAttributes,
});

this.tags.push({
this.tags.push({
element: container,
parentId: this.options.id,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ import SimpleCircle from "../circle-type/simple-circle";
import {BaseCircle} from "./base-circle";

export class CircleFactory {
private circleClass: BaseCircle;

public create(type: string): BaseCircle {
public static create(type: string): BaseCircle {
let circleClass: BaseCircle;
switch (type.toLowerCase()) {
case "half":
this.circleClass = new HalfCircle();
circleClass = new HalfCircle();
break;
case "plain":
this.circleClass = new PlainCircle();
circleClass = new PlainCircle();
break;
case "simple":
this.circleClass = new SimpleCircle();
circleClass = new SimpleCircle();
break;
default:
this.circleClass = new SimpleCircle();
circleClass = new SimpleCircle();
}

return this.circleClass;
return circleClass;
}
}
12 changes: 6 additions & 6 deletions src/base-classes/circle.ts → src/base-class/circle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Api} from "../api";
import {IAvailableOptions} from "../interfaces/iavailable-options";
import {IAvailableOptions} from "../interface/iavailable-options";
import {CircleFactory} from "./circle-factory";
import Options from "./options";

Expand All @@ -24,13 +24,13 @@ class Circle {
/**
* @description Initializes the circle by given type
* @param options
* @param checkDataAttributes
*/
public static initializeCircleType(options: IAvailableOptions) {
public static initializeCircleType(options: IAvailableOptions, checkDataAttributes = false) {
const size = Circle.getParentSize(options.id);
const circleFactory = new CircleFactory();
const circle = circleFactory.create(options.type);
const circle = CircleFactory.create(options.type);
const optionsManager = new Options();
const mergedOptions = optionsManager.mergeOptions(options);
const mergedOptions = optionsManager.mergeOptions(options, checkDataAttributes);

circle.initialize(mergedOptions, size);
circle.drawCircle();
Expand Down Expand Up @@ -60,7 +60,7 @@ class Circle {
percent: 1,
};

Circle.initializeCircleType(options);
Circle.initializeCircleType(options, true);

return new Api(options);
}
Expand Down
22 changes: 9 additions & 13 deletions src/base-classes/options.ts → src/base-class/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {IAvailableOptions} from "../interfaces/iavailable-options";
import {IAvailableOptions} from "../interface/iavailable-options";

class Options {
/**
Expand Down Expand Up @@ -44,24 +44,20 @@ class Options {
return dataOptions;
}

/**
* @description Transforms option ex no-percentage-sign into noPercentageSign
* @param option
* @returns {string}
*/
public static dashToCamelCase(option: string) {
return option.replace(/([A-Z])/g, (val) => `-${val.toLowerCase()}`);
}

/**
* @description Merge default options and custom option on initialisation
* @param options
* @param checkDataAttributes
* @returns Options['defaultOptions']
*/
public mergeOptions(options: IAvailableOptions) {
const dataOptions = Options.getDataAttributes(options);
public mergeOptions(options: IAvailableOptions, checkDataAttributes = false) {
let mergedOptions = {...this.defaultOptions, ...options};
if (checkDataAttributes) {
const dataOptions = Options.getDataAttributes(options);
mergedOptions = {...mergedOptions, ...dataOptions};
}

return {...this.defaultOptions, ...options, ...dataOptions};
return mergedOptions;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/base-classes/svg-tags.ts → src/base-class/svg-tags.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ObjectHelper from "../helpers/object-helper";
import SvgTagsHelper from "../helpers/svg-tags-helper";
import {IAttributes} from "../interfaces/iattributes";
import {IDictionary} from "../interfaces/idictionary";
import ObjectHelper from "../helper/object-helper";
import SvgTagsHelper from "../helper/svg-tags-helper";
import {IAttributes} from "../interface/iattributes";
import {IDictionary} from "../interface/idictionary";

class SvgTags {
public static namespaceURI = "http://www.w3.org/2000/svg";
Expand Down
8 changes: 4 additions & 4 deletions src/circle-type/half-circle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SvgTags from "../base-classes/svg-tags";
import ObjectHelper from "../helpers/object-helper";
import {StyleHelper} from "../helpers/style-helper";
import SvgTagsHelper from "../helpers/svg-tags-helper";
import SvgTags from "../base-class/svg-tags";
import ObjectHelper from "../helper/object-helper";
import {StyleHelper} from "../helper/style-helper";
import SvgTagsHelper from "../helper/svg-tags-helper";
import SimpleCircle from "./simple-circle";

/**
Expand Down
14 changes: 7 additions & 7 deletions src/circle-type/plain-circle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {BaseCircle} from "../base-classes/base-circle";
import SvgTags from "../base-classes/svg-tags";
import ObjectHelper from "../helpers/object-helper";
import {StyleHelper} from "../helpers/style-helper";
import SvgTagsHelper from "../helpers/svg-tags-helper";
import {IAvailableOptions} from "../interfaces/iavailable-options";
import {ISize} from "../interfaces/isize";
import {BaseCircle} from "../base-class/base-circle";
import SvgTags from "../base-class/svg-tags";
import ObjectHelper from "../helper/object-helper";
import {StyleHelper} from "../helper/style-helper";
import SvgTagsHelper from "../helper/svg-tags-helper";
import {IAvailableOptions} from "../interface/iavailable-options";
import {ISize} from "../interface/isize";

/**
* Every circle gets dynamically called by the given type in the options object example: { type: 'PlainCircle' }
Expand Down
16 changes: 8 additions & 8 deletions src/circle-type/simple-circle.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {BaseCircle} from "../base-classes/base-circle";
import SvgTags from "../base-classes/svg-tags";
import ObjectHelper from "../helpers/object-helper";
import {StyleHelper} from "../helpers/style-helper";
import SvgTagsHelper from "../helpers/svg-tags-helper";
import {IAttributes} from "../interfaces/iattributes";
import {IAvailableOptions} from "../interfaces/iavailable-options";
import {ISize} from "../interfaces/isize";
import {BaseCircle} from "../base-class/base-circle";
import SvgTags from "../base-class/svg-tags";
import ObjectHelper from "../helper/object-helper";
import {StyleHelper} from "../helper/style-helper";
import SvgTagsHelper from "../helper/svg-tags-helper";
import {IAttributes} from "../interface/iattributes";
import {IAvailableOptions} from "../interface/iavailable-options";
import {ISize} from "../interface/isize";

/**
* Every circle gets dynamically called by the given type in the options object
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/object-helper.ts → src/helper/object-helper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {IDictionary} from "../interfaces/idictionary";
import {IDictionary} from "../interface/idictionary";

export default class ObjectHelper {
public static extractPropertyFromObject(object: IDictionary, property: string) {
let value: string | number | object = "";
let value: string | object | number | boolean | [];
if (object.hasOwnProperty(property) && object[property]) {
value = object[property];
}
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/style-helper.ts → src/helper/style-helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ICalculationParams} from "../interfaces/icalculation-params";
import {IProgressColor} from "../interfaces/iprogress-color";
import {ICalculationParams} from "../interface/icalculation-params";
import {IProgressColor} from "../interface/iprogress-color";
import SvgTagsHelper from "./svg-tags-helper";

export class StyleHelper {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {IAttributes} from "../interfaces/iattributes";
import {ICalculationParams} from "../interfaces/icalculation-params";
import {IAttributes} from "../interface/iattributes";
import {ICalculationParams} from "../interface/icalculation-params";

class SvgTagsHelper {
/**
Expand Down Expand Up @@ -43,8 +43,8 @@ class SvgTagsHelper {
const angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;

return {
x: centerX + (radius * Math.cos(angleInRadians)),
y: centerY + (radius * Math.sin(angleInRadians)),
x: centerX + Math.round(radius * Math.cos(angleInRadians) + Number.EPSILON),
y: centerY + Math.round(radius * Math.sin(angleInRadians) + Number.EPSILON),
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "../styles/main.scss";
import Circle from "./base-classes/circle";
import {IAvailableOptions} from "./interfaces/iavailable-options";
import "../style/main.scss";
import Circle from "./base-class/circle";
import {IAvailableOptions} from "./interface/iavailable-options";

/**
* @description Gets called from html script tag
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions src/interface/idictionary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IDictionary {
[key: string]: string | object | number | boolean | [];
[key: number]: string | object | number | boolean | [];
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions src/interfaces/idictionary.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ae3c434

Please sign in to comment.