legend.js 26.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 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
                self.shapeList.push(textShape);

                if (legendOption.orient == 'horizontal') {
                    lastX += itemWidth + 5
                             + zrArea.getTextWidth(itemName, font)
                             + itemGap;
                }
                else {
                    lastY += itemHeight + itemGap;
                }
            }
        }

        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 已提交
221
            var font = self.getFont(legendOption.textStyle);
K
kener 已提交
222 223
            var totalWidth = 0;
            var totalHeight = 0;
K
kener 已提交
224 225 226 227 228 229
            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 已提交
230 231
            if (legendOption.orient == 'horizontal') {
                // 水平布局,计算总宽度
K
kener 已提交
232
                totalHeight = itemHeight;
K
kener 已提交
233
                for (var i = 0; i < dataLength; i++) {
K
kener 已提交
234
                    if (data[i] === '') {
K
kener 已提交
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
                        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 已提交
261 262 263 264 265 266 267 268 269
                }
            }
            else {
                // 垂直布局,计算总高度
                for (var i = 0; i < dataLength; i++) {
                    maxWidth = Math.max(
                        maxWidth,
                        zrArea.getTextWidth(
                            data[i],
K
kener 已提交
270
                            font
K
kener 已提交
271 272 273
                        )
                    );
                }
K
kener 已提交
274 275 276
                maxWidth += itemWidth;
                totalWidth = maxWidth;
                for (var i = 0; i < dataLength; i++) {
K
kener 已提交
277
                    if (data[i] === '') {
K
kener 已提交
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
                        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 已提交
300 301
            }

K
kener 已提交
302 303
            zrWidth = zr.getWidth();
            zrHeight = zr.getHeight();
K
kener 已提交
304 305 306 307 308 309 310 311 312 313 314 315
            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 已提交
316 317
                        - legendOption.padding[3]
                        - legendOption.borderWidth * 2;
K
kener 已提交
318 319 320
                    break;
                default :
                    x = legendOption.x - 0;
K
kener 已提交
321
                    x = isNaN(x) ? 0 : x;
K
kener 已提交
322 323 324 325 326 327 328 329 330 331 332
                    break;
            }

            var y;
            switch (legendOption.y) {
                case 'top' :
                    y = legendOption.padding[0] + legendOption.borderWidth;
                    break;
                case 'bottom' :
                    y = zrHeight
                        - totalHeight
K
kener 已提交
333
                        - legendOption.padding[0]
K
kener 已提交
334
                        - legendOption.padding[2]
K
kener 已提交
335
                        - legendOption.borderWidth * 2;
K
kener 已提交
336 337 338 339 340 341
                    break;
                case 'center' :
                    y = Math.floor((zrHeight - totalHeight) / 2);
                    break;
                default :
                    y = legendOption.y - 0;
K
kener 已提交
342
                    y = isNaN(y) ? 0 : y;
K
kener 已提交
343 344 345 346 347 348 349
                    break;
            }

            return {
                x : x,
                y : y,
                width : totalWidth,
K
kener 已提交
350 351
                height : totalHeight,
                maxWidth : maxWidth
K
kener 已提交
352 353 354 355 356 357 358 359
            };
        }

        /**
         * 根据名称返回series数据
         */
        function _getSeriesByName(name) {
            var series = option.series;
K
kener 已提交
360 361
            var hasFind;
            var data;
K
kener 已提交
362 363 364 365 366 367
            for (var i = 0, l = series.length; i < l; i++) {
                if (series[i].name == name) {
                    // 系列名称优先
                    return series[i];
                }

K
kener 已提交
368 369 370
                if (
                    series[i].type == ecConfig.CHART_TYPE_PIE 
                    || series[i].type == ecConfig.CHART_TYPE_RADAR
L
lang 已提交
371
                    || series[i].type == ecConfig.CHART_TYPE_CHORD
K
kener 已提交
372
                ) {
K
kener 已提交
373
                    // 饼图、雷达图、和弦图得查找里面的数据名字
K
kener 已提交
374 375
                    hasFind = false;
                    data = series[i].data;
K
kener 已提交
376 377
                    for (var j = 0, k = data.length; j < k; j++) {
                        if (data[j].name == name) {
K
kener 已提交
378
                            data = data[j];
K
kener 已提交
379 380 381 382
                            data.type = 
                                series[i].type == ecConfig.CHART_TYPE_CHORD 
                                ? ecConfig.CHART_TYPE_PIE // 和弦图复用pie图样式
                                : series[i].type;
K
kener 已提交
383 384 385 386 387
                            hasFind = true;
                            break;
                        }
                    }
                    if (hasFind) {
K
kener 已提交
388
                        return data;
K
kener 已提交
389 390
                    }
                }
K
kener 已提交
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
                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 已提交
407 408 409 410 411
            }
            return;
        }

        function _getItemShapeByType(x, y, width, height, color, itemType) {
412 413 414 415 416 417 418 419 420 421 422
            var itemShape = {
                shape : 'icon',
                zlevel : _zlevelBase,
                style : {
                    iconType : 'legendicon' + itemType,
                    x : x,
                    y : y,
                    width : width,
                    height : height,
                    color : color,
                    strokeColor : color,
K
kener 已提交
423
                    lineWidth : 3
424
                },
425 426
                hoverable : legendOption.selectedMode,
                clickable : legendOption.selectedMode
427 428
            };
            // 特殊设置
K
kener 已提交
429 430
            switch (itemType) {
                case 'line' :
431 432
                    itemShape.style.brushType = 'stroke';
                    break;
K
kener 已提交
433
                case 'k' :
434 435 436 437 438 439 440 441 442
                    itemShape.style.brushType = 'both';
                    itemShape.style.color = self.deepQuery(
                        [ecConfig], 'k.itemStyle.normal.color'
                    ) || '#fff';
                    itemShape.style.strokeColor = color != '#ccc' 
                        ? self.deepQuery(
                              [ecConfig], 'k.itemStyle.normal.lineStyle.color'
                          ) || '#ff3200'
                        : color;
K
kener 已提交
443
            }
444
            return itemShape;
K
kener 已提交
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
        }

        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) {
            if (!self.deepQuery([newOption], 'legend.data')) {
                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 已提交
482
                if (itemName === '') {
K
kener 已提交
483 484
                    continue;
                }
K
kener 已提交
485 486
                serie = _getSeriesByName(itemName);
                if (!serie) {
K
kener 已提交
487 488 489
                    _selectedMap[itemName] = false;
                } 
                else {
K
kener 已提交
490 491 492
                    color = self.deepQuery(
                        [serie], 'itemStyle.normal.color'
                    );
K
smooth  
kener 已提交
493
                    if (color && serie.type != ecConfig.CHART_TYPE_K) {
K
kener 已提交
494 495 496 497 498
                        setColor(itemName, color);
                    }
                    _selectedMap[itemName] = true;
                }
            }
K
kener 已提交
499 500 501
            if (selected) {
                for (var k in selected) {
                    _selectedMap[k] = selected[k];
K
kener 已提交
502 503
                }
            }
K
kener 已提交
504
            _buildShape();
K
kener 已提交
505 506 507 508 509
        }

        /**
         * 刷新
         */
K
kener 已提交
510 511 512 513 514 515 516 517
        function refresh(newOption) {
            if (newOption) {
                option = newOption;
                option.legend = self.reformOption(option.legend);
                // 补全padding属性
                option.legend.padding = self.reformCssArray(
                    option.legend.padding
                );
518 519 520 521 522
                if (option.legend.selected) {
                    for (var k in option.legend.selected) {
                        _selectedMap[k] = option.legend.selected[k];
                    }
                }
K
kener 已提交
523
            }
K
kener 已提交
524
            legendOption = option.legend;
K
kener 已提交
525
            
K
kener 已提交
526 527 528 529 530 531 532 533 534 535 536 537 538 539
            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 已提交
540 541 542 543
        
        function hasColor(legendName) {
            return _colorMap[legendName] ? _colorMap[legendName] : false;
        }
K
kener 已提交
544

K
kener 已提交
545
        function add(name, color){
K
kener 已提交
546 547 548 549 550 551 552 553 554 555 556 557
            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 已提交
558 559
                }
                else {
K
kener 已提交
560 561 562 563 564 565
                    found = true;
                    continue;
                }
            }
            legendOption.data = finalData;
        }
566 567 568 569 570 571 572
        
        /**
         * 特殊图形元素回调设置
         * @param {Object} name
         * @param {Object} itemShape
         */
        function getItemShape(name) {
K
kener 已提交
573 574 575
            if (typeof name == 'undefined') {
                return;
            }
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
            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 已提交
599
                    zr.modShape(shape.id, itemShape);
600 601 602
                }
            }
        }
K
kener 已提交
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617

        function isSelected(itemName) {
            if (typeof _selectedMap[itemName] != 'undefined') {
                return _selectedMap[itemName];
            }
            else {
                // 没在legend里定义的都为true啊~
                return true;
            }
        }

        self.init = init;
        self.refresh = refresh;
        self.setColor = setColor;
        self.getColor = getColor;
K
kener 已提交
618
        self.hasColor = hasColor;
K
kener 已提交
619 620
        self.add = add;
        self.del = del;
621 622
        self.getItemShape = getItemShape;
        self.setItemShape = setItemShape;
K
kener 已提交
623 624 625 626
        self.isSelected = isSelected;

        init(option);
    }
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
    
    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 已提交
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
        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 已提交
664
                yEnd : y + 4
K
kener 已提交
665 666 667 668 669 670 671 672 673 674
            });
            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 已提交
675
                yEnd : y + height - 4
K
kener 已提交
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
            });
            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);
            */
        },
692 693 694 695 696 697 698 699 700 701 702 703 704 705
        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) {
            ctx.rect(style.x, style.y + 1, style.width, style.height - 2);
K
kener 已提交
706 707 708
        },
        force : function(ctx, style) {
            require('zrender/shape').get('icon').get('circle')(ctx, style);
K
kener 已提交
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
        },
        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);
728
        }
K
kener 已提交
729
    };
730
    
731 732
    require('../component').define('legend', Legend);
    
K
kener 已提交
733 734 735 736
    return Legend;
});