2021-09-07 09:07:27 +00:00
import {
Graph ,
2022-01-08 01:49:35 +00:00
MaxWindow ,
KeyHandler ,
RubberBandHandler ,
2021-09-07 09:07:27 +00:00
InternalEvent ,
2022-01-08 01:49:35 +00:00
MaxLog ,
domUtils ,
Client ,
2021-09-07 09:07:27 +00:00
} from '@maxgraph/core' ;
2021-04-25 03:39:40 +00:00
import { globalTypes } from '../.storybook/preview' ;
export default {
title : 'Windows/Windows' ,
argTypes : {
... globalTypes ,
contextMenu : {
type : 'boolean' ,
2021-08-30 14:20:26 +00:00
defaultValue : false ,
2021-04-25 03:39:40 +00:00
} ,
rubberBand : {
type : 'boolean' ,
2021-08-30 14:20:26 +00:00
defaultValue : true ,
} ,
} ,
2021-04-25 03:39:40 +00:00
} ;
const Template = ( { label , ... args } ) => {
2022-01-08 01:49:35 +00:00
Client . setImageBasePath ( '/images' ) ;
2021-04-25 03:39:40 +00:00
const container = document . createElement ( 'div' ) ;
container . style . position = 'relative' ;
container . style . overflow = 'hidden' ;
container . style . width = ` ${ args . width } px ` ;
container . style . height = ` ${ args . height } px ` ;
container . style . background = 'url(/images/grid.gif)' ;
container . style . cursor = 'default' ;
// Note that we're using the container scrollbars for the graph so that the
// container extends to the parent div inside the window
2022-01-08 01:49:35 +00:00
let wnd = new MaxWindow (
2021-04-25 03:39:40 +00:00
'Scrollable, resizable, given height' ,
container ,
50 ,
50 ,
220 ,
224 ,
true ,
true
) ;
// Creates the graph inside the given container
2021-08-30 14:20:26 +00:00
const graph = new Graph ( container ) ;
2021-04-25 03:39:40 +00:00
// Adds rubberband selection and keystrokes
graph . setTooltips ( true ) ;
graph . setPanning ( true ) ;
2022-01-08 01:49:35 +00:00
if ( args . rubberBand ) new RubberBandHandler ( graph ) ;
2021-04-25 03:39:40 +00:00
2022-01-08 01:49:35 +00:00
new KeyHandler ( graph ) ;
2021-04-25 03:39:40 +00:00
2021-08-30 14:20:26 +00:00
if ( ! args . contextMenu ) InternalEvent . disableContextMenu ( container ) ;
2021-04-25 03:39:40 +00:00
// Gets the default parent for inserting new cells. This
// is normally the first child of the root (ie. layer 0).
const parent = graph . getDefaultParent ( ) ;
// Adds cells to the model in a single step
2022-01-08 01:49:35 +00:00
graph . batchUpdate ( ( ) => {
2021-04-25 03:39:40 +00:00
const v1 = graph . insertVertex ( parent , null , 'Hello,' , 20 , 20 , 80 , 30 ) ;
const v2 = graph . insertVertex ( parent , null , 'World!' , 200 , 150 , 80 , 30 ) ;
const e1 = graph . insertEdge ( parent , null , '' , v1 , v2 ) ;
2022-01-08 01:49:35 +00:00
} ) ;
2021-04-25 03:39:40 +00:00
wnd . setMaximizable ( true ) ;
wnd . setResizable ( true ) ;
wnd . setVisible ( true ) ;
const lorem =
'Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ' ;
let content = document . createElement ( 'div' ) ;
2022-01-08 01:49:35 +00:00
domUtils . write ( content , lorem + lorem + lorem ) ;
2021-04-25 03:39:40 +00:00
2022-01-08 01:49:35 +00:00
wnd = new MaxWindow (
2021-04-25 03:39:40 +00:00
'Scrollable, resizable, auto height' ,
content ,
300 ,
50 ,
200 ,
null ,
true ,
true
) ;
wnd . setMaximizable ( true ) ;
wnd . setScrollable ( true ) ;
wnd . setResizable ( true ) ;
wnd . setVisible ( true ) ;
content = content . cloneNode ( true ) ;
content . style . width = '400px' ;
2022-01-08 01:49:35 +00:00
wnd = new MaxWindow (
2021-04-25 03:39:40 +00:00
'Scrollable, resizable, fixed content' ,
content ,
520 ,
50 ,
220 ,
200 ,
true ,
true
) ;
wnd . setMaximizable ( true ) ;
wnd . setScrollable ( true ) ;
wnd . setResizable ( true ) ;
wnd . setVisible ( true ) ;
2022-01-08 01:49:35 +00:00
MaxLog . show ( ) ;
2021-04-25 03:39:40 +00:00
return container ;
2021-08-30 14:20:26 +00:00
} ;
2021-04-25 03:39:40 +00:00
2021-08-30 14:20:26 +00:00
export const Default = Template . bind ( { } ) ;