@tscircuit/schematic-viewer 1.3.0 → 1.4.1
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 +1 -1
- package/biome.json +45 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.js +734 -688
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
- package/src/Schematic.tsx +141 -65
- package/src/lib/render-context/index.ts +1 -1
- package/src/lib/types/core.ts +14 -49
- package/src/lib/types/source-component.ts +6 -1
- package/src/lib/utils/collect-element-refs.ts +5 -4
- package/src/lib/utils/colors.ts +235 -0
- package/src/lib/utils/direction-to-vec.ts +3 -3
- package/src/schematic-components/SVGPathComponent.tsx +71 -112
- package/src/schematic-components/SchematicChip.tsx +222 -0
- package/src/schematic-components/SchematicComponent.tsx +25 -22
- package/src/schematic-components/SchematicComponentFromSymbol.tsx +46 -0
- package/src/schematic-components/SchematicElement.tsx +0 -28
- package/src/schematic-components/SchematicNetLabel.tsx +3 -0
- package/src/schematic-components/SchematicText.tsx +4 -6
- package/src/schematic-components/SchematicTrace.tsx +4 -3
- package/src/schematic-components/TableViewer.tsx +1 -1
- package/src/schematic-components/index.tsx +6 -14
- package/src/stories/basics/schematic-net-label.stories.tsx +2 -0
- package/src/stories/basics/schematic-net-labels-2.stories.tsx +22 -20
- package/src/stories/bug-connections.stories.tsx +18 -13
- package/src/stories/bug-high-port-numbers.stories.tsx +107 -85
- package/src/stories/bug-one-sided.stories.tsx +17 -15
- package/src/stories/bug-pin-spacing.stories.tsx +19 -17
- package/src/stories/bugs/bug1-y-flip.stories.tsx +7 -5
- package/src/stories/bugs/bug3-scaling-trace.stories.tsx +11 -5
- package/src/stories/bugs/bug4-schematic-line.stories.tsx +0 -1
- package/src/stories/bugs/bug5-diode.stories.tsx +3 -2
- package/src/stories/bugs/bug6-trace-scaling.stories.tsx +5 -41
- package/src/stories/bugs/bug8-autolayout.stories.tsx +20 -29
- package/src/stories/circuit-components/diode.stories.tsx +3 -1
- package/src/stories/circuit-components/resistor.stories.tsx +3 -1
- package/src/stories/led-circuit-react.stories.tsx +35 -48
- package/src/stories/rotated-resistor.stories.tsx +10 -8
- package/src/stories/three-sided-bug.stories.tsx +17 -15
- package/src/pages/led-circuit.tsx +0 -96
- package/src/schematic-components/ProjectComponent.tsx +0 -70
- package/src/schematic-components/SchematicBox.tsx +0 -29
- package/src/schematic-components/SchematicBug.tsx +0 -107
- package/src/schematic-components/SchematicLine.tsx +0 -48
- package/src/schematic-components/SchematicPath.tsx +0 -51
- package/src/schematic-components/SchematicPort.tsx +0 -63
- package/src/schematic-components/SimpleCapacitor.tsx +0 -29
- package/src/schematic-components/SimpleDiode.tsx +0 -42
- package/src/schematic-components/SimpleGround.tsx +0 -30
- package/src/schematic-components/SimpleInductor.tsx +0 -29
- package/src/schematic-components/SimplePowerSource.tsx +0 -43
- package/src/schematic-components/SimpleResistor.tsx +0 -28
- package/src/stories/led-circuit-builder.stories.tsx +0 -104
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// Kicad-2020 color scheme
|
|
2
|
+
export const colorMap = {
|
|
3
|
+
"3d_viewer": {
|
|
4
|
+
background_bottom: "rgb(102, 102, 128)",
|
|
5
|
+
background_top: "rgb(204, 204, 230)",
|
|
6
|
+
board: "rgb(51, 43, 23)",
|
|
7
|
+
copper: "rgb(179, 156, 0)",
|
|
8
|
+
silkscreen_bottom: "rgb(230, 230, 230)",
|
|
9
|
+
silkscreen_top: "rgb(230, 230, 230)",
|
|
10
|
+
soldermask: "rgb(20, 51, 36)",
|
|
11
|
+
solderpaste: "rgb(128, 128, 128)",
|
|
12
|
+
},
|
|
13
|
+
board: {
|
|
14
|
+
anchor: "rgb(255, 38, 226)",
|
|
15
|
+
aux_items: "rgb(255, 255, 255)",
|
|
16
|
+
b_adhes: "rgb(0, 0, 132)",
|
|
17
|
+
b_crtyd: "rgb(255, 38, 226)",
|
|
18
|
+
b_fab: "rgb(88, 93, 132)",
|
|
19
|
+
b_mask: "rgba(2, 255, 238, 0.400)",
|
|
20
|
+
b_paste: "rgb(0, 194, 194)",
|
|
21
|
+
b_silks: "rgb(232, 178, 167)",
|
|
22
|
+
background: "rgb(0, 16, 35)",
|
|
23
|
+
cmts_user: "rgb(89, 148, 220)",
|
|
24
|
+
copper: {
|
|
25
|
+
b: "rgb(77, 127, 196)",
|
|
26
|
+
f: "rgb(200, 52, 52)",
|
|
27
|
+
in1: "rgb(127, 200, 127)",
|
|
28
|
+
in10: "rgb(237, 124, 51)",
|
|
29
|
+
in11: "rgb(91, 195, 235)",
|
|
30
|
+
in12: "rgb(247, 111, 142)",
|
|
31
|
+
in13: "rgb(167, 165, 198)",
|
|
32
|
+
in14: "rgb(40, 204, 217)",
|
|
33
|
+
in15: "rgb(232, 178, 167)",
|
|
34
|
+
in16: "rgb(242, 237, 161)",
|
|
35
|
+
in17: "rgb(237, 124, 51)",
|
|
36
|
+
in18: "rgb(91, 195, 235)",
|
|
37
|
+
in19: "rgb(247, 111, 142)",
|
|
38
|
+
in2: "rgb(206, 125, 44)",
|
|
39
|
+
in20: "rgb(167, 165, 198)",
|
|
40
|
+
in21: "rgb(40, 204, 217)",
|
|
41
|
+
in22: "rgb(232, 178, 167)",
|
|
42
|
+
in23: "rgb(242, 237, 161)",
|
|
43
|
+
in24: "rgb(237, 124, 51)",
|
|
44
|
+
in25: "rgb(91, 195, 235)",
|
|
45
|
+
in26: "rgb(247, 111, 142)",
|
|
46
|
+
in27: "rgb(167, 165, 198)",
|
|
47
|
+
in28: "rgb(40, 204, 217)",
|
|
48
|
+
in29: "rgb(232, 178, 167)",
|
|
49
|
+
in3: "rgb(79, 203, 203)",
|
|
50
|
+
in30: "rgb(242, 237, 161)",
|
|
51
|
+
in4: "rgb(219, 98, 139)",
|
|
52
|
+
in5: "rgb(167, 165, 198)",
|
|
53
|
+
in6: "rgb(40, 204, 217)",
|
|
54
|
+
in7: "rgb(232, 178, 167)",
|
|
55
|
+
in8: "rgb(242, 237, 161)",
|
|
56
|
+
in9: "rgb(141, 203, 129)",
|
|
57
|
+
},
|
|
58
|
+
cursor: "rgb(255, 255, 255)",
|
|
59
|
+
drc: "rgb(194, 194, 194)",
|
|
60
|
+
drc_error: "rgba(215, 91, 107, 0.800)",
|
|
61
|
+
drc_exclusion: "rgb(255, 255, 255)",
|
|
62
|
+
drc_warning: "rgba(255, 208, 66, 0.902)",
|
|
63
|
+
dwgs_user: "rgb(194, 194, 194)",
|
|
64
|
+
eco1_user: "rgb(180, 219, 210)",
|
|
65
|
+
eco2_user: "rgb(216, 200, 82)",
|
|
66
|
+
edge_cuts: "rgb(208, 210, 205)",
|
|
67
|
+
f_adhes: "rgb(132, 0, 132)",
|
|
68
|
+
f_crtyd: "rgb(255, 0, 245)",
|
|
69
|
+
f_fab: "rgb(175, 175, 175)",
|
|
70
|
+
f_mask: "rgba(216, 100, 255, 0.400)",
|
|
71
|
+
f_paste: "rgba(180, 160, 154, 0.902)",
|
|
72
|
+
f_silks: "rgb(242, 237, 161)",
|
|
73
|
+
footprint_text_back: "rgb(0, 0, 132)",
|
|
74
|
+
footprint_text_front: "rgb(194, 194, 194)",
|
|
75
|
+
footprint_text_invisible: "rgb(132, 132, 132)",
|
|
76
|
+
grid: "rgb(132, 132, 132)",
|
|
77
|
+
grid_axes: "rgb(194, 194, 194)",
|
|
78
|
+
margin: "rgb(255, 38, 226)",
|
|
79
|
+
microvia: "rgb(0, 132, 132)",
|
|
80
|
+
no_connect: "rgb(0, 0, 132)",
|
|
81
|
+
pad_back: "rgb(77, 127, 196)",
|
|
82
|
+
pad_front: "rgb(200, 52, 52)",
|
|
83
|
+
pad_plated_hole: "rgb(194, 194, 0)",
|
|
84
|
+
pad_through_hole: "rgb(227, 183, 46)",
|
|
85
|
+
plated_hole: "rgb(26, 196, 210)",
|
|
86
|
+
ratsnest: "rgba(245, 255, 213, 0.702)",
|
|
87
|
+
select_overlay: "rgb(4, 255, 67)",
|
|
88
|
+
through_via: "rgb(236, 236, 236)",
|
|
89
|
+
user_1: "rgb(194, 194, 194)",
|
|
90
|
+
user_2: "rgb(89, 148, 220)",
|
|
91
|
+
user_3: "rgb(180, 219, 210)",
|
|
92
|
+
user_4: "rgb(216, 200, 82)",
|
|
93
|
+
user_5: "rgb(194, 194, 194)",
|
|
94
|
+
user_6: "rgb(89, 148, 220)",
|
|
95
|
+
user_7: "rgb(180, 219, 210)",
|
|
96
|
+
user_8: "rgb(216, 200, 82)",
|
|
97
|
+
user_9: "rgb(232, 178, 167)",
|
|
98
|
+
via_blind_buried: "rgb(187, 151, 38)",
|
|
99
|
+
via_hole: "rgb(227, 183, 46)",
|
|
100
|
+
via_micro: "rgb(0, 132, 132)",
|
|
101
|
+
via_through: "rgb(236, 236, 236)",
|
|
102
|
+
worksheet: "rgb(200, 114, 171)",
|
|
103
|
+
},
|
|
104
|
+
gerbview: {
|
|
105
|
+
axes: "rgb(0, 0, 132)",
|
|
106
|
+
background: "rgb(0, 0, 0)",
|
|
107
|
+
dcodes: "rgb(255, 255, 255)",
|
|
108
|
+
grid: "rgb(132, 132, 132)",
|
|
109
|
+
layers: [
|
|
110
|
+
"rgb(132, 0, 0)",
|
|
111
|
+
"rgb(194, 194, 0)",
|
|
112
|
+
"rgb(194, 0, 194)",
|
|
113
|
+
"rgb(194, 0, 0)",
|
|
114
|
+
"rgb(0, 132, 132)",
|
|
115
|
+
"rgb(0, 132, 0)",
|
|
116
|
+
"rgb(0, 0, 132)",
|
|
117
|
+
"rgb(132, 132, 132)",
|
|
118
|
+
"rgb(132, 0, 132)",
|
|
119
|
+
"rgb(194, 194, 194)",
|
|
120
|
+
"rgb(132, 0, 132)",
|
|
121
|
+
"rgb(132, 0, 0)",
|
|
122
|
+
"rgb(132, 132, 0)",
|
|
123
|
+
"rgb(194, 194, 194)",
|
|
124
|
+
"rgb(0, 0, 132)",
|
|
125
|
+
"rgb(0, 132, 0)",
|
|
126
|
+
"rgb(132, 0, 0)",
|
|
127
|
+
"rgb(194, 194, 0)",
|
|
128
|
+
"rgb(194, 0, 194)",
|
|
129
|
+
"rgb(194, 0, 0)",
|
|
130
|
+
"rgb(0, 132, 132)",
|
|
131
|
+
"rgb(0, 132, 0)",
|
|
132
|
+
"rgb(0, 0, 132)",
|
|
133
|
+
"rgb(132, 132, 132)",
|
|
134
|
+
"rgb(132, 0, 132)",
|
|
135
|
+
"rgb(194, 194, 194)",
|
|
136
|
+
"rgb(132, 0, 132)",
|
|
137
|
+
"rgb(132, 0, 0)",
|
|
138
|
+
"rgb(132, 132, 0)",
|
|
139
|
+
"rgb(194, 194, 194)",
|
|
140
|
+
"rgb(0, 0, 132)",
|
|
141
|
+
"rgb(0, 132, 0)",
|
|
142
|
+
"rgb(132, 0, 0)",
|
|
143
|
+
"rgb(194, 194, 0)",
|
|
144
|
+
"rgb(194, 0, 194)",
|
|
145
|
+
"rgb(194, 0, 0)",
|
|
146
|
+
"rgb(0, 132, 132)",
|
|
147
|
+
"rgb(0, 132, 0)",
|
|
148
|
+
"rgb(0, 0, 132)",
|
|
149
|
+
"rgb(132, 132, 132)",
|
|
150
|
+
"rgb(132, 0, 132)",
|
|
151
|
+
"rgb(194, 194, 194)",
|
|
152
|
+
"rgb(132, 0, 132)",
|
|
153
|
+
"rgb(132, 0, 0)",
|
|
154
|
+
"rgb(132, 132, 0)",
|
|
155
|
+
"rgb(194, 194, 194)",
|
|
156
|
+
"rgb(0, 0, 132)",
|
|
157
|
+
"rgb(0, 132, 0)",
|
|
158
|
+
"rgb(132, 0, 0)",
|
|
159
|
+
"rgb(194, 194, 0)",
|
|
160
|
+
"rgb(194, 0, 194)",
|
|
161
|
+
"rgb(194, 0, 0)",
|
|
162
|
+
"rgb(0, 132, 132)",
|
|
163
|
+
"rgb(0, 132, 0)",
|
|
164
|
+
"rgb(0, 0, 132)",
|
|
165
|
+
"rgb(132, 132, 132)",
|
|
166
|
+
"rgb(132, 0, 132)",
|
|
167
|
+
"rgb(194, 194, 194)",
|
|
168
|
+
"rgb(132, 0, 132)",
|
|
169
|
+
"rgb(132, 0, 0)",
|
|
170
|
+
],
|
|
171
|
+
negative_objects: "rgb(132, 132, 132)",
|
|
172
|
+
worksheet: "rgb(0, 0, 132)",
|
|
173
|
+
},
|
|
174
|
+
meta: {
|
|
175
|
+
filename: "kicad_2020",
|
|
176
|
+
name: "KiCad 2020",
|
|
177
|
+
version: 2,
|
|
178
|
+
},
|
|
179
|
+
palette: [
|
|
180
|
+
"rgb(132, 0, 0)",
|
|
181
|
+
"rgb(194, 194, 0)",
|
|
182
|
+
"rgb(194, 0, 194)",
|
|
183
|
+
"rgb(194, 0, 0)",
|
|
184
|
+
"rgb(0, 132, 132)",
|
|
185
|
+
"rgb(0, 132, 0)",
|
|
186
|
+
"rgb(0, 0, 132)",
|
|
187
|
+
"rgb(132, 132, 132)",
|
|
188
|
+
"rgb(132, 0, 132)",
|
|
189
|
+
"rgb(194, 194, 194)",
|
|
190
|
+
"rgb(132, 0, 132)",
|
|
191
|
+
"rgb(132, 0, 0)",
|
|
192
|
+
"rgb(132, 132, 0)",
|
|
193
|
+
"rgb(194, 194, 194)",
|
|
194
|
+
"rgb(0, 0, 132)",
|
|
195
|
+
"rgb(0, 132, 0)",
|
|
196
|
+
],
|
|
197
|
+
schematic: {
|
|
198
|
+
aux_items: "rgb(46, 46, 46)",
|
|
199
|
+
background: "rgb(245, 241, 237)",
|
|
200
|
+
brightened: "rgb(255, 0, 255)",
|
|
201
|
+
bus: "rgb(0, 0, 132)",
|
|
202
|
+
bus_junction: "rgb(0, 0, 132)",
|
|
203
|
+
component_body: "rgb(255, 255, 194)",
|
|
204
|
+
component_outline: "rgb(132, 0, 0)",
|
|
205
|
+
cursor: "rgb(15, 15, 15)",
|
|
206
|
+
erc_error: "rgba(230, 9, 13, 0.800)",
|
|
207
|
+
erc_warning: "rgba(209, 146, 0, 0.800)",
|
|
208
|
+
fields: "rgb(132, 0, 132)",
|
|
209
|
+
grid: "rgb(181, 181, 181)",
|
|
210
|
+
grid_axes: "rgb(0, 0, 132)",
|
|
211
|
+
hidden: "rgb(194, 194, 194)",
|
|
212
|
+
junction: "rgb(0, 150, 0)",
|
|
213
|
+
label_global: "rgb(132, 0, 0)",
|
|
214
|
+
label_hier: "rgb(114, 86, 0)",
|
|
215
|
+
label_local: "rgb(15, 15, 15)",
|
|
216
|
+
net_name: "rgb(132, 132, 132)",
|
|
217
|
+
no_connect: "rgb(0, 0, 132)",
|
|
218
|
+
note: "rgb(0, 0, 194)",
|
|
219
|
+
override_item_colors: false,
|
|
220
|
+
pin: "rgb(132, 0, 0)",
|
|
221
|
+
pin_name: "rgb(0, 100, 100)",
|
|
222
|
+
pin_number: "rgb(169, 0, 0)",
|
|
223
|
+
reference: "rgb(0, 100, 100)",
|
|
224
|
+
shadow: "rgba(102, 179, 255, 0.800)",
|
|
225
|
+
sheet: "rgb(132, 0, 0)",
|
|
226
|
+
sheet_background: "rgba(253, 255, 231, 0.000)",
|
|
227
|
+
sheet_fields: "rgb(132, 0, 132)",
|
|
228
|
+
sheet_filename: "rgb(114, 86, 0)",
|
|
229
|
+
sheet_label: "rgb(0, 100, 100)",
|
|
230
|
+
sheet_name: "rgb(0, 100, 100)",
|
|
231
|
+
value: "rgb(0, 100, 100)",
|
|
232
|
+
wire: "rgb(0, 150, 0)",
|
|
233
|
+
worksheet: "rgb(132, 0, 0)",
|
|
234
|
+
},
|
|
235
|
+
}
|
|
@@ -17,7 +17,7 @@ export const vecToDirection = ({ x, y }: { x: number; y: number }) => {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export const rotateClockwise = (
|
|
20
|
-
direction: "up" | "down" | "left" | "right"
|
|
20
|
+
direction: "up" | "down" | "left" | "right",
|
|
21
21
|
) => {
|
|
22
22
|
if (direction === "up") return "right"
|
|
23
23
|
else if (direction === "right") return "down"
|
|
@@ -26,7 +26,7 @@ export const rotateClockwise = (
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export const rotateCounterClockwise = (
|
|
29
|
-
direction: "up" | "down" | "left" | "right"
|
|
29
|
+
direction: "up" | "down" | "left" | "right",
|
|
30
30
|
) => {
|
|
31
31
|
if (direction === "up") return "left"
|
|
32
32
|
else if (direction === "left") return "down"
|
|
@@ -36,7 +36,7 @@ export const rotateCounterClockwise = (
|
|
|
36
36
|
|
|
37
37
|
export const rotateDirection = (
|
|
38
38
|
direction: "up" | "down" | "left" | "right",
|
|
39
|
-
num90DegreeClockwiseTurns: number
|
|
39
|
+
num90DegreeClockwiseTurns: number,
|
|
40
40
|
) => {
|
|
41
41
|
while (num90DegreeClockwiseTurns > 0) {
|
|
42
42
|
direction = rotateClockwise(direction)
|
|
@@ -1,28 +1,41 @@
|
|
|
1
1
|
import { useGlobalStore } from "lib/render-context"
|
|
2
2
|
import getSVGPathBounds from "lib/utils/get-svg-path-bounds"
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { useState } from "react"
|
|
5
4
|
import {
|
|
6
5
|
applyToPoint,
|
|
7
|
-
toSVG,
|
|
8
|
-
inverse,
|
|
9
6
|
compose,
|
|
10
|
-
translate,
|
|
11
7
|
scale,
|
|
8
|
+
toSVG,
|
|
9
|
+
translate,
|
|
12
10
|
} from "transformation-matrix"
|
|
13
11
|
|
|
12
|
+
interface PathProps {
|
|
13
|
+
type?: "path"
|
|
14
|
+
strokeWidth: number
|
|
15
|
+
stroke: string
|
|
16
|
+
fill?: string
|
|
17
|
+
d: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface CircleProps {
|
|
21
|
+
type: "circle"
|
|
22
|
+
cx: number
|
|
23
|
+
cy: number
|
|
24
|
+
r: number
|
|
25
|
+
strokeWidth: number
|
|
26
|
+
stroke: string
|
|
27
|
+
fill?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type SVGElement = PathProps | CircleProps
|
|
31
|
+
|
|
14
32
|
interface Props {
|
|
15
33
|
rotation: number
|
|
16
34
|
center: { x: number; y: number }
|
|
17
35
|
size: { width: number; height: number }
|
|
18
36
|
invertY?: boolean
|
|
19
37
|
shiftToBottom?: boolean
|
|
20
|
-
paths:
|
|
21
|
-
strokeWidth: number
|
|
22
|
-
stroke: string
|
|
23
|
-
fill?: string
|
|
24
|
-
d: string
|
|
25
|
-
}>
|
|
38
|
+
paths: SVGElement[]
|
|
26
39
|
zIndex?: number
|
|
27
40
|
hoverContent?: any
|
|
28
41
|
}
|
|
@@ -38,36 +51,16 @@ export const SVGPathComponent = ({
|
|
|
38
51
|
hoverContent,
|
|
39
52
|
}: Props) => {
|
|
40
53
|
const ct = useGlobalStore((s) => s.camera_transform)
|
|
41
|
-
const pathBounds = getSVGPathBounds(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) >
|
|
45
|
-
0.01
|
|
46
|
-
if (badRatio) {
|
|
47
|
-
// console.warn(
|
|
48
|
-
// `Ratio doesn't match for component. ${pathBounds.width}:${pathBounds.height} is not close to ${size.width}:${size.height}`
|
|
49
|
-
// )
|
|
50
|
-
}
|
|
51
|
-
// pathBounds.height = Math.max(pathBounds.height, 0.01)
|
|
52
|
-
// pathBounds.width = Math.max(pathBounds.width, 0.01)
|
|
53
|
-
|
|
54
|
-
// Three sizes:
|
|
55
|
-
// pathBound size (the size of the path in "d")
|
|
56
|
-
// innerSize (the screen-space size of the path)
|
|
57
|
-
// fullSize (the screen-space size of the svg element, innerSize plus padding)
|
|
58
|
-
|
|
59
|
-
const padding = {
|
|
60
|
-
x: 0,
|
|
61
|
-
y: 0,
|
|
62
|
-
}
|
|
54
|
+
const pathBounds = getSVGPathBounds(
|
|
55
|
+
paths.filter((p): p is PathProps => p.type !== "circle").map((p) => p.d),
|
|
56
|
+
)
|
|
63
57
|
|
|
58
|
+
const padding = { x: 0, y: 0 }
|
|
64
59
|
const absoluteCenter = applyToPoint(ct, center)
|
|
65
|
-
|
|
66
60
|
const innerSize = {
|
|
67
61
|
width: size.width * ct.a,
|
|
68
62
|
height: size.height * Math.abs(ct.d),
|
|
69
63
|
}
|
|
70
|
-
|
|
71
64
|
const fullSize = {
|
|
72
65
|
width: innerSize.width + padding.x * 2,
|
|
73
66
|
height: innerSize.height + padding.y * 2,
|
|
@@ -78,95 +71,61 @@ export const SVGPathComponent = ({
|
|
|
78
71
|
const svgLeft = absoluteCenter.x - fullSize.width / 2
|
|
79
72
|
const svgTop = absoluteCenter.y - fullSize.height / 2
|
|
80
73
|
|
|
81
|
-
// const viewBox = `${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`
|
|
82
|
-
// const viewBox2 = `${svgLeft} ${svgTctualAbsWidth} ${actualAbsHeight}`
|
|
83
|
-
|
|
84
|
-
// console.log(
|
|
85
|
-
// pathBounds,
|
|
86
|
-
// fullSize,
|
|
87
|
-
// fullSize.width / pathBounds.width,
|
|
88
|
-
// fullSize.height / pathBounds.height
|
|
89
|
-
// )
|
|
90
74
|
const preferredRatio =
|
|
91
75
|
pathBounds.width === 0
|
|
92
76
|
? innerSize.height / pathBounds.height
|
|
93
77
|
: innerSize.width / pathBounds.width
|
|
78
|
+
|
|
94
79
|
const svgToScreen = compose(
|
|
95
|
-
// translate(0, 0)
|
|
96
80
|
scale(
|
|
97
81
|
pathBounds.width === 0
|
|
98
82
|
? preferredRatio
|
|
99
83
|
: fullSize.width / pathBounds.width,
|
|
100
84
|
pathBounds.height === 0
|
|
101
85
|
? preferredRatio
|
|
102
|
-
: fullSize.height / pathBounds.height
|
|
86
|
+
: fullSize.height / pathBounds.height,
|
|
103
87
|
),
|
|
104
|
-
translate(-pathBounds.minX, -pathBounds.minY)
|
|
105
|
-
// translate(center.x, center.y)
|
|
88
|
+
translate(-pathBounds.minX, -pathBounds.minY),
|
|
106
89
|
)
|
|
107
|
-
// console.log(svgToScreen)
|
|
108
|
-
// console.log(toSVG(svgToScreen))
|
|
109
|
-
// console.log(paths[0].d)
|
|
110
|
-
// translate(..., ...),
|
|
111
90
|
|
|
112
91
|
return (
|
|
113
|
-
|
|
114
|
-
{
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
92
|
+
<svg
|
|
93
|
+
onMouseOver={() => setHovering(Boolean(hoverContent))}
|
|
94
|
+
onMouseOut={() => setHovering(false)}
|
|
95
|
+
style={{
|
|
96
|
+
position: "absolute",
|
|
97
|
+
cursor: hovering ? "pointer" : undefined,
|
|
98
|
+
zIndex,
|
|
99
|
+
transform: [
|
|
100
|
+
invertY ? "scale(1, 1)" : "scale(1, -1)",
|
|
101
|
+
shiftToBottom ? "translate(0, 100%)" : "",
|
|
102
|
+
rotation === 0 ? "" : `rotate(${rotation}deg)`,
|
|
103
|
+
].join(" "),
|
|
104
|
+
left: svgLeft,
|
|
105
|
+
top: svgTop,
|
|
106
|
+
}}
|
|
107
|
+
overflow="visible"
|
|
108
|
+
width={fullSize.width}
|
|
109
|
+
height={fullSize.height}
|
|
110
|
+
>
|
|
111
|
+
{paths.map((p, i) =>
|
|
112
|
+
p.type === "circle" ? (
|
|
113
|
+
<circle
|
|
114
|
+
key={i}
|
|
115
|
+
transform={toSVG(
|
|
116
|
+
compose(
|
|
117
|
+
scale(1, 1), // Add a smaller scale factor for circles
|
|
118
|
+
svgToScreen,
|
|
119
|
+
),
|
|
120
|
+
)}
|
|
121
|
+
cx={p.cx}
|
|
122
|
+
cy={p.cy}
|
|
123
|
+
r={p.r}
|
|
124
|
+
fill={"none"}
|
|
125
|
+
strokeWidth={2.25 * (p.strokeWidth || 1)}
|
|
126
|
+
stroke={p.stroke || "red"}
|
|
128
127
|
/>
|
|
129
|
-
|
|
130
|
-
style={{
|
|
131
|
-
position: "absolute",
|
|
132
|
-
left: svgLeft + fullSize.width + 10,
|
|
133
|
-
pointerEvents: "none",
|
|
134
|
-
zIndex: 1000,
|
|
135
|
-
color: "red",
|
|
136
|
-
mixBlendMode: "difference",
|
|
137
|
-
top: svgTop,
|
|
138
|
-
fontFamily: "monospace",
|
|
139
|
-
fontSize: 14,
|
|
140
|
-
}}
|
|
141
|
-
>
|
|
142
|
-
{hoverContent}
|
|
143
|
-
</div>
|
|
144
|
-
</>
|
|
145
|
-
)}
|
|
146
|
-
<svg
|
|
147
|
-
onMouseOver={() => setHovering(Boolean(hoverContent))}
|
|
148
|
-
onMouseOut={() => setHovering(false)}
|
|
149
|
-
style={{
|
|
150
|
-
position: "absolute",
|
|
151
|
-
// backgroundColor: hovering ? "rgba(0, 0, 255, 0.5)" : "transparent",
|
|
152
|
-
cursor: hovering ? "pointer" : undefined,
|
|
153
|
-
zIndex,
|
|
154
|
-
transform: [
|
|
155
|
-
invertY ? "scale(1, 1)" : "scale(1, -1)", // TODO based on ct.d
|
|
156
|
-
shiftToBottom ? "translate(0, 100%)" : "",
|
|
157
|
-
rotation === 0 ? "" : `rotate(${rotation}rad)`,
|
|
158
|
-
].join(" "),
|
|
159
|
-
left: svgLeft,
|
|
160
|
-
top: svgTop,
|
|
161
|
-
// overflow: "hidden",
|
|
162
|
-
// backgroundColor: badRatio ? "rgba(255, 0, 0, 0.1)" : "transparent",
|
|
163
|
-
// backgroundColor: "rgba(255, 0, 0, 0.1)",
|
|
164
|
-
}}
|
|
165
|
-
overflow="visible"
|
|
166
|
-
width={fullSize.width}
|
|
167
|
-
height={fullSize.height}
|
|
168
|
-
>
|
|
169
|
-
{paths.map((p, i) => (
|
|
128
|
+
) : (
|
|
170
129
|
<path
|
|
171
130
|
key={i}
|
|
172
131
|
transform={toSVG(svgToScreen)}
|
|
@@ -174,11 +133,11 @@ export const SVGPathComponent = ({
|
|
|
174
133
|
strokeLinecap="round"
|
|
175
134
|
strokeWidth={1.5 * (p.strokeWidth || 1)}
|
|
176
135
|
stroke={p.stroke || "red"}
|
|
177
|
-
d={p.d}
|
|
136
|
+
d={p.d || ""}
|
|
178
137
|
/>
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
|
|
138
|
+
),
|
|
139
|
+
)}
|
|
140
|
+
</svg>
|
|
182
141
|
)
|
|
183
142
|
}
|
|
184
143
|
|