Compare commits
99 Commits
yarn-works
...
main
Author | SHA1 | Date |
---|---|---|
vargburz | b3e7f943ad | 1 week ago |
vargburz | a8408a748c | 4 weeks ago |
vargburz | 6e6fa7dc8e | 1 month ago |
rozetko | f67ce313dd | 1 month ago |
rozetko | c1c3b77dac | 1 month ago |
rozetko | 53c233b969 | 1 month ago |
vargburz | ebcb3185cd | 1 month ago |
vargburz | 6422b49bf0 | 1 month ago |
vargburz | 3f9342b5e1 | 1 month ago |
vargburz | bb46fe79be | 1 month ago |
rozetko | 0c3b404155 | 2 months ago |
rozetko | 85cd952b9f | 2 months ago |
rozetko | 701feaaf2f | 2 months ago |
rozetko | ebb49adf82 | 2 months ago |
rozetko | f38829787c | 2 months ago |
rozetko | 6549415feb | 2 months ago |
rozetko | 117c0af469 | 2 months ago |
rozetko | aac8f6f5ac | 2 months ago |
rozetko | f4354d7a77 | 2 months ago |
rozetko | 529f439ac9 | 2 months ago |
rozetko | 121f7a0305 | 2 months ago |
rozetko | 7e721ab880 | 2 months ago |
rozetko | 3663d3eaaa | 2 months ago |
Coin de Gamma | bd598d6a0b | 4 months ago |
glitch4347 | 4620ef7aa9 | 4 months ago |
rozetko | 44a4e6ce74 | 4 months ago |
glitch4347 | 04a01b75a1 | 4 months ago |
glitch4347 | bf3aab2db1 | 4 months ago |
Coin de Gamma | 348a289f1a | 6 months ago |
glitch4347 | 17a2fdf94e | 6 months ago |
Coin de Gamma | dc89f6cbb9 | 6 months ago |
glitch4347 | 547c15c0b6 | 6 months ago |
glitch4347 | 32d122ba4d | 6 months ago |
glitch4347 | 9c165f4e1f | 6 months ago |
Coin de Gamma | ec2bd27acd | 6 months ago |
glitch4347 | 815144d209 | 6 months ago |
glitch4347 | 1a80ca2cab | 6 months ago |
Coin de Gamma | ee08db2f54 | 6 months ago |
glitch4347 | 884fed6582 | 6 months ago |
glitch4347 | 8aca72ce04 | 6 months ago |
Coin de Gamma | c62a1c386f | 6 months ago |
glitch4347 | de6237891c | 6 months ago |
rozetko | 7bcd0d298a | 8 months ago |
rozetko | ee2f02be96 | 8 months ago |
rozetko | 456b888fe1 | 8 months ago |
rozetko | a34c0574e4 | 8 months ago |
rozetko | 73dbf0ea67 | 8 months ago |
rozetko | ff5973b106 | 8 months ago |
rozetko | 878e86d849 | 8 months ago |
vargburz | 1e8f8d0cb3 | 8 months ago |
rozetko | 39412e5f65 | 8 months ago |
rozetko | 37da147343 | 8 months ago |
glitch4347 | 0dac1c390e | 8 months ago |
glitch4347 | 07f454fe51 | 8 months ago |
vargburz | 88d6b2b24a | 8 months ago |
glitch4347 | 837004c2ad | 9 months ago |
glitch4347 | e46c7bdfb6 | 9 months ago |
rozetko | ee7a57685f | 9 months ago |
rozetko | 963011b274 | 9 months ago |
glitch4347 | 283f0995e8 | 9 months ago |
rozetko | 19689a68cd | 9 months ago |
glitch4347 | 79b759569f | 9 months ago |
glitch4347 | d66da50c1a | 9 months ago |
glitch4347 | d9d1b5e501 | 9 months ago |
Coin de Gamma | b8cd14e4b8 | 9 months ago |
glitch4347 | e470d58611 | 9 months ago |
glitch4347 | 26d5956c17 | 9 months ago |
glitch4347 | 43241bbcb7 | 9 months ago |
glitch4347 | 82fc9a10f1 | 9 months ago |
rozetko | 57ae85c20e | 9 months ago |
glitch4347 | 98e4e42fc4 | 9 months ago |
glitch4347 | 6fbf833150 | 9 months ago |
glitch4347 | a0e27d5efd | 9 months ago |
glitch4347 | 727f8cac86 | 9 months ago |
glitch4347 | 869488d405 | 9 months ago |
glitch4347 | d97b0e9b0c | 9 months ago |
glitch4347 | 11ab01a7d2 | 9 months ago |
glitch4347 | 326c666435 | 10 months ago |
rozetko | 33cf970d5f | 10 months ago |
glitch4347 | 03a562c0d2 | 10 months ago |
glitch4347 | 38b6eb2326 | 10 months ago |
rozetko | af9aaf6d82 | 10 months ago |
glitch4347 | bf679019fc | 10 months ago |
glitch4347 | 86099c57b3 | 10 months ago |
glitch4347 | 9a6c5cd7f4 | 10 months ago |
glitch4347 | aadcd013bf | 10 months ago |
glitch4347 | a5c737fa81 | 10 months ago |
rozetko | c451df6e3b | 10 months ago |
rozetko | 3ff6f7b8e8 | 10 months ago |
glitch4347 | 1d1a34f9bf | 10 months ago |
glitch4347 | 8346bceedf | 10 months ago |
vargburz | 1ca84c53f8 | 10 months ago |
vargburz | 85793a7965 | 10 months ago |
vargburz | 7e4a895e93 | 10 months ago |
glitch4347 | f1c3ef6f1d | 10 months ago |
rozetko | 6a0ea4303e | 10 months ago |
glitch4347 | 08b128ea91 | 10 months ago |
glitch4347 | f1582fc610 | 10 months ago |
glitch4347 | e98997995f | 10 months ago |
50 changed files with 2535 additions and 3443 deletions
@ -0,0 +1,42 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
<head> |
||||||
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> |
||||||
|
<meta content="utf-8" http-equiv="encoding"> |
||||||
|
|
||||||
|
<script src="../dist/index.dev.js" type="text/javascript"></script> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
<div id="chart" style="width: 50%; height: 500px;"></div> |
||||||
|
|
||||||
|
<script type="text/javascript"> |
||||||
|
let options = { |
||||||
|
renderLegend: false, usePanning: false, |
||||||
|
axis: { |
||||||
|
x: { format: 'numeric', range: [0, 100] }, |
||||||
|
y: { invert: true, range: [0, 100] }, |
||||||
|
y1: { isActive: true, format: 'numeric', range: [0, 1000] }, |
||||||
|
}, |
||||||
|
zoomEvents: { |
||||||
|
mouse: { zoom: { isActive: false, orientation: 'horizontal' } }, |
||||||
|
scroll: { zoom: { isActive: false, orientation: 'horizontal' } } |
||||||
|
}, |
||||||
|
} |
||||||
|
const data1 = [[0,0], [35, 40], [65, 60], [100, 100]]; |
||||||
|
const data2 = [[0,0], [35, 50], [65, 65], [80, 100]]; |
||||||
|
const data3 = [[0,0], [35, 20], [65, 50], [100, 80]]; |
||||||
|
const data4 = [[0,900], [35, 800], [65, 700], [100, 600]]; |
||||||
|
var pod = new LinePod( |
||||||
|
document.getElementById('chart'), |
||||||
|
[ |
||||||
|
{ target: 'test1', datapoints: data1, color: 'green', renderArea: 'Above' }, |
||||||
|
{ target: 'test2', datapoints: data2, color: 'blue', renderArea: 'Below' }, |
||||||
|
{ target: 'test3', datapoints: data3, color: 'orange', renderArea: 'Below', yOrientation: 'right' }, |
||||||
|
{ target: 'test4', datapoints: data4, color: 'purple', renderArea: 'Above', yOrientation: 'right' }, |
||||||
|
], |
||||||
|
options |
||||||
|
); |
||||||
|
pod.render(); |
||||||
|
</script> |
||||||
|
</body> |
||||||
|
</html> |
@ -0,0 +1,51 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
<head> |
||||||
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> |
||||||
|
<meta content="utf-8" http-equiv="encoding"> |
||||||
|
|
||||||
|
<script src="../dist/index.dev.js" type="text/javascript"></script> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
<div id="chart" style="width: 100%; height: 500px;"></div> |
||||||
|
|
||||||
|
<script type="text/javascript"> |
||||||
|
const startTime = 1701790172908; |
||||||
|
const timeSerieData = [5, 6, 3, 7, 5, 6, 8, 4, 5, 6, 4, 3, 5, 7, 8] |
||||||
|
.map((el, idx) => [startTime + idx * 1000, el]); |
||||||
|
const markersData1 = [3, 6, 9].map(el => ({ |
||||||
|
x: startTime + el * 1000, |
||||||
|
color: 'red', |
||||||
|
alwaysDisplay: false, |
||||||
|
html: new Date(startTime).toISOString(), |
||||||
|
})); |
||||||
|
const markersData2 = [4, 11].map(el => ({ |
||||||
|
x: startTime + el * 1000, |
||||||
|
color: 'blue', |
||||||
|
alwaysDisplay: true, |
||||||
|
html: new Date(startTime).toISOString(), |
||||||
|
})); |
||||||
|
let options = { |
||||||
|
renderLegend: false, |
||||||
|
axis: { |
||||||
|
y: { range: [0, 10] }, |
||||||
|
x: { format: 'time' } |
||||||
|
}, |
||||||
|
} |
||||||
|
var pod = new LinePod( |
||||||
|
document.getElementById('chart'), |
||||||
|
[ |
||||||
|
{ datapoints: timeSerieData, color: 'black' }, |
||||||
|
], |
||||||
|
options, |
||||||
|
{ |
||||||
|
series: [ |
||||||
|
{ data: markersData1 }, |
||||||
|
{ data: markersData2 }, |
||||||
|
] |
||||||
|
} |
||||||
|
); |
||||||
|
pod.render(); |
||||||
|
</script> |
||||||
|
</body> |
||||||
|
</html> |
@ -0,0 +1,47 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
<head> |
||||||
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> |
||||||
|
<meta content="utf-8" http-equiv="encoding"> |
||||||
|
|
||||||
|
<script src="../dist/index.dev.js" type="text/javascript"></script> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
<div id="chart" style="width: 100%; height: 500px;"></div> |
||||||
|
|
||||||
|
<script type="text/javascript"> |
||||||
|
const startTime = 1701790172908; |
||||||
|
const timeSerieData = [5, 6, 3, 7, 5, 6, 8, 4, 5, 6, 4, 3, 5, 7, 8] |
||||||
|
.map((el, idx) => [startTime + idx * 1000, el]); |
||||||
|
const markersData = [3, 6, 9].map(el => ({ |
||||||
|
x: startTime + el * 1000, |
||||||
|
payload: el, |
||||||
|
color: 'red', |
||||||
|
})); |
||||||
|
let options = { |
||||||
|
renderLegend: false, |
||||||
|
axis: { |
||||||
|
y: { range: [0, 10] }, |
||||||
|
x: { format: 'time' } |
||||||
|
}, |
||||||
|
} |
||||||
|
var pod = new LinePod( |
||||||
|
document.getElementById('chart'), |
||||||
|
[ |
||||||
|
{ datapoints: timeSerieData, color: 'black' }, |
||||||
|
], |
||||||
|
options, |
||||||
|
{ |
||||||
|
series: [ |
||||||
|
{ data: markersData }, |
||||||
|
], |
||||||
|
events: { |
||||||
|
onMouseMove: (el) => { console.log(el); }, |
||||||
|
onMouseOut: () => { console.log('mouse out'); } |
||||||
|
} |
||||||
|
} |
||||||
|
); |
||||||
|
pod.render(); |
||||||
|
</script> |
||||||
|
</body> |
||||||
|
</html> |
@ -0,0 +1,33 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
<head> |
||||||
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> |
||||||
|
<meta content="utf-8" http-equiv="encoding"> |
||||||
|
<script src="../dist/index.dev.js" type="text/javascript"></script> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
<div id="chart" style="width: 50%; height: 500px;"></div> |
||||||
|
<script type="text/javascript"> |
||||||
|
const startTime = 1590590148; |
||||||
|
const data = Array.from( |
||||||
|
{ length: 20 }, |
||||||
|
(el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 30)] |
||||||
|
); |
||||||
|
let options = { |
||||||
|
renderLegend: false, usePanning: false, |
||||||
|
axis: { y: { range: [0, 50] } }, |
||||||
|
zoomEvents: { mouse: { |
||||||
|
zoom: { isActive: false }, |
||||||
|
pan: { isActive: false }, |
||||||
|
} }, |
||||||
|
eventsCallbacks: { mouseClick: console.log } |
||||||
|
} |
||||||
|
var pod = new LinePod( |
||||||
|
document.getElementById('chart'), |
||||||
|
[{ datapoints: data }], |
||||||
|
options |
||||||
|
); |
||||||
|
pod.render(); |
||||||
|
</script> |
||||||
|
</body> |
||||||
|
</html> |
@ -0,0 +1,29 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
<head> |
||||||
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> |
||||||
|
<meta content="utf-8" http-equiv="encoding"> |
||||||
|
<script src="../dist/index.dev.js" type="text/javascript"></script> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
<div id="chart" style="width: 50%; height: 500px;"></div> |
||||||
|
<script type="text/javascript"> |
||||||
|
const startTime = 1590590148; |
||||||
|
const data = Array.from( |
||||||
|
{ length: 20 }, |
||||||
|
(el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 30)] |
||||||
|
); |
||||||
|
let options = { |
||||||
|
renderLegend: false, usePanning: false, |
||||||
|
axis: { y: { range: [0, 50] } }, |
||||||
|
eventsCallbacks: { mouseMove: console.log } |
||||||
|
} |
||||||
|
var pod = new LinePod( |
||||||
|
document.getElementById('chart'), |
||||||
|
[{ datapoints: data }], |
||||||
|
options |
||||||
|
); |
||||||
|
pod.render(); |
||||||
|
</script> |
||||||
|
</body> |
||||||
|
</html> |
@ -0,0 +1,33 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
<head> |
||||||
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> |
||||||
|
<meta content="utf-8" http-equiv="encoding"> |
||||||
|
<script src="../dist/index.dev.js" type="text/javascript"></script> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
<div id="chart" style="width: 50%; height: 500px;"></div> |
||||||
|
<script type="text/javascript"> |
||||||
|
const startTime = 1590590148; |
||||||
|
const data = Array.from( |
||||||
|
{ length: 20 }, |
||||||
|
(el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 30)] |
||||||
|
); |
||||||
|
let options = { |
||||||
|
renderLegend: false, usePanning: false, |
||||||
|
axis: { y: { range: [0, 50] } }, |
||||||
|
zoomEvents: { mouse: { |
||||||
|
zoom: { isActive: false }, |
||||||
|
pan: { isActive: false }, |
||||||
|
} }, |
||||||
|
eventsCallbacks: { contextMenu: (position) => console.log('contextMenu', position) } |
||||||
|
} |
||||||
|
var pod = new LinePod( |
||||||
|
document.getElementById('chart'), |
||||||
|
[{ datapoints: data }], |
||||||
|
options |
||||||
|
); |
||||||
|
pod.render(); |
||||||
|
</script> |
||||||
|
</body> |
||||||
|
</html> |
@ -0,0 +1,41 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
<head> |
||||||
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> |
||||||
|
<meta content="utf-8" http-equiv="encoding"> |
||||||
|
|
||||||
|
<script src="../dist/index.dev.js" type="text/javascript"></script> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
<div id="chart" style="width: 100%; height: 500px;"></div> |
||||||
|
|
||||||
|
<script type="text/javascript"> |
||||||
|
const startTime = 1701790172908; |
||||||
|
const timeSerieData = [5, 6, 3, 7, 5, 6, 8, 4, 5, 6, 4, 3, 5, 7, 8] |
||||||
|
.map((el, idx) => [startTime + idx * 1000, el]); |
||||||
|
const segmentsData = [3, 6, 9].map(el => [startTime + el * 1000, startTime + (el + 1) * 1100]); |
||||||
|
let options = { |
||||||
|
renderLegend: false, |
||||||
|
axis: { |
||||||
|
y: { range: [0, 10] }, |
||||||
|
x: { format: 'time' } |
||||||
|
}, |
||||||
|
} |
||||||
|
var pod = new LinePod( |
||||||
|
document.getElementById('chart'), |
||||||
|
[ |
||||||
|
{ datapoints: timeSerieData, color: 'black' }, |
||||||
|
], |
||||||
|
options, |
||||||
|
undefined, |
||||||
|
[ |
||||||
|
{ |
||||||
|
data: segmentsData, |
||||||
|
color:'#FFE545' |
||||||
|
} |
||||||
|
] |
||||||
|
); |
||||||
|
pod.render(); |
||||||
|
</script> |
||||||
|
</body> |
||||||
|
</html> |
@ -0,0 +1,46 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
<head> |
||||||
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> |
||||||
|
<meta content="utf-8" http-equiv="encoding"> |
||||||
|
|
||||||
|
<script src="../dist/index.dev.js" type="text/javascript"></script> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
<div id="chart" style="width: 100%; height: 500px;"></div> |
||||||
|
|
||||||
|
<script type="text/javascript"> |
||||||
|
const startTime = 1701790172908; |
||||||
|
const timeSerieData = [5, 6, 3, 7, 5, 6, 8, 4, 5, 6, 4, 3, 5, 7, 8] |
||||||
|
.map((el, idx) => [startTime + idx * 1000, el]); |
||||||
|
const segmentsData = [3, 6, 9].map(el => [startTime + el * 1000, startTime + (el + 1) * 1100]); |
||||||
|
let options = { |
||||||
|
renderLegend: false, |
||||||
|
axis: { |
||||||
|
y: { range: [0, 10] }, |
||||||
|
x: { format: 'time' } |
||||||
|
}, |
||||||
|
} |
||||||
|
var pod = new LinePod( |
||||||
|
document.getElementById('chart'), |
||||||
|
[ |
||||||
|
{ datapoints: timeSerieData, color: 'black' }, |
||||||
|
], |
||||||
|
options, |
||||||
|
undefined, |
||||||
|
[ |
||||||
|
{ |
||||||
|
data: segmentsData, |
||||||
|
color:'#FFE545', |
||||||
|
select: true, |
||||||
|
opacity: 0.4, |
||||||
|
opacitySelect: 0.8, |
||||||
|
onSelect: console.log, |
||||||
|
onUnselect: console.log |
||||||
|
} |
||||||
|
] |
||||||
|
); |
||||||
|
pod.render(); |
||||||
|
</script> |
||||||
|
</body> |
||||||
|
</html> |
@ -0,0 +1,37 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
<head> |
||||||
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> |
||||||
|
<meta content="utf-8" http-equiv="encoding"> |
||||||
|
<script src="../dist/index.dev.js" type="text/javascript"></script> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
<div id="chart" style="width: 50%; height: 500px;"></div> |
||||||
|
<script type="text/javascript"> |
||||||
|
const startTime = 1590590148; |
||||||
|
const data = Array.from( |
||||||
|
{ length: 20 }, |
||||||
|
(el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 30)] |
||||||
|
); |
||||||
|
let options = { |
||||||
|
renderLegend: false, usePanning: false, |
||||||
|
axis: { y: { range: [0, 50] } }, |
||||||
|
zoomEvents: { mouse: { |
||||||
|
zoom: { isActive: true, orientation: "horizontal" }, |
||||||
|
pan: { isActive: false }, |
||||||
|
}}, |
||||||
|
events: { |
||||||
|
zoomOut: function(centers, ranges) { |
||||||
|
console.log('zoomOut', centers, ranges); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
var pod = new LinePod( |
||||||
|
document.getElementById('chart'), |
||||||
|
[{ datapoints: data }], |
||||||
|
options |
||||||
|
); |
||||||
|
pod.render(); |
||||||
|
</script> |
||||||
|
</body> |
||||||
|
</html> |
@ -1,16 +1,37 @@ |
|||||||
{ |
{ |
||||||
"name": "@chartwerk/line-pod", |
"name": "@chartwerk/line-pod", |
||||||
"version": "0.6.9", |
"version": "0.7.8", |
||||||
"description": "Chartwerk line chart", |
"description": "Chartwerk line chart", |
||||||
"workspaces": [ |
"main": "dist/index.js", |
||||||
"packages/line-pod", |
"files": [ |
||||||
"packages/react" |
"/dist" |
||||||
], |
], |
||||||
|
"scripts": { |
||||||
|
"build": "rm -rf dist && cd react && yarn build && cd .. && webpack --config build/webpack.prod.conf.js && webpack --config build/webpack.dev.conf.js", |
||||||
|
"dev": "webpack --watch --config build/webpack.dev.conf.js", |
||||||
|
"test": "echo \"Error: no test specified\" && exit 1", |
||||||
|
"update-core": "yarn up @chartwerk/core && yarn up @chartwerk/core@latest" |
||||||
|
}, |
||||||
"repository": { |
"repository": { |
||||||
"type": "git", |
"type": "git", |
||||||
"url": "http://code.corpglory.net/chartwerk/line-pod.git" |
"url": "http://code.corpglory.net/chartwerk/line-pod.git" |
||||||
}, |
}, |
||||||
"author": "CorpGlory", |
"author": "CorpGlory", |
||||||
"license": "ISC", |
"license": "ISC", |
||||||
"packageManager": "yarn@3.2.1" |
"dependencies": { |
||||||
|
"@chartwerk/core": "^0.6.26" |
||||||
|
}, |
||||||
|
"devDependencies": { |
||||||
|
"copy-webpack-plugin": "^11.0.0", |
||||||
|
"css-loader": "^6.8.1", |
||||||
|
"style-loader": "^3.3.3", |
||||||
|
"ts-loader": "^9.4.3", |
||||||
|
"typescript": "^5.1.3", |
||||||
|
"webpack": "^5.87.0", |
||||||
|
"webpack-cli": "^5.1.4" |
||||||
|
}, |
||||||
|
"packageManager": "yarn@3.2.1", |
||||||
|
"workspaces": [ |
||||||
|
"react/*" |
||||||
|
] |
||||||
} |
} |
||||||
|
@ -1,33 +0,0 @@ |
|||||||
{ |
|
||||||
"name": "line-pod", |
|
||||||
"version": "0.6.9", |
|
||||||
"description": "Chartwerk line chart", |
|
||||||
"main": "dist/index.js", |
|
||||||
"files": [ |
|
||||||
"/dist" |
|
||||||
], |
|
||||||
"scripts": { |
|
||||||
"build": "webpack --config build/webpack.prod.conf.js && webpack --config build/webpack.dev.conf.js", |
|
||||||
"dev": "webpack --watch --config build/webpack.dev.conf.js", |
|
||||||
"test": "echo \"Error: no test specified\" && exit 1", |
|
||||||
"update-core": "yarn up @chartwerk/core && yarn up @chartwerk/core@latest" |
|
||||||
}, |
|
||||||
"repository": { |
|
||||||
"type": "git", |
|
||||||
"url": "https://gitlab.com/chartwerk/line-pod.git" |
|
||||||
}, |
|
||||||
"author": "CorpGlory", |
|
||||||
"license": "ISC", |
|
||||||
"dependencies": { |
|
||||||
"@chartwerk/core": "latest" |
|
||||||
}, |
|
||||||
"devDependencies": { |
|
||||||
"css-loader": "^6.8.1", |
|
||||||
"style-loader": "^3.3.3", |
|
||||||
"ts-loader": "^9.4.3", |
|
||||||
"typescript": "^5.1.3", |
|
||||||
"webpack": "^5.87.0", |
|
||||||
"webpack-cli": "^5.1.4" |
|
||||||
}, |
|
||||||
"packageManager": "yarn@3.2.1" |
|
||||||
} |
|
@ -1,13 +0,0 @@ |
|||||||
import { Serie, Options } from '@chartwerk/core'; |
|
||||||
|
|
||||||
type LineTimeSerieParams = { |
|
||||||
maxLength: number, |
|
||||||
renderDots: boolean, |
|
||||||
renderLines: boolean, // TODO: refactor same as scatter-pod
|
|
||||||
dashArray: string; // dasharray attr, only for lines
|
|
||||||
class: string; // option to add custom class to each serie element
|
|
||||||
renderArea: boolean; // TODO: move to render type
|
|
||||||
} |
|
||||||
|
|
||||||
export type LineTimeSerie = Serie & Partial<LineTimeSerieParams>; |
|
||||||
export type LineOptions = Options; |
|
@ -1,27 +0,0 @@ |
|||||||
# React + TypeScript + Vite |
|
||||||
|
|
||||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. |
|
||||||
|
|
||||||
Currently, two official plugins are available: |
|
||||||
|
|
||||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh |
|
||||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh |
|
||||||
|
|
||||||
## Expanding the ESLint configuration |
|
||||||
|
|
||||||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: |
|
||||||
|
|
||||||
- Configure the top-level `parserOptions` property like this: |
|
||||||
|
|
||||||
```js |
|
||||||
parserOptions: { |
|
||||||
ecmaVersion: 'latest', |
|
||||||
sourceType: 'module', |
|
||||||
project: ['./tsconfig.json', './tsconfig.node.json'], |
|
||||||
tsconfigRootDir: __dirname, |
|
||||||
}, |
|
||||||
``` |
|
||||||
|
|
||||||
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` |
|
||||||
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` |
|
||||||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list |
|
@ -1,13 +0,0 @@ |
|||||||
<!doctype html> |
|
||||||
<html lang="en"> |
|
||||||
<head> |
|
||||||
<meta charset="UTF-8" /> |
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> |
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
|
||||||
<title>Line-Pod Demo</title> |
|
||||||
</head> |
|
||||||
<body> |
|
||||||
<div id="root"></div> |
|
||||||
<script type="module" src="/src/main.tsx"></script> |
|
||||||
</body> |
|
||||||
</html> |
|
@ -1,126 +0,0 @@ |
|||||||
import type { LineTimeSerie, LineOptions } from 'line-pod'; |
|
||||||
import { LinePod } from 'line-pod'; |
|
||||||
// import { AxisRange } from '@chartwerk/core/dist/types';
|
|
||||||
|
|
||||||
import { useEffect, useRef, useState, PropsWithChildren, forwardRef } from 'react'; |
|
||||||
|
|
||||||
import * as _ from 'lodash'; |
|
||||||
|
|
||||||
export type AxisRange = [number, number] | undefined; |
|
||||||
export type ChartwerkLinePodProps = { |
|
||||||
id: string; |
|
||||||
series: LineTimeSerie[]; |
|
||||||
options: LineOptions; |
|
||||||
className?: string; |
|
||||||
// TODO: callback types should be exported from chartwerk
|
|
||||||
onZoomIn?: (ranges: AxisRange[]) => void; |
|
||||||
onZoomOut?: (centers: { x: number, y: number }) => void; |
|
||||||
onMouseMove?: (event: any) => void; |
|
||||||
onMouseOut?: () => void; |
|
||||||
onLegendClick?: (idx: number) => void, |
|
||||||
onPanning?: (event: { ranges: AxisRange[], d3Event: any }) => void; |
|
||||||
onPanningEnd?: (ranges: AxisRange[]) => void; |
|
||||||
onContextMenu?: (evt: any) => void; |
|
||||||
onSharedCrosshairMove?: (evt: any) => void; |
|
||||||
onRenderStart?: () => void, |
|
||||||
onRenderEnd?: () => void, |
|
||||||
} |
|
||||||
|
|
||||||
export const ChartwerkLinePod = forwardRef<HTMLDivElement, PropsWithChildren<ChartwerkLinePodProps>>((props, ref) => { |
|
||||||
const [pod, setPod] = useState<LinePod | null>(null); |
|
||||||
const [hack, setHack] = useState<number | null>(null); |
|
||||||
|
|
||||||
const chartRef = useRef(null); |
|
||||||
const chart = chartRef.current; |
|
||||||
|
|
||||||
useEffect(() => { |
|
||||||
// this function will be called on component unmount
|
|
||||||
return () => { |
|
||||||
if (pod === null) { |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
console.log('remove chart'); |
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
pod.removeEventListeners(); |
|
||||||
} |
|
||||||
}, []); |
|
||||||
|
|
||||||
useEffect(() => { |
|
||||||
if (chart === null) { |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
let eventsCallbacks = _.cloneDeep(props.options.eventsCallbacks || {}); |
|
||||||
if (props.onZoomIn) { |
|
||||||
eventsCallbacks.zoomIn = props.onZoomIn; |
|
||||||
} |
|
||||||
if (props.onZoomOut) { |
|
||||||
eventsCallbacks.zoomOut = props.onZoomOut; |
|
||||||
} |
|
||||||
if (props.onMouseMove) { |
|
||||||
eventsCallbacks.mouseMove = props.onMouseMove; |
|
||||||
} |
|
||||||
if (props.onMouseOut) { |
|
||||||
eventsCallbacks.mouseOut = props.onMouseOut; |
|
||||||
} |
|
||||||
if (props.onLegendClick) { |
|
||||||
eventsCallbacks.onLegendClick = props.onLegendClick; |
|
||||||
} |
|
||||||
if (props.onPanning) { |
|
||||||
eventsCallbacks.panning = props.onPanning; |
|
||||||
} |
|
||||||
if (props.onPanningEnd) { |
|
||||||
eventsCallbacks.panningEnd = props.onPanningEnd; |
|
||||||
} |
|
||||||
if (props.onContextMenu) { |
|
||||||
eventsCallbacks.contextMenu = props.onContextMenu; |
|
||||||
} |
|
||||||
if (props.onSharedCrosshairMove) { |
|
||||||
eventsCallbacks.sharedCrosshairMove = props.onSharedCrosshairMove; |
|
||||||
} |
|
||||||
if (props.onRenderStart) { |
|
||||||
eventsCallbacks.renderStart = props.onRenderStart; |
|
||||||
} |
|
||||||
|
|
||||||
if (pod === null) { |
|
||||||
console.log('create chart'); |
|
||||||
|
|
||||||
const newPod = new LinePod( |
|
||||||
// @ts-ignore
|
|
||||||
chart, |
|
||||||
props.series, |
|
||||||
{ |
|
||||||
...props.options, |
|
||||||
eventsCallbacks, |
|
||||||
} |
|
||||||
); |
|
||||||
setPod( |
|
||||||
newPod |
|
||||||
); |
|
||||||
console.log('initial chart render'); |
|
||||||
newPod.render(); |
|
||||||
} else { |
|
||||||
console.log('update chart'); |
|
||||||
pod.updateData(props.series, { |
|
||||||
...props.options, |
|
||||||
eventsCallbacks, |
|
||||||
}); |
|
||||||
} |
|
||||||
}, [chart, pod, props.id, props.series, props.options]); |
|
||||||
|
|
||||||
// TODO: it's a hack to render the LinePod right after the div appears in DOM
|
|
||||||
setTimeout(() => { |
|
||||||
if (hack === null) { |
|
||||||
setHack(1); |
|
||||||
} |
|
||||||
}, 1); |
|
||||||
|
|
||||||
return ( |
|
||||||
<div ref={ref}> |
|
||||||
<div id={props.id} className={props.className} ref={chartRef}></div> |
|
||||||
{props.children} |
|
||||||
</div> |
|
||||||
); |
|
||||||
}); |
|
@ -1 +0,0 @@ |
|||||||
export { ChartwerkLinePod } from './components/ChartwerkLinePod'; |
|
@ -1,36 +0,0 @@ |
|||||||
{ |
|
||||||
"name": "react-line-pod", |
|
||||||
"version": "0.0.0", |
|
||||||
"type": "module", |
|
||||||
"main": "dist/react-line-pod.js", |
|
||||||
"types": "dist/main.d.ts", |
|
||||||
"files": [ |
|
||||||
"dist" |
|
||||||
], |
|
||||||
"scripts": { |
|
||||||
"dev": "vite", |
|
||||||
"build": "tsc --p ./tsconfig-build.json && vite build", |
|
||||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", |
|
||||||
"preview": "vite preview" |
|
||||||
}, |
|
||||||
"dependencies": { |
|
||||||
"react": "^18.2.0", |
|
||||||
"react-dom": "^18.2.0" |
|
||||||
}, |
|
||||||
"devDependencies": { |
|
||||||
"@types/lodash": "^4.14.201", |
|
||||||
"@types/react": "^18.2.15", |
|
||||||
"@types/react-dom": "^18.2.7", |
|
||||||
"@typescript-eslint/eslint-plugin": "^6.0.0", |
|
||||||
"@typescript-eslint/parser": "^6.0.0", |
|
||||||
"@vitejs/plugin-react": "^4.0.3", |
|
||||||
"eslint": "^8.45.0", |
|
||||||
"eslint-plugin-react-hooks": "^4.6.0", |
|
||||||
"eslint-plugin-react-refresh": "^0.4.3", |
|
||||||
"line-pod": "workspace:^", |
|
||||||
"lodash": "^4.17.21", |
|
||||||
"typescript": "^5.0.2", |
|
||||||
"vite": "^4.4.5", |
|
||||||
"vite-plugin-dts": "^3.6.3" |
|
||||||
} |
|
||||||
} |
|
@ -1,36 +0,0 @@ |
|||||||
import { ChartwerkLinePod } from '../lib/main'; |
|
||||||
|
|
||||||
function App() { |
|
||||||
const startTime = 1590590148; |
|
||||||
const arrayLength = 20; |
|
||||||
const data1 = Array.from({ length: arrayLength }, (el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 40)]); |
|
||||||
const data2 = Array.from({ length: arrayLength }, (el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 10)]); |
|
||||||
const data3 = Array.from({ length: arrayLength }, (el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 20) + 90]); |
|
||||||
|
|
||||||
const options = { |
|
||||||
renderLegend: false, usePanning: false, |
|
||||||
axis: { |
|
||||||
y: { invert: false, range: [0, 350] }, |
|
||||||
y1: { isActive: true, range: [0, 10], ticksCount: 8 }, |
|
||||||
x: { format: 'time' } |
|
||||||
}, |
|
||||||
zoomEvents: { |
|
||||||
mouse: { zoom: { isActive: true, orientation: 'horizontal' } }, |
|
||||||
scroll: { zoom: { isActive: true, orientation: 'horizontal' } } |
|
||||||
} |
|
||||||
}; |
|
||||||
const series = [ |
|
||||||
{ target: 'test1', datapoints: data1, color: 'green', dashArray: '5,3', class: 'first', renderArea: true }, |
|
||||||
{ target: 'test2', datapoints: data2, color: 'blue', yOrientation: 'right' }, |
|
||||||
{ target: 'test3', datapoints: data3, color: 'orange' }, |
|
||||||
]; |
|
||||||
|
|
||||||
return ( |
|
||||||
<> |
|
||||||
{/* @ts-ignore */} |
|
||||||
<ChartwerkLinePod id="demo" series={series} options={options}></ChartwerkLinePod> |
|
||||||
</> |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
export default App; |
|
@ -1,10 +0,0 @@ |
|||||||
import App from './App.tsx'; |
|
||||||
|
|
||||||
import React from 'react'; |
|
||||||
import ReactDOM from 'react-dom/client'; |
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root')!).render( |
|
||||||
<React.StrictMode> |
|
||||||
<App /> |
|
||||||
</React.StrictMode> |
|
||||||
); |
|
@ -1 +0,0 @@ |
|||||||
/// <reference types="vite/client" />
|
|
@ -1,6 +0,0 @@ |
|||||||
{ |
|
||||||
"extends": "./tsconfig.json", |
|
||||||
"include": [ |
|
||||||
"lib" |
|
||||||
] |
|
||||||
} |
|
@ -1,25 +0,0 @@ |
|||||||
{ |
|
||||||
"compilerOptions": { |
|
||||||
"target": "ES2020", |
|
||||||
"useDefineForClassFields": true, |
|
||||||
"lib": ["ES2020", "DOM", "DOM.Iterable"], |
|
||||||
"module": "ESNext", |
|
||||||
"skipLibCheck": true, |
|
||||||
|
|
||||||
/* Bundler mode */ |
|
||||||
"moduleResolution": "bundler", |
|
||||||
"allowImportingTsExtensions": true, |
|
||||||
"resolveJsonModule": true, |
|
||||||
"isolatedModules": true, |
|
||||||
"noEmit": true, |
|
||||||
"jsx": "react-jsx", |
|
||||||
|
|
||||||
/* Linting */ |
|
||||||
"strict": true, |
|
||||||
"noUnusedLocals": true, |
|
||||||
"noUnusedParameters": true, |
|
||||||
"noFallthroughCasesInSwitch": true |
|
||||||
}, |
|
||||||
"include": ["src", "lib"], |
|
||||||
"references": [{ "path": "./tsconfig.node.json" }] |
|
||||||
} |
|
@ -1,10 +0,0 @@ |
|||||||
{ |
|
||||||
"compilerOptions": { |
|
||||||
"composite": true, |
|
||||||
"skipLibCheck": true, |
|
||||||
"module": "ESNext", |
|
||||||
"moduleResolution": "bundler", |
|
||||||
"allowSyntheticDefaultImports": true |
|
||||||
}, |
|
||||||
"include": ["vite.config.ts"] |
|
||||||
} |
|
@ -1,29 +0,0 @@ |
|||||||
import { defineConfig } from 'vite'; |
|
||||||
import react from '@vitejs/plugin-react'; |
|
||||||
import dts from 'vite-plugin-dts'; |
|
||||||
|
|
||||||
import { resolve } from 'path'; |
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
|
||||||
export default defineConfig({ |
|
||||||
plugins: [ |
|
||||||
react(), |
|
||||||
dts({ include: ['lib'] }), |
|
||||||
], |
|
||||||
optimizeDeps: { |
|
||||||
include: ['line-pod'], |
|
||||||
}, |
|
||||||
build: { |
|
||||||
copyPublicDir: false, |
|
||||||
lib: { |
|
||||||
entry: resolve(__dirname, 'lib/main.ts'), |
|
||||||
formats: ['es'] |
|
||||||
}, |
|
||||||
rollupOptions: { |
|
||||||
external: ['react', 'react/jsx-runtime'], |
|
||||||
}, |
|
||||||
commonjsOptions: { |
|
||||||
include: [/line-pod/], |
|
||||||
}, |
|
||||||
} |
|
||||||
}); |
|
@ -0,0 +1,26 @@ |
|||||||
|
const path = require('path'); |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
entry: './src/index.tsx', |
||||||
|
module: { |
||||||
|
rules: [ |
||||||
|
{ |
||||||
|
test: /\.tsx?$/, |
||||||
|
use: 'ts-loader', |
||||||
|
exclude: /node_modules/, |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
resolve: { |
||||||
|
extensions: ['.tsx', '.ts', '.js'], |
||||||
|
}, |
||||||
|
output: { |
||||||
|
filename: 'index.js', |
||||||
|
path: path.resolve(__dirname, '../dist'), |
||||||
|
libraryTarget: 'umd', |
||||||
|
umdNamedDefine: true, |
||||||
|
}, |
||||||
|
externals: [ |
||||||
|
'@chartwerk/line-pod', 'react' |
||||||
|
] |
||||||
|
}; |
@ -0,0 +1,8 @@ |
|||||||
|
const baseWebpackConfig = require('./webpack.base.conf'); |
||||||
|
|
||||||
|
var conf = baseWebpackConfig; |
||||||
|
conf.devtool = 'inline-source-map'; |
||||||
|
conf.mode = 'development'; |
||||||
|
conf.output.filename = 'index.dev.js'; |
||||||
|
|
||||||
|
module.exports = conf; |
@ -0,0 +1,6 @@ |
|||||||
|
const baseWebpackConfig = require('./webpack.base.conf'); |
||||||
|
|
||||||
|
var conf = baseWebpackConfig; |
||||||
|
conf.mode = 'production'; |
||||||
|
|
||||||
|
module.exports = baseWebpackConfig; |
@ -0,0 +1,23 @@ |
|||||||
|
{ |
||||||
|
"name": "line-pod-react", |
||||||
|
"version": "0.0.1", |
||||||
|
"description": "React wrapper around line-pod", |
||||||
|
"main": "dist/index.js", |
||||||
|
"repository": "http://code.corpglory.net/chartwerk/line-pod.git", |
||||||
|
"author": "CorpGlory Inc.", |
||||||
|
"license": "ISC", |
||||||
|
"scripts": { |
||||||
|
"build": "webpack --config build/webpack.prod.conf.js", |
||||||
|
"dev": "webpack --config build/webpack.dev.conf.js" |
||||||
|
}, |
||||||
|
"dependencies": { |
||||||
|
"@chartwerk/line-pod": "workspace:*", |
||||||
|
"react": "^18.2.0", |
||||||
|
"react-dom": "^18.2.0" |
||||||
|
}, |
||||||
|
"devDependencies": { |
||||||
|
"ts-loader": "^9.5.1", |
||||||
|
"typescript": "^5.4.3", |
||||||
|
"webpack": "^5.87.0" |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,74 @@ |
|||||||
|
import { LineTimeSerie, LineOptions, LinePod } from '@chartwerk/line-pod'; |
||||||
|
import { MarkersConf } from '@chartwerk/line-pod/dist/models/marker'; |
||||||
|
import { SegmentSerie } from '@chartwerk/line-pod/dist/models/segment'; |
||||||
|
|
||||||
|
import React, { useEffect, useRef, useState } from 'react'; |
||||||
|
|
||||||
|
import _ from 'lodash'; |
||||||
|
|
||||||
|
|
||||||
|
export type ChartwerkLinePodProps = { |
||||||
|
id?: string; |
||||||
|
series: LineTimeSerie[]; |
||||||
|
options?: LineOptions; |
||||||
|
markersConf?: MarkersConf, |
||||||
|
segments?: SegmentSerie[], |
||||||
|
className?: string; |
||||||
|
} |
||||||
|
|
||||||
|
export function ChartwerkLinePod(props: ChartwerkLinePodProps) { |
||||||
|
|
||||||
|
const [pod, setPod] = useState<LinePod | null>(null); |
||||||
|
const [hack, setHack] = useState<number | null>(null); |
||||||
|
|
||||||
|
const chartRef = useRef(null); |
||||||
|
const chart = chartRef.current; |
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
// this function will be called on component unmount
|
||||||
|
return () => { |
||||||
|
if(pod === null) { return; } |
||||||
|
// @ts-ignore
|
||||||
|
pod.removeEventListeners(); |
||||||
|
} |
||||||
|
}, []); |
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
if(chart === null) { return; } |
||||||
|
if(pod === null) { |
||||||
|
const newPod = new LinePod( |
||||||
|
// @ts-ignore
|
||||||
|
chart, |
||||||
|
props.series, |
||||||
|
props.options, |
||||||
|
props.markersConf, |
||||||
|
props.segments |
||||||
|
); |
||||||
|
setPod(newPod); |
||||||
|
newPod.render(); |
||||||
|
} else { |
||||||
|
if(props.markersConf) { |
||||||
|
pod.updateMarkers(props.markersConf); |
||||||
|
} |
||||||
|
if(props.segments) { |
||||||
|
pod.updateSegments(props.segments); |
||||||
|
} |
||||||
|
// TODO: actually it's wrong logic with updates
|
||||||
|
// because it creates new pod anyway
|
||||||
|
pod.updateData(props.series, props.options); |
||||||
|
} |
||||||
|
}, [chart, props.id, props.options, props.markersConf, props.segments]); |
||||||
|
|
||||||
|
// TODO: it's a hack to render the LinePod right after the div appears in DOM
|
||||||
|
setTimeout(() => { |
||||||
|
if(hack === null) { |
||||||
|
setHack(1); |
||||||
|
} |
||||||
|
}, 1); |
||||||
|
|
||||||
|
return ( |
||||||
|
<div id={props.id} className={props.className} ref={chartRef}></div> |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
export default ChartwerkLinePod; |
@ -0,0 +1,139 @@ |
|||||||
|
import { MarkerElem, MarkersConf, MarkerSerie } from '../models/marker'; |
||||||
|
import { LineTimeSerie, LineOptions } from '../types'; |
||||||
|
|
||||||
|
import { Margin, PodState } from '@chartwerk/core'; |
||||||
|
|
||||||
|
import d3 from 'd3'; |
||||||
|
|
||||||
|
export class Markers { |
||||||
|
private _layerContainer = null; |
||||||
|
private _chartHeight = 0; |
||||||
|
|
||||||
|
constructor( |
||||||
|
private _chartContainer: d3.Selection<HTMLElement, unknown, null, undefined>, |
||||||
|
private _markerConf: MarkersConf, |
||||||
|
private _state: PodState<LineTimeSerie, LineOptions>, |
||||||
|
private _margin: Margin, |
||||||
|
) { } |
||||||
|
|
||||||
|
clear() { |
||||||
|
if(this._layerContainer !== null) { |
||||||
|
this._layerContainer.remove(); |
||||||
|
} |
||||||
|
this._chartContainer.selectAll('.marker-content').remove(); |
||||||
|
} |
||||||
|
|
||||||
|
render(metricContainer: d3.Selection<SVGGElement, unknown, null, undefined>, chartHeight: number) { |
||||||
|
this._chartHeight = chartHeight; |
||||||
|
this._layerContainer = metricContainer |
||||||
|
.append('g') |
||||||
|
.attr('class', 'markers-layer'); |
||||||
|
for(const serie of this._markerConf.series) { |
||||||
|
this.renderSerie(serie); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private _getLinePosition(marker: MarkerElem): number { |
||||||
|
return this._state.xScale(marker.x); |
||||||
|
} |
||||||
|
|
||||||
|
private _renderCircle(marker: MarkerElem) { |
||||||
|
const linePosition = this._getLinePosition(marker); |
||||||
|
|
||||||
|
let circle = this._layerContainer.append('circle') |
||||||
|
.attr('class', 'gap-circle') |
||||||
|
.attr('stroke', marker.color) |
||||||
|
.attr('stroke-width', '2px') |
||||||
|
.attr('r', 4) |
||||||
|
.attr('cx', linePosition) |
||||||
|
.attr('cy', 5) |
||||||
|
|
||||||
|
circle |
||||||
|
.attr('pointer-events', 'all') |
||||||
|
.style('cursor', 'pointer') |
||||||
|
.on('mousemove', () => { |
||||||
|
const onMouseMove = this._markerConf.events?.onMouseMove; |
||||||
|
if(onMouseMove) { |
||||||
|
onMouseMove(marker); |
||||||
|
return |
||||||
|
} |
||||||
|
if(marker.alwaysDisplay) { |
||||||
|
return; |
||||||
|
} |
||||||
|
this._chartContainer |
||||||
|
.selectAll(`.marker-content-${marker.x}`) |
||||||
|
.style('visibility', 'visible') |
||||||
|
.style('z-index', 9999); |
||||||
|
}) |
||||||
|
.on('mouseout', () => { |
||||||
|
const onMouseOut = this._markerConf.events?.onMouseOut; |
||||||
|
if(onMouseOut) { |
||||||
|
onMouseOut() |
||||||
|
return |
||||||
|
} |
||||||
|
if(marker.alwaysDisplay) { |
||||||
|
return; |
||||||
|
} |
||||||
|
this._chartContainer |
||||||
|
.selectAll(`.marker-content-${marker.x}`) |
||||||
|
.style('visibility', 'hidden') |
||||||
|
.style('z-index', 1); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
private _renderLine(marker: MarkerElem) { |
||||||
|
const linePosition = this._getLinePosition(marker); |
||||||
|
|
||||||
|
this._layerContainer.append('line') |
||||||
|
.attr('class', 'gap-line') |
||||||
|
.attr('stroke', marker.color) |
||||||
|
.attr('stroke-width', '1px') |
||||||
|
.attr('stroke-opacity', '0.3') |
||||||
|
.attr('stroke-dasharray', '4') |
||||||
|
.attr('x1', linePosition) |
||||||
|
.attr('x2', linePosition) |
||||||
|
.attr('y1', 0) |
||||||
|
// @ts-ignore // TODO: remove ignore but boxParams are protected
|
||||||
|
.attr('y2', this._state.boxParams.height) |
||||||
|
.attr('pointer-events', 'none'); |
||||||
|
} |
||||||
|
|
||||||
|
private _renderTooltip(marker: MarkerElem) { |
||||||
|
if(marker.html === undefined) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
const linePosition = this._getLinePosition(marker); |
||||||
|
|
||||||
|
const div = this._chartContainer |
||||||
|
.append('div') |
||||||
|
.attr('class', `marker-content marker-content-${marker.x}`) |
||||||
|
// @ts-ignore // TODO: remove ignore but boxParams are protected
|
||||||
|
.style('top', `${this._state.boxParams.height - this._chartHeight}px`) |
||||||
|
.style('visibility', marker.alwaysDisplay ? 'visible' : 'hidden') |
||||||
|
.style('position', 'absolute') |
||||||
|
.style('border', '1px solid black') |
||||||
|
.style('background-color', 'rgb(33, 37, 41)') |
||||||
|
.style('color', 'rgb(255, 255, 255)') |
||||||
|
.style('line-height', '1.55') |
||||||
|
.style('font-size', '0.875rem') |
||||||
|
.style('border-radius', '0.5rem') |
||||||
|
.style('padding', 'calc(0.3125rem) 0.625rem') |
||||||
|
.style('position', 'absolute') |
||||||
|
.style('white-space', 'nowrap') |
||||||
|
.style('pointer-events', 'none') |
||||||
|
.style('z-index', 1) |
||||||
|
.html(marker.html); |
||||||
|
|
||||||
|
// align tooltip: center (we need it to be rendered first)
|
||||||
|
div.style('left', `${linePosition + this._margin.left - div.node().getBoundingClientRect().width / 2}px`) |
||||||
|
} |
||||||
|
|
||||||
|
protected renderSerie(serie: MarkerSerie) { |
||||||
|
serie.data.forEach((marker: MarkerElem) => { |
||||||
|
this._renderLine(marker); |
||||||
|
this._renderCircle(marker); |
||||||
|
this._renderTooltip(marker); |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,73 @@ |
|||||||
|
import { SegmentSerie, SegmentElement } from "../models/segment"; |
||||||
|
import { PodState } from "@chartwerk/core"; |
||||||
|
import { LineTimeSerie, LineOptions } from "../types"; |
||||||
|
|
||||||
|
import * as d3 from "d3"; |
||||||
|
|
||||||
|
const OPACITY = 0.3; |
||||||
|
const OPACITY_SELECT = 0.3; |
||||||
|
|
||||||
|
export class Segments { |
||||||
|
// TODO: more semantic name
|
||||||
|
private _d3Holder = null; |
||||||
|
private _metricCon = null; |
||||||
|
|
||||||
|
constructor( |
||||||
|
private _series: SegmentSerie[], |
||||||
|
private _state: PodState<LineTimeSerie, LineOptions> |
||||||
|
) { |
||||||
|
} |
||||||
|
|
||||||
|
render(metricContainer: d3.Selection<SVGGElement, unknown, null, undefined>, chartContainer: d3.Selection<SVGGElement, unknown, null, undefined>) { |
||||||
|
if(this._d3Holder !== null) { |
||||||
|
this._d3Holder.remove(); |
||||||
|
} |
||||||
|
this._d3Holder = metricContainer.append('g').attr('class', 'markers-layer'); |
||||||
|
for (const s of this._series) { |
||||||
|
this.renderSerie(chartContainer, s); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected renderSerie(chartContainer: d3.Selection<SVGGElement, unknown, null, undefined>, serie: SegmentSerie) { |
||||||
|
// TODO: it's hack with core, need to find a better way
|
||||||
|
const overlay = chartContainer.select('.overlay'); |
||||||
|
serie.data.forEach((d) => { |
||||||
|
// @ts-ignore
|
||||||
|
const startPositionX = this._state.xScale(d[0]) as number; |
||||||
|
// @ts-ignore
|
||||||
|
const endPositionX = this._state.xScale(d[1]) as number; |
||||||
|
const width = endPositionX - startPositionX // Math.max(endPositionX - startPositionX, MIMIMUM_SEGMENT_WIDTH);
|
||||||
|
const opacity = serie.opacity || OPACITY; |
||||||
|
const opacitySelect = serie.opacitySelect || OPACITY_SELECT; |
||||||
|
this._d3Holder.append('rect') |
||||||
|
.attr('class', 'segment') |
||||||
|
.attr('x', startPositionX) |
||||||
|
.attr('y', 0) |
||||||
|
.attr('width', width) |
||||||
|
// @ts-ignore // TODO: remove ignore but boxParams are protected
|
||||||
|
.attr('height', this._state.boxParams.height) |
||||||
|
.attr('opacity', opacity) |
||||||
|
.style('fill', serie.color) |
||||||
|
.on('mouseover', function() { |
||||||
|
if(serie.select === true) { |
||||||
|
d3.select(this).attr('opacity', opacitySelect); |
||||||
|
if(serie.onSelect) { |
||||||
|
serie.onSelect(d); |
||||||
|
} |
||||||
|
} |
||||||
|
}) |
||||||
|
.on('mouseout', function(e) { |
||||||
|
if(serie.select === true) { |
||||||
|
d3.select(this).attr('opacity', opacity); |
||||||
|
if(serie.onUnselect) { |
||||||
|
serie.onUnselect(d); |
||||||
|
} |
||||||
|
} |
||||||
|
}) |
||||||
|
.on('mousemove', function(e) { |
||||||
|
var event = new MouseEvent('mousemove', d3.event); |
||||||
|
overlay.node().dispatchEvent(event) |
||||||
|
}) |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
export type MarkerElem = { |
||||||
|
x: number; |
||||||
|
color: string; |
||||||
|
html?: string; |
||||||
|
alwaysDisplay?: boolean; |
||||||
|
payload?: any; |
||||||
|
} |
||||||
|
|
||||||
|
export type MarkerSerie = { |
||||||
|
data: MarkerElem[]; |
||||||
|
} |
||||||
|
|
||||||
|
export type MarkersConf = { |
||||||
|
series: MarkerSerie[], |
||||||
|
events?: { |
||||||
|
onMouseMove?: (el: MarkerElem) => void; |
||||||
|
onMouseOut?: () => void; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
export type SegmentElement = [number, number, any?]; |
||||||
|
|
||||||
|
export type SegmentSerie = { |
||||||
|
color: string; |
||||||
|
data: SegmentElement[] // [from, to, payload?] payload is any data for tooltip,
|
||||||
|
select?: boolean, |
||||||
|
opacity?: number, |
||||||
|
opacitySelect?: number, |
||||||
|
onSelect?: (SegmentElement) => void |
||||||
|
onUnselect?: (SegmentElement) => void |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
import { Serie, Options } from '@chartwerk/core'; |
||||||
|
import { AxisRange } from '@chartwerk/core/dist/types'; |
||||||
|
|
||||||
|
type LineTimeSerieParams = { |
||||||
|
maxLength: number; |
||||||
|
renderDots: boolean; |
||||||
|
renderLines: boolean; // TODO: refactor same as scatter-pod
|
||||||
|
dashArray: string; // dasharray attr, only for lines
|
||||||
|
class: string; // option to add custom class to each serie element
|
||||||
|
renderArea: AreaType; // default is none
|
||||||
|
} |
||||||
|
|
||||||
|
export enum AreaType { |
||||||
|
NONE = 'None', |
||||||
|
ABOVE = 'Above', |
||||||
|
BELOW = 'Below', |
||||||
|
} |
||||||
|
|
||||||
|
export type LineTimeSerie = Serie & Partial<LineTimeSerieParams>; |
||||||
|
export type LineOptions = Options & { |
||||||
|
events? : { |
||||||
|
zoomOut?: (centers: { |
||||||
|
x: number; |
||||||
|
y: number; |
||||||
|
}, range: AxisRange[]) => void; |
||||||
|
contextMenu?: (position: { |
||||||
|
x: number; |
||||||
|
y: number; |
||||||
|
}) => void; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
export type MouseObj = { |
||||||
|
x: number, |
||||||
|
y: number, |
||||||
|
xVal: number, |
||||||
|
yVal: number, |
||||||
|
series: { value: [number, number], color: string, label: string }[], |
||||||
|
chartX: number, |
||||||
|
chartWidth: number |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
{ |
||||||
|
"compilerOptions": { |
||||||
|
"target": "es5", |
||||||
|
"rootDir": "./src", |
||||||
|
"module": "esnext", |
||||||
|
"moduleResolution": "node", |
||||||
|
"declaration": true, |
||||||
|
"declarationDir": "dist", |
||||||
|
"allowSyntheticDefaultImports": true, |
||||||
|
"inlineSourceMap": false, |
||||||
|
"sourceMap": true, |
||||||
|
"noEmitOnError": false, |
||||||
|
"emitDecoratorMetadata": false, |
||||||
|
"experimentalDecorators": true, |
||||||
|
"noImplicitReturns": true, |
||||||
|
"noImplicitThis": false, |
||||||
|
"noImplicitUseStrict": false, |
||||||
|
"noImplicitAny": false, |
||||||
|
"noUnusedLocals": false, |
||||||
|
"baseUrl": "./src", |
||||||
|
}, |
||||||
|
"include": ["src/**/*"] |
||||||
|
} |
Loading…
Reference in new issue