I am following the instructions at https://www.telerik.com/kendo-vue-ui/components/diagram/ but I am running a standalone Vue application with .vue files.
To start, it fails at kendo.dataviz, saing kendo is not defined (at visualTemplate function).
I had a look at the code in STACKBLITZ and it seems like the sample code was put together in a hurry. Kind of "let's import everything and not worry about it too much". The same for the imports in the index.js. Performance matters and I don't want to be importing more than I need into my components.
https://stackblitz.com/edit/jhqgbd?file=index.js
So, what do I actually need to make it work in Vue?
import Vue from 'vue'
import '@progress/kendo-ui'
import '@progress/kendo-theme-default/dist/all.css'
import { DataSourceInstaller, DiagramInstaller } from '@progress/kendo-diagram-vue-wrapper'
Vue.use(DiagramInstaller);
Vue.use(DataSourceInstaller);
new Vue({
el: '#vueapp',
data: function() {
return {
diagramModel: {
children: 'items'
},
diagramData: myData
}
},
methods: {
kendowidgetready: function (widget) {
widget.bringIntoView(widget.shapes)
},
visualTemplate: function (options) {
var dataviz = kendo.dataviz
var g = new dataviz.diagram.Group()
var dataItem = options.dataItem
g.append(new dataviz.diagram.Rectangle({
width: 210,
height: 75,
stroke: {
width: 0
},
fill: {
gradient: {
type: 'linear',
stops: [{
color: dataItem.colorScheme,
offset: 0,
opacity: 0.5
}, {
color: dataItem.colorScheme,
offset: 1,
opacity: 1
}]
}
}
}))
g.append(new dataviz.diagram.TextBlock({
text: dataItem.firstName + ' ' + dataItem.lastName,
x: 85,
y: 20,
fill: '#fff'
}))
g.append(new dataviz.diagram.TextBlock({
text: dataItem.title,
x: 85,
y: 40,
fill: '#fff'
}))
g.append(new dataviz.diagram.Image({
source: 'https://demos.telerik.com/kendo-ui/content/dataviz/diagram/people/' + dataItem.image,
x: 3,
y: 3,
width: 68,
height: 68
}))
return g
}
}
})
I created a working example here. The only issue I found was, that DataSourceInstaller
doesn't exists in @progress/kendo-diagram-vue-wrapper
. I had to import it from @progress/kendo-datasource-vue-wrapper
.
As diagramData
, I took the data from the link you have postet.
As index.html
I also took the one from your link, but did a little bit cleanup.
Complete example
index.js
import Vue from 'vue';
import '@progress/kendo-ui';
import '@progress/kendo-theme-default/dist/all.css';
import { DataSourceInstaller } from '@progress/kendo-datasource-vue-wrapper';
import { DiagramInstaller } from '@progress/kendo-diagram-vue-wrapper';
import diagramData from './data';
Vue.use(DiagramInstaller);
Vue.use(DataSourceInstaller);
new Vue({
el: '#vueapp',
data() {
return {
diagramModel: {
children: 'items',
},
diagramData,
}
},
methods: {
kendowidgetready(widget) {
widget.bringIntoView(widget.shapes);
},
visualTemplate(options) {
var dataviz = kendo.dataviz;
var g = new dataviz.diagram.Group();
var dataItem = options.dataItem;
g.append(new dataviz.diagram.Rectangle({
width: 210,
height: 75,
stroke: {
width: 0,
},
fill: {
gradient: {
type: 'linear',
stops: [{
color: dataItem.colorScheme,
offset: 0,
opacity: 0.5,
}, {
color: dataItem.colorScheme,
offset: 1,
opacity: 1,
}],
},
},
}));
g.append(new dataviz.diagram.TextBlock({
text: dataItem.firstName + ' ' + dataItem.lastName,
x: 85,
y: 20,
fill: '#fff',
}));
g.append(new dataviz.diagram.TextBlock({
text: dataItem.title,
x: 85,
y: 40,
fill: '#fff',
}));
g.append(new dataviz.diagram.Image({
source: 'https://demos.telerik.com/kendo-ui/content/dataviz/diagram/people/' + dataItem.image,
x: 3,
y: 3,
width: 68,
height: 68,
}));
return g;
},
},
});
index.html
<!DOCTYPE html>
<html>
<head>
<title>Kendo UI for Vue Example Application</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="vueapp">
<kendo-hierarchicaldatasource
ref="remoteDataSourceComponent"
:data="diagramData"
schema-model-children="items">
</kendo-hierarchicaldatasource>
<kendo-diagram
data-source-ref="remoteDataSourceComponent"
layout-type="layered"
:shape-defaults-visual="visualTemplate"
connection-defaults-stroke-color="#979797"
:connection-defaults-stroke-width="2"
@kendowidgetready="kendowidgetready">
</kendo-diagram>
</div>
</body>
</html>
data.js
export default [{
firstName: 'Antonio',
lastName: 'Moreno',
image: 'antonio.jpg',
title: 'Team Lead',
colorScheme: '#1696d3',
items: [{
firstName: 'Elizabeth',
image: 'elizabeth.jpg',
lastName: 'Brown',
title: 'Design Lead',
colorScheme: '#ef6944',
items: [{
firstName: 'Ann',
lastName: 'Devon',
image: 'ann.jpg',
title: 'UI Designer',
colorScheme: '#ef6944'
}]
}, {
firstName: 'Diego',
lastName: 'Roel',
image: 'diego.jpg',
title: 'QA Engineer',
colorScheme: '#ee587b',
items: [{
firstName: 'Fran',
lastName: 'Wilson',
image: 'fran.jpg',
title: 'QA Intern',
colorScheme: '#ee587b'
}]
}, {
firstName: 'Felipe',
lastName: 'Izquiedro',
image: 'felipe.jpg',
title: 'Senior Developer',
colorScheme: '#75be16',
items: [{
firstName: 'Daniel',
lastName: 'Tonini',
image: 'daniel.jpg',
title: 'Developer',
colorScheme: '#75be16'
}]
}]
}]