Skip to content

Commit 58236b7

Browse files
author
Anisha1234
committed
scaling svg according to parent div
Please enter the commit message for your changes. Lines starting
1 parent 9a64fee commit 58236b7

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

jschart/index.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,8 +2813,13 @@ function build_chart(chart) {
28132813
);
28142814
return;
28152815
}
2816-
2817-
var table = chart.dom.div.append("table");
2816+
2817+
var table = chart.dom.div.append("table")
2818+
.attr("class", "graphtable")
2819+
.style("max-width", chart.dimensions.viewport_width+"px")
2820+
.style("flex", "0.9 0.9 auto")
2821+
.style("width", 0)
2822+
.style("word-break", "break-all");
28182823

28192824
var row = table.append("tr")
28202825
.classed("wrapper", true)
@@ -2917,13 +2922,8 @@ function build_chart(chart) {
29172922
.enter()
29182923
.append("svg")
29192924
.classed("svg", true)
2920-
.attr(
2921-
"width",
2922-
chart.dimensions.viewport_width +
2923-
chart.dimensions.margin.left +
2924-
chart.dimensions.margin.right
2925-
)
2926-
.attr("height", get_svg_height(chart));
2925+
.attr("viewBox", "0 0" + " " + (chart.dimensions.viewport_width + chart.dimensions.margin.left +
2926+
chart.dimensions.margin.right) + " " + (get_svg_height(chart) + 20) + "");
29272927

29282928
chart.chart.defs = chart.chart.svg.append("defs");
29292929
if (!chart.options.scatterplot) {
@@ -3703,9 +3703,11 @@ exports.create_jschart = function(
37033703

37043704
d3.select('#'+location)
37053705
.style("display","flex")
3706-
.style( "justify-content","center")
3707-
.style("align-items","center")
37083706

3707+
d3.selectAll(".svg")
3708+
.style("width",'100%')
3709+
.style("height","auto")
3710+
37093711
// add an entry to the chart generating queue
37103712
charts_queue.defer(
37113713
generate_chart,
@@ -5390,7 +5392,7 @@ function get_svg_height(chart) {
53905392
chart.dimensions.margin.bottom +
53915393
( Math.ceil(chart.datasets.all.length / chart.state.legend_columns) -
53925394
1 + chart.options.legend_entries.length
5393-
) * chart.dimensions.legend_properties.row_height;
5395+
) * chart.dimensions.legend_properties.row_height;
53945396
}
53955397

53965398
function reload_chart(chart) {

0 commit comments

Comments
 (0)