Skip to content

Commit

Permalink
Merge pull request #309 from idrawjs/dev-v0.4
Browse files Browse the repository at this point in the history
Dev v0.4
  • Loading branch information
chenshenhai committed Apr 21, 2024
2 parents 371ba79 + 86b4c6d commit e4b3620
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 62 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": false,
"version": "0.4.0-beta.21",
"version": "0.4.0-beta.22",
"workspaces": [
"packages/*"
],
Expand Down
8 changes: 4 additions & 4 deletions packages/board/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@idraw/board",
"version": "0.4.0-beta.21",
"version": "0.4.0-beta.22",
"description": "",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand All @@ -21,12 +21,12 @@
"author": "chenshenhai",
"license": "MIT",
"devDependencies": {
"@idraw/types": "^0.4.0-beta.21"
"@idraw/types": "^0.4.0-beta.22"
},
"dependencies": {},
"peerDependencies": {
"@idraw/util": "^0.4.0-beta.21",
"@idraw/renderer": "^0.4.0-beta.21"
"@idraw/util": "^0.4.0-beta.22",
"@idraw/renderer": "^0.4.0-beta.22"
},
"publishConfig": {
"access": "public",
Expand Down
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@idraw/core",
"version": "0.4.0-beta.21",
"version": "0.4.0-beta.22",
"description": "",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand All @@ -21,13 +21,13 @@
"author": "chenshenhai",
"license": "MIT",
"devDependencies": {
"@idraw/types": "^0.4.0-beta.21"
"@idraw/types": "^0.4.0-beta.22"
},
"dependencies": {},
"peerDependencies": {
"@idraw/board": "^0.4.0-beta.21",
"@idraw/renderer": "^0.4.0-beta.21",
"@idraw/util": "^0.4.0-beta.21"
"@idraw/board": "^0.4.0-beta.22",
"@idraw/renderer": "^0.4.0-beta.22",
"@idraw/util": "^0.4.0-beta.22"
},
"publishConfig": {
"access": "public",
Expand Down
12 changes: 6 additions & 6 deletions packages/idraw/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "idraw",
"version": "0.4.0-beta.21",
"version": "0.4.0-beta.22",
"description": "",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand All @@ -22,11 +22,11 @@
"license": "MIT",
"devDependencies": {},
"dependencies": {
"@idraw/board": "^0.4.0-beta.21",
"@idraw/core": "^0.4.0-beta.21",
"@idraw/renderer": "^0.4.0-beta.21",
"@idraw/types": "^0.4.0-beta.21",
"@idraw/util": "^0.4.0-beta.21"
"@idraw/board": "^0.4.0-beta.22",
"@idraw/core": "^0.4.0-beta.22",
"@idraw/renderer": "^0.4.0-beta.22",
"@idraw/types": "^0.4.0-beta.22",
"@idraw/util": "^0.4.0-beta.22"
},
"publishConfig": {
"access": "public",
Expand Down
8 changes: 4 additions & 4 deletions packages/lab/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "@idraw/lab",
"version": "0.4.0-beta.21",
"version": "0.4.0-beta.22",
"dependencies": {
"@ant-design/icons": "^5.1.3",
"@idraw/core": "^0.4.0-beta.21",
"@idraw/util": "^0.4.0-beta.21",
"@idraw/core": "^0.4.0-beta.22",
"@idraw/util": "^0.4.0-beta.22",
"antd": "^5.5.0",
"classnames": "^2.3.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@idraw/types": "^0.4.0-beta.21",
"@idraw/types": "^0.4.0-beta.22",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.1"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@idraw/renderer",
"version": "0.4.0-beta.21",
"version": "0.4.0-beta.22",
"description": "",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand All @@ -21,11 +21,11 @@
"author": "chenshenhai",
"license": "MIT",
"devDependencies": {
"@idraw/types": "^0.4.0-beta.21"
"@idraw/types": "^0.4.0-beta.22"
},
"dependencies": {},
"peerDependencies": {
"@idraw/util": "^0.4.0-beta.21"
"@idraw/util": "^0.4.0-beta.22"
},
"publishConfig": {
"access": "public",
Expand Down
43 changes: 25 additions & 18 deletions packages/renderer/src/draw/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { drawBoxShadow, getOpacity } from './box';
export function drawCircle(ctx: ViewContext2D, elem: Element<'circle'>, opts: RendererDrawElementOptions) {
const { detail, angle } = elem;
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
const { background = '#000000', borderColor = '#000000', boxSizing, borderWidth = 0 } = detail;
const { background = '#000000', borderColor = '#000000', boxSizing, borderWidth = 0, borderDash } = detail;
let bw: number = 0;
if (typeof borderWidth === 'number' && borderWidth > 0) {
bw = borderWidth as number;
Expand All @@ -16,7 +16,7 @@ export function drawCircle(ctx: ViewContext2D, elem: Element<'circle'>, opts: Re
bw = bw * viewScaleInfo.scale;

// const { scale, offsetTop, offsetBottom, offsetLeft, offsetRight } = viewScaleInfo;
const { x, y, w, h } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h }, { viewScaleInfo, viewSizeInfo }) || elem;
const { x, y, w, h } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h }, { viewScaleInfo }) || elem;
const viewElem = { ...elem, ...{ x, y, w, h, angle } };

rotateElement(ctx, { x, y, w, h, angle }, () => {
Expand All @@ -29,10 +29,12 @@ export function drawCircle(ctx: ViewContext2D, elem: Element<'circle'>, opts: Re
// 'content-box'
const centerX = x + a;
const centerY = y + b;
const radiusA = a;
const radiusB = b;
if (bw > 0) {
if (boxSizing === 'border-box') {
a = a - bw;
b = b - bw;
if (boxSizing === 'content-box') {
a = a;
b = b;
} else if (boxSizing === 'center-line') {
a = a - bw / 2;
b = b - bw / 2;
Expand All @@ -47,18 +49,6 @@ export function drawCircle(ctx: ViewContext2D, elem: Element<'circle'>, opts: Re
const opacity = getOpacity(viewElem) * parentOpacity;
ctx.globalAlpha = opacity;

// draw border
if (typeof bw === 'number' && bw > 0) {
const ba = bw / 2 + a;
const bb = bw / 2 + b;
ctx.beginPath();
ctx.strokeStyle = borderColor;
ctx.lineWidth = bw;
ctx.circle(centerX, centerY, ba, bb, 0, 0, 2 * Math.PI);
ctx.closePath();
ctx.stroke();
}

// draw content
ctx.beginPath();
const fillStyle = createColorStyle(ctx, background, {
Expand All @@ -67,10 +57,27 @@ export function drawCircle(ctx: ViewContext2D, elem: Element<'circle'>, opts: Re
opacity: ctx.globalAlpha
});
ctx.fillStyle = fillStyle;
ctx.circle(centerX, centerY, a, b, 0, 0, 2 * Math.PI);
ctx.circle(centerX, centerY, radiusA, radiusB, 0, 0, 2 * Math.PI);
ctx.closePath();
ctx.fill();
ctx.globalAlpha = parentOpacity;

// draw border
if (typeof bw === 'number' && bw > 0) {
const ba = bw / 2 + a;
const bb = bw / 2 + b;
ctx.beginPath();
if (borderDash) {
const lineDash = borderDash.map((n) => n * viewScaleInfo.scale);
ctx.setLineDash(lineDash);
}
ctx.strokeStyle = borderColor;
ctx.lineWidth = bw;
ctx.circle(centerX, centerY, ba, bb, 0, 0, 2 * Math.PI);
ctx.closePath();
ctx.stroke();
ctx.setLineDash([]);
}
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@idraw/types",
"version": "0.4.0-beta.21",
"version": "0.4.0-beta.22",
"description": "",
"main": "src/index.ts",
"types": "src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/util/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@idraw/util",
"version": "0.4.0-beta.21",
"version": "0.4.0-beta.22",
"description": "",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
7 changes: 5 additions & 2 deletions packages/util/src/lib/view-box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const defaultElemConfig = getDefaultElementDetailConfig();
export function calcViewBoxSize(viewElem: Element, opts: { viewScaleInfo: ViewScaleInfo; viewSizeInfo: ViewSizeInfo }): ViewBoxSize {
const { viewScaleInfo } = opts;
const { scale } = viewScaleInfo;
let { borderRadius } = viewElem.detail;
let { borderRadius, borderDash } = viewElem.detail;
const hasBorderDash = Array.isArray(borderDash) && borderDash.length > 0;

const { boxSizing = defaultElemConfig.boxSizing, borderWidth } = viewElem.detail;

if (Array.isArray(borderWidth)) {
Expand All @@ -24,7 +26,8 @@ export function calcViewBoxSize(viewElem: Element, opts: { viewScaleInfo: ViewSc
if (typeof borderWidth === 'number') {
bw = (borderWidth || 0) * scale;
}
if (boxSizing === 'border-box') {
if (boxSizing === 'border-box' && !hasBorderDash) {
// TODO
x = viewElem.x + bw / 2;
y = viewElem.y + bw / 2;
w = viewElem.w - bw;
Expand Down
34 changes: 17 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e4b3620

Please sign in to comment.