Udpate default script to a random svg line graph generator
This commit is contained in:
32
app.py
32
app.py
@@ -41,16 +41,34 @@ API_URL = 'https://isolator.peterstockings.com/execute' #'http://127.0.0.1:5000/
|
|||||||
DEFAULT_FUNCTION_NAME = 'foo'
|
DEFAULT_FUNCTION_NAME = 'foo'
|
||||||
|
|
||||||
DEFAULT_SCRIPT = """async (req) => {
|
DEFAULT_SCRIPT = """async (req) => {
|
||||||
console.log(`Hello ${environment.name}`)
|
console.log(`Method:${req.method}`)
|
||||||
return HtmlResponse(
|
console.log(`Generating ${environment.lines} random lines...`)
|
||||||
`<div>
|
let svgContent = "";
|
||||||
<h1>Method:${req.method}</h1>
|
|
||||||
<h3>Hello ${environment.name}</h3>
|
for (let i = 0; i < environment.lines; i++) {
|
||||||
</div>`)
|
console.log(i)
|
||||||
|
let pathD = "M2 " + Math.random() * 79;
|
||||||
|
let circles = "";
|
||||||
|
|
||||||
|
for (let x = 12; x <= 202; x += 10) {
|
||||||
|
let y = Math.random() * 79
|
||||||
|
pathD += ` L${x} ${y}`;
|
||||||
|
circles += `<circle cx="${x}" cy="${y}" r="1"></circle>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
let pathColor = `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${Math.random() * 255})`;
|
||||||
|
svgContent += `
|
||||||
|
<g style="fill: ${pathColor}; stroke: ${pathColor};">
|
||||||
|
<path d="${pathD}" fill="none" stroke="${pathColor}"></path>
|
||||||
|
${circles}
|
||||||
|
</g>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HtmlResponse(`<svg viewBox="0 0 204 79" preserveAspectRatio="none">${svgContent}</svg>`);
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
DEFAULT_ENVIRONMENT = """{
|
DEFAULT_ENVIRONMENT = """{
|
||||||
"name": "Peter"
|
"lines": 3
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
def map_isolator_response_to_flask_response(response):
|
def map_isolator_response_to_flask_response(response):
|
||||||
|
|||||||
Reference in New Issue
Block a user