{"spec_id":"lightcurve-transit","library":"echarts","language":"javascript","code":"// anyplot.ai\n// lightcurve-transit: Astronomical Light Curve\n// Library: echarts 5.5.1 | JavaScript 22.22.3\n// Quality: 86/100 | Created: 2026-06-20\n\n//# anyplot-orientation: landscape\n\nconst t = window.ANYPLOT_TOKENS;\n\n// --- Data (deterministic LCG) -----------------------------------------------\nlet seed = 42;\nfunction lcg() {\n    seed = (seed * 1664525 + 1013904223) >>> 0;\n    return seed / 0x100000000;\n}\nfunction randn() {\n    const u1 = Math.max(lcg(), 1e-10);\n    const u2 = lcg();\n    return Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);\n}\n\nfunction transitModel(phase) {\n    const depth = 0.012, center = 0.5, halfDur = 0.05, halfFlat = 0.035;\n    const d = Math.abs(phase - center);\n    if (d >= halfDur) return 1.0;\n    if (d <= halfFlat) return 1.0 - depth;\n    return 1.0 - depth * (halfDur - d) / (halfDur - halfFlat);\n}\n\nconst N = 400;\nconst scatterData = [];\nconst errorData = [];\n\nfor (let i = 0; i < N; i++) {\n    const phase = i / N;\n    const model = transitModel(phase);\n    const err = 0.0018 + lcg() * 0.0008;\n    const flux = model + randn() * err;\n    scatterData.push([phase, +flux.toFixed(5)]);\n    errorData.push([phase, +flux.toFixed(5), +err.toFixed(5)]);\n}\n\nconst modelCurve = [];\nfor (let i = 0; i <= 500; i++) {\n    const phase = i / 500;\n    modelCurve.push([phase, +transitModel(phase).toFixed(5)]);\n}\n\n// --- Init -------------------------------------------------------------------\nconst chart = echarts.init(document.getElementById(\"container\"));\n\n// --- Option -----------------------------------------------------------------\nchart.setOption({\n    animation: false,\n    color: t.palette,\n    backgroundColor: \"transparent\",\n    title: {\n        text: \"Astronomical Light Curve · lightcurve-transit · javascript · echarts · anyplot.ai\",\n        left: \"center\",\n        top: 20,\n        textStyle: { color: t.ink, fontSize: 18 }\n    },\n    legend: {\n        right: 80,\n        top: 75,\n        orient: \"vertical\",\n        textStyle: { color: t.inkSoft, fontSize: 14 },\n        itemGap: 14,\n        backgroundColor: t.elevatedBg,\n        borderColor: t.grid,\n        borderWidth: 1,\n        padding: [10, 16],\n        data: [\n            { name: \"Photometry\", icon: \"circle\" },\n            { name: \"Transit Model\", icon: \"path://M0,8 L30,8\" }\n        ]\n    },\n    grid: { left: 110, right: 215, top: 95, bottom: 80 },\n    xAxis: {\n        type: \"value\",\n        name: \"Orbital Phase\",\n        nameLocation: \"middle\",\n        nameGap: 40,\n        nameTextStyle: { color: t.inkSoft, fontSize: 14 },\n        min: 0,\n        max: 1,\n        axisLabel: { color: t.inkSoft, fontSize: 13 },\n        axisLine: { lineStyle: { color: t.inkSoft } },\n        axisTick: { lineStyle: { color: t.inkSoft } },\n        splitLine: { show: false }\n    },\n    yAxis: {\n        type: \"value\",\n        name: \"Relative Flux\",\n        nameLocation: \"middle\",\n        nameGap: 60,\n        nameTextStyle: { color: t.inkSoft, fontSize: 14 },\n        scale: true,\n        axisLabel: {\n            color: t.inkSoft,\n            fontSize: 13,\n            formatter: v => v.toFixed(3)\n        },\n        axisLine: { lineStyle: { color: t.inkSoft } },\n        axisTick: { lineStyle: { color: t.inkSoft } },\n        splitLine: { lineStyle: { color: t.grid } }\n    },\n    series: [\n        {\n            type: \"custom\",\n            silent: true,\n            z: 2,\n            data: errorData,\n            renderItem(params, api) {\n                const cx = api.coord([api.value(0), api.value(1)]);\n                const top = api.coord([api.value(0), api.value(1) + api.value(2)]);\n                const bot = api.coord([api.value(0), api.value(1) - api.value(2)]);\n                const cap = 3;\n                return {\n                    type: \"group\",\n                    children: [\n                        {\n                            type: \"line\",\n                            shape: { x1: cx[0], y1: top[1], x2: cx[0], y2: bot[1] },\n                            style: { stroke: t.palette[0], lineWidth: 1, opacity: 0.4 }\n                        },\n                        {\n                            type: \"line\",\n                            shape: { x1: cx[0] - cap, y1: top[1], x2: cx[0] + cap, y2: top[1] },\n                            style: { stroke: t.palette[0], lineWidth: 1, opacity: 0.4 }\n                        },\n                        {\n                            type: \"line\",\n                            shape: { x1: cx[0] - cap, y1: bot[1], x2: cx[0] + cap, y2: bot[1] },\n                            style: { stroke: t.palette[0], lineWidth: 1, opacity: 0.4 }\n                        }\n                    ]\n                };\n            }\n        },\n        {\n            type: \"scatter\",\n            name: \"Photometry\",\n            data: scatterData,\n            symbol: \"circle\",\n            symbolSize: 5,\n            itemStyle: { color: t.palette[0], opacity: 0.75 },\n            z: 3,\n            markArea: {\n                silent: true,\n                z: 1,\n                itemStyle: { color: t.inkSoft, opacity: 0.08 },\n                label: {\n                    show: true,\n                    position: \"insideTop\",\n                    formatter: \"Transit Window\",\n                    color: t.inkSoft,\n                    fontSize: 11\n                },\n                data: [[{ xAxis: 0.45 }, { xAxis: 0.55 }]]\n            },\n            markLine: {\n                silent: true,\n                symbol: \"none\",\n                lineStyle: { color: t.inkSoft, type: \"dashed\", width: 1, opacity: 0.5 },\n                label: {\n                    position: \"insideStartTop\",\n                    formatter: \"depth ≈ 1.2%\",\n                    color: t.inkSoft,\n                    fontSize: 11\n                },\n                data: [{ yAxis: 0.988 }]\n            }\n        },\n        {\n            type: \"line\",\n            name: \"Transit Model\",\n            data: modelCurve,\n            symbol: \"none\",\n            lineStyle: { color: t.palette[1], width: 2.5 },\n            z: 4\n        }\n    ]\n});\n"}