Although it is not officially provided as an API by Desmos and therefore not documented, there is a very useful method called GraphingCalculator.controller.dispatch() that allows you to make Desmos perform various actions. I'm not sure if there's much demand for this, but I've worked hard to decipher the Desmos source code, so I'm leaving the results here as a memo.
Below, Calc refers to the return value of Desmos.GraphingCalculator().
Calc.controller.dispatch({ type: string, ...options })By doing this, you can make Desmos perform various actions. The required optionswill vary depending on the type.
These are examples that aren't possible with the standard API but seem quite handy.
// Insert an expression at specified index
Calc.controller.dispatch({
type: "insert-item-at-index",
state: {
id: Calc.controller.generateId(),
type: "expression",
latex: "a=1"
},
index: 2
})
// Toggle Ticker
Calc.controller.dispatch({ type:"toggle-ticker" })
// Execute action
Calc.controller.dispatch({ type: "action-single-step", id: "1" })Here is a list of available type values along with the required arguments. The type annotations are just rough guesses, so they may be quite unreliable. For unclear cases, I've used object or any.
There’s a good chance some of this is incorrect, so if you notice any mistakes, please let me know through the contact. Also, note that these may change significantly in future updates.
type argument =
| { type: "render" }
| { type: "undo" }
| { type: "redo" }
| { type: "clear-undoredo-history" }
| {
type: "on-special-key-pressed";
key: "Enter" | "Up" | "PageUp" | "Down" | "PageDown" | "Backspace" | "Delete";
}
| { type: "select-previous-expression" }
| { type: "select-next-expression" }
| { type: "toggle-label-for-all-selected-points" }
| { type: "set-label-state-for-selected-points"; state: object }
| { type: "move-selected-item-to-expression-list" }
| {
type: "update-all-selected-items";
update: {
prop:
| "folderId"
| "visible"
| "color"
| "colorLatex"
| "showLabel"
| "label"
| "dragMode"
| "lineWidth"
| "lineOpacity"
| "lineStyle"
| "strictIntersection"
| "disableGraphInteractions";
value: any;
};
}
| { type: "delete-all-selected-items" }
| { type: "upward-delete-selected-expression" }
| { type: "downward-delete-selected-expression" }
| { type: "table-show-more-rows"; id: string }
| { type: "navigate-table-by-key"; id: string; key: string }
| {
type: "delete-item-and-animate-out";
id: string;
setFocusAfterDelete: boolean;
}
| {
type: "finish-deleting-item-after-animation";
id: string;
setFocusAfterDelete: boolean;
}
| { type: "expression-zoom-fit"; id: string; focusAfterTap: boolean }
| { type: "expression-zoom-fit-residuals"; id: string; focusAfterTap: boolean }
| { type: "set-expression-properties-from-api"; id: string; properties: object }
| { type: "add-item-to-end-from-api"; state: object }
| { type: "duplicate-expression"; id: string }
| { type: "set-highlighted-expressions"; ids: string[] }
| { type: "paste-expression"; data: object[] }
| { type: "duplicate-folder"; id: string; StringDecoder: any }
| {
type: "insert-item-at-index";
state: object;
index: number;
focus?: boolean;
folderId?: string;
}
| { type: "new-expression-at-end" }
| { type: "new-expression" }
| { type: "new-note" }
| { type: "new-folder" }
| { type: "new-images"; files: any[] }
| { type: "new-inference" }
| { type: "open-inference-wizard" }
| { type: "set-inference-wizard-data"; update: object[] }
| { type: "set-inference-object-data"; id: string; update: object[] }
| { type: "set-inference-wizard-sample-data" }
| { type: "change-image"; id: string; files: any[] }
| { type: "new-table" }
| { type: "paste-table"; data: any }
| { type: "convert-or-create-table"; index: number }
| { type: "insert-several-expressions"; expressions: object[] }
| { type: "append-number-list"; latex: string }
| { type: "remove-item-by-id"; id: string }
| { type: "replace-item-at-index"; state: object; index: number; focus?: boolean }
| { type: "create-sliders-for-item"; id: string; variables: any; doNotChangeFocus: boolean }
| { type: "create-sliders-for-ticker"; variables: any }
| { type: "convert-image-to-draggable"; id: string }
| {
type: "start-dragdrop";
dragTarget: { calcId: string; type: string };
grabPt: { x: number; y: number };
mousePt: number;
}
| { type: "update-dragdrop"; mousePt: number }
| { type: "stop-dragdrop" }
| { type: "set-selected-id"; id: string; state: string }
| { type: "set-all-selected-ids"; ids: string[] }
| { type: "toggle-selected-with-multi-select"; id: string; state: any }
| { type: "set-selected-index"; index: number }
| { type: "set-none-selected" }
| { type: "commit-tentative-selection" }
| { type: "clear-tentative-selection" }
| {
type: "set-focus-location";
location?: { type: "expression" | "image" | "table" | "graph-paper" };
}
| { type: "focus-first-expression" }
| { type: "move-focus-to-item"; id: string; where: any }
| { type: "blur-focus-location"; location: { type: string } }
| { type: "set-folder-collapsed"; id: string; isCollapsed: boolean }
| { type: "set-all-folders-collapsed"; isCollapsed: boolean }
| { type: "set-item-secret"; id: string; isSecret: boolean }
| { type: "set-item-in-front-of-everything"; id: string; inFrontOfEverything: boolean }
| { type: "set-item-readonly"; id: string; readonly: any }
| { type: "set-item-disable-graph-interactions"; id: string; disableGraphInteractions: any }
| {
type: "set-tablecolumn-disable-graph-interactions";
tableId: string;
columnId: string;
disableGraphInteractions: any;
}
| { type: "set-tablecolumn-color"; tableId: string; columnId: string; color: string }
| { type: "set-tableregression-color"; tableId: string; color: string }
| { type: "set-tablecolumn-colorlatex"; tableId: string; columnId: string; colorLatex: string }
| { type: "set-cdf-props"; id: string; props: any }
| { type: "toggle-item-hidden"; id: string }
| { type: "toggle-tablecolumn-hidden"; tableId: string; columnId: string }
| { type: "toggle-item-settings-menu"; menu: object }
| { type: "close-item-settings-menu" }
| { type: "toggle-fraction-evaluation"; id: string }
| { type: "set-item-label"; id: string; label: string }
| { type: "set-item-showlabel"; id: string; showLabel: any }
| { type: "set-item-color"; id: string; color: string }
| { type: "set-item-description"; id: string; description: string }
| { type: "set-item-fill"; id: string; fill: any }
| { type: "set-image-opacity"; id: string; opacity: number }
| { type: "set-image-in-foreground"; id: string; foreground: any }
| { type: "image-upload-error"; token: any }
| {
type: "image-upload-success";
token: any;
id: string;
url: string;
width: number;
height: number;
name: string;
}
| { type: "image-load-success"; id: string }
| { type: "image-load-error"; id: string }
| { type: "image-retry-loading"; id: string }
| { type: "set-item-dragmode"; id: string; dragMode: any }
| { type: "set-tablecolumn-dragmode"; tableId: string; columnId: string; dragMode: any }
| { type: "set-tablecolumn-points"; tableId: string; columnId: string; bool: any }
| { type: "set-tablecolumn-lines"; tableId: string; columnId: string; bool: any }
| { type: "set-tablecolumn-linestyle"; tableId: string; columnId: string; lineStyle: any }
| { type: "set-tablecolumn-linewidth"; tableId: string; columnId: string; lineWidth: any }
| { type: "set-tablecolumn-lineopacity"; tableId: string; columnId: string; lineOpacity: any }
| { type: "set-tablecolumn-pointsize"; tableId: string; columnId: string; pointSize: any }
| { type: "set-tablecolumn-pointoutline"; tableId: string; columnId: string; pointOutline: any }
| { type: "set-tablecolumn-pointopacity"; tableId: string; columnId: string; pointOpacity: any }
| { type: "set-tablecolumn-pointstyle"; tableId: string; columnId: string; pointStyle: any }
| { type: "set-item-points"; id: string; points: any }
| { type: "set-item-pointstyle"; id: string; pointStyle: any }
| { type: "set-item-lines"; id: string; lines: any }
| { type: "set-item-extend-to-3D"; id: string; extendTo3D: boolean }
| { type: "set-item-linestyle"; id: string; lineStyle: any }
| { type: "set-item-arrow-mode"; id: string; value: any }
| { type: "set-item-label-dropdown-open"; id: string; open: boolean }
| { type: "set-item-fillopacity"; id: string; fillOpacity: number }
| { type: "set-item-surfaceopacity"; id: string; surfaceOpacity: number }
| { type: "set-item-lineopacity"; id: string; lineOpacity: any }
| { type: "set-item-pointopacity"; id: string; pointOpacity: any }
| { type: "set-item-pointoutline"; id: string; pointOutline: any }
| { type: "set-item-pointsize"; id: string; pointSize: any }
| { type: "set-item-linewidth"; id: string; lineWidth: any }
| { type: "set-item-resolution"; id: string; resolution: any }
| { type: "set-item-colorlatex"; id: string; colorLatex: string }
| { type: "set-item-labelSize"; id: string; labelSize: any }
| { type: "set-item-labelangle"; id: string; labelAngle: any }
| { type: "set-item-label-orientation"; id: string; labelOrientation: any }
| { type: "set-suppress-text-outline"; id: string; suppressTextOutline: any }
| { type: "set-item-interactive-label"; id: string; interactiveLabel: any }
| { type: "set-item-editable-label-mode"; id: string; editableLabelMode: any }
| { type: "plot-residuals"; id: string }
| { type: "toggle-logmode"; id: string }
| { type: "set-item-latex"; id: string; latex: string; source?: "user-edit" }
| { type: "set-visualization-prop"; id: string; prop: any; value: any }
| { type: "set-clickableinfo-prop"; id: string; prop: any; value: any }
| { type: "set-clickableinfo-rule-latex"; id: string; latex: string }
| { type: "set-folder-title"; id: string; title: string }
| { type: "set-image-mq-attribute"; id: string; attribute: any; latex: string }
| { type: "set-image-name"; id: string; name: string }
| { type: "set-image-draggable"; id: string; draggable: boolean }
| { type: "update-degree-mode"; mode: string }
| { type: "set-graph-settings"; xAxisScale: any; yAxisScale: any; backgroundColor3d: any }
| { type: "set-polar-mode"; polarMode: boolean }
| { type: "set-domain-minlatex"; id: string; latex: string; variable: any }
| { type: "set-domain-maxlatex"; id: string; latex: string; variable: any }
| { type: "set-note-text"; id: string; text: string }
| {
type: "set-edit-list-mode";
isEditListMode: boolean;
focusExpressionList: any;
}
| { type: "set-ghost-mode"; value: any }
| { type: "set-projector-mode"; value: any }
| { type: "set-inverted-colors"; value: any }
| { type: "set-tablecell-latex"; tableId: string; cell: any; latex: string }
| { type: "set-state"; state: any; opts: any }
| { type: "set-blank"; degreeMode: any; opts: any }
| { type: "restore-history"; history: any }
| { type: "clear-unsaved-changes" }
| { type: "reset-graph" }
| { type: "clear-graph" }
| { type: "hide-progress-update-legend" }
| { type: "evaluator-progress-update" }
| {
type: "on-evaluator-changes";
changes: any;
timingData: any;
graphData: any;
eventUpdates: any;
dependencyOrder: any;
}
| { type: "add-helper-expression"; state: any }
| { type: "tick"; time: number }
| { type: "tick-ticker"; time: number }
| { type: "adjust-slider-by-keyboard"; id: string; adjustment: any }
| { type: "adjust-slider-by-dragging-thumb"; id: string; target: any }
| { type: "set-slider-minlatex"; id: string; latex: string }
| { type: "set-slider-maxlatex"; id: string; latex: string }
| { type: "set-slider-steplatex"; id: string; latex: string }
| { type: "set-slider-dragging"; id: string; dragging: any }
| { type: "play-slider-from-min"; id: string }
| { type: "set-slider-isplaying"; id: string; isPlaying: boolean }
| { type: "set-slider-loopmode"; id: string; loopMode: any }
| { type: "set-slider-animationperiod"; id: string; animationPeriod: any }
| { type: "show-expressions-list"; focusHideIcon: any }
| { type: "hide-expressions-list"; focusShowIcon: any }
| { type: "open-drawer" }
| { type: "re-randomize" }
| { type: "resize-exp-list"; expListWidth: any }
| { type: "toast/show"; toast: any }
| { type: "toast/close" }
| { type: "toast/undo" }
| { type: "toast/learn-more" }
| { type: "start-moving-points"; points: any }
| { type: "stop-moving-points"; points: any }
| {
type: "on-move-points";
points: any;
previousScreenPts: any;
screenPts: any;
projection: any;
transform: any;
keyboardDirection: any;
}
| { type: "commit-user-requested-viewport"; viewport: any }
| { type: "commit-user-requested-rotation"; worldRotation3D: any; axis3D: any; speed3D: any }
| { type: "toggle-lock-viewport" }
| { type: "toggle-complex-mode" }
| {
type: "set-axis-limit-latex";
limit: "xmin" | "xmax" | "ymin" | "ymax" | "zmin" | "zmax";
latex: string;
updateYZAlso: boolean;
}
| { type: "toggle-graph-settings"; focusOnOpen: boolean }
| { type: "close-graph-settings"; focusIconAfterClose: boolean }
| { type: "toggle-add-expression"; focusOnOpen: boolean }
| { type: "close-add-expression"; focusIconAfterClose: boolean }
| { type: "ui/container-resized"; size: { width: number; height: number } }
| { type: "enter-printmode" }
| { type: "exit-printmode" }
| { type: "expression-size-exceeded" }
| { type: "keypad/set-layout"; layout: any }
| { type: "keypad/set-minimized"; minimized: any }
| { type: "keypad/type-text"; text: string }
| { type: "keypad/press-key"; key: string }
| { type: "keypad/audio-trace"; command: any }
| { type: "set-audio-trace-speed"; speed: number }
| { type: "keypad/custom-command"; command: any }
| { type: "keypad/shift" }
| { type: "keypad/123" }
| { type: "keypad/abc" }
| { type: "keypad/audio" }
| { type: "keypad/functions" }
| { type: "grapher/drag-start" }
| { type: "grapher/drag-move" }
| { type: "grapher/drag-end" }
| { type: "open-on-web" }
| { type: "file-is-dragged-over" }
| { type: "file-is-not-dragged-over" }
| { type: "zoom"; direction: any }
| { type: "set-hovered-image"; id: string; url: string }
| { type: "set-depressed-image"; id: string; url: string }
| { type: "clickable-item-clicked"; id: string; listIndex: number }
| { type: "action-single-step"; id: string }
| { type: "update-expression-search-str"; str: string }
| { type: "update-expression-replace-str"; str: string }
| { type: "rename-identifier-global"; search: string; replace: string }
| { type: "rename-identifier-in-item"; id: string; search: string; replace: string }
| { type: "update-ticker-handlerlatex"; latex: string }
| { type: "update-ticker-minsteplatex"; latex: string }
| { type: "set-braille-mode"; mode: any }
| { type: "set-six-key-input"; useSixKeyInput: any }
| { type: "set-show-constructions-open"; open: any; setFocus: any }
| {
type: "select-geo-tool";
tool: string;
forceSingleUse: any;
focusGraphPaper: any;
}
| { type: "cancel-geo-toolplay" }
| { type: "update-click-to-insert-mode"; clickToInsertMode: any }
| { type: "commit-geo-objects"; committed: any; clearToolAndSelection: any; toolIdToLatex: any }
| { type: "rename-identifier"; from: any; to: any; geoFolder: any }
| { type: "set-active-token"; style: any; identifier: any }
| { type: "unset-active-token"; style: any; identifier: any }
| {
type: "select-expression-that-defines-token";
identifier: any;
multiSelectMode: any;
toggle: any;
}
| { type: "close-expression-search" }
| { type: "open-expression-search"; latex: string; rename: any }
| { type: "open-ticker" }
| { type: "close-ticker" }
| { type: "toggle-ticker" }
| { type: "set-tool-preview-state"; state: any }
| { type: "apply-transformation-to-selected"; assignmentLatex: any }
| { type: "set-geometry-toolbar"; toolbar: any }
| { type: "set-geometry-custom-toolbar-setting"; tool: any; value: any }
| { type: "set-author-mode"; enabled: boolean }
| { type: "set-translucent-surfaces"; value: any }
| { type: "set-perspective-distortion"; value: any }
| { type: "mute-global" }
| { type: "unmute-global" }
| { type: "mark-too-complex-for-gl"; errors: any; fixed: any }
| { type: "update-legacy-random-seed-behavior" }
| { type: "export-latex-to-explist"; latex: string; color: any; indexToInsert: number }
| { type: "create-table-regression"; tableId: string; columnIds: string[]; regressionType: any }
| { type: "remove-table-regression"; tableId: string }
| { type: "update-table-regression"; tableId: string; update: any }
| { type: "export-table-regression"; tableId: string; mode: any }
| { type: "export-inference-item-to-expression-list"; item: any; id: string }
| { type: "set-table-regression-dropdown-open"; tableId: string; open: boolean }
| { type: "set-popover-open"; open: boolean; guid: string }
| { type: "expand-evaluation"; id: string }
| { type: "collapse-evaluation"; id: string }
| { type: "run-within-dispatch"; cb: () => void };