Skip to content

Commit 47b079f

Browse files
committed
feat(math): component dot
1 parent 76f05e5 commit 47b079f

5 files changed

Lines changed: 50 additions & 1 deletion

File tree

packages/math/src/dot/index.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { theme } from '@sciux/utils-theme'
2+
import { type } from 'arktype'
3+
import { defineComponent } from 'sciux-laplace'
4+
import { generateTexNode } from '../utils/tex'
5+
6+
const T = type({
7+
x: type.number,
8+
y: type.number,
9+
label: 'string | undefined',
10+
})
11+
12+
export const dot = defineComponent<'dot', typeof T.infer, { division: number | undefined }>((attrs, context) => {
13+
return {
14+
name: 'dot',
15+
attrs: T,
16+
defaults: {
17+
x: 0,
18+
y: 0,
19+
},
20+
setup() {
21+
const container = document.createElementNS('http://www.w3.org/2000/svg', 'g')
22+
container.setAttribute('transform', `translate(${attrs.x.value * (context.division ?? 1)}, ${attrs.y.value * (context.division ?? 1)})`)
23+
24+
const dotSvg = document.createElementNS('http://www.w3.org/2000/svg', 'circle')
25+
dotSvg.id = 'dot-circle'
26+
container.id = 'canvas-dot'
27+
dotSvg.setAttribute('stroke', 'none')
28+
dotSvg.setAttribute('fill', theme.pallete('primary'))
29+
dotSvg.setAttribute('r', '2')
30+
31+
if (attrs.label.value) {
32+
const label = generateTexNode(attrs.label.value)
33+
container.append(label)
34+
}
35+
36+
container.appendChild(dotSvg)
37+
return container
38+
},
39+
}
40+
})

packages/math/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from './angle'
22
export * from './axis'
33
export * from './circle'
4+
export * from './dot'
45
export * from './figure'
56
export * from './function'
67
export * from './line'

packages/sciux/src/math.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Animation, Component } from 'sciux-laplace'
22
import type { RegisterContext } from './types'
3-
import { angle, angleArcCreation, angleCreation, axis, axisCreation, circle, circleCreation, figure, func, funcCreation, line, lineCreation, parametric, parametricCreation, plane, planeCreation, projectionCreation, tools, vector, vectorCreation } from '@sciux/math'
3+
import { angle, angleArcCreation, angleCreation, axis, axisCreation, circle, circleCreation, dot, figure, func, funcCreation, line, lineCreation, parametric, parametricCreation, plane, planeCreation, projectionCreation, tools, vector, vectorCreation } from '@sciux/math'
44
import { withSpace } from 'sciux-laplace'
55
import { canvasSpace } from './widget'
66

@@ -14,6 +14,7 @@ export default function ({ animations, context }: RegisterContext): void {
1414
canvasSpace.set('axis', axis)
1515
canvasSpace.set('plane', withSpace(plane as Component<'plane', any, any>, canvasSpace))
1616
canvasSpace.set('parametric', parametric)
17+
canvasSpace.set('dot', dot)
1718
const creation = <Animation<[], any, any>[]> animations.get('creation')
1819
creation.push(angleCreation, angleArcCreation, circleCreation, lineCreation, funcCreation, parametricCreation, axisCreation, planeCreation, projectionCreation, vectorCreation)
1920
Object.assign(context, tools)

test/src/examples.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ins02 from './template/instance/ins02.sciux?raw'
44
import angle from './template/math/angle.sciux?raw'
55
import axis from './template/math/axis.sciux?raw'
66
import circle from './template/math/circle.sciux?raw'
7+
import dot from './template/math/dot.sciux?raw'
78
import figure from './template/math/figure.sciux?raw'
89
import parametric from './template/math/parametric.sciux?raw'
910
import plane from './template/math/plane.sciux?raw'
@@ -22,6 +23,7 @@ export default {
2223
plane,
2324
parametric,
2425
axis,
26+
dot,
2527
},
2628
'INSTANCE': {
2729
ins01,

test/src/template/math/dot.sciux

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<canvas :width="200" :height="300" :origin="[100, 150]">
2+
<plane :x="0" :y="0" :domain="[0, 10]" :range="[0, 12]" :division="15">
3+
<dot label="(5, 7)" :x="5" :y="7" />
4+
</plane>
5+
</canvas>

0 commit comments

Comments
 (0)