legend.js 29.4 KB
Newer Older
K
kener 已提交
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
/**
 * echarts组件:图例
 *
 * @desc echarts基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据统计图表。
 * @author Kener (@Kener-林峰, linzhifeng@baidu.com)
 *
 */
define(function (require) {
    /**
     * 构造函数
     * @param {Object} messageCenter echart消息中心
     * @param {ZRender} zr zrender实例
     * @param {Object} option 图表参数
     * @param {Object=} selected 用于状态保持
     */
    function Legend(messageCenter, zr, option, selected) {
        var Base = require('./base');
        Base.call(this, zr);

        var ecConfig = require('../config');
        var zrArea = require('zrender/tool/area');

        var self = this;
        self.type = ecConfig.COMPONENT_TYPE_LEGEND;

        var legendOption;                       // 图例选项,共享数据源
        var _zlevelBase = self.getZlevelBase();

        var _itemGroupLocation = {};    // 图例元素组的位置参数,通过计算所得x, y, width, height

        var _colorIndex = 0;
        var _colorMap = {};
        var _selectedMap = {};

35 36 37 38 39
        var icon = require('zrender/shape').get('icon');
        for (var k in legendIcon) {
            icon.define('legendicon' + k, legendIcon[k]);
            //console.log('legendicon' + k, legendIcon[k])
        }
K
kener 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

        function _buildShape() {
            _itemGroupLocation = _getItemGroupLocation();

            _buildBackground();
            _buildItem();

            for (var i = 0, l = self.shapeList.length; i < l; i++) {
                self.shapeList[i].id = zr.newShapeId(self.type);
                zr.addShape(self.shapeList[i]);
            }
        }

        /**
         * 构建所有图例元素
         */
        function _buildItem() {
            var data = legendOption.data;
            var dataLength = data.length;
            var itemName;
            var itemType;
            var itemShape;
            var textShape;
            var font = self.getFont(legendOption.textStyle);

            var zrWidth = zr.getWidth();
K
kener 已提交
66
            var zrHeight = zr.getHeight();
K
kener 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
            var lastX = _itemGroupLocation.x;
            var lastY = _itemGroupLocation.y;
            var itemWidth = legendOption.itemWidth;
            var itemHeight = legendOption.itemHeight;
            var itemGap = legendOption.itemGap;
            var color;

            if (legendOption.orient == 'vertical'
                && legendOption.x == 'right'
            ) {
                lastX = _itemGroupLocation.x
                        + _itemGroupLocation.width
                        - itemWidth;
            }

            for (var i = 0; i < dataLength; i++) {
                itemName = data[i];
K
kener 已提交
84
                if (itemName === '') {
K
kener 已提交
85 86 87 88 89 90 91 92 93 94 95 96
                    if (legendOption.orient == 'horizontal') {
                        lastX = _itemGroupLocation.x;
                        lastY += itemHeight + itemGap;
                    }
                    else {
                        legendOption.x == 'right'
                        ? lastX -= _itemGroupLocation.maxWidth + itemGap
                        : lastX += _itemGroupLocation.maxWidth + itemGap;
                        lastY = _itemGroupLocation.y;
                    }
                    continue;
                }
K
kener 已提交
97 98 99 100
                itemType = _getSeriesByName(itemName);
                if (itemType) {
                    itemType = itemType.type;
                } else {
101
                    itemType = 'bar';
K
kener 已提交
102 103 104 105 106 107
                }
                color = getColor(itemName);

                if (legendOption.orient == 'horizontal') {
                    if (zrWidth - lastX < 200   // 最后200px做分行预判
                        && (itemWidth + 5
K
kener 已提交
108 109
                            + zrArea.getTextWidth(itemName, font)
                            // 分行的最后一个不用算itemGap
K
kener 已提交
110
                            + (i == dataLength - 1 || data[i+1] === ''
K
kener 已提交
111 112
                               ? 0 : itemGap))
                            >= zrWidth - lastX
K
kener 已提交
113
                    ) {
K
kener 已提交
114
                        lastX = _itemGroupLocation.x;
K
kener 已提交
115 116 117
                        lastY += itemHeight + itemGap;
                    }
                }
K
kener 已提交
118 119 120 121
                else {
                    if (zrHeight - lastY < 200   // 最后200px做分行预判
                        && (itemHeight
                            // 分行的最后一个不用算itemGap
K
kener 已提交
122
                            + (i == dataLength - 1 || data[i+1] === ''
K
kener 已提交
123 124 125 126 127 128 129 130 131
                               ? 0 : itemGap))
                            >= zrHeight - lastY
                    ) {
                        legendOption.x == 'right'
                        ? lastX -= _itemGroupLocation.maxWidth + itemGap
                        : lastX += _itemGroupLocation.maxWidth + itemGap;
                        lastY = _itemGroupLocation.y;
                    }
                }
K
kener 已提交
132 133 134 135 136

                // 图形
                itemShape = _getItemShapeByType(
                    lastX, lastY,
                    itemWidth, itemHeight,
137 138
                    (_selectedMap[itemName] ? color : '#ccc'),
                    itemType
K
kener 已提交
139 140
                );
                itemShape._name = itemName;
141 142 143
                if (legendOption.selectedMode) {
                    itemShape.onclick = _legendSelected;
                }
K
kener 已提交
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
                self.shapeList.push(itemShape);

                // 文字
                textShape = {
                    shape : 'text',
                    zlevel : _zlevelBase,
                    style : {
                        x : lastX + itemWidth + 5,
                        y : lastY,
                        color : _selectedMap[itemName]
                                ? legendOption.textStyle.color
                                : '#ccc',
                        text: itemName,
                        textFont: font,
                        textBaseline: 'top'
                    },
160 161
                    hoverable : legendOption.selectedMode,
                    clickable : legendOption.selectedMode
K
kener 已提交
162 163 164 165 166 167 168 169 170 171
                };

                if (legendOption.orient == 'vertical'
                    && legendOption.x == 'right'
                ) {
                    textShape.style.x -= (itemWidth + 10);
                    textShape.style.textAlign = 'right';
                }

                textShape._name = itemName;
172 173 174
                if (legendOption.selectedMode) {
                    textShape.onclick = _legendSelected;
                }
K
kener 已提交
175 176 177 178 179 180 181 182 183 184 185
                self.shapeList.push(textShape);

                if (legendOption.orient == 'horizontal') {
                    lastX += itemWidth + 5
                             + zrArea.getTextWidth(itemName, font)
                             + itemGap;
                }
                else {
                    lastY += itemHeight + itemGap;
                }
            }
K
kener 已提交
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 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
        
            if (legendOption.orient == 'horizontal'
                && legendOption.x == 'center'
                && lastY != _itemGroupLocation.y
            ) {
                // 多行橫排居中优化
                var lineOffsetArray = []; // 每行宽度
                lastX = _itemGroupLocation.x;
                for (var i = 2, l = self.shapeList.length; i < l; i++) {
                    if (self.shapeList[i].style.x == lastX) {
                        lineOffsetArray.push(
                            (
                                _itemGroupLocation.width 
                                - (
                                    self.shapeList[i - 1].style.x
                                    + zrArea.getTextWidth(
                                          self.shapeList[i - 1].style.text, font
                                      )
                                    - lastX
                                )
                            ) / 2
                        );
                    }
                    else if (i == l - 1) {
                        lineOffsetArray.push(
                            (
                                _itemGroupLocation.width 
                                - (
                                    self.shapeList[i].style.x
                                    + zrArea.getTextWidth(
                                          self.shapeList[i].style.text, font
                                      )
                                    - lastX
                                )
                            ) / 2
                        );
                    }
                }
                var curLineIndex = -1;
                for (var i = 1, l = self.shapeList.length; i < l; i++) {
                    if (self.shapeList[i].style.x == lastX) {
                        curLineIndex++;
                    }
                    if (lineOffsetArray[curLineIndex] === 0) {
                        continue;
                    }
                    else {
                        self.shapeList[i].style.x += 
                            lineOffsetArray[curLineIndex];
                    }
                }
            }
K
kener 已提交
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
        }

        function _buildBackground() {
            var pTop = legendOption.padding[0];
            var pRight = legendOption.padding[1];
            var pBottom = legendOption.padding[2];
            var pLeft = legendOption.padding[3];

            self.shapeList.push({
                shape : 'rectangle',
                zlevel : _zlevelBase,
                hoverable :false,
                style : {
                    x : _itemGroupLocation.x - pLeft,
                    y : _itemGroupLocation.y - pTop,
                    width : _itemGroupLocation.width + pLeft + pRight,
                    height : _itemGroupLocation.height + pTop + pBottom,
                    brushType : legendOption.borderWidth === 0
                                ? 'fill' : 'both',
                    color : legendOption.backgroundColor,
                    strokeColor : legendOption.borderColor,
                    lineWidth : legendOption.borderWidth
                }
            });
        }

        /**
         * 根据选项计算图例实体的位置坐标
         */
        function _getItemGroupLocation() {
            var data = legendOption.data;
            var dataLength = data.length;
            var itemGap = legendOption.itemGap;
            var itemWidth = legendOption.itemWidth + 5; // 5px是图形和文字的间隔,不可配
            var itemHeight = legendOption.itemHeight;
K
kener 已提交
273
            var font = self.getFont(legendOption.textStyle);
K
kener 已提交
274 275
            var totalWidth = 0;
            var totalHeight = 0;
K
kener 已提交
276 277 278 279 280 281
            var padding = legendOption.padding;
            var zrWidth = zr.getWidth() - padding[1] - padding[3];
            var zrHeight = zr.getHeight() - padding[0] - padding[2];
            
            var temp = 0; // 宽高计算,用于多行判断
            var maxWidth = 0; // 垂直布局有用
K
kener 已提交
282 283
            if (legendOption.orient == 'horizontal') {
                // 水平布局,计算总宽度
K
kener 已提交
284
                totalHeight = itemHeight;
K
kener 已提交
285
                for (var i = 0; i < dataLength; i++) {
K
kener 已提交
286
                    if (data[i] === '') {
K
kener 已提交
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
                        temp -= itemGap;
                        if (temp > zrWidth) {
                            totalWidth = zrWidth;
                            totalHeight += itemHeight + itemGap;
                        }
                        else {
                            totalWidth = Math.max(totalWidth, temp);
                        }
                        totalHeight += itemHeight + itemGap;
                        temp = 0;
                        continue;
                    }
                    temp += itemWidth
                            + zrArea.getTextWidth(
                                  data[i],
                                  font
                              )
                            + itemGap;
                }
                totalHeight = Math.max(totalHeight, itemHeight);
                temp -= itemGap;    // 减去最后一个的itemGap
                if (temp > zrWidth) {
                    totalWidth = zrWidth;
                    totalHeight += itemHeight + itemGap;
                } else {
                    totalWidth = Math.max(totalWidth, temp);
K
kener 已提交
313 314 315 316 317 318 319 320 321
                }
            }
            else {
                // 垂直布局,计算总高度
                for (var i = 0; i < dataLength; i++) {
                    maxWidth = Math.max(
                        maxWidth,
                        zrArea.getTextWidth(
                            data[i],
K
kener 已提交
322
                            font
K
kener 已提交
323 324 325
                        )
                    );
                }
K
kener 已提交
326 327 328
                maxWidth += itemWidth;
                totalWidth = maxWidth;
                for (var i = 0; i < dataLength; i++) {
K
kener 已提交
329
                    if (data[i] === '') {
K
kener 已提交
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
                        temp -= itemGap;
                        if (temp > zrHeight) {
                            totalHeight = zrHeight;
                            totalWidth += maxWidth + itemGap;
                        }
                        else {
                            totalHeight = Math.max(totalHeight, temp);
                        }
                        totalWidth += maxWidth + itemGap;
                        temp = 0;
                        continue;
                    }
                    temp += itemHeight + itemGap;
                }
                totalWidth = Math.max(totalWidth, maxWidth);
                temp -= itemGap;    // 减去最后一个的itemGap
                if (temp > zrHeight) {
                    totalHeight = zrHeight;
                    totalWidth += maxWidth + itemGap;
                } else {
                    totalHeight = Math.max(totalHeight, temp);
                }
K
kener 已提交
352 353
            }

K
kener 已提交
354 355
            zrWidth = zr.getWidth();
            zrHeight = zr.getHeight();
K
kener 已提交
356 357 358 359 360 361 362 363 364 365 366 367
            var x;
            switch (legendOption.x) {
                case 'center' :
                    x = Math.floor((zrWidth - totalWidth) / 2);
                    break;
                case 'left' :
                    x = legendOption.padding[3] + legendOption.borderWidth;
                    break;
                case 'right' :
                    x = zrWidth
                        - totalWidth
                        - legendOption.padding[1]
K
kener 已提交
368 369
                        - legendOption.padding[3]
                        - legendOption.borderWidth * 2;
K
kener 已提交
370 371 372
                    break;
                default :
                    x = legendOption.x - 0;
K
kener 已提交
373
                    x = isNaN(x) ? 0 : x;
K
kener 已提交
374 375 376 377 378 379 380 381 382 383 384
                    break;
            }

            var y;
            switch (legendOption.y) {
                case 'top' :
                    y = legendOption.padding[0] + legendOption.borderWidth;
                    break;
                case 'bottom' :
                    y = zrHeight
                        - totalHeight
K
kener 已提交
385
                        - legendOption.padding[0]
K
kener 已提交
386
                        - legendOption.padding[2]
K
kener 已提交
387
                        - legendOption.borderWidth * 2;
K
kener 已提交
388 389 390 391 392 393
                    break;
                case 'center' :
                    y = Math.floor((zrHeight - totalHeight) / 2);
                    break;
                default :
                    y = legendOption.y - 0;
K
kener 已提交
394
                    y = isNaN(y) ? 0 : y;
K
kener 已提交
395 396 397 398 399 400 401
                    break;
            }

            return {
                x : x,
                y : y,
                width : totalWidth,
K
kener 已提交
402 403
                height : totalHeight,
                maxWidth : maxWidth
K
kener 已提交
404 405 406 407 408 409 410 411
            };
        }

        /**
         * 根据名称返回series数据
         */
        function _getSeriesByName(name) {
            var series = option.series;
K
kener 已提交
412 413
            var hasFind;
            var data;
K
kener 已提交
414 415 416 417 418 419
            for (var i = 0, l = series.length; i < l; i++) {
                if (series[i].name == name) {
                    // 系列名称优先
                    return series[i];
                }

K
kener 已提交
420 421 422
                if (
                    series[i].type == ecConfig.CHART_TYPE_PIE 
                    || series[i].type == ecConfig.CHART_TYPE_RADAR
L
lang 已提交
423
                    || series[i].type == ecConfig.CHART_TYPE_CHORD
K
kener 已提交
424
                ) {
K
kener 已提交
425
                    // 饼图、雷达图、和弦图得查找里面的数据名字
K
kener 已提交
426 427
                    hasFind = false;
                    data = series[i].data;
K
kener 已提交
428 429
                    for (var j = 0, k = data.length; j < k; j++) {
                        if (data[j].name == name) {
K
kener 已提交
430
                            data = data[j];
K
kener 已提交
431 432 433 434
                            data.type = 
                                series[i].type == ecConfig.CHART_TYPE_CHORD 
                                ? ecConfig.CHART_TYPE_PIE // 和弦图复用pie图样式
                                : series[i].type;
K
kener 已提交
435 436 437 438 439
                            hasFind = true;
                            break;
                        }
                    }
                    if (hasFind) {
K
kener 已提交
440
                        return data;
K
kener 已提交
441 442
                    }
                }
K
kener 已提交
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
                else if (series[i].type == ecConfig.CHART_TYPE_FORCE) {
                    // 力导布局查找categories配置
                    hasFind = false;
                    data = series[i].categories;
                    for (var j = 0, k = data.length; j < k; j++) {
                        if (data[j].name == name) {
                            data = data[j];
                            data.type = ecConfig.CHART_TYPE_FORCE;
                            hasFind = true;
                            break;
                        }
                    }
                    if (hasFind) {
                        return data;
                    }
                }
K
kener 已提交
459 460 461 462 463
            }
            return;
        }

        function _getItemShapeByType(x, y, width, height, color, itemType) {
464 465 466 467 468 469 470 471 472 473 474
            var itemShape = {
                shape : 'icon',
                zlevel : _zlevelBase,
                style : {
                    iconType : 'legendicon' + itemType,
                    x : x,
                    y : y,
                    width : width,
                    height : height,
                    color : color,
                    strokeColor : color,
K
kener 已提交
475
                    lineWidth : 3
476
                },
477 478
                hoverable : legendOption.selectedMode,
                clickable : legendOption.selectedMode
479 480
            };
            // 特殊设置
K
kener 已提交
481 482
            switch (itemType) {
                case 'line' :
483 484
                    itemShape.style.brushType = 'stroke';
                    break;
K
kener 已提交
485
                case 'k' :
486
                    itemShape.style.brushType = 'both';
487 488
                    itemShape.style.color = self.query(
                        ecConfig, 'k.itemStyle.normal.color'
489 490
                    ) || '#fff';
                    itemShape.style.strokeColor = color != '#ccc' 
491 492
                        ? self.query(
                              ecConfig, 'k.itemStyle.normal.lineStyle.color'
493 494
                          ) || '#ff3200'
                        : color;
K
kener 已提交
495
            }
496
            return itemShape;
K
kener 已提交
497 498 499 500 501 502 503 504 505 506 507 508 509
        }

        function _legendSelected(param) {
            var itemName = param.target._name;
            _selectedMap[itemName] = !_selectedMap[itemName];
            messageCenter.dispatch(
                ecConfig.EVENT.LEGEND_SELECTED,
                param.event,
                {selected : _selectedMap}
            );
        }

        function init(newOption) {
510
            if (!self.query(newOption, 'legend.data')) {
K
kener 已提交
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
                return;
            }

            option = newOption;

            option.legend = self.reformOption(option.legend);
            // 补全padding属性
            option.legend.padding = self.reformCssArray(
                option.legend.padding
            );

            legendOption = option.legend;

            self.clear();

            _selectedMap = {};

            var data = legendOption.data || [];
            var itemName;
            var serie;
            var color;
            for (var i = 0, dataLength = data.length; i < dataLength; i++) {
                itemName = data[i];
K
kener 已提交
534
                if (itemName === '') {
K
kener 已提交
535 536
                    continue;
                }
K
kener 已提交
537 538
                serie = _getSeriesByName(itemName);
                if (!serie) {
K
kener 已提交
539 540 541
                    _selectedMap[itemName] = false;
                } 
                else {
542 543
                    color = self.query(
                        serie, 'itemStyle.normal.color'
K
kener 已提交
544
                    );
K
smooth  
kener 已提交
545
                    if (color && serie.type != ecConfig.CHART_TYPE_K) {
K
kener 已提交
546 547 548 549 550
                        setColor(itemName, color);
                    }
                    _selectedMap[itemName] = true;
                }
            }
K
kener 已提交
551 552 553
            if (selected) {
                for (var k in selected) {
                    _selectedMap[k] = selected[k];
K
kener 已提交
554 555
                }
            }
K
kener 已提交
556
            _buildShape();
K
kener 已提交
557 558 559 560 561
        }

        /**
         * 刷新
         */
K
kener 已提交
562 563 564 565 566 567 568 569
        function refresh(newOption) {
            if (newOption) {
                option = newOption;
                option.legend = self.reformOption(option.legend);
                // 补全padding属性
                option.legend.padding = self.reformCssArray(
                    option.legend.padding
                );
570 571 572 573 574
                if (option.legend.selected) {
                    for (var k in option.legend.selected) {
                        _selectedMap[k] = option.legend.selected[k];
                    }
                }
K
kener 已提交
575
            }
K
kener 已提交
576
            legendOption = option.legend;
K
kener 已提交
577
            
K
kener 已提交
578 579 580 581 582 583 584 585 586 587 588 589 590 591
            self.clear();
            _buildShape();
        }

        function setColor(legendName, color) {
            _colorMap[legendName] = color;
        }

        function getColor(legendName) {
            if (!_colorMap[legendName]) {
                _colorMap[legendName] = zr.getColor(_colorIndex++);
            }
            return _colorMap[legendName];
        }
K
kener 已提交
592 593 594 595
        
        function hasColor(legendName) {
            return _colorMap[legendName] ? _colorMap[legendName] : false;
        }
K
kener 已提交
596

K
kener 已提交
597
        function add(name, color){
K
kener 已提交
598 599 600 601 602 603 604 605 606 607 608 609
            legendOption.data.push(name);
            setColor(name,color);
            _selectedMap[name] = true;
        }

        function del(name){
            var data = legendOption.data;
            var finalData = [];
            var found = false;
            for (var i = 0, dataLength = data.length; i < dataLength; i++) {
                if (found || data[i] != name) {
                    finalData.push(data[i]);
K
kener 已提交
610 611
                }
                else {
K
kener 已提交
612 613 614 615 616 617
                    found = true;
                    continue;
                }
            }
            legendOption.data = finalData;
        }
618 619 620 621 622 623 624
        
        /**
         * 特殊图形元素回调设置
         * @param {Object} name
         * @param {Object} itemShape
         */
        function getItemShape(name) {
K
kener 已提交
625 626 627
            if (typeof name == 'undefined') {
                return;
            }
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
            var shape;
            for (var i = 0, l = self.shapeList.length; i < l; i++) {
                shape = self.shapeList[i];
                if (shape._name == name && shape.shape != 'text') {
                    return shape;
                }
            }
        }
        
        /**
         * 特殊图形元素回调设置
         * @param {Object} name
         * @param {Object} itemShape
         */
        function setItemShape(name, itemShape) {
            var shape;
            for (var i = 0, l = self.shapeList.length; i < l; i++) {
                shape = self.shapeList[i];
                if (shape._name == name && shape.shape != 'text') {
                    if (!_selectedMap[name]) {
                        itemShape.style.color = '#ccc';
                        itemShape.style.strokeColor = '#ccc';
                    }
K
kener 已提交
651
                    zr.modShape(shape.id, itemShape);
652 653 654
                }
            }
        }
K
kener 已提交
655 656 657 658 659 660 661 662 663 664

        function isSelected(itemName) {
            if (typeof _selectedMap[itemName] != 'undefined') {
                return _selectedMap[itemName];
            }
            else {
                // 没在legend里定义的都为true啊~
                return true;
            }
        }
K
kener 已提交
665 666 667 668
        
        function getSelectedMap() {
            return _selectedMap;
        }
K
kener 已提交
669 670 671 672 673

        self.init = init;
        self.refresh = refresh;
        self.setColor = setColor;
        self.getColor = getColor;
K
kener 已提交
674
        self.hasColor = hasColor;
K
kener 已提交
675 676
        self.add = add;
        self.del = del;
677 678
        self.getItemShape = getItemShape;
        self.setItemShape = setItemShape;
K
kener 已提交
679
        self.isSelected = isSelected;
K
kener 已提交
680
        self.getSelectedMap = getSelectedMap;
K
kener 已提交
681 682 683

        init(option);
    }
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
    
    var legendIcon = {
        line : function (ctx, style) {
            var dy = style.height / 2;
            ctx.moveTo(style.x,     style.y + dy);
            ctx.lineTo(style.x + style.width,style.y + dy);
        },
        pie : function (ctx, style) {
            var x = style.x;
            var y = style.y;
            var width = style.width;
            var height = style.height;
            var sector = require('zrender/shape').get('sector');
            sector.buildPath(ctx, {
                x : x + width / 2,
                y : y + height + 2,
                r : height + 2,
                r0 : 6,
                startAngle : 45,
                endAngle : 135
            });
        },
K
kener 已提交
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
        chord : function(ctx, style) {
            var x = style.x;
            var y = style.y;
            var width = style.width;
            var height = style.height;
            var beziercurve = require('zrender/shape').get('beziercurve');
            ctx.moveTo(x, y + height);
            beziercurve.buildPath(ctx, {
                xStart : x,
                yStart : y + height,
                cpX1 : x + width,
                cpY1 : y + height,
                cpX2 : x,
                cpY2 : y + 4,
                xEnd : x + width,
K
,号  
kener 已提交
721
                yEnd : y + 4
K
kener 已提交
722 723 724 725 726 727 728 729 730 731
            });
            ctx.lineTo(x + width, y);
            beziercurve.buildPath(ctx, {
                xStart : x + width,
                yStart : y,
                cpX1 : x,
                cpY1 : y,
                cpX2 : x + width,
                cpY2 : y + height - 4,
                xEnd : x,
K
,号  
kener 已提交
732
                yEnd : y + height - 4
K
kener 已提交
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
            });
            ctx.lineTo(x, y + height);
            /*
            var x = style.x + 2;
            var y = style.y;
            var width = style.width - 2;
            var height = style.height;
            var r = width / Math.sqrt(3);
            ctx.moveTo(x, y);
            ctx.quadraticCurveTo(x + width / 4 * 3, y, x + width, y + height);
            ctx.arc(
                x + width / 2, y + height + r / 2, 
                r, -Math.PI / 6, -Math.PI / 6 * 5, true);
            ctx.quadraticCurveTo(x - width / 2, y + height / 3, x, y);
            */
        },
749 750 751 752 753 754 755 756 757 758 759 760 761
        k : function (ctx, style) {
            var x = style.x;
            var y = style.y;
            var width = style.width;
            var height = style.height;
            var candle = require('zrender/shape').get('candle');
            candle.buildPath(ctx, {
                x : x + width / 2,
                y : [y + 1, y + 1, y + height - 6, y + height],
                width : width - 6
            });
        },
        bar : function (ctx, style) {
K
kener 已提交
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
            //ctx.rect(style.x, style.y + 1, style.width, style.height - 2);
            var x = style.x;
            var y = style.y +1;
            var width = style.width;
            var height = style.height - 2;
            var r = 3;
            
            ctx.moveTo(x + r, y);
            ctx.lineTo(x + width - r, y);
            ctx.quadraticCurveTo(
                x + width, y, x + width, y + r
            );
            ctx.lineTo(x + width, y + height - r);
            ctx.quadraticCurveTo(
                x + width, y + height, x + width - r, y + height
            );
            ctx.lineTo(x + r, y + height);
            ctx.quadraticCurveTo(
                x, y + height, x, y + height - r
            );
            ctx.lineTo(x, y + r);
            ctx.quadraticCurveTo(x, y, x + r, y);
K
kener 已提交
784 785 786
        },
        force : function(ctx, style) {
            require('zrender/shape').get('icon').get('circle')(ctx, style);
K
kener 已提交
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
        },
        radar: function(ctx, style) {
            var n = 6;
            var x = style.x + style.width / 2;
            var y = style.y + style.height / 2;
            var r = style.height / 2;

            var dStep = 2 * Math.PI / n;
            var deg = -Math.PI / 2;
            var xStart = x + r * Math.cos(deg);
            var yStart = y + r * Math.sin(deg);
            
            ctx.moveTo(xStart, yStart);
            deg += dStep;
            for (var i = 0, end = n - 1; i < end; i ++) {
                ctx.lineTo(x + r * Math.cos(deg), y + r * Math.sin(deg));
                deg += dStep;
            }
            ctx.lineTo(xStart, yStart);
806
        }
K
kener 已提交
807
    };
808
    
809 810
    require('../component').define('legend', Legend);
    
K
kener 已提交
811 812 813 814
    return Legend;
});