Slackbot
06/24/2023, 10:42 AMFil
06/24/2023, 11:10 AMFil
06/24/2023, 11:12 AMfitExtent
is the proper way to fit a projection to an extent, so the solution is using that function. Maybe it doesn't work because you're fitting to the (clipped) sphere instead of the rectangle. Without seeing your code it's impossible to tellsicheng mao
06/24/2023, 11:15 AMfitExtent
, don't know how to clip a rectangular part on top of the clipped circle. I found the composition of the projection operations (translate, rotate, fitExtent) kind of complex to keep track.sicheng mao
06/24/2023, 11:18 AM// here size is a responsive size of the window (I create a full-screen canvas)
const canvas = el.value!
const length = (size.height < size.width) ? size.height : size.width
const { ctx } = initCanvas(canvas, length, length * projectionRatio)
const { width, height } = canvas
const l = width
const r = size.width / size.height
// w, h as the view field width and height adapt to actual window shape
const w = l / Math.sqrt(1 + 1 / (r * r))
const h = l / Math.sqrt(1 + (r * r))
// auxiliary figures
ctx.clearRect(0, 0, width, height)
ctx.fillStyle = '#000'
ctx.fillRect(0, 0, width, height)
ctx.strokeStyle = 'blue' // Border color
ctx.lineWidth = 2 // Border width
ctx.strokeRect((l - w) / 2, (l - h) / 2, w, h)
const scale = width / 1024
const adapt = Math.sqrt(scale)
projection
.rotate(rotation)
.clipAngle(30)
.fitExtent([[0, 0], [width, height]], stars)
const starPath = geoPath(projection, ctx).pointRadius(d => Math.max(adapt * starSize(d.properties.mag), 0.1))
// draw stars
stars.features.forEach((star) => {
ctx.beginPath()
starPath(star)
ctx.fillStyle = starColor(star.properties.bv)
ctx.fill()
})
sicheng mao
06/24/2023, 11:30 AMsicheng mao
06/24/2023, 11:37 AMsicheng mao
06/24/2023, 11:38 AMsicheng mao
06/24/2023, 11:50 AMconst projection = geoEquirectangular()
const projectionRatio = 1 // since we use 30° clip circle
const zenith = getZenith()
const rotation = getAngles(zenith)
const canvas = el.value!
const length = (size.height < size.width) ? size.height : size.width
const { ctx } = initCanvas(canvas, length, length * projectionRatio)
const { width, height } = canvas
const l = width
const r = size.width / size.height
// w, h as the view field width and height adapt to actual window shape
const w = l / Math.sqrt(1 + 1 / (r * r))
const h = l / Math.sqrt(1 + (r * r))
// auxiliary figures
ctx.clearRect(0, 0, width, height)
ctx.fillStyle = '#000'
ctx.fillRect(0, 0, width, height)
ctx.strokeStyle = 'blue' // Border color
ctx.lineWidth = 2 // Border width
ctx.strokeRect((l - w) / 2, (l - h) / 2, w, h)
const scale = width / 1024
const adapt = Math.sqrt(scale)
console.log(l, w)
projection
.rotate(rotation)
.clipAngle(30)
.fitExtent([[0, 0], [width, height]], stars)
.postclip(geoClipRectangle((l - w) / 2, (l - h) / 2, (l + w) / 2, (l + h) / 2))
// .fitWidth(size.width, stars)
// .translate([[(l - w) / 2, (l - h) / 2], [(l + w) / 2, (l + h) / 2]])
// .fitExtent... the second one doesn't work well
const starPath = geoPath(projection, ctx).pointRadius(d => Math.max(adapt * starSize(d.properties.mag), 0.1))
// draw stars
stars.features.forEach((star) => {
ctx.beginPath()
starPath(star)
ctx.fillStyle = starColor(star.properties.bv)
ctx.fill()
})
Fil
06/24/2023, 12:12 PMfitExtent(dimensions, {type:"Sphere"})
it should work. But I can't help you much if you don't share the codesicheng mao
06/24/2023, 12:14 PMsicheng mao
06/24/2023, 12:18 PMsicheng mao
06/24/2023, 12:23 PMsicheng mao
06/24/2023, 12:24 PMsicheng mao
06/24/2023, 1:34 PMpnpm i
and then pnpm dev
, the code is in src/component/celestial.vue
sicheng mao
06/24/2023, 1:50 PMFil
06/24/2023, 2:07 PMconst projection = d3.geoEquirectangular()
.fitExtent([[0, 0], [width, height]], {type: "MultiPoint", coordinates: [[-30, 0], [0, 30], [0, -30], [30, 0]]})
.rotate([30, 0]);
sicheng mao
06/24/2023, 3:21 PMsicheng mao
06/24/2023, 9:05 PM[-30, -30],[-30, 30], [30,-30], [30,30]
instead has the same effect, even use [-30,30], [-30,30]
produces the same result.sicheng mao
06/24/2023, 9:16 PMsicheng mao
06/24/2023, 9:18 PMsicheng mao
06/24/2023, 10:40 PMFil
06/25/2023, 9:29 AMsicheng mao
06/25/2023, 9:37 AMsicheng mao
06/25/2023, 9:40 AMFil
06/25/2023, 9:56 AMsicheng mao
06/25/2023, 4:18 PM