@onetype/framework 2.0.39 → 2.0.41
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/addons/render/transforms/item/functions/run.js +6 -2
- package/lib/load.js +0 -1
- package/package.json +1 -1
- package/lib/items/transforms/accordion/accordion.js +0 -172
- package/lib/items/transforms/chart/area.js +0 -153
- package/lib/items/transforms/chart/bar.js +0 -137
- package/lib/items/transforms/chart/bubble.js +0 -166
- package/lib/items/transforms/chart/doughnut.js +0 -124
- package/lib/items/transforms/chart/line.js +0 -149
- package/lib/items/transforms/chart/pie.js +0 -122
- package/lib/items/transforms/chart/radar.js +0 -154
- package/lib/items/transforms/chart/scatter.js +0 -149
- package/lib/items/transforms/codeflask/codeflask.js +0 -97
- package/lib/items/transforms/codemirror/codemirror.js +0 -228
- package/lib/items/transforms/comparison/comparison.js +0 -139
- package/lib/items/transforms/heatmap/heatmap.js +0 -493
- package/lib/items/transforms/interact/interact.js +0 -276
- package/lib/items/transforms/particles/particles.js +0 -328
- package/lib/items/transforms/sparkline/sparkline.js +0 -239
- package/lib/items/transforms/swiper/swiper.js +0 -140
- package/lib/items/transforms/tabs/tabs.js +0 -459
- package/lib/items/transforms/typed/typed.js +0 -172
|
@@ -8,7 +8,11 @@ transforms.Fn('item.run', function(item, node, data = null)
|
|
|
8
8
|
item.Fn('load').then(() =>
|
|
9
9
|
{
|
|
10
10
|
item.Get('code').call({}, data, node, item);
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
|
|
12
|
+
requestAnimationFrame(() =>
|
|
13
|
+
{
|
|
14
|
+
node.removeAttribute('ot');
|
|
15
|
+
node.removeAttribute('ot-init');
|
|
16
|
+
});
|
|
13
17
|
});
|
|
14
18
|
});
|
package/lib/load.js
CHANGED
|
@@ -23,7 +23,6 @@ onetype.Assets('sources', import.meta.url, { js: '../addons/modules/sources/fron
|
|
|
23
23
|
onetype.Assets('directives', import.meta.url, { js: '../addons/render/directives/front' });
|
|
24
24
|
onetype.Assets('directives/items', import.meta.url, { js: 'items/directives' });
|
|
25
25
|
onetype.Assets('transforms', import.meta.url, { js: '../addons/render/transforms' });
|
|
26
|
-
onetype.Assets('transforms/items', import.meta.url, { js: 'items/transforms' });
|
|
27
26
|
onetype.Assets('pages', import.meta.url, { js: '../addons/render/pages', css: '../addons/render/pages/front' });
|
|
28
27
|
onetype.Assets('elements', import.meta.url, { js: '../addons/render/elements/front', css: '../addons/render/elements/front' });
|
|
29
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onetype/framework",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.41",
|
|
4
4
|
"description": "OneType Framework — Full-stack isomorphic JavaScript framework built from scratch. One addon abstraction powers databases, servers, commands, pages, directives, queues, and more.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/load.js",
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
transforms.ItemAdd({
|
|
2
|
-
id: 'accordion',
|
|
3
|
-
icon: 'expand_more',
|
|
4
|
-
name: 'Accordion',
|
|
5
|
-
description: 'Collapsible accordion component with multiple items. Supports single or multiple open panels with smooth animations.',
|
|
6
|
-
config: {
|
|
7
|
-
'multiple': ['boolean', false],
|
|
8
|
-
'first-open': ['boolean', true],
|
|
9
|
-
'animation-duration': ['number', 300],
|
|
10
|
-
'icon': ['boolean', true],
|
|
11
|
-
'icon-position': ['string', 'right']
|
|
12
|
-
},
|
|
13
|
-
code: function(data, node, transformer)
|
|
14
|
-
{
|
|
15
|
-
const id = 'accordion-' + onetype.Generate(8);
|
|
16
|
-
|
|
17
|
-
this.setup = () =>
|
|
18
|
-
{
|
|
19
|
-
node.classList.add('accordion');
|
|
20
|
-
node.classList.add(id);
|
|
21
|
-
|
|
22
|
-
const children = Array.from(node.children);
|
|
23
|
-
const items = [];
|
|
24
|
-
|
|
25
|
-
for(let i = 0; i < children.length; i += 2)
|
|
26
|
-
{
|
|
27
|
-
const header = children[i];
|
|
28
|
-
const content = children[i + 1];
|
|
29
|
-
|
|
30
|
-
if(!header || !content)
|
|
31
|
-
{
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const wrapper = document.createElement('div');
|
|
36
|
-
const headerWrapper = document.createElement('div');
|
|
37
|
-
const contentWrapper = document.createElement('div');
|
|
38
|
-
|
|
39
|
-
wrapper.className = 'accordion-item';
|
|
40
|
-
headerWrapper.className = 'accordion-header';
|
|
41
|
-
contentWrapper.className = 'accordion-content';
|
|
42
|
-
|
|
43
|
-
headerWrapper.appendChild(header);
|
|
44
|
-
contentWrapper.appendChild(content);
|
|
45
|
-
|
|
46
|
-
wrapper.appendChild(headerWrapper);
|
|
47
|
-
wrapper.appendChild(contentWrapper);
|
|
48
|
-
|
|
49
|
-
items.push(wrapper);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
node.innerHTML = '';
|
|
53
|
-
items.forEach(item => node.appendChild(item));
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
this.icons = () =>
|
|
57
|
-
{
|
|
58
|
-
if(!data['icon'])
|
|
59
|
-
{
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const headers = node.querySelectorAll('.accordion-header');
|
|
64
|
-
|
|
65
|
-
headers.forEach(header =>
|
|
66
|
-
{
|
|
67
|
-
const icon = document.createElement('span');
|
|
68
|
-
icon.className = 'accordion-icon';
|
|
69
|
-
icon.innerHTML = '▼';
|
|
70
|
-
|
|
71
|
-
if(data['icon-position'] === 'left')
|
|
72
|
-
{
|
|
73
|
-
header.insertBefore(icon, header.firstChild);
|
|
74
|
-
}
|
|
75
|
-
else
|
|
76
|
-
{
|
|
77
|
-
header.appendChild(icon);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
this.styles = () =>
|
|
83
|
-
{
|
|
84
|
-
const duration = data['animation-duration'];
|
|
85
|
-
const style = document.createElement('style');
|
|
86
|
-
|
|
87
|
-
style.textContent = `
|
|
88
|
-
.${id} .accordion-content {
|
|
89
|
-
max-height: 0;
|
|
90
|
-
overflow: hidden;
|
|
91
|
-
transition: max-height ${duration}ms ease-in-out;
|
|
92
|
-
}
|
|
93
|
-
.${id} .accordion-item.active .accordion-content {
|
|
94
|
-
max-height: 2000px;
|
|
95
|
-
}
|
|
96
|
-
.${id} .accordion-header {
|
|
97
|
-
cursor: pointer;
|
|
98
|
-
display: flex;
|
|
99
|
-
justify-content: space-between;
|
|
100
|
-
align-items: center;
|
|
101
|
-
}
|
|
102
|
-
.${id} .accordion-icon {
|
|
103
|
-
transition: transform ${duration}ms ease;
|
|
104
|
-
display: inline-block;
|
|
105
|
-
}
|
|
106
|
-
.${id} .accordion-item.active .accordion-icon {
|
|
107
|
-
transform: rotate(180deg);
|
|
108
|
-
}
|
|
109
|
-
`;
|
|
110
|
-
|
|
111
|
-
document.head.appendChild(style);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
this.toggle = (item) =>
|
|
115
|
-
{
|
|
116
|
-
const isActive = item.classList.contains('active');
|
|
117
|
-
|
|
118
|
-
if(!data['multiple'])
|
|
119
|
-
{
|
|
120
|
-
const items = node.querySelectorAll('.accordion-item');
|
|
121
|
-
items.forEach(otherItem =>
|
|
122
|
-
{
|
|
123
|
-
if(otherItem !== item)
|
|
124
|
-
{
|
|
125
|
-
otherItem.classList.remove('active');
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if(isActive)
|
|
131
|
-
{
|
|
132
|
-
item.classList.remove('active');
|
|
133
|
-
}
|
|
134
|
-
else
|
|
135
|
-
{
|
|
136
|
-
item.classList.add('active');
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
this.events = () =>
|
|
141
|
-
{
|
|
142
|
-
const headers = node.querySelectorAll('.accordion-header');
|
|
143
|
-
|
|
144
|
-
headers.forEach(header =>
|
|
145
|
-
{
|
|
146
|
-
header.addEventListener('click', () =>
|
|
147
|
-
{
|
|
148
|
-
const item = header.parentElement;
|
|
149
|
-
this.toggle(item);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
this.initialize = () =>
|
|
155
|
-
{
|
|
156
|
-
if(data['first-open'])
|
|
157
|
-
{
|
|
158
|
-
const firstItem = node.querySelector('.accordion-item');
|
|
159
|
-
if(firstItem)
|
|
160
|
-
{
|
|
161
|
-
firstItem.classList.add('active');
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
this.setup();
|
|
167
|
-
this.icons();
|
|
168
|
-
this.styles();
|
|
169
|
-
this.events();
|
|
170
|
-
this.initialize();
|
|
171
|
-
}
|
|
172
|
-
});
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
transforms.ItemAdd({
|
|
2
|
-
id: 'ot-chart-area',
|
|
3
|
-
icon: 'area_chart',
|
|
4
|
-
name: 'Area Chart',
|
|
5
|
-
description: 'Filled area chart visualization. Show data trends with colored regions under the line.',
|
|
6
|
-
js: [
|
|
7
|
-
'https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js'
|
|
8
|
-
],
|
|
9
|
-
config: {
|
|
10
|
-
'labels': ['array', ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']],
|
|
11
|
-
'datasets': ['array', []],
|
|
12
|
-
'stacked': ['boolean', false],
|
|
13
|
-
'smooth': ['boolean', true],
|
|
14
|
-
'options': ['object', {}]
|
|
15
|
-
},
|
|
16
|
-
code: function(data, node, transformer)
|
|
17
|
-
{
|
|
18
|
-
this.setup = () =>
|
|
19
|
-
{
|
|
20
|
-
node.innerHTML = '';
|
|
21
|
-
node.classList.add('ot-chart-area');
|
|
22
|
-
|
|
23
|
-
const canvas = document.createElement('canvas');
|
|
24
|
-
this.canvas = canvas;
|
|
25
|
-
node.appendChild(canvas);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
this.colors = () =>
|
|
29
|
-
{
|
|
30
|
-
const style = getComputedStyle(document.body);
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
brand: style.getPropertyValue('--ot-brand').trim(),
|
|
34
|
-
blue: style.getPropertyValue('--ot-blue').trim(),
|
|
35
|
-
green: style.getPropertyValue('--ot-green').trim(),
|
|
36
|
-
orange: style.getPropertyValue('--ot-orange').trim(),
|
|
37
|
-
red: style.getPropertyValue('--ot-red').trim(),
|
|
38
|
-
brandOpacity: style.getPropertyValue('--ot-brand-opacity').trim(),
|
|
39
|
-
blueOpacity: style.getPropertyValue('--ot-blue-opacity').trim(),
|
|
40
|
-
greenOpacity: style.getPropertyValue('--ot-green-opacity').trim(),
|
|
41
|
-
orangeOpacity: style.getPropertyValue('--ot-orange-opacity').trim(),
|
|
42
|
-
redOpacity: style.getPropertyValue('--ot-red-opacity').trim()
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
this.datasets = () =>
|
|
47
|
-
{
|
|
48
|
-
const datasets = data['datasets'];
|
|
49
|
-
const colors = this.colors();
|
|
50
|
-
const palette = [colors.brand, colors.blue, colors.green, colors.orange, colors.red];
|
|
51
|
-
const paletteOpacity = [colors.brandOpacity, colors.blueOpacity, colors.greenOpacity, colors.orangeOpacity, colors.redOpacity];
|
|
52
|
-
const smooth = data['smooth'];
|
|
53
|
-
|
|
54
|
-
if(datasets.length === 0)
|
|
55
|
-
{
|
|
56
|
-
return [{
|
|
57
|
-
label: 'Sample Data',
|
|
58
|
-
data: [30, 45, 28, 56, 42, 65],
|
|
59
|
-
backgroundColor: paletteOpacity[0],
|
|
60
|
-
borderColor: palette[0],
|
|
61
|
-
borderWidth: 2,
|
|
62
|
-
fill: true,
|
|
63
|
-
tension: smooth ? 0.4 : 0
|
|
64
|
-
}];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return datasets.map((dataset, index) =>
|
|
68
|
-
{
|
|
69
|
-
const color = palette[index % palette.length];
|
|
70
|
-
const colorOpacity = paletteOpacity[index % paletteOpacity.length];
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
...dataset,
|
|
74
|
-
backgroundColor: dataset.backgroundColor || colorOpacity,
|
|
75
|
-
borderColor: dataset.borderColor || color,
|
|
76
|
-
borderWidth: dataset.borderWidth || 2,
|
|
77
|
-
fill: dataset.fill !== undefined ? dataset.fill : true,
|
|
78
|
-
tension: dataset.tension !== undefined ? dataset.tension : (smooth ? 0.4 : 0)
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
this.config = () =>
|
|
84
|
-
{
|
|
85
|
-
const style = getComputedStyle(document.body);
|
|
86
|
-
const textColor = style.getPropertyValue('--ot-text-1').trim();
|
|
87
|
-
const gridColor = style.getPropertyValue('--ot-bg-3-border').trim();
|
|
88
|
-
const stacked = data['stacked'];
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
type: 'line',
|
|
92
|
-
data: {
|
|
93
|
-
labels: data['labels'],
|
|
94
|
-
datasets: this.datasets()
|
|
95
|
-
},
|
|
96
|
-
options: {
|
|
97
|
-
responsive: true,
|
|
98
|
-
maintainAspectRatio: false,
|
|
99
|
-
interaction: {
|
|
100
|
-
intersect: false,
|
|
101
|
-
mode: 'index'
|
|
102
|
-
},
|
|
103
|
-
plugins: {
|
|
104
|
-
legend: {
|
|
105
|
-
labels: {
|
|
106
|
-
color: textColor,
|
|
107
|
-
font: {
|
|
108
|
-
family: style.getPropertyValue('--ot-font-primary').trim()
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
filler: {
|
|
113
|
-
propagate: false
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
scales: {
|
|
117
|
-
x: {
|
|
118
|
-
ticks: { color: textColor },
|
|
119
|
-
grid: { color: gridColor }
|
|
120
|
-
},
|
|
121
|
-
y: {
|
|
122
|
-
stacked: stacked,
|
|
123
|
-
ticks: { color: textColor },
|
|
124
|
-
grid: { color: gridColor },
|
|
125
|
-
beginAtZero: true
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
...data['options']
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
this.initialize = () =>
|
|
134
|
-
{
|
|
135
|
-
setTimeout(() =>
|
|
136
|
-
{
|
|
137
|
-
if(typeof Chart === 'undefined')
|
|
138
|
-
{
|
|
139
|
-
console.error('Chart.js library not loaded');
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const context = this.canvas.getContext('2d');
|
|
144
|
-
this.instance = new Chart(context, this.config());
|
|
145
|
-
|
|
146
|
-
node.chart = this.instance;
|
|
147
|
-
}, 100);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
this.setup();
|
|
151
|
-
this.initialize();
|
|
152
|
-
}
|
|
153
|
-
});
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
transforms.ItemAdd({
|
|
2
|
-
id: 'ot-chart-bar',
|
|
3
|
-
icon: 'bar_chart',
|
|
4
|
-
name: 'Bar Chart',
|
|
5
|
-
description: 'Vertical or horizontal bar charts. Compare values across categories with bars.',
|
|
6
|
-
js: [
|
|
7
|
-
'https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js'
|
|
8
|
-
],
|
|
9
|
-
config: {
|
|
10
|
-
'labels': ['array', ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']],
|
|
11
|
-
'datasets': ['array', []],
|
|
12
|
-
'stacked': ['boolean', false],
|
|
13
|
-
'horizontal': ['boolean', false],
|
|
14
|
-
'options': ['object', {}]
|
|
15
|
-
},
|
|
16
|
-
code: function(data, node, transformer)
|
|
17
|
-
{
|
|
18
|
-
this.setup = () =>
|
|
19
|
-
{
|
|
20
|
-
node.innerHTML = '';
|
|
21
|
-
node.classList.add('ot-chart-bar');
|
|
22
|
-
|
|
23
|
-
const canvas = document.createElement('canvas');
|
|
24
|
-
this.canvas = canvas;
|
|
25
|
-
node.appendChild(canvas);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
this.colors = () =>
|
|
29
|
-
{
|
|
30
|
-
const style = getComputedStyle(document.body);
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
brand: style.getPropertyValue('--ot-brand').trim(),
|
|
34
|
-
blue: style.getPropertyValue('--ot-blue').trim(),
|
|
35
|
-
green: style.getPropertyValue('--ot-green').trim(),
|
|
36
|
-
orange: style.getPropertyValue('--ot-orange').trim(),
|
|
37
|
-
red: style.getPropertyValue('--ot-red').trim()
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
this.datasets = () =>
|
|
42
|
-
{
|
|
43
|
-
const datasets = data['datasets'];
|
|
44
|
-
const colors = this.colors();
|
|
45
|
-
const palette = [colors.brand, colors.blue, colors.green, colors.orange, colors.red];
|
|
46
|
-
|
|
47
|
-
if(datasets.length === 0)
|
|
48
|
-
{
|
|
49
|
-
return [{
|
|
50
|
-
label: 'Sample Data',
|
|
51
|
-
data: [42, 56, 28, 84, 65, 39],
|
|
52
|
-
backgroundColor: palette[0],
|
|
53
|
-
borderColor: palette[0],
|
|
54
|
-
borderWidth: 0
|
|
55
|
-
}];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return datasets.map((dataset, index) =>
|
|
59
|
-
{
|
|
60
|
-
const color = palette[index % palette.length];
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
...dataset,
|
|
64
|
-
backgroundColor: dataset.backgroundColor || color,
|
|
65
|
-
borderColor: dataset.borderColor || color,
|
|
66
|
-
borderWidth: dataset.borderWidth || 0
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
this.config = () =>
|
|
72
|
-
{
|
|
73
|
-
const style = getComputedStyle(document.body);
|
|
74
|
-
const textColor = style.getPropertyValue('--ot-text-1').trim();
|
|
75
|
-
const gridColor = style.getPropertyValue('--ot-bg-3-border').trim();
|
|
76
|
-
const stacked = data['stacked'];
|
|
77
|
-
const horizontal = data['horizontal'];
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
type: horizontal ? 'bar' : 'bar',
|
|
81
|
-
data: {
|
|
82
|
-
labels: data['labels'],
|
|
83
|
-
datasets: this.datasets()
|
|
84
|
-
},
|
|
85
|
-
options: {
|
|
86
|
-
indexAxis: horizontal ? 'y' : 'x',
|
|
87
|
-
responsive: true,
|
|
88
|
-
maintainAspectRatio: false,
|
|
89
|
-
plugins: {
|
|
90
|
-
legend: {
|
|
91
|
-
labels: {
|
|
92
|
-
color: textColor,
|
|
93
|
-
font: {
|
|
94
|
-
family: style.getPropertyValue('--ot-font-primary').trim()
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
scales: {
|
|
100
|
-
x: {
|
|
101
|
-
stacked: stacked,
|
|
102
|
-
ticks: { color: textColor },
|
|
103
|
-
grid: { color: gridColor }
|
|
104
|
-
},
|
|
105
|
-
y: {
|
|
106
|
-
stacked: stacked,
|
|
107
|
-
ticks: { color: textColor },
|
|
108
|
-
grid: { color: gridColor },
|
|
109
|
-
beginAtZero: true
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
...data['options']
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
this.initialize = () =>
|
|
118
|
-
{
|
|
119
|
-
setTimeout(() =>
|
|
120
|
-
{
|
|
121
|
-
if(typeof Chart === 'undefined')
|
|
122
|
-
{
|
|
123
|
-
console.error('Chart.js library not loaded');
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const context = this.canvas.getContext('2d');
|
|
128
|
-
this.instance = new Chart(context, this.config());
|
|
129
|
-
|
|
130
|
-
node.chart = this.instance;
|
|
131
|
-
}, 100);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
this.setup();
|
|
135
|
-
this.initialize();
|
|
136
|
-
}
|
|
137
|
-
});
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
transforms.ItemAdd({
|
|
2
|
-
id: 'ot-chart-bubble',
|
|
3
|
-
icon: 'bubble_chart',
|
|
4
|
-
name: 'Bubble Chart',
|
|
5
|
-
description: 'Bubble chart with three dimensions. Display data points as sized bubbles on X/Y axes.',
|
|
6
|
-
js: [
|
|
7
|
-
'https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js'
|
|
8
|
-
],
|
|
9
|
-
config: {
|
|
10
|
-
'datasets': ['array', []],
|
|
11
|
-
'options': ['object', {}]
|
|
12
|
-
},
|
|
13
|
-
code: function(data, node, transformer)
|
|
14
|
-
{
|
|
15
|
-
this.setup = () =>
|
|
16
|
-
{
|
|
17
|
-
node.innerHTML = '';
|
|
18
|
-
node.classList.add('ot-chart-bubble');
|
|
19
|
-
|
|
20
|
-
const canvas = document.createElement('canvas');
|
|
21
|
-
this.canvas = canvas;
|
|
22
|
-
node.appendChild(canvas);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
this.colors = () =>
|
|
26
|
-
{
|
|
27
|
-
const style = getComputedStyle(document.body);
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
brand: style.getPropertyValue('--ot-brand').trim(),
|
|
31
|
-
blue: style.getPropertyValue('--ot-blue').trim(),
|
|
32
|
-
green: style.getPropertyValue('--ot-green').trim(),
|
|
33
|
-
orange: style.getPropertyValue('--ot-orange').trim(),
|
|
34
|
-
red: style.getPropertyValue('--ot-red').trim(),
|
|
35
|
-
brandOpacity: style.getPropertyValue('--ot-brand-opacity').trim(),
|
|
36
|
-
blueOpacity: style.getPropertyValue('--ot-blue-opacity').trim(),
|
|
37
|
-
greenOpacity: style.getPropertyValue('--ot-green-opacity').trim(),
|
|
38
|
-
orangeOpacity: style.getPropertyValue('--ot-orange-opacity').trim(),
|
|
39
|
-
redOpacity: style.getPropertyValue('--ot-red-opacity').trim()
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
this.datasets = () =>
|
|
44
|
-
{
|
|
45
|
-
const datasets = data['datasets'];
|
|
46
|
-
const colors = this.colors();
|
|
47
|
-
const palette = [colors.brand, colors.blue, colors.green, colors.orange, colors.red];
|
|
48
|
-
const paletteOpacity = [colors.brandOpacity, colors.blueOpacity, colors.greenOpacity, colors.orangeOpacity, colors.redOpacity];
|
|
49
|
-
|
|
50
|
-
if(datasets.length === 0)
|
|
51
|
-
{
|
|
52
|
-
return [{
|
|
53
|
-
label: 'Sample Data',
|
|
54
|
-
data: [
|
|
55
|
-
{x: 10, y: 20, r: 8},
|
|
56
|
-
{x: 15, y: 35, r: 12},
|
|
57
|
-
{x: 20, y: 30, r: 10},
|
|
58
|
-
{x: 25, y: 45, r: 15},
|
|
59
|
-
{x: 30, y: 40, r: 6},
|
|
60
|
-
{x: 35, y: 55, r: 20}
|
|
61
|
-
],
|
|
62
|
-
backgroundColor: paletteOpacity[0],
|
|
63
|
-
borderColor: palette[0],
|
|
64
|
-
borderWidth: 2
|
|
65
|
-
}];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return datasets.map((dataset, index) =>
|
|
69
|
-
{
|
|
70
|
-
const color = palette[index % palette.length];
|
|
71
|
-
const colorOpacity = paletteOpacity[index % paletteOpacity.length];
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
...dataset,
|
|
75
|
-
backgroundColor: dataset.backgroundColor || colorOpacity,
|
|
76
|
-
borderColor: dataset.borderColor || color,
|
|
77
|
-
borderWidth: dataset.borderWidth || 2
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
this.config = () =>
|
|
83
|
-
{
|
|
84
|
-
const style = getComputedStyle(document.body);
|
|
85
|
-
const textColor = style.getPropertyValue('--ot-text-1').trim();
|
|
86
|
-
const gridColor = style.getPropertyValue('--ot-bg-3-border').trim();
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
type: 'bubble',
|
|
90
|
-
data: {
|
|
91
|
-
datasets: this.datasets()
|
|
92
|
-
},
|
|
93
|
-
options: {
|
|
94
|
-
responsive: true,
|
|
95
|
-
maintainAspectRatio: false,
|
|
96
|
-
plugins: {
|
|
97
|
-
legend: {
|
|
98
|
-
labels: {
|
|
99
|
-
color: textColor,
|
|
100
|
-
font: {
|
|
101
|
-
family: style.getPropertyValue('--ot-font-primary').trim()
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
tooltip: {
|
|
106
|
-
callbacks: {
|
|
107
|
-
label: function(context)
|
|
108
|
-
{
|
|
109
|
-
const label = context.dataset.label || '';
|
|
110
|
-
const x = context.parsed.x;
|
|
111
|
-
const y = context.parsed.y;
|
|
112
|
-
const r = context.raw.r;
|
|
113
|
-
return label + ': (x: ' + x + ', y: ' + y + ', size: ' + r + ')';
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
scales: {
|
|
119
|
-
x: {
|
|
120
|
-
type: 'linear',
|
|
121
|
-
position: 'bottom',
|
|
122
|
-
ticks: { color: textColor },
|
|
123
|
-
grid: { color: gridColor },
|
|
124
|
-
title: {
|
|
125
|
-
display: true,
|
|
126
|
-
text: 'X Axis',
|
|
127
|
-
color: textColor
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
y: {
|
|
131
|
-
type: 'linear',
|
|
132
|
-
ticks: { color: textColor },
|
|
133
|
-
grid: { color: gridColor },
|
|
134
|
-
title: {
|
|
135
|
-
display: true,
|
|
136
|
-
text: 'Y Axis',
|
|
137
|
-
color: textColor
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
...data['options']
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
this.initialize = () =>
|
|
147
|
-
{
|
|
148
|
-
setTimeout(() =>
|
|
149
|
-
{
|
|
150
|
-
if(typeof Chart === 'undefined')
|
|
151
|
-
{
|
|
152
|
-
console.error('Chart.js library not loaded');
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const context = this.canvas.getContext('2d');
|
|
157
|
-
this.instance = new Chart(context, this.config());
|
|
158
|
-
|
|
159
|
-
node.chart = this.instance;
|
|
160
|
-
}, 100);
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
this.setup();
|
|
164
|
-
this.initialize();
|
|
165
|
-
}
|
|
166
|
-
});
|