Skip to content

Commit 82e13c0

Browse files
authored
Merge pull request #310 from tom-writes-code/feature/reduce-chart-size
Reduce default chart size to 80% of available screen
2 parents 9e435e8 + 8c29f7a commit 82e13c0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/notebooks/logic/chartJs.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function generateChartHTMLEmbedded(id: number, detail: ChartDetail, label
3131

3232
const hasYaxis = detail.type === `bar` || detail.type === `line`;
3333

34-
const script = /*javascript*/`
34+
const script = /*javascript*/ `
3535
if (!window.ibmicharts) {
3636
window.ibmicharts = {};
3737
}
@@ -41,6 +41,11 @@ export function generateChartHTMLEmbedded(id: number, detail: ChartDetail, label
4141
if (!theChart) {
4242
const chartEle = document.getElementById('myChart${id}');
4343
if (chartEle) {
44+
const maxHeight = window.innerHeight * 0.8;
45+
const maxWidth = window.innerWidth * 0.8;
46+
const targetSize = Math.min(maxHeight, maxWidth);
47+
chartEle.style.maxHeight = targetSize + 'px';
48+
chartEle.style.maxWidth = targetSize + 'px';
4449
try {
4550
window.ibmicharts['myChart${id}'] = new Chart(chartEle.getContext('2d'), {
4651
type: '${detail.type}',

0 commit comments

Comments
 (0)