Divooka Graphs

A Methodox Office document can carry Divooka programs, graphs of nodes and wires, as a third language beside Lua and C#. A document's graphs are kept inside it as .dvj documents, the text form of the .dvk that Divooka Compute opens, and each graph plays one of the parts of the programming model:

Graph Part Used as
A Function graph named in capitals a Function =DVK.LOANPAYMENT(B1, B2, B3) in Formula; LOANPAYMENT(param.Principal, param.Rate, param.Years) as an Impulse smart object
A Routine a Command Run in Tools ▸ Scripts; --script Report.dvj#StampRegion on the command line
An Events graph event handlers runs when the document is opened, saved, edited, recalculated, refreshed or shown

Graphs run on Divooka's No-Reflection Interpreter, which prepares a graph once and then calls it as often as needed, so a column of two hundred cells calling one graph prepares it once.

The graph editor

Tools ▸ Scripts (Alt+F11) lists a document's graph documents beside its Lua, C# and Python scripts. Select a .dvj and the graph opens on a canvas where the text editor would be, one tab per graph: Function graphs show an fx icon, Routines a play icon, the Events graph a bell. The editor's tools join the pane's strip.

The graph editor in Formula's Scripts tab: the PRICE Function graph of the Graph Editor example, with the pointer over the Add node and its tooltip naming the member, its toolbox and package, what it does and what each input means

  • Moving about. Drag with the middle button, or with Alt or Space held, to pan; the wheel zooms at the pointer; F fits the graph. A long graph opens at its start at a readable size.
  • Adding nodes. Right-click the empty canvas, or use the + button, to open a searchable palette there. It lists only what the document's edition runs, value nodes (Number, Text Line, Text, Boolean, Comment), Branch in Routines and Events graphs, the event type's events in an Events graph, and each Document Parameter by name, placed as its read and wired to the graph's This Document. Overloads are told apart by their inputs. Calls that change the document are offered only in Routines and Events graphs, never in a Function. Dragging a wire out of a pin and letting go on the empty canvas opens the palette there, and the chosen node is wired to it.
  • What a node is. Hover over a node to see what it calls, the toolbox and package it comes from, as Divooka Compute shows them, and its documentation: what it does, what each input means and what it returns. That is how to find out what a node such as the Loan Letter's Amortization Schedule is.
  • Wiring and editing. Drag from pin to pin to connect; a wire whose types do not fit is refused, and the strip says why. Alt-click a wire, draw across it, or right-click it and choose Delete Wire, to disconnect. Literals are edited on the pins.
  • The node menu. Right-click a node for Cut (Ctrl+X), Copy (Ctrl+C), Paste (Ctrl+V), Duplicate (Ctrl+D), Rename and Delete (Delete). Copied nodes keep the wires among them and paste into another graph, or another document's, as well as this one. A graph's Input and Output (or Begin and Return) cannot be deleted.
  • A graph's inputs and outputs. Edit Inputs on the menu of a graph's Input or Output node, Inputs and Outputs on its tab's menu, or the strip's interface button changes a Function's inputs and outputs, or a Routine's inputs, after the graph exists, in the same form a new graph takes them (Principal, Rate, Years=30); wires stay on the ports whose names are kept. The tab's menu also has Rename Graph and Delete Graph.
  • New graphs. The layers button adds a Function (with its inputs and outputs, such as Principal, Rate, Years=30; name:text for inputs of other types), a Routine, or the document's Events graph on a chosen event type.
  • Edits go into the document by themselves. A moment after each change on the canvas (never in the middle of a drag), the graph is written into the document, and the cells and smart objects that use it recalculate at once: change Add's Summand1 in the Graph Editor example and B2 follows. Each change is a step of the window's Edit ▸ Undo, which takes it back and moves the canvas back with it.
  • Errors lead to their node. When a cell's or an event handler's error names a node, the red bar over the document has a button that opens the graph with that node selected. A Routine that fails on a node selects it after the run. Nodes the edition does not run are marked on the canvas, with the reason on hover.

Open in Divooka Compute, the external-link button, opens the graph in Divooka Compute, the full Divooka editor, when one is installed; otherwise the button is disabled and its tooltip says Divooka Compute is not installed. Editions says where Methodox Office looks for it. A copy of the document goes with the graph, so in Compute This Document is that copy and the add-node menu lists its parameters under Office ▸ Parameters; Methodox Office also sends its Office nodes, so Compute offers them without installing anything. Save in Compute and the graph comes back into the document as one undoable change; if the document's copy was changed meanwhile, Methodox Office asks which to keep. A graph using nodes the Standard edition does not run is kept as Compute wrote it, and shows why it does not run. See the document session.

Function graphs

A Function graph whose name is in capitals is a worksheet function: LOANPAYMENT in a workbook's Loan.dvj is called as =DVK.LOANPAYMENT(...). A graph that returns a table spills it, as =DVK.AMORTIZE(B1, B2, B3) spills a loan's schedule, and a graph that returns a picture shows it in its cell, fitted and in proportion, as Excel's IMAGE does; the cell's value is Image W×H. In Impulse and Expo the same graph is the source of a smart object, called by name with numbers, quoted text, param.Name and smart.Name as arguments; a graph that returns a picture, such as a chart, fills an image smart object. See Worksheet Functions and Smart objects.

A Function graph that uses a fetching node is a data-source Function, which fetches only when the document is refreshed (Data ▸ Refresh Data, Ctrl+Shift+F5, in Formula; Refresh All, Ctrl+Shift+F9, in Impulse and Expo) or a parameter it reads changes, and answers from what it last fetched in between.

Routines

A Routine graph is a Command: it changes the document, as one undoable step, when run from Tools ▸ Scripts, where the list beside Run picks which of a graph document's Routines runs, or from the command line:

MethodoxFormula --script "Report.dvj#StampRegion" --open "Region Events.xlsx" --save-as Stamped.xlsx

#Name after the graph document names the Routine to run.

Event handlers

An Events graph implements one of the Office event types, and its handlers run when the document is enabled and the event happens:

Event type Events
Every document Opened, BeforeSave, Saved, ParameterChanged
Workbooks WorkbookOpened, RangeChanged (one range per sheet for each edit), Calculated
Text documents SmartObjectsRefreshed
Presentations SlideShowStarted, SlideShowAdvanced, SlideShowEnded

Each handler runs as one transaction on the document. An event a handler's own changes cause is not delivered back to it, undo and redo raise no events, and more than 64 events in one second pause the handlers, so a handler cannot loop.

The Office nodes

In the Standard edition, a graph may use the Divooka standard library's pure routines (numbers, text, logic, dates, arrays, lists, sets, dictionaries, conversions) and these Office nodes:

Group Nodes
Document This Document (the graph's own document); Open Office Document (a file, outside Methodox Office; inside Office, the graph's own document) and Save Office Document
Parameters Parameter, Number Parameter, Text Parameter, Boolean Parameter, Has Parameter, Parameter Names, each taking the document and naming the parameter it reads; Set Parameter in Commands only
Data HTTP Get, HTTP Get Bytes, Read Text File (through the person's grants); Json Number, Json Numbers, Json Text, Json Texts at a dotted path; Format Url
Tables Columns, Sequence, Number Column, Row Count, Amortization Schedule
Images Chart (a table drawn by Formula's chart engine as a picture), From Bytes
Document edits in Commands, each taking the document: Set Cell, Get Cell, Set Formula, Write Table, Add Sheet, Add Paragraph, Add Slide, Slide Count, Document Name, Document Path, Run Command; and Log

The same nodes are offered in Divooka Compute, so a graph made there is the graph Methodox Office runs. Graphs from earlier releases, whose Parameter nodes found the document by themselves, are brought to this shape when they are read; see Document Parameters.

Methodox Office + Divooka Compute also lets a graph use the Divooka packages installed beside it (see Editions). A graph that uses a node its edition does not allow is refused before it runs, and the message names the graph and the node; so does a failure while it runs, in a cell's message or the Scripts pane's output.

Try it

Examples\Automation has:

  • Loan Calculator.xlsx: =DVK.LOANPAYMENT and a spilled =DVK.AMORTIZE schedule, with the loan's terms as Document Parameters (Tools ▸ Parameters). Open its graph in Divooka Compute to see the same parameters offered there.
  • Loan Letter.docx: the same graphs as smart objects in a letter; hover over the Amortization Schedule node in Loan.dvj to see where it comes from.
  • Weather.xlsx: data-source Functions fetching a forecast from Open-Meteo. The Weather Report draws its 24-hour chart with a graph, and the Market Dashboard redraws itself from an Events graph.
  • Region Events.xlsx: an Events graph logging what changes, and the StampRegion Routine.
  • Graph Editor.xlsx: the Pricing graph to edit, with B2 following every change; a graph that uses a node the Standard edition refuses; and in B10 a Function whose answer is a picture, drawn in its cell.
  • Graphs\*.dvj: the graphs on their own, for Divooka Compute.

Enable each document first; the weather examples then ask to Allow their requests to api.open-meteo.com.