@visuallyjs/browser-ui-svelte 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AreaChartComponent.svelte +37 -0
- package/BarChartComponent.svelte +37 -0
- package/BubbleChartComponent.svelte +38 -0
- package/ColorPickerComponent.svelte +94 -0
- package/ColumnChartComponent.svelte +38 -0
- package/ControlsComponent.svelte +66 -0
- package/DecoratorComponent.svelte +55 -0
- package/DefaultGroupComponent.svelte +5 -0
- package/DefaultNodeComponent.svelte +5 -0
- package/DiagramComponent.svelte +46 -0
- package/DiagramPaletteComponent.svelte +47 -0
- package/DiagramProvider.svelte +9 -0
- package/EdgeTypePickerComponent.svelte +47 -0
- package/ExportControlsComponent.svelte +94 -0
- package/GaugeChartComponent.svelte +31 -0
- package/InspectorComponent.svelte +79 -0
- package/LineChartComponent.svelte +38 -0
- package/MiniviewComponent.svelte +73 -0
- package/PaletteComponent.svelte +73 -0
- package/PieChartComponent.svelte +37 -0
- package/SankeyChartComponent.svelte +44 -0
- package/ScatterChartComponent.svelte +38 -0
- package/ShapeComponent.svelte +66 -0
- package/ShapePaletteComponent.svelte +82 -0
- package/SurfaceComponent.svelte +270 -0
- package/SurfaceProvider.svelte +9 -0
- package/WrapperComponent.svelte +27 -0
- package/XYChartComponent.svelte +32 -0
- package/components.d.ts +29 -0
- package/components.js +29 -0
- package/definitions.d.ts +841 -0
- package/definitions.js +1 -0
- package/diagram-store.d.ts +30 -0
- package/diagram-store.js +58 -0
- package/index.d.ts +27 -0
- package/index.js +33 -0
- package/inspector-store.d.ts +24 -0
- package/inspector-store.js +42 -0
- package/package.json +1 -0
- package/store-adapter.d.ts +15 -0
- package/store-adapter.js +47 -0
- package/surface-store.d.ts +41 -0
- package/surface-store.js +73 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { onMount } from "svelte";
|
|
4
|
+
|
|
5
|
+
import {AreaChart, type BrowserElement} from "@visuallyjs/browser-ui"
|
|
6
|
+
import {type AreaChartComponentProps} from "./definitions";
|
|
7
|
+
|
|
8
|
+
let container:BrowserElement;
|
|
9
|
+
|
|
10
|
+
let {options, className = "", data, url, dataSourceFilter }:AreaChartComponentProps = $props();
|
|
11
|
+
|
|
12
|
+
let chart:AreaChart;
|
|
13
|
+
|
|
14
|
+
export function getChart() {
|
|
15
|
+
return chart;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
$effect(() => {
|
|
19
|
+
if (chart) {
|
|
20
|
+
chart.setDataSourceFilter(dataSourceFilter)
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
onMount(async () => {
|
|
25
|
+
|
|
26
|
+
chart = new AreaChart(container, Object.assign({dataSourceFilter}, options))
|
|
27
|
+
|
|
28
|
+
if (url != null) {
|
|
29
|
+
chart.load({url});
|
|
30
|
+
} else if (data != null) {
|
|
31
|
+
chart.load({data});
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<div class={className} bind:this={container}></div>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { onMount } from "svelte";
|
|
4
|
+
|
|
5
|
+
import {BarChart, type BrowserElement} from "@visuallyjs/browser-ui"
|
|
6
|
+
import {type BarChartComponentProps} from "./definitions";
|
|
7
|
+
|
|
8
|
+
let container:BrowserElement;
|
|
9
|
+
|
|
10
|
+
let {options, className = "", data, url, dataSourceFilter }:BarChartComponentProps = $props();
|
|
11
|
+
|
|
12
|
+
let chart:BarChart;
|
|
13
|
+
|
|
14
|
+
export function getChart() {
|
|
15
|
+
return chart;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
$effect(() => {
|
|
19
|
+
if (chart) {
|
|
20
|
+
chart.setDataSourceFilter(dataSourceFilter)
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
onMount(async () => {
|
|
25
|
+
|
|
26
|
+
chart = new BarChart(container, Object.assign({dataSourceFilter}, options))
|
|
27
|
+
|
|
28
|
+
if (url != null) {
|
|
29
|
+
chart.load({url});
|
|
30
|
+
} else if (data != null) {
|
|
31
|
+
chart.load({data});
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<div class={className} bind:this={container}></div>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { onMount } from "svelte";
|
|
4
|
+
|
|
5
|
+
import {type BrowserElement, BubbleChart} from "@visuallyjs/browser-ui"
|
|
6
|
+
import {type BubbleChartComponentProps} from "./definitions";
|
|
7
|
+
|
|
8
|
+
let container:BrowserElement;
|
|
9
|
+
|
|
10
|
+
// BubbleChartOptions
|
|
11
|
+
let {options, className = "", data, url, dataSourceFilter }:BubbleChartComponentProps = $props();
|
|
12
|
+
|
|
13
|
+
let chart:BubbleChart;
|
|
14
|
+
|
|
15
|
+
export function getChart() {
|
|
16
|
+
return chart;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
$effect(() => {
|
|
20
|
+
if (chart) {
|
|
21
|
+
chart.setDataSourceFilter(dataSourceFilter)
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
onMount(async () => {
|
|
26
|
+
|
|
27
|
+
chart = new BubbleChart(container, Object.assign({dataSourceFilter}, options))
|
|
28
|
+
|
|
29
|
+
if (url != null) {
|
|
30
|
+
chart.load({url});
|
|
31
|
+
} else if (data != null) {
|
|
32
|
+
chart.load({data});
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<div class={className} bind:this={container}></div>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {onMount} from "svelte"
|
|
3
|
+
import {type ColorPickerComponentProps} from "./definitions";
|
|
4
|
+
import {
|
|
5
|
+
CLASS_COLOR_PICKER,
|
|
6
|
+
CLASS_COLOR_PICKER_SWATCH,
|
|
7
|
+
CLASS_COLOR_PICKER_SWATCHES,
|
|
8
|
+
EVENT_CONTEXT_UPDATE,
|
|
9
|
+
EVENT_CHANGE, INSPECTOR_CONTEXT_RECENT_COLORS, Inspector, log
|
|
10
|
+
} from "@visuallyjs/browser-ui"
|
|
11
|
+
import {getInspectorContext} from "./inspector-store";
|
|
12
|
+
|
|
13
|
+
let colorInput:HTMLInputElement
|
|
14
|
+
|
|
15
|
+
let inspector:Inspector
|
|
16
|
+
|
|
17
|
+
let props:ColorPickerComponentProps = $props()
|
|
18
|
+
|
|
19
|
+
const maxColors = props.maxColors || 10
|
|
20
|
+
|
|
21
|
+
const swatches = $state([] as Array<string>)
|
|
22
|
+
function setSwatches(s:Array<string>) {
|
|
23
|
+
swatches.length = 0
|
|
24
|
+
swatches.push(...s)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function addColor(v:string) {
|
|
28
|
+
const _s = inspector.ensureContext(INSPECTOR_CONTEXT_RECENT_COLORS, ():Array<string> => [])
|
|
29
|
+
v = v.toUpperCase()
|
|
30
|
+
const exists = _s.find(__s => __s.toUpperCase() === v) != null
|
|
31
|
+
|
|
32
|
+
if (!exists) {
|
|
33
|
+
const s = _s.slice()
|
|
34
|
+
s.unshift(v)
|
|
35
|
+
if (s.length > maxColors) {
|
|
36
|
+
s.length = maxColors
|
|
37
|
+
}
|
|
38
|
+
inspector.updateContext(INSPECTOR_CONTEXT_RECENT_COLORS, s)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const contextUpdateListener = (kv:{key:string, value:Array<string>}) => {
|
|
43
|
+
if (kv.key === INSPECTOR_CONTEXT_RECENT_COLORS) {
|
|
44
|
+
setSwatches(kv.value.slice())
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function setCurrentColor() {
|
|
49
|
+
const v = inspector.getValue(props.propertyName)
|
|
50
|
+
if (v != null) {
|
|
51
|
+
colorInput.value = v
|
|
52
|
+
addColor(v)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function colorPicked() {
|
|
57
|
+
const v = colorInput.value
|
|
58
|
+
inspector.setValue(props.propertyName, v)
|
|
59
|
+
addColor(v)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
onMount(async() => {
|
|
63
|
+
|
|
64
|
+
const ic = getInspectorContext(true)
|
|
65
|
+
if (ic == null) {
|
|
66
|
+
log(`WARN: color picker cannot find an inspector context; cannot mount.`)
|
|
67
|
+
} else {
|
|
68
|
+
ic.listen(i => {
|
|
69
|
+
inspector = i
|
|
70
|
+
setSwatches(inspector.ensureContext(INSPECTOR_CONTEXT_RECENT_COLORS, ():Array<string> => []))
|
|
71
|
+
colorInput.addEventListener(EVENT_CHANGE, colorPicked)
|
|
72
|
+
inspector.bind(EVENT_CONTEXT_UPDATE, contextUpdateListener)
|
|
73
|
+
inspector.bind(EVENT_CHANGE, setCurrentColor)
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
function selectSwatch(c:string) {
|
|
81
|
+
inspector.setValue(props.propertyName, c)
|
|
82
|
+
colorInput.value = c
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
</script>
|
|
87
|
+
<div class={CLASS_COLOR_PICKER}>
|
|
88
|
+
<input type="color" bind:this={colorInput} vjs-att={props.propertyName}/>
|
|
89
|
+
<div class={CLASS_COLOR_PICKER_SWATCHES}>
|
|
90
|
+
{#each swatches as color}
|
|
91
|
+
<div title={color} class={CLASS_COLOR_PICKER_SWATCH} style="background-color:{color}" data-color={color} on:click={() => selectSwatch(color)}></div>
|
|
92
|
+
{/each}
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { onMount } from "svelte";
|
|
4
|
+
|
|
5
|
+
import {type BrowserElement, ColumnChart} from "@visuallyjs/browser-ui"
|
|
6
|
+
import {type ColumnChartComponentProps} from "./definitions";
|
|
7
|
+
|
|
8
|
+
let container:BrowserElement;
|
|
9
|
+
|
|
10
|
+
// ColumnChartOptions
|
|
11
|
+
let {options, className = "", data, url, dataSourceFilter }:ColumnChartComponentProps = $props();
|
|
12
|
+
|
|
13
|
+
let chart:ColumnChart;
|
|
14
|
+
|
|
15
|
+
export function getChart() {
|
|
16
|
+
return chart;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
$effect(() => {
|
|
20
|
+
if (chart) {
|
|
21
|
+
chart.setDataSourceFilter(dataSourceFilter)
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
onMount(async () => {
|
|
26
|
+
|
|
27
|
+
chart = new ColumnChart(container, Object.assign({dataSourceFilter}, options))
|
|
28
|
+
|
|
29
|
+
if (url != null) {
|
|
30
|
+
chart.load({url});
|
|
31
|
+
} else if (data != null) {
|
|
32
|
+
chart.load({data});
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<div class={className} bind:this={container}></div>
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { onMount } from "svelte"
|
|
4
|
+
|
|
5
|
+
import {type BrowserElement, ControlsComponent, log, Surface} from "@visuallyjs/browser-ui"
|
|
6
|
+
import {internal_getSurfaceContext} from "./surface-store";
|
|
7
|
+
import {type ControlsComponentProps} from "./definitions";
|
|
8
|
+
import {internal_getDiagramContext} from "./diagram-store";
|
|
9
|
+
|
|
10
|
+
let container:BrowserElement
|
|
11
|
+
let surface:Surface
|
|
12
|
+
let initialised = false
|
|
13
|
+
|
|
14
|
+
let {
|
|
15
|
+
clear,
|
|
16
|
+
undoRedo,
|
|
17
|
+
zoomToExtents,
|
|
18
|
+
clearMessage,
|
|
19
|
+
buttons,
|
|
20
|
+
orientation,
|
|
21
|
+
className = ""
|
|
22
|
+
}:ControlsComponentProps = $props()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const sc = internal_getSurfaceContext(true)
|
|
26
|
+
if (sc != null) {
|
|
27
|
+
sc.listen(s => {
|
|
28
|
+
surface = s
|
|
29
|
+
_maybeInit()
|
|
30
|
+
})
|
|
31
|
+
} else {
|
|
32
|
+
const dc = internal_getDiagramContext(true)
|
|
33
|
+
if (dc != null) {
|
|
34
|
+
dc.listen(d => {
|
|
35
|
+
surface = d.$ui as Surface
|
|
36
|
+
_maybeInit()
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
log(`WARN: ControlsComponent did not find a Surface or Diagram context. Cannot mount.`)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const options = {
|
|
45
|
+
clear:clear !== false,
|
|
46
|
+
undoRedo:undoRedo !== false,
|
|
47
|
+
zoomToExtents:zoomToExtents !== false,
|
|
48
|
+
clearMessage,
|
|
49
|
+
buttons:buttons || [],
|
|
50
|
+
orientation
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function _maybeInit() {
|
|
54
|
+
if (!initialised && surface != null && container != null) {
|
|
55
|
+
initialised = true
|
|
56
|
+
new ControlsComponent(container, surface, options)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
onMount(async () => {
|
|
61
|
+
_maybeInit()
|
|
62
|
+
})
|
|
63
|
+
</script>
|
|
64
|
+
<div bind:this={container} class={className}>
|
|
65
|
+
|
|
66
|
+
</div>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, onDestroy } from 'svelte';
|
|
3
|
+
import {log, Surface} from "@visuallyjs/browser-ui";
|
|
4
|
+
import {internal_getSurfaceContext} from "./surface-store";
|
|
5
|
+
import {type DecoratorComponentProps} from "./definitions";
|
|
6
|
+
|
|
7
|
+
let container: HTMLElement;
|
|
8
|
+
let surface: Surface | undefined;
|
|
9
|
+
let initialised = false
|
|
10
|
+
|
|
11
|
+
let {
|
|
12
|
+
placement = 'floating',
|
|
13
|
+
position = { x: 0, y: 0 },
|
|
14
|
+
constraints
|
|
15
|
+
}:DecoratorComponentProps = $props()
|
|
16
|
+
|
|
17
|
+
const sc = internal_getSurfaceContext(true)
|
|
18
|
+
if (sc != null) {
|
|
19
|
+
sc.listen(s => {
|
|
20
|
+
surface = s
|
|
21
|
+
_maybeInit()
|
|
22
|
+
})
|
|
23
|
+
}else {
|
|
24
|
+
log(`WARN: DecoratorComponent did not find a Surface context. Cannot mount.`)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function _maybeInit() {
|
|
28
|
+
if (!initialised && surface != null && container != null) {
|
|
29
|
+
initialised = true
|
|
30
|
+
if (container.firstElementChild) {
|
|
31
|
+
const element = container.firstElementChild as HTMLElement;
|
|
32
|
+
|
|
33
|
+
if (placement === 'fixed') {
|
|
34
|
+
surface.fixElement(element, position, constraints);
|
|
35
|
+
} else {
|
|
36
|
+
surface.floatElement(element, position);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
onMount(async () => {
|
|
43
|
+
_maybeInit()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
onDestroy(() => {
|
|
47
|
+
if (surface && placement === 'fixed' && container && container.firstElementChild) {
|
|
48
|
+
surface.unfixElement(container.firstElementChild as HTMLElement);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<div bind:this={container} style="display: inline-block;">
|
|
54
|
+
<slot></slot>
|
|
55
|
+
</div>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { onMount } from "svelte";
|
|
4
|
+
|
|
5
|
+
import {type BrowserElement, createDiagram, Diagram, Surface} from "@visuallyjs/browser-ui"
|
|
6
|
+
|
|
7
|
+
import { internal_getSurfaceContext } from "./surface-store";
|
|
8
|
+
import {internal_getDiagramContext} from "./diagram-store";
|
|
9
|
+
import {type DiagramComponentProps} from "./definitions";
|
|
10
|
+
|
|
11
|
+
let container:BrowserElement;
|
|
12
|
+
|
|
13
|
+
let {options, className = "", data, url, modelOptions }:DiagramComponentProps = $props();
|
|
14
|
+
|
|
15
|
+
const diagramContext = internal_getDiagramContext(false)
|
|
16
|
+
const surfaceContext = internal_getSurfaceContext(false)
|
|
17
|
+
let diagram:Diagram
|
|
18
|
+
|
|
19
|
+
export function getDiagram() {
|
|
20
|
+
return diagram;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
onMount(async () => {
|
|
24
|
+
|
|
25
|
+
diagram = createDiagram(container, options, modelOptions)
|
|
26
|
+
|
|
27
|
+
if (surfaceContext != null && diagram.$ui instanceof Surface) {
|
|
28
|
+
surfaceContext.set(diagram.$ui);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (diagramContext != null) {
|
|
32
|
+
diagramContext.set(diagram)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (url != null) {
|
|
36
|
+
diagram.load({url});
|
|
37
|
+
} else if (data != null) {
|
|
38
|
+
diagram.load({data});
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<div class={className} bind:this={container}>
|
|
45
|
+
<slot />
|
|
46
|
+
</div>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import {type DiagramPaletteProps} from "./definitions";
|
|
4
|
+
import {Diagram, DiagramPalette, log} from "@visuallyjs/browser-ui";
|
|
5
|
+
import {internal_getDiagramContext} from "./diagram-store";
|
|
6
|
+
import {onMount} from "svelte";
|
|
7
|
+
|
|
8
|
+
let diagram:Diagram
|
|
9
|
+
let container:HTMLElement
|
|
10
|
+
const props:DiagramPaletteProps = $props()
|
|
11
|
+
|
|
12
|
+
onMount(async() => {
|
|
13
|
+
const dc = internal_getDiagramContext(true)
|
|
14
|
+
if (dc != null) {
|
|
15
|
+
dc.listen((d) => {
|
|
16
|
+
diagram = d
|
|
17
|
+
_init()
|
|
18
|
+
})
|
|
19
|
+
} else {
|
|
20
|
+
log(`WARN: DiagramPaletteComponent could not find a Diagram context. Cannot mount.`)
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
function _init() {
|
|
26
|
+
new DiagramPalette(container, diagram, {
|
|
27
|
+
fill:props.fill,
|
|
28
|
+
outline:props.outline,
|
|
29
|
+
dragSize:props.dragSize,
|
|
30
|
+
inspector:props.inspector,
|
|
31
|
+
iconSize:props.iconSize,
|
|
32
|
+
showLabels:props.showLabels,
|
|
33
|
+
paletteStrokeWidth:props.paletteStrokeWidth,
|
|
34
|
+
showAllMessage:props.showAllMessage,
|
|
35
|
+
onCellAdded:props.onCellAdded,
|
|
36
|
+
mode:props.mode,
|
|
37
|
+
allowClickToAdd:props.allowClickToAdd,
|
|
38
|
+
autoExitDrawMode:props.autoExitDrawMode,
|
|
39
|
+
selectAfterAdd:props.selectAfterAdd,
|
|
40
|
+
onVertexAdded:props.onVertexAdded,
|
|
41
|
+
preparedShapes:props.preparedShapes
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<div class={props.className} bind:this={container}></div>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
type EdgePropertyMappings,
|
|
4
|
+
EdgeTypePicker,
|
|
5
|
+
Inspector, INSPECTOR_CONTEXT_EDGE_PROPERTY_MAPPINGS,
|
|
6
|
+
log
|
|
7
|
+
} from "@visuallyjs/browser-ui"
|
|
8
|
+
import {onMount} from "svelte"
|
|
9
|
+
import {type EdgeTypePickerComponentProps} from "./definitions";
|
|
10
|
+
import {getInspectorContext} from "./inspector-store";
|
|
11
|
+
|
|
12
|
+
let container:HTMLElement
|
|
13
|
+
let inspector:Inspector
|
|
14
|
+
let edgeTypePicker:EdgeTypePicker
|
|
15
|
+
|
|
16
|
+
let { propertyName }:EdgeTypePickerComponentProps = $props()
|
|
17
|
+
|
|
18
|
+
const resolveMappings = ():EdgePropertyMappings => {
|
|
19
|
+
const mappings = inspector.getFromContext<EdgePropertyMappings>(INSPECTOR_CONTEXT_EDGE_PROPERTY_MAPPINGS)
|
|
20
|
+
return mappings || inspector.$ui.$getEdgePropertyMappings()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
onMount(async() => {
|
|
24
|
+
|
|
25
|
+
const ic = getInspectorContext(true)
|
|
26
|
+
if (ic == null) {
|
|
27
|
+
log(`WARN: color picker cannot find an inspector context; cannot mount.`)
|
|
28
|
+
} else {
|
|
29
|
+
ic.listen(i => {
|
|
30
|
+
inspector = i
|
|
31
|
+
const edgeMappings = resolveMappings()
|
|
32
|
+
edgeTypePicker = new EdgeTypePicker(inspector.$ui, container, edgeMappings, inspector.getValue(propertyName), (v) => {
|
|
33
|
+
inspector.setValue(propertyName, v)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
edgeTypePicker.render(propertyName, inspector._currentCommonData)
|
|
37
|
+
|
|
38
|
+
inspector.onChange(() => {
|
|
39
|
+
edgeTypePicker.select(propertyName, inspector.getValue(propertyName))
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
</script>
|
|
47
|
+
<div bind:this={container}></div>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { internal_getSurfaceContext} from "./surface-store"
|
|
4
|
+
import {
|
|
5
|
+
CLASS_CONTROLS,
|
|
6
|
+
CLASS_EXPORT_CONTROLS,
|
|
7
|
+
SvgExportUI,
|
|
8
|
+
ImageExportUI,
|
|
9
|
+
log, Surface
|
|
10
|
+
} from "@visuallyjs/browser-ui"
|
|
11
|
+
import {type ExportControlsComponentProps} from "./definitions";
|
|
12
|
+
import {internal_getDiagramContext} from "./diagram-store";
|
|
13
|
+
|
|
14
|
+
let surface:Surface
|
|
15
|
+
let initialized = false
|
|
16
|
+
|
|
17
|
+
let {
|
|
18
|
+
className = "",
|
|
19
|
+
showLabel = true,
|
|
20
|
+
label = "Export:",
|
|
21
|
+
svgOptions = undefined,
|
|
22
|
+
imageOptions = undefined,
|
|
23
|
+
allowSvgExport = true,
|
|
24
|
+
allowPngExport = true,
|
|
25
|
+
allowJpgExport = true
|
|
26
|
+
|
|
27
|
+
}:ExportControlsComponentProps = $props()
|
|
28
|
+
|
|
29
|
+
className = `${className} ${CLASS_CONTROLS} ${CLASS_EXPORT_CONTROLS}`
|
|
30
|
+
|
|
31
|
+
const sc = internal_getSurfaceContext(true)
|
|
32
|
+
if (sc != null) {
|
|
33
|
+
sc.listen(s => {
|
|
34
|
+
surface = s
|
|
35
|
+
_maybeInit()
|
|
36
|
+
})
|
|
37
|
+
} else {
|
|
38
|
+
const dc = internal_getDiagramContext(true)
|
|
39
|
+
if (dc != null) {
|
|
40
|
+
dc.listen(d => {
|
|
41
|
+
surface = d.$ui as Surface
|
|
42
|
+
_maybeInit()
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
log(`WARN: ExportControlsComponent did not find a Surface or Diagram context. Cannot mount.`)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function _maybeInit() {
|
|
51
|
+
if (!initialized && surface != null) {
|
|
52
|
+
initialized = true
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function exportSVG() {
|
|
57
|
+
svgOptions = svgOptions || {}
|
|
58
|
+
new SvgExportUI(surface).export(svgOptions)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function exportPNG() {
|
|
62
|
+
// show an image export ui, which will default to PNG. `dimensions` is optional - if not supplied the resulting PNG
|
|
63
|
+
// will have the same size as the content.
|
|
64
|
+
imageOptions = imageOptions || {}
|
|
65
|
+
new ImageExportUI(surface).export(imageOptions)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function exportJPG() {
|
|
69
|
+
// show an image export ui targetting a JPG output. Here we show an alternative to providing a list of dimensions - we just mandate the
|
|
70
|
+
// width we want for the output. Again, this is optional. You don't need to provide this or `dimensions`. See note above.
|
|
71
|
+
imageOptions = imageOptions || {}
|
|
72
|
+
new ImageExportUI(surface).export(Object.assign(imageOptions || {}, {type:"image/jpeg"}))
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
</script>
|
|
76
|
+
<div class={className}>
|
|
77
|
+
|
|
78
|
+
{#if showLabel}
|
|
79
|
+
<span>{label}</span>
|
|
80
|
+
{/if}
|
|
81
|
+
|
|
82
|
+
{#if allowSvgExport}
|
|
83
|
+
<i><a href="#" id="exportSvg" on:click={() => exportSVG()}>SVG</a></i>
|
|
84
|
+
{/if}
|
|
85
|
+
|
|
86
|
+
{#if allowPngExport}
|
|
87
|
+
<i><a href="#" id="exportPng" on:click={() => exportPNG()}>PNG</a></i>
|
|
88
|
+
{/if}
|
|
89
|
+
|
|
90
|
+
{#if allowJpgExport}
|
|
91
|
+
<i><a href="#" id="exportJpg" on:click={() => exportJPG()}>JPG</a></i>
|
|
92
|
+
{/if}
|
|
93
|
+
|
|
94
|
+
</div>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { onMount } from "svelte";
|
|
4
|
+
|
|
5
|
+
import {GaugeChart, type BrowserElement} from "@visuallyjs/browser-ui"
|
|
6
|
+
import {type GaugeChartComponentProps} from "./definitions";
|
|
7
|
+
|
|
8
|
+
let container:BrowserElement;
|
|
9
|
+
|
|
10
|
+
let {options, className = "", data, url }:GaugeChartComponentProps = $props();
|
|
11
|
+
|
|
12
|
+
let chart:GaugeChart;
|
|
13
|
+
|
|
14
|
+
export function getChart() {
|
|
15
|
+
return chart;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
onMount(async () => {
|
|
19
|
+
|
|
20
|
+
chart = new GaugeChart(container, options)
|
|
21
|
+
|
|
22
|
+
if (url != null) {
|
|
23
|
+
chart.load({url});
|
|
24
|
+
} else if (data != null) {
|
|
25
|
+
chart.load({data});
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<div class={className} bind:this={container}></div>
|