The list below describes past changes and additions to MindFusion JavaScript Pack:
The DiagramDocument class represents a collection of diagram pages or sheets, represented by DiagramPage objects. New pages can be added to the document and existing pages can be removed and reordered by using the addPage and removePage methods respectively. The toJson, saveToXml and saveToString methods of DiagramDocument save all pages in a single file, and respectively the fromJson, loadFromXml and loadFromString methods load all pages from the file. DiagramDocument can also load files created by the serialization methods of Diagram, and will show them in a single page.
DiagramPage is derived from Diagram and only adds a few properties, so any code that processes Diagram objects will work with DiagramPage objects too. A diagram document forwards each event raised by its pages, giving you a chance to use the same handler for events raised by different pages. If a page should implement distinct user interaction or validation logic, it is also possible to attach handlers to the Diagram events inherited by DiagramPage.
A single DiagramPage could be assigned to the diagram property of DiagramView, and that lets you create your own user interface for presenting a list of pages to the user and selecting a current page. The package also includes a TabbedDiagramView that presents all pages of a document in a tabbed user interface where each tab corresponds to a page. The page displayed in the active tab is exposed by the selectedPage property of TabbedDiagramView. The active page can be changed interactively by activating its associated tab. New pages can be added and removed to / from the document through buttons in the tab strip and the pages can be rearranged by dragging their associated tabs with the mouse.
The TabbedDiagramView control is a view that displays DiagramDocument objects. Individual diagram pages can be activated through the tabs located at the top or at the bottom of the control. The appearance and behavior of the tab strip can be customized using various properties. The location and visibility of the strip is specified through the tabAlignment property. Its height can be changed via the tabsSize property. showAddButton and showNavigationButtons determine the visibility of the buttons for interactive tab creation and tab navigation respectively. showTabCloseButtons specifies whether the tabs can be closed interactively, by clicking on the small 'x' button displayed in each tab. allowReorder enables interactive tab rearrangement by mouse dragging.
TabbedDiagramView comes as s a part of the diagramming-controls npm package or the MindFusion.Diagramming.Controls namespace for UMD users.
For npm users simply import the diagramming-controls package:
JavaScript Copy Code |
---|
import * as Controls from '@mindfusion/diagramming-controls'; |
For UMD users, add references to files from distrbution's /umd folder using <script> tags. Note that the order of the scripts matters.
HTML Copy Code |
---|
<!-- core Diagramming --> <!-- for TabbedDiagramView --> |
JavaScript Copy Code |
---|
var doc = new MindFusion.Diagramming.DiagramDocument(); |
or simply
JavaScript Copy Code |
---|
var diagramView = MindFusion.Diagramming.Controls.TabbedDiagramView.create( |
You can specify a title, iconUrl and titleColor for diagram pages by setting the corresponding properties.
Default images for the navigation buttons must be located in an ./icons folder. Alternatively, you can style the control with a predefined css theme, in which case the themes included in the distribution must be located in a ./themes folder and referenced in the head of the HTML document, e.g.
HTML / JavaScript Copy Code |
---|
<link rel="stylesheet" type="text/css" href="themes/business.css" /> |
The RadialTreeLayout class arranges tree levels in concentric circles around the root. The levelDistance property specifies the distance between adjacent circles. The direction property specifies placement of first child node. Set stretchFactor to a value larger than 1 in order to stretch level circles into ellipses, providing more space for the layout when using wider nodes.
The control now supports several ways to zoom using lasso tool:
MindFusion.Diagramming for Blazor allows integrating the JavaScript diagramming API into Blazor applications. It contains a set of .NET wrapper classes, that use Blazor's JSInterop API to create and manipulate the client-side objects. The package provides easy access from C# code to the most of the MindFusion.Diagramming functionality, including different node types, layouts and styling. Additional UI components such as Overview, NodeListView, ZoomControl and Ruler are included too.
New localization files added to distribution:
The @mindfusion/diagramming-react package now contains functional-component wrappers for the DiagramView and auxiliary controls, and has been upgraded to React 18. Old class-component wrappers have been moved to the @mindfusion/diagramming-react-cc package.
Using the functional components looks like this:
JSX Copy Code |
---|
const [diagram] = useState(new Diagramming.Diagram()); |
The DiagramView control exposes a forwardRef, that can be passed on to other controls, such as the Overview and ZoomControl. To obtain a reference to the underlying core controls, use the respective find method of the ref.
The NodeLabel class allows multiple captions to be displayed for a single DiagramNode of any type. Node labels provide a set of properties allowing full customization of their display and positioning. Label position is defined by specifying a pin point and offset from it, set through setCornerPosition, setEdgePosition, setCenterPosition methods. In addition, the horizontalAlign and verticalAlign properties of NodeLabel specify on which side of pin point to draw the label's caption.
For example, following code adds extra labels to top-left and bottom-right corners of a ShapeNode:
JavaScript Copy Code |
---|
var node = diagram.factory.createShapeNode(10, 50, 40, 30); |
The control now handles DOM Pointer events to implement multi-touch interactions, such as zooming, node rotation or simultaneous drawing of multiple diagram items:
Built-in multi-touch can be disabled altogether by setting enableMultiTouch to false, e.g. if you need to handle touch events yourself or through a third-party gesture library. If disabled, the control will revert to its mouse event handling code from previous versions. It will also no longer be able to capture mouse input during drag operations (to detect mouse pointer leaving the view), which is handled through DOM Pointers API.
The TowerChart control and TowerRenderer component draw tower charts, rendering series side by side to allow comparing data sequence and sizes. Assign the series to compare to leftSeries and rightSeries properties of the chart. The chart segments are arranged according to the value of towerLayout property, and their shape is drawn as specified by segmentShape.
Tower charts require three-dimensional series. The first dimension specifies event order or timing and is used to sort or position segments. Second dimension specifies duration and is rendered as segment length along the main axis. Third dimension specifies a value rendered as segment width along the cross axis. You could use the stock EventSeries class as data container, or implement the Series interface to provide data from your own data structures.
The DataViews module now includes a Property Grid providing user interface for browsing and editing the properties of an object. The PropertyGrid control can be bound to any object or an array of objects as specified by its selectedObject property. If showAllProperties is set to true, the control enumerates all properties and fields of the object and its prototype chain, resolves their data types and displays their name and value in a grid layout. If showAllProperties is set to false, only properties and fields included in the metaData dictionary are displayed.
MindFusion UI for React contains React functional wrapper components for ListView, TreeView, TabControl and ToolStrip controls from the @mindfusion/common-ui package. The components override core controls' DOM generation functions to generate React VDOM elements instead.
The React wrappers can be installed from the @mindfusion/ui-react package on npm:
npm i @mindfusion/ui-react
All wrapper components expose a forwardRef that can be passed on to other components. To obtain a reference to the underlying core control, use the respective find method of the ref, for example list1.current.find().
Properties and events defined by core controls can be set directly in JSX syntax:
JSX Copy Code |
---|
<ListView |
Several often-used methods such as addItem, removeItem, and selectItem are defined in the wrapper components' API. Other methods must be called through the respective core control:
JSX Copy Code |
---|
list1.current.addItem(<ListItem imageSrc={na} title="unknown"></ListItem>); |
The distribution includes ES5-compatible scripts located in Scripts/umd folder, whose classes are exposed as members of global MindFusion namespace object.
The Scripts/esm folder contains ES6 code that lets you import the classes from respective modules.
JsDiagram source code has been refactored following ES6 standards, including modules, classes, properties and native collections. ArrayList, Dictionary and Set classes from MindFusion.Collections namespace have been removed, and replaced by respective JavaScript native Array, Map and Set. Get/set functions have been replaced by getter/setter properties, which should help using the diagram API with binding expressions of various JS frameworks. You could enable propFunctions in CompatConfig in order to continue using legacy get/set functions during migration. The distribution still includes ES5-compatible scripts located in Scripts/umd folder, which are transpiled from current ES6 code, and whose classes are exposed as members of global MindFusion namespace object as in previous versions. The Scripts/esm folder contains ES6 code that lets you import JsDiagram classes from respective modules.
The Diagram control has been refactored into two classes. What remains of Diagram is now just a model class that defines diagram structure and implements serialization. The new DiagramView class deals with rendering and user interaction. You can show the same diagram in several views, each one rendering at different scroll positions and zoom levels. The separation also makes it easier to use the diagramming API in node.js server code, avoiding the need to load DOM shim/polyfill packages.
The TreeViewNode class represents nodes that can display hierarchical data. The root items displayed in the node can be accessed through the rootItems property. Items can be added and removed individually by using the addItem and removeItem methods, or in bulk by calling the fromObject method, which loads the tree view items from an array of objects.
The printPreview and print methods of DiagramView let you export the diagram as a list of smaller images in HTML page. Supported options include printArea (defaults to diagram's content bounds) and pageSize (defaults to DiagramView's viewport). Note that print methods use HTMLCanvasElement.toDataURL() internally, so any limitations it has will apply (such as canvas size and CORS).
The OrthogonalLayout class implements an orthogonal graph layout algorithm. Each link is drawn as a chain of alternating horizontal and vertical segments. Nodes are placed in a way that facilitates few links bends and crossings. This algorithm was designed for planar graphs where the nodes have at most four incident links, and produces best results with such graphs as input. It can arrange any arbitrary graph as well, by adding some dummy nodes and links to planarize the graph and reduce its vertex degree, and removing them after the layout.
To port a project that uses an earlier version of MindFusion.Scheduling to v.2.0:
Date and time localization of the Calendar can now be done via the CLDR locale data JSON distributions, instead of writing the "date" object in the localization file. You can continue using the localization files for string localization. For more information see the Localization topic.
MindFusion.Mapping source code has been refactored and is now dependent on the following MindFusion shared libraries: drawing, controls, common, and common.collections.
MindFusion.Keyboard source code has been refactored and is now dependent on the MindFusion common shared library.
MindFusion.DataViews source code has been refactored and is now dependent on the following MindFusion shared libraries: controls, common, and common.ui.
MindFusion.UI source code has been refactored and is now dependent on the following MindFusion shared libraries: drawing, controls, common and common.collections.
TopologicalLayout applies graph topological ordering to the diagram (topological ordering of a graph is one where link's origin node is placed before link's destination node). The layout algorithm arranges nodes in a row or a column, depending on the value of the direction property, in such a way that there are no backward links when the graph is acyclic. If the graph contains cycles, the algorithms selects ordering with as few backward links as possible. Links that connect non-adjacent nodes are rendered as arcs, whose amplitude is proportional to the distance between respective connected nodes. Forward links are rendered at one side of the nodes and back links are rendered at the opposite side. All that makes it easy to discern graph features such as overall flow direction, cycles and nested cycles.
Appearance of adjustment handles can be customized via ActiveItemHandlesStyle, SelectedItemHandlesStyle and DisabledHandlesStyle properties. The HandlesVisualStyle objects returned by them provide sub-properties corresponding to graphic attributes of the different handle types. Adjustment handles can now be painted not only in solid color but with arbitrary brushes such as gradients and patterns.
The GridView React component allows integrating the MindFusion.DataViews API into React applications. It is a wrapper component for the Grid control, handles the rendering and
keeps its DOM in sync with React’s virtual DOM. Grid properties can be set from JSX, and grid events can be handled through JSX syntax as well.
JSX Copy Code |
---|
import dv from 'grid-library' import { GridView } from 'grid-library-react'; ... var columns = [ new dv.GridColumn("index", dv.IntegerType, false), new dv.GridColumn("name", dv.StringType), new dv.GridColumn("registered", dv.DateType), ] var model = new dv.ArrayModel(dataArray, columns, "index"); this.state = { model: model }; ... <GridView id='view' model={this.state.model} {...props} onRowCreating={(grid, args) => this.onGridRowCreating(grid, args)} onRowDeleting={(grid, args) => this.onGridRowDeleting(grid, args)} /> |
GridView can be installed from the grid-library-react package on npm:
npm i grid-library-react
ControlNode objects display custom HTML content, specified via their Template property. A node's DOM structure is created inside the Content div element, which is then rendered on top of the diagram canvas. Note that this prevents ControlNodes drawing in diagram' usual Z order, and they will always appear on top of other diagram items.
By default the diagram intercepts mouse events of all hosted html elements to enable moving nodes or drawing links. You can specify that interactive elements, such as buttons or text boxes, should receive input instead by setting their data-interactive attribute to true.
You can register event handlers for elements in the template by assigning function names to data-event attributes in the form data-event-'eventName'='handlerName'. Alternatively, you can attach event listeners using DOM API once nodeDomCreated is raised to signify that content is available. E.g. access child elements by calling args.getNode().getContent().querySelector(...) and attach handlers via elements' addEventListener method.
ControlNodes create DOM elements from their template only in the main diagram, and render images instead when shown in Overview or NodeListView. Note that in this case image elements in the template will render only if specified in base64 format. The Utils.toDataUrl method helps you convert an image URL to base64 data URL.
New ControlNodes.html example included in distribution demonstrates the ControlNode API.
Composite nodes can now contain buttons. Button components respond to user clicks by calling the JavaScript function whose name is assigned to their clickHandler attribute. A button can show a text label assigned to the text attribute, or an image whose URL is assigned to imageLocation. The following example adds a button to CompositeNode template:
JavaScript Copy Code |
---|
{ component: "Button", brush: "#ccc", text: "Delete", width: 30, cornerRadius: 3.5, clickHandler: "onDeleteClick" } |
Serialization and clipboard operations should now work under Electron.js. In previous versions they would throw exceptions due to restricted use of eval.
For compatibility with MindFusion diagramming API for other platforms, StrokeThickness is now specified in diagram's MeasureUnit instead of pixels. You can set CompatConfig.pixelThickness = true in order to revert to using pixel values.
The list below describes recent changes and additions to MindFusion.Charting for JavaScript:
The origin property of the Axis class lets you specify the origin of an axis. If set to a non-null value, the component renders an axis line inside the plot. Bars are drawn below that axis line if their values are smaller than the origin. For stacked bar charts, each bar length corresponds to the difference between bar's value and origin.
The Plot.drawOrigins and Plot2D.drawOrigins methods allow you to draw the axis origin lines when rendering the chart plot by yourself.
JsDataViews Grid is a grid control, that binds to an array of objects and displays the data in tabular format. Grid column data types include String, Integer, RealNumber, Date, DateTime, Currency, Image and Lookup.
Some of the main features of the grid control are:
The Shape class used to specify ShapeNode geometry can also be used as a component in CompositeNode. When its isOutline attribute is set, the shape will control CompositeNode's geometry too, defining hit test and clip area, and link alignment points along node's border. If isOutline is disabled, the shape will serve mostly as a decorative element. The code below shows a sample fragment from node's template specifying shape component's properties:
JavaScript Copy Code |
---|
{ |
VideoNode objects display video streams, along with UI elements to play, pause, seek and change volume. Call node's setVideoLocation method to specify its video URL. Auto-playing is not supported at this time, and the video can be started only by users clicking the play button. VideoNode is built around Video component, which can also be used in CompositeNode templates.
The DiagramView React component allows integrating the MindFusion.Diagramming API into React applications. It renders a Diagram instance assigned to "diagram" prop as its model. Most diagram properties can be set from JSX, and all diagram events can be handled through JSX syntax as well. For more information, see the Integration with React help topic.
The diagram-view Vue.js component allows integrating the MindFusion.Diagramming API into Vue.js applications. It renders a Diagram instance assigned to "diagram" prop as its model. Most diagram properties can be set from the vue template, and all diagram events can be handled through the v-on directive as well. For more information, see the Integration with Vue.js help topic.
The diagram-view Angular component allows integrating the MindFusion.Diagramming API into Angular applications. It renders a Diagram instance assigned to "diagram" property as its model. Most diagram properties can be set from the html template, and all diagram events can be handled through event binding syntax as well. For more information, see the Integration with Angular help topic.
Canvas overlaysCanvas-based decoration layers can display Circle and Poly drawings at specified geographical locations. The radius of the circles and the stroke thickness can be set in meters (scalable) or in pixels (fixed-width).
Polylines can be drawn as straight lines or smooth curves.
Some of the code in the MindFusion.Mapping namespace has been refactored.
Important |
---|
A reference to the mindfusion-common/jsmodules package or to the MindFusion.Common.Full.js should be added to projects that use MindFusion.Mapping |
JavaScript Copy Code |
---|
//register the CustomEvent class |
JavaScript Copy Code |
---|
// attach a handler - when the item is drawn function onItemDraw(sender, args) { |
Some of the code in the MindFusion.Scheduling namespace has been refactored.
Important |
---|
A reference to the mindfusion-common/jsmodules package or to the MindFusion.Common.Full.js should be added to projects that use MindFusion.Scheduling |
You can use the virtual keyboard with Quill.
An input control with the ability to parse and select dates from a popup calendar and/or time from a popup list.
A lightweight month calendar control.
An input control with the ability select images from the filesystem or a predefined list.
Some of the code in the MindFusion.UI namespace has been refactored.
Important |
---|
A reference to the mindfusion-common/jsmodules package or to the MindFusion.Common.Full.js should be added to projects that use MindFusion.Common.UI |