Skip to content

Commit d4535f7

Browse files
Fix export in chart demo (#28820)
1 parent 34352ea commit d4535f7

File tree

16 files changed

+130
-82
lines changed

16 files changed

+130
-82
lines changed

apps/demos/Demos/Charts/ExportCustomMarkup/Angular/app/app.component.html

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
<div class="chart_environment">
22
<div id="custom_markup_container">
33
<svg version="1.1" width="820px" height="420px">
4+
<path
5+
d="M 0 0 L 820 0 L 820 420 L 0 420 L 0 0"
6+
stroke="#999999"
7+
stroke-width="1"
8+
stroke-linecap="butt"
9+
fill="white"
10+
stroke-linejoin="miter"
11+
></path>
412
<path d="M 13 407 L 128 407 L 232 39 L 13 39" fill="#6D39C3"></path>
513
<path
614
d="M 46 381 L 161 381 L 265 13 L 46 13"
@@ -34,15 +42,6 @@
3442
<tspan x="0" y="0">Export a chart with</tspan>
3543
<tspan x="0" y="19.2">custom elements</tspan>
3644
</text>
37-
<path
38-
opacity="0.8"
39-
d="M 0 0 L 820 0 L 820 420 L 0 420 L 0 0"
40-
stroke="#999999"
41-
stroke-width="1"
42-
stroke-linecap="butt"
43-
fill="none"
44-
stroke-linejoin="miter"
45-
></path>
4645
</svg>
4746
</div>
4847
<dx-chart id="chart" [dataSource]="oilProductionData" palette="Violet">

apps/demos/Demos/Charts/ExportCustomMarkup/Angular/app/app.component.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
66
import { DxChartModule, DxChartComponent, DxButtonModule } from 'devextreme-angular';
77

88
import { exportFromMarkup } from 'devextreme/viz/export';
9-
// import canvg from 'canvg';
9+
import { Canvg } from 'canvg';
1010
import { Service, OilProductionDataItem } from './app.service';
1111

1212
if (!/localhost/.test(document.location.host)) {
@@ -42,11 +42,12 @@ export class AppComponent {
4242
format: 'png',
4343
svgToCanvas(svg, canvas) {
4444
return new Promise((resolve) => {
45-
// canvg(canvas, new XMLSerializer().serializeToString(svg), {
46-
// ignoreDimensions: true,
47-
// ignoreClear: true,
48-
// renderCallback: resolve,
49-
// });
45+
const v = Canvg.fromString(
46+
canvas.getContext("2d"),
47+
new XMLSerializer().serializeToString(svg)
48+
);
49+
50+
resolve(v.render());
5051
});
5152
},
5253
});

apps/demos/Demos/Charts/ExportCustomMarkup/React/App.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
} from 'devextreme-react/chart';
55
import { Button } from 'devextreme-react/button';
66
import { exportFromMarkup } from 'devextreme/viz/export';
7-
// import toCanvas from 'canvg';
7+
import { Canvg } from 'canvg';
88
import { dataSource } from './data.ts';
99
import Form from './Form.tsx';
1010

@@ -39,15 +39,14 @@ function App() {
3939
height: 420,
4040
margin: 0,
4141
format: 'png',
42-
// eslint-disable-next-line no-unused-vars
4342
svgToCanvas(svg: Node, canvas) {
44-
// eslint-disable-next-line no-unused-vars
4543
return new Promise((resolve) => {
46-
// toCanvas(canvas, new XMLSerializer().serializeToString(svg), {
47-
// ignoreDimensions: true,
48-
// ignoreClear: true,
49-
// renderCallback: resolve,
50-
// });
44+
const v = Canvg.fromString(
45+
canvas.getContext("2d"),
46+
new XMLSerializer().serializeToString(svg)
47+
);
48+
49+
resolve(v.render());
5150
});
5251
},
5352
},

apps/demos/Demos/Charts/ExportCustomMarkup/React/Form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const fontFamily = "'Segoe UI', 'Helvetica Neue', 'Trebuchet MS', Verdana, sans-
55
const Form = React.forwardRef<HTMLDivElement, {}>((_, ref) => (
66
<div id="custom_markup_container" ref={ref}>
77
<svg width="820px" height="420px">
8+
<path opacity="1" d="M 0 0 L 820 0 L 820 420 L 0 420 L 0 0" stroke="#999999" strokeWidth="1"
9+
strokeLinecap="butt" fill="white" strokeLinejoin="miter"></path>
810
<path d="M 13 407 L 128 407 L 232 39 L 13 39" fill="#6D39C3"></path>
911
<path d="M 46 381 L 161 381 L 265 13 L 46 13" opacity="0.5" fill="#6D39C3"></path>
1012
<text transform="translate(30,89)"
@@ -22,8 +24,6 @@ const Form = React.forwardRef<HTMLDivElement, {}>((_, ref) => (
2224
<tspan x="0" y="0">Export a chart with</tspan>
2325
<tspan x="0" y="19.2">custom elements</tspan>
2426
</text>
25-
<path opacity="0.8" d="M 0 0 L 820 0 L 820 420 L 0 420 L 0 0" stroke="#999999" strokeWidth="1"
26-
strokeLinecap="butt" fill="none" strokeLinejoin="miter"></path>
2727
</svg>
2828
</div>
2929
));

apps/demos/Demos/Charts/ExportCustomMarkup/ReactJs/App.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from 'devextreme-react/chart';
1010
import { Button } from 'devextreme-react/button';
1111
import { exportFromMarkup } from 'devextreme/viz/export';
12-
// import toCanvas from 'canvg';
12+
import { Canvg } from 'canvg';
1313
import { dataSource } from './data.js';
1414
import Form from './Form.js';
1515

@@ -37,15 +37,13 @@ function App() {
3737
height: 420,
3838
margin: 0,
3939
format: 'png',
40-
// eslint-disable-next-line no-unused-vars
4140
svgToCanvas(svg, canvas) {
42-
// eslint-disable-next-line no-unused-vars
4341
return new Promise((resolve) => {
44-
// toCanvas(canvas, new XMLSerializer().serializeToString(svg), {
45-
// ignoreDimensions: true,
46-
// ignoreClear: true,
47-
// renderCallback: resolve,
48-
// });
42+
const v = Canvg.fromString(
43+
canvas.getContext('2d'),
44+
new XMLSerializer().serializeToString(svg),
45+
);
46+
resolve(v.render());
4947
});
5048
},
5149
});

apps/demos/Demos/Charts/ExportCustomMarkup/ReactJs/Form.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ const Form = React.forwardRef((_, ref) => (
1010
width="820px"
1111
height="420px"
1212
>
13+
<path
14+
opacity="1"
15+
d="M 0 0 L 820 0 L 820 420 L 0 420 L 0 0"
16+
stroke="#999999"
17+
strokeWidth="1"
18+
strokeLinecap="butt"
19+
fill="white"
20+
strokeLinejoin="miter"
21+
></path>
1322
<path
1423
d="M 13 407 L 128 407 L 232 39 L 13 39"
1524
fill="#6D39C3"
@@ -69,15 +78,6 @@ const Form = React.forwardRef((_, ref) => (
6978
custom elements
7079
</tspan>
7180
</text>
72-
<path
73-
opacity="0.8"
74-
d="M 0 0 L 820 0 L 820 420 L 0 420 L 0 0"
75-
stroke="#999999"
76-
strokeWidth="1"
77-
strokeLinecap="butt"
78-
fill="none"
79-
strokeLinejoin="miter"
80-
></path>
8181
</svg>
8282
</div>
8383
));

apps/demos/Demos/Charts/ExportCustomMarkup/Vue/App.vue

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import {
6969
} from 'devextreme-vue/chart';
7070
import { exportFromMarkup } from 'devextreme/viz/export';
7171
import DxButton from 'devextreme-vue/button';
72-
// import toCanvas from 'canvg';
72+
import { Canvg } from 'canvg';
7373
import { dataSource } from './data.ts';
7474
import Form from './Form.vue';
7575
@@ -102,15 +102,14 @@ function onClick() {
102102
height: 420,
103103
margin: 0,
104104
format: 'png',
105-
// eslint-disable-next-line no-unused-vars
106105
svgToCanvas(svg, canvas) {
107-
// eslint-disable-next-line no-unused-vars
108106
return new Promise((resolve) => {
109-
// toCanvas(canvas, new XMLSerializer().serializeToString(svg), {
110-
// ignoreDimensions: true,
111-
// ignoreClear: true,
112-
// renderCallback: resolve,
113-
// });
107+
const v = Canvg.fromString(
108+
canvas.getContext("2d"),
109+
new XMLSerializer().serializeToString(svg)
110+
);
111+
112+
resolve(v.render());
114113
});
115114
},
116115
});

apps/demos/Demos/Charts/ExportCustomMarkup/Vue/Form.vue

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
width="820px"
88
height="420px"
99
>
10+
<path
11+
d="M 0 0 L 820 0 L 820 420 L 0 420 L 0 0"
12+
stroke="#999999"
13+
stroke-width="1"
14+
stroke-linecap="butt"
15+
fill="white"
16+
stroke-linejoin="miter"
17+
/>
1018
<path
1119
d="M 13 407 L 128 407 L 232 39 L 13 39"
1220
fill="#6D39C3"
@@ -46,15 +54,6 @@
4654
y="19.2"
4755
>custom elements</tspan>
4856
</text>
49-
<path
50-
opacity="0.8"
51-
d="M 0 0 L 820 0 L 820 420 L 0 420 L 0 0"
52-
stroke="#999999"
53-
stroke-width="1"
54-
stroke-linecap="butt"
55-
fill="none"
56-
stroke-linejoin="miter"
57-
/>
5857
</svg>
5958
</div>
6059
</template>

apps/demos/configs/Angular/config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,7 @@ window.config = {
241241
/**/
242242

243243
/** canvg */
244-
'stackblur-canvas': 'npm:stackblur-canvas/dist/stackblur.min.js',
245-
'rgbcolor': 'npm:rgbcolor/index.js',
246-
'canvg': 'npm:canvg/dist/browser/canvg.min.js',
244+
'canvg': 'externals:canvg.bundle.js',
247245
/**/
248246

249247
/** vectormap */

apps/demos/configs/React/config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ window.config = {
102102
/**/
103103

104104
/** canvg */
105-
'stackblur-canvas': 'npm:stackblur-canvas/dist/stackblur.min.js',
106-
'rgbcolor': 'npm:rgbcolor/index.js',
107-
'canvg': 'npm:canvg/dist/browser/canvg.min.js',
105+
'canvg': 'externals:canvg.bundle.js',
108106
/**/
109107

110108
/** whatwg-fetch */

0 commit comments

Comments
 (0)