1
0
Fork 0

wip(lab): Work on xray mode

This commit is contained in:
Joost De Cock 2022-01-28 19:55:32 +01:00
parent c05d9dce23
commit ec2fd35208
9 changed files with 215 additions and 89 deletions

View file

@ -18,7 +18,7 @@ const tabClasses = active => `
const Wrap = props => <div className="max-w-screen-xl m-auto">{props.children}</div>
const LabDraft = props => {
const { app, pattern, gist, updateGist } = props
const { app, pattern, gist, updateGist, unsetGist } = props
const [tab, setTab] = useState(props.pattern.config.name)
@ -71,12 +71,12 @@ const LabDraft = props => {
{Object.keys(patternProps.parts).map((name) => (
<Part
key={name}
partName={name}
part={patternProps.parts[name]}
locale={gist.locale}
paperless={gist.paperless}
units={gist.units}
name={name}
app={app}
gist={gist}
updateGist={updateGist}
unsetGist={unsetGist}
/>
))}
</g>

View file

@ -3,13 +3,17 @@ import Point from '../point'
import Snippet from '../snippet'
import { getProps } from '../utils'
const Part = (props) => {
const raiseEvent = (evt) => console.log('raiseEVent not implemtned', evt)
const Part = props => {
const { partName, part, app, gist, updateGist } = props
const focusPoint = (point, i) => {
const p = props.part.points[point]
const pathString = `M ${p.x} ${props.part.topLeft.y} `
+ `L ${p.x} ${props.part.bottomRight.y} `
+ `M ${props.part.topLeft.x} ${p.y} `
+ `L ${props.part.bottomRight.x} ${p.y} `
const p = part.points[point]
const pathString = `M ${p.x} ${part.topLeft.y} `
+ `L ${p.x} ${part.bottomRight.y} `
+ `M ${part.topLeft.x} ${p.y} `
+ `L ${part.bottomRight.x} ${p.y} `
const classes = 'focus point c' + (i % 8) // Cycle through 8 colors
return (
<React.Fragment key={'fp' + point}>
@ -20,8 +24,8 @@ const Part = (props) => {
r="5"
className="contrast"
onClick={() =>
props.raiseEvent('clearFocus', {
part: props.name,
raiseEvent('clearFocus', {
part: partName,
type: 'points',
name: point
})
@ -32,10 +36,10 @@ const Part = (props) => {
}
const focusCoords = (p, i) => {
let pathString = `M ${p.x} ${props.part.topLeft.y} `
pathString += `L ${p.x} ${props.part.bottomRight.y} `
pathString += `M ${props.part.topLeft.x} ${p.y} `
pathString += `L ${props.part.bottomRight.x} ${p.y} `
let pathString = `M ${p.x} ${part.topLeft.y} `
pathString += `L ${p.x} ${part.bottomRight.y} `
pathString += `M ${part.topLeft.x} ${p.y} `
pathString += `L ${part.bottomRight.x} ${p.y} `
let classes = 'focus coords c' + (i % 4) // Cycle through 4 CSS classes
return (
<React.Fragment key={'cp' + i}>
@ -46,8 +50,8 @@ const Part = (props) => {
r="5"
className={classes}
onClick={() =>
props.raiseEvent('clearFocus', {
part: props.name,
raiseEvent('clearFocus', {
partName: partName,
type: 'coords',
data: p
})
@ -57,79 +61,74 @@ const Part = (props) => {
)
}
let grid = props.paperless ? (
let grid = gist.paperless ? (
<rect
x={props.part.topLeft.x}
y={props.part.topLeft.y}
width={props.part.width}
height={props.part.height}
x={part.topLeft.x}
y={part.topLeft.y}
width={part.width}
height={part.height}
className="grid"
fill={'url(#grid-' + props.name + ')'}
fill={'url(#grid-' + partName + ')'}
/>
) : null
let focus = []
if (props.develop) {
if (props.focus && typeof props.focus[props.name] !== 'undefined') {
for (let i in props.focus[props.name].points)
focus.push(focusPoint(props.focus[props.name].points[i], i))
for (let i in props.focus[props.name].paths) {
let name = props.focus[props.name].paths[i]
focus.push(
<path
key={'fpa-' + name}
d={props.part.paths[name].asPathstring()}
className={'focus path c' + (i % 4)}
onClick={() =>
props.raiseEvent('clearFocus', {
part: props.name,
type: 'paths',
name
})
}
/>
)
}
for (let i in props.focus[props.name].coords)
focus.push(focusCoords(props.focus[props.name].coords[i], i))
}
}
//if (gist.debug) {
// if (focus && typeof props.focus[props.name] !== 'undefined') {
// for (let i in props.focus[props.name].points)
// focus.push(focusPoint(props.focus[props.name].points[i], i))
// for (let i in props.focus[props.name].paths) {
// let name = props.focus[props.name].paths[i]
// focus.push(
// <path
// key={'fpa-' + name}
// d={props.part.paths[name].asPathstring()}
// className={'focus path c' + (i % 4)}
// onClick={() =>
// props.raiseEvent('clearFocus', {
// part: props.name,
// type: 'paths',
// name
// })
// }
// />
// )
// }
// for (let i in props.focus[props.name].coords)
// focus.push(focusCoords(props.focus[props.name].coords[i], i))
// }
//}
return (
<g {...getProps(props.part)} id={`part-${props.name}`}>
<g {...getProps(part)} id={`part-${partName}`}>
{grid}
{Object.keys(props.part.paths).map((name) => (
{Object.keys(part.paths).map((pathName) => (
<Path
key={name}
name={name}
part={props.name}
locale={props.locale}
path={props.part.paths[name]}
focus={props.focus}
pathName={pathName}
path={part.paths[pathName]}
topLeft={props.part.topLeft}
bottomRight={props.part.bottomRight}
develop={props.develop}
raiseEvent={props.raiseEvent}
app={props.app}
{...props}
/>
))}
{Object.keys(props.part.points).map((name) => (
<Point
key={name}
name={name}
part={props.name}
locale={props.locale}
pointName={name}
point={props.part.points[name]}
focus={props.focus}
topLeft={props.part.topLeft}
bottomRight={props.part.bottomRight}
develop={props.develop}
raiseEvent={props.raiseEvent}
app={props.app}
{...props}
/>
))}
{Object.keys(props.part.snippets).map((name) => (
<Snippet key={name} name={name} snippet={props.part.snippets[name]} />
{Object.keys(props.part.snippets).map((snippetName) => (
<Snippet
key={name}
snippetName={snippetName}
snippet={props.part.snippets[snippetName]}
{...props}
/>
))}
{focus}
</g>

View file

@ -1,15 +1,16 @@
import TextOnPath from '../text-on-path'
import { getProps } from '../utils'
const Path = (props) => {
if (!props.path.render) return null
const Path = props => {
const { path, part, name } = props
if (!path.render) return null
const output = []
const pathId = 'path-' + props.part + '-' + props.name
const pathId = 'path-' + part + '-' + name
output.push(
<path id={pathId} key={pathId} d={props.path.asPathstring()} {...getProps(props.path)} />
<path id={pathId} key={pathId} d={path.asPathstring()} {...getProps(path)} />
)
if (props.path.attributes.get('data-text'))
output.push(<TextOnPath key={'text-on-path-' + props.name} pathId={pathId} {...props} />)
if (path.attributes.get('data-text'))
output.push(<TextOnPath key={'text-on-path-' + name} pathId={pathId} {...props} />)
return output
}

View file

@ -1,12 +1,35 @@
import Text from '../text'
import Circle from '../circle'
const Point = (props) => {
const XrayPoint = props => (
<g>
<circle
cx={props.point.x}
cy={props.point.y}
r={2 * props.gist.scale}
className="stroke-sm stroke-lining fill-lining fill-opacity-25" />
<circle
cx={props.point.x}
cy={props.point.y}
r={7.5 * props.gist.scale}
className="fillhovertrap"
onClick={() => props.updateGist(
['xray', parts, 'props.partName', 'points', props.name],
props.point
)}
/>
</g>
)
const Point = props => {
const { point, name } = props
const output = []
if (props.point.attributes && props.point.attributes.get('data-text'))
output.push(<Text {...props} key={'point-' + props.name} />)
if (props.point.attributes && props.point.attributes.get('data-circle'))
output.push(<Circle point={props.point} key={'circle-' + props.name} />)
if (props.gist.xray) output.push(<XrayPoint {...props} key={'xp-' + props.name} />)
if (point.attributes && point.attributes.get('data-text'))
output.push(<Text {...props} key={'point-' + name} />)
if (point.attributes && point.attributes.get('data-circle'))
output.push(<Circle point={point} key={'circle-' + name} />)
return output.length < 1 ? null : output
}