geo-svg.html 24.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->


<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <script src="lib/esl.js"></script>
        <script src="lib/config.js"></script>
        <script src="lib/jquery.min.js"></script>
        <script src="lib/facePrint.js"></script>
        <script src="lib/testHelper.js"></script>
        <!-- <script src="ut/lib/canteen.js"></script> -->
        <link rel="stylesheet" href="lib/reset.css" />
    </head>
    <body>
        <style>
        </style>



40 41
        <div id="main_simple_geo_json"></div>
        <div id="main_simple_geo_svg"></div>
42
        <div id="main_simple_geo_svg_coord"></div>
1
100pah 已提交
43
        <div id="main_geo_json_focus_blur"></div>
1
100pah 已提交
44
        <div id="main_geo_svg_emphasis_select"></div>
1
100pah 已提交
45 46 47
        <div id="main_pure_geo_svg"></div>
        <div id="main_pure_map_svg"></div>
        <div id="main_map_geo_svg"></div>
48 49 50 51 52





1
100pah 已提交
53
        <script>
1
100pah 已提交
54
            function listenAndPrintEvent(chart) {
1
100pah 已提交
55 56 57 58 59 60
                if (!chart) {
                    return;
                }
                const out = {
                };
                chart.on('geoselectchanged', function (params) {
1
100pah 已提交
61 62 63 64
                    out.geoselectechanged = {
                        allSelected: params.allSelected
                    };
                    console.log('geoselectechanged', params);
1
100pah 已提交
65 66 67
                    chart.__testHelper.updateInfo(out, 'event');
                });
                chart.on('selectchanged', function (params) {
1
100pah 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81
                    out.selectechanged = {
                        selected: params.selected
                    };
                    console.log('selectechanged', params);
                    chart.__testHelper.updateInfo(out, 'event');
                });
                chart.on('click', function (params) {
                    out.click = {
                        componentIndex: params.componentIndex,
                        componentType: params.componentType,
                        geoIndex: params.geoIndex,
                        name: params.name
                    };
                    console.log('click', params);
1
100pah 已提交
82 83 84 85 86 87
                    chart.__testHelper.updateInfo(out, 'event');
                });
            }
        </script>


88

89 90


91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
        <script>
        require(['echarts'/*, 'map/js/china' */], function (echarts) {
            const testGeoJson1 = {
                'type': 'FeatureCollection',
                'features': [
                    {
                        'type': 'Feature',
                        'geometry': {
                            'type': 'Polygon',
                            'coordinates': [
                                [[2000, 2000], [5000, 2000], [5000, 5000], [2000, 5000]]
                            ]
                        },
                        'properties': {
                            'name': 'Afghanistan',
                            'childNum': 1
                        }
                    }
                ]
            };

            echarts.registerMap('testGeoJson1', testGeoJson1);

            option = {
1
100pah 已提交
115 116
                tooltip: {
                },
117 118 119
                geo: {
                    map: 'testGeoJson1',
                    roam: true,
1
100pah 已提交
120
                    selectedMode: 'single',
121 122 123 124 125 126 127 128 129 130
                    // height: '100%',
                    // center
                    // layoutCenter: ['30%', 40],
                    // layoutSize: 40,
                    // boundingCoords
                    zoom: 1,
                    aspectScale: 1
                }
            };

131
            var chart = testHelper.create(echarts, 'main_simple_geo_json', {
132
                title: [
133
                    'simple geo geoJSON location:',
134 135 136 137
                    'Should be a square and 80% of canvas height.',
                    'At the center of the canvas.'
                ],
                option: option,
1
100pah 已提交
138 139
                info: {},
                infoKey: 'event',
1
100pah 已提交
140
                height: 200
141 142
            });

1
100pah 已提交
143
            listenAndPrintEvent(chart);
144 145 146 147 148 149

        });
        </script>



150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177





        <script>
        require(['echarts'/*, 'map/js/china' */], function (echarts) {
            const svg = [
                '<?xml version="1.0" encoding="utf-8"?>',
                '<svg xmlns="http://www.w3.org/2000/svg" xmlns:ooo="http://xml.openoffice.org/svg/export" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" version="1.2" fill-rule="evenodd" xml:space="preserve">',
                '<path d="M 0,0 L 0,100 100,100 100,0 Z" fill="none" stroke="rgb(56,93,138)" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter"/>',
                '</svg>'
            ].join('')

            echarts.registerMap('testGeoSVG', { svg: svg });

            option = {
                tooltip: {
                },
                geo: {
                    map: 'testGeoSVG',
                    roam: true,
                    selectedMode: 'single',
                    // height: '100%',
                    // center
                    // layoutCenter: ['30%', 40],
                    // layoutSize: 40,
                    // boundingCoords
178 179
                    // zoom: 1,
                    // aspectScale: 1
180 181 182 183 184 185 186 187 188 189 190
                }
            };

            var chart = testHelper.create(echarts, 'main_simple_geo_svg', {
                title: [
                    'Should be a square and 80% of canvas height.',
                    'At the center of the canvas.'
                ],
                option: option,
                info: {},
                infoKey: 'event',
1
100pah 已提交
191
                height: 200
192 193
            });

1
100pah 已提交
194
            listenAndPrintEvent(chart);
195 196 197 198 199 200 201 202

        });
        </script>





1
100pah 已提交
203 204


205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
        <script>
        require(['echarts'/*, 'map/js/china' */], function (echarts) {
            const svg = [
                '<?xml version="1.0" encoding="utf-8"?>',
                '<svg xmlns="http://www.w3.org/2000/svg" xmlns:ooo="http://xml.openoffice.org/svg/export" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" fill-rule="evenodd" xml:space="preserve">',
                '<path name="left_rect" d="M 0,0 L 0,100 100,100 100,0 Z" fill="#765" stroke="rgb(56,93,138)" stroke-width="0" stroke-linecap="square" stroke-linejoin="miter"/>',
                '<path name="right_rect" d="M 150,0 L 150,100 250,100 250,0 Z" fill="#567" stroke="rgb(56,93,138)" stroke-width="0" stroke-linecap="square" stroke-linejoin="miter"/>',
                '</svg>'
            ].join('')

            echarts.registerMap('testGeoSVG_coord', { svg: svg });

            option = {
                animation: false,
                tooltip: {
                },
                geo: {
                    map: 'testGeoSVG_coord',
                    roam: true,
                    top: 0,
                    bottom: 0,
                    left: 0,
                    right: 0,
                },
                series: [{
                    type: 'scatter',
                    geoIndex: 0,
                    coordinateSystem: 'geo',
                    symbolSize: 30,
                    data: [{
                        value: [200, 50],
                        itemStyle: {
                            color: 'blue'
                        }
                    }]
                }]
            };

            var chart = testHelper.create(echarts, 'main_simple_geo_svg_coord', {
                title: [
                    'A **blue circle** should be in the center of the right rect.',
                    '**Click** inside the rect or outside the rect.',
                    'Check SVG coord displayed (via convertFromPixel).',
                    '(The left rect is 100*100 and left-top corner is (0,0))',
                    '**Click btn1**, check Pixel.point[1] should be around 100',
                    '**Click btn2**, check Pixel.point[1] should be around 200'
                ],
                option: option,
                infoKey: 'SVG coord',
                info: {},
                height: 200,
                buttons: [{
                    text: 'converToPixel({ geoIndex: 0 }, "left_rect")',
                    onclick: function () {
                        var point = chart.convertToPixel({ geoIndex: 0 }, 'left_rect');
                        console.log(point);
                        chart.__testHelper.updateInfo(
                            { point: point },
                            'Pixel'
                        );
                    }
                }, {
                    text: 'convertToPixel({ geoIndex: 0 }, [100, 100])',
                    onclick: function () {
                        var point = chart.convertToPixel({ geoIndex: 0 }, [100, 100]);
                        console.log(point);
                        chart.__testHelper.updateInfo(
                            { point: point },
                            'Pixel'
                        );
                    }
                }]
            });

            if (chart) {
                chart.getZr().on('click', function (event) {
                    var x = event.offsetX;
                    var y = event.offsetY;
                    console.log(x, y);
                    var svgCoord = chart.convertFromPixel({ geoIndex: 0 }, [x, y]);
                    console.log(svgCoord);
                    chart.__testHelper.updateInfo(
                        { x: svgCoord[0], y: svgCoord[1] },
                        'SVG coord'
                    );
                });
            }

        });
        </script>





1
100pah 已提交
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360

        <script>
        require(['echarts'/*, 'map/js/china' */], function (echarts) {
            const testGeoJson1 = {
                'type': 'FeatureCollection',
                'features': [
                    {
                        'type': 'Feature',
                        'geometry': {
                            'type': 'Polygon',
                            'coordinates': [
                                [[2000, 2000], [5000, 2000], [5000, 5000], [2000, 5000]]
                            ]
                        },
                        'properties': {
                            'name': 'Afghanistan'
                        }
                    },
                    {
                        'type': 'Feature',
                        'geometry': {
                            'type': 'Polygon',
                            'coordinates': [
                                [[6000, 2300], [9300, 2300], [9000, 5000]]
                            ]
                        },
                        'properties': {
                            'name': 'BBB'
                        }
                    }
                ]
            };

            echarts.registerMap('testGeoJson2', testGeoJson1);

            option = {
                tooltip: {
                },
                geo: {
                    map: 'testGeoJson2',
                    roam: true,
                    selectedMode: 'single',
                    label: {
                        show: true
                    },
                    emphasis: {
                        focus: 'self'
                    },
                    // height: '100%',
                    // center
                    // layoutCenter: ['30%', 40],
                    // layoutSize: 40,
                    // boundingCoords
                    zoom: 1,
                    aspectScale: 1
                }
            };

            var chart = testHelper.create(echarts, 'main_geo_json_focus_blur', {
                title: [
                    'check geoJSON focus-blur',
361
                    '**Click** them, check click info'
1
100pah 已提交
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
                ],
                option: option,
                info: {},
                infoKey: 'event',
                height: 200
            });

            listenAndPrintEvent(chart);

        });
        </script>






1
100pah 已提交
379 380 381 382 383
        <script>
        require(['echarts'/*, 'map/js/china' */], function (echarts) {
            const svg = [
                '<?xml version="1.0" encoding="utf-8"?>',
                '<svg xmlns="http://www.w3.org/2000/svg" xmlns:ooo="http://xml.openoffice.org/svg/export" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" fill-rule="evenodd" xml:space="preserve">',
384
                '<path name="a" d="M 0,0 L 0,100 100,100 100,0 Z" transform="rotate(45)" fill="rgb(16,193,138)" stroke="green" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter"/>',
1
100pah 已提交
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
                '<path name="a" d="M 110,0 L 110,100 210,100 210,0 Z" fill="rgb(16,193,138)" stroke="green" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter"/>',
                '<g name="b">',
                    '<path d="M 0,110 L 0,210 100,110 Z" fill="rgb(16,193,138)" stroke="green" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter"/>',
                    '<path d="M 110,110 L 110,210 210,110 Z" fill="rgb(16,193,138)" stroke="green" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter"/>',
                '</g>',
                '<radialGradient id="XMLID_1_" cx="0" cy="220" r="59.4363" gradientUnits="userSpaceOnUse">',
                    '<stop  offset="0" style="stop-color:#E6E6E6"/>',
                    '<stop  offset="1" style="stop-color:#4D4D4D"/>',
                '</radialGradient>',
                '<path name="c" d="M 0,220 L 0,320 100,220 Z" fill="url(#XMLID_1_)" stroke="green" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter"/>',
                '<radialGradient id="XMLID_2_" cx="110" cy="220" r="59.4363" gradientUnits="userSpaceOnUse">',
                    '<stop  offset="0" style="stop-color:#E6E6E6"/>',
                    '<stop  offset="1" style="stop-color:#4D4D4D"/>',
                '</radialGradient>',
                '<path name="c" d="M 110,220 L 110,320 210,220 Z" fill="url(#XMLID_2_)" stroke="green" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter"/>',
                '</svg>'
            ].join('')

            echarts.registerMap('testGeoSVG_select_hover', { svg: svg });

            option = {
                // tooltip: {
                // },
                geo: {
                    map: 'testGeoSVG_select_hover',
                    roam: true,
                    selectedMode: 'single',
                    // height: '100%',
                    // center
                    // layoutCenter: ['30%', 40],
                    // layoutSize: 40,
                    // boundingCoords
                    zoom: 1,
                    aspectScale: 1,
                    label: {
                        show: true
                    },
                    emphasis: {
1
100pah 已提交
423
                        focus: 'self',
1
100pah 已提交
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
                        label: {
                            show: true,
                            fontSize: 100
                        }
                    },
                    select: {
                        itemStyle: {
                            color: 'red'
                        }
                    }
                }
            };

            var chart = testHelper.create(echarts, 'main_geo_svg_emphasis_select', {
                title: [
                    'click buttons',
1
100pah 已提交
440
                    'hover check',
441 442
                    'check focus-blur',
                    'check label no scale/rotate'
1
100pah 已提交
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
                ],
                option: option,
                info: {},
                infoKey: 'event',
                height: 200,
                button: [{
                    text: 'highlight a',
                    onclick: function () {
                        chart.dispatchAction({ type: 'highlight', geoIndex: 0, name: 'a' });
                    }
                }, {
                    text: 'downplay a',
                    onclick: function () {
                        chart.dispatchAction({ type: 'downplay', geoIndex: 0, name: 'a' });
                    }
                }, {
                    text: 'select a',
                    onclick: function () {
                        chart.dispatchAction({ type: 'geoSelect', geoIndex: 0, name: 'a' });
                    }
                }, {
                    text: 'unselect a',
                    onclick: function () {
                        chart.dispatchAction({ type: 'geoUnSelect', geoIndex: 0, name: 'a' });
                    }
                }, {
                    text: 'highlight b',
                    onclick: function () {
                        chart.dispatchAction({ type: 'highlight', geoIndex: 0, name: 'b' });
                    }
                }, {
                    text: 'downplay b',
                    onclick: function () {
                        chart.dispatchAction({ type: 'downplay', geoIndex: 0, name: 'b' });
                    }
                }, {
                    text: 'select b',
                    onclick: function () {
                        chart.dispatchAction({ type: 'geoSelect', geoIndex: 0, name: 'b' });
                    }
                }, {
                    text: 'unselect b',
                    onclick: function () {
                        chart.dispatchAction({ type: 'geoUnSelect', geoIndex: 0, name: 'b' });
                    }
                }]
            });

            listenAndPrintEvent(chart);

            if (chart) {
                chart.on('highlight', function () {
                });
            }

        });
        </script>





505 506


507 508 509 510
        <script>
        require(['echarts'/*, 'map/js/china' */], function (echarts) {
            var option;
            $.ajax({
1
100pah 已提交
511
                url: '../../vis-data/map/svg/seats/seatmap-example.svg',
512 513 514 515 516 517 518 519
                dataType: 'text'
            }).done(function (svg) {

                echarts.registerMap('seatmap', {
                    svg: svg
                });

                option = {
1
100pah 已提交
520 521
                    tooltip: {
                    },
522 523 524
                    geo: {
                        map: 'seatmap',
                        roam: true,
1
100pah 已提交
525
                        selectedMode: 'multiple',
1
100pah 已提交
526 527 528
                        tooltip: {
                            show: true
                        },
529 530 531 532 533 534 535 536
                        // height: 100,
                        // zoom: 1.5
                        emphasis: {
                            label: {
                                textBorderColor: '#fff',
                                textBorderWidth: 2
                            }
                        },
1
100pah 已提交
537 538 539 540 541 542 543 544 545 546
                        select: {
                            itemStyle: {
                                color: '#b50205'
                            },
                            label: {
                                show: false,
                                textBorderColor: '#fff',
                                textBorderWidth: 2
                            }
                        }
547 548 549 550 551 552 553 554 555 556
                    },
                    // series: {
                    //     type: 'scatter',
                    //     coordinateSystem: 'geo',
                    //     // ?????????????????????????
                    //     geoIndex: 0,
                    //     data: [[11, 22], [33, 44]]
                    // }
                };

1
100pah 已提交
557
                var chart = testHelper.create(echarts, 'main_pure_geo_svg', {
558
                    title: [
1
100pah 已提交
559
                        'pure geo component with svg resource',
1
100pah 已提交
560 561
                        'click seat: check **allSelected** correct.',
                        'hover seat: check **tooltip** and **label** correct.'
562 563
                    ],
                    option: option,
1
100pah 已提交
564 565
                    info: {},
                    infoKey: 'event',
566 567 568 569 570
                    height: 300
                    // buttons: [{text: 'btn-txt', onclick: function () {}}],
                    // recordCanvas: true,
                });

1
100pah 已提交
571
                listenAndPrintEvent(chart);
1
100pah 已提交
572

573 574 575 576 577 578 579 580
            });

        });
        </script>




1
100pah 已提交
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623


        <script>
        require(['echarts'/*, 'map/js/china' */], function (echarts) {
            var option;
            $.ajax({
                url: '../../vis-data/map/svg/seats/seatmap-example.svg',
                dataType: 'text'
            }).done(function (svg) {

                echarts.registerMap('seatmap', {
                    svg: svg
                });

                option = {
                    tooltip: {
                    },
                    series: {
                        type: 'map',
                        map: 'seatmap',
                        roam: true,
                        selectedMode: 'multiple',
                        // height: 100,
                        // zoom: 1.5
                        emphasis: {
                            label: {
                                textBorderColor: '#fff',
                                textBorderWidth: 2
                            }
                        },
                        select: {
                            itemStyle: {
                                color: '#b50205'
                            },
                            label: {
                                show: false,
                                textBorderColor: '#fff',
                                textBorderWidth: 2
                            }
                        }
                    }
                };

1
100pah 已提交
624
                var chart = testHelper.create(echarts, 'main_pure_map_svg', {
1
100pah 已提交
625
                    title: [
1
100pah 已提交
626
                        'pure map series with svg resource',
1
100pah 已提交
627 628 629
                        'Hover seat: check **tooltip** correct.'
                    ],
                    option: option,
1
100pah 已提交
630 631
                    info: {},
                    infoKey: 'event',
1
100pah 已提交
632 633 634 635 636
                    height: 300
                    // buttons: [{text: 'btn-txt', onclick: function () {}}],
                    // recordCanvas: true,
                });

1
100pah 已提交
637
                listenAndPrintEvent(chart);
1
100pah 已提交
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668

            });

        });
        </script>





        <script>
        require(['echarts'/*, 'map/js/china' */], function (echarts) {
            var option;
            $.ajax({
                url: '../../vis-data/map/svg/seats/seatmap-example.svg',
                dataType: 'text'
            }).done(function (svg) {

                echarts.registerMap('seatmap', {
                    svg: svg
                });

                option = {
                    tooltip: {
                    },
                    geo: {
                        map: 'seatmap',
                        roam: true,
                        selectedMode: 'multiple',
                        // height: 100,
                        // zoom: 1.5
1
100pah 已提交
669 670 671
                        tooltip: {
                            show: true
                        },
1
100pah 已提交
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
                        emphasis: {
                            label: {
                                textBorderColor: '#fff',
                                textBorderWidth: 2
                            }
                        },
                        select: {
                            itemStyle: {
                                color: '#b50205'
                            },
                            label: {
                                show: false,
                                textBorderColor: '#fff',
                                textBorderWidth: 2
                            }
                        }
                    },
                    series: {
                        type: 'map',
                        selectedMode: 'multiple',
                        coordinateSystem: 'geo',
                        geoIndex: 0
                    }
                };

                var chart = testHelper.create(echarts, 'main_map_geo_svg', {
                    title: [
                        'map series on declared geo with svg resource',
                        'Hover seat: check **tooltip** correct.'
                    ],
                    option: option,
                    info: {},
                    infoKey: 'event',
                    height: 300
                    // buttons: [{text: 'btn-txt', onclick: function () {}}],
                    // recordCanvas: true,
                });

1
100pah 已提交
710
                listenAndPrintEvent(chart);
1
100pah 已提交
711 712 713 714 715 716 717

            });

        });
        </script>


718 719 720 721 722





723 724 725
    </body>
</html>