Published
Edited
Apr 9, 2021
1 star
Insert cell
Insert cell
penrose = require("@penrose/core")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
baseURL = "https://raw.githubusercontent.com/penrose/penrose/main/examples/"
Insert cell
registry = (await fetch(baseURL + "registry.json")).json()
Insert cell
Insert cell
domains = objToMap(registry.domains)
Insert cell
substances = objToMap(registry.substances, ([key, d]) => d.domain === _domain.key)
Insert cell
styles = objToMap(registry.styles, ([key, d]) => d.domain === _domain.key)
Insert cell
objToMap = (obj, filter = () => true) => new Map(
Object.entries(obj)
.filter(filter)
.map(([key, value]) => ([value.name, {key, ...value}]))
)
Insert cell
Insert cell
function highlight(editor) {
editor.textContent = editor.textContent;
highlightjs.registerLanguage('penrose-dsl', penroseLanguage('dsl'))
highlightjs.registerLanguage('penrose-sty', penroseLanguage('sty'))
highlightjs.registerLanguage('penrose-sub', penroseLanguage('sub'))
highlightjs.highlightElement(editor)
}
Insert cell
function penroseLanguage(type) {
let keywords = null;

if (type === "dsl") {
keywords = "type value constructor function predicate notation Prop";
}
if (type === "sty") {
keywords =
"forall where with delete as true false layer encourage ensure override bove below";
}
if (type === "sub") {
keywords = "AutoLabel Label NoLabel All";
}

const COMMENT = {
variants: [highlightjs.COMMENT('--', '$'), highlightjs.C_BLOCK_COMMENT_MODE]
};
return function(hljs) {
return {
name: `Penrose-${type}`,
alias: [type],
aliases: ['penrose'],
keywords: keywords,
contains: [COMMENT, highlightjs.QUOTE_STRING_MODE]
};
};
}
Insert cell
editorStyle = `
border: 1px solid #eee;
background: #fafafa;
font-family: Menlo,Consolas,monospace;
font-size: 13px;
padding: 10px;
tab-size: 4;
line-hieght: 1.4;
overflow-wrap: break-word;
max-height: 250px;
`
Insert cell
Insert cell
import {Radio} from "@observablehq/inputs"
Insert cell
import {Editor, highlightjs} from '@cmudig/editor'
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more