Default Font for all TextBlocks


The documentation says that the default font for TextBlocks is “10px sans-serif”.
Is there a way to override this default without having to specify it for every TextBlock?


I’m afraid not. Though we have considered making this an option in the past and might do so for 1.5. For now you’ll have to set it for every textblock.

Often when there are a lot of defaults you want to set on something like each TextBlock, we use a function that returns an object with the set of defaults. For instance in org chart editor sample we have this:

// This function provides a common style for most of the TextBlocks.
// Some of these values may be overridden in a particular TextBlock.
function textStyle() {
  return { font: "9pt  Segoe UI,sans-serif", stroke: "white" };

Then we start each textblock by calling it, like the three times its used here:

        $(go.TextBlock, textStyle(),  // the name
            row: 0, column: 0, columnSpan: 5,
            font: "12pt Segoe UI,sans-serif",
            editable: true, isMultiline: false,
            minSize: new go.Size(10, 16)
          new go.Binding("text", "name").makeTwoWay()),
        $(go.TextBlock, "Title: ", textStyle(),
          { row: 1, column: 0 }),
        $(go.TextBlock, textStyle(),

Thanks Simon, that will work too

By the way, although calling a function once per TextBlock might seem slow, that’s only needed when building the template.

At run-time, when the template is copied to create each Node (or Link), there’s no overhead involved, because it no longer matters how the template was constructed.

Thanks Walter, that’s good to know