Notebooks 2.0 is here.

Published
Edited
Jan 22, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
tanStrength = 4
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
class PluginError extends Error {
constructor(message, type="GENERAL_ERROR") {
super(message);
this.error = message;
this.type = this.errorTypes[type];
}
static errorTypes = {
"GENERAL_ERROR":1,
"WRONG_TYPE":2,
"METHOD_NOT_IMPLEMENTED":3
}
}
Insert cell
Insert cell
class Plugin {
pluginTypes = ["quoteParameter"];
constructor(name,type) {
this.name = name;
if (this.pluginTypes.includes(type)) {
this.type = type;
} else {
throw new PluginError("Wrong plugin type", PluginError.errorTypes["WRONG_TYPE"]);
}
}

getName() {
return this.name;
}

getType() {
return this.type;
}
getCallMethodName() {
throw new PluginError("Method not implemented", PluginError.errorTypes["METHOD_NOT_IMPLEMENTED"]);
}
}
Insert cell
Insert cell
class QuotePlugin extends Plugin {
constructor(name){
super(name,"quoteParameter");
this.name = name;
}

getCallMethodName() {
return {
name:"getParameter",
parameters:[
"supply"
]
};
}

getParameter(supply) {
throw new PluginError("Method not implemented", PluginError.errorTypes["METHOD_NOT_IMPLEMENTED"]);
}
}
Insert cell
Insert cell
class LinearQuotePlugin extends QuotePlugin {
constructor(){
super("linear");
}

getParameter(supply) {
return supply;
}
}
Insert cell
Insert cell
Insert cell
class TangentialQuotePlugin extends QuotePlugin {
constructor() {
super("tangential");
}

getCallMethodName() {
return {
name:"getParameter",
parameters:[
"supply",
"strength"
]
};
}
getParameter(supply,strength=4) {
if (strength<=2) strength = 2;
if (strength>=8) strength = 8;
return Math.tanh(2*supply**strength);
}
}
Insert cell
Insert cell
Insert cell
Insert cell
testPluginWrong = new Plugin("testName","testType")
Insert cell
Insert cell
testPluginCorrect = new Plugin("testName","quoteParameter")
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