(series, opts, config, context, chartData)
| 2952 | } |
| 2953 | |
| 2954 | function drawLegend(series, opts, config, context, chartData) { |
| 2955 | if (opts.legend.show === false) { |
| 2956 | return; |
| 2957 | } |
| 2958 | let legendData = chartData.legendData; |
| 2959 | let legendList = legendData.points; |
| 2960 | let legendArea = legendData.area; |
| 2961 | let padding = opts.legend.padding; |
| 2962 | let fontSize = opts.legend.fontSize; |
| 2963 | let shapeWidth = 15 * opts.pixelRatio; |
| 2964 | let shapeRight = 5 * opts.pixelRatio; |
| 2965 | let itemGap = opts.legend.itemGap; |
| 2966 | let lineHeight = Math.max(opts.legend.lineHeight * opts.pixelRatio, fontSize); |
| 2967 | |
| 2968 | //画背景及边框 |
| 2969 | context.beginPath(); |
| 2970 | context.setLineWidth(opts.legend.borderWidth); |
| 2971 | context.setStrokeStyle(opts.legend.borderColor); |
| 2972 | context.setFillStyle(opts.legend.backgroundColor); |
| 2973 | context.moveTo(legendArea.start.x, legendArea.start.y); |
| 2974 | context.rect(legendArea.start.x, legendArea.start.y, legendArea.width, legendArea.height); |
| 2975 | context.closePath(); |
| 2976 | context.fill(); |
| 2977 | context.stroke(); |
| 2978 | |
| 2979 | legendList.forEach(function(itemList, listIndex) { |
| 2980 | let width = 0; |
| 2981 | let height = 0; |
| 2982 | width = legendData.widthArr[listIndex]; |
| 2983 | height = legendData.heightArr[listIndex]; |
| 2984 | let startX = 0; |
| 2985 | let startY = 0; |
| 2986 | if (opts.legend.position == 'top' || opts.legend.position == 'bottom') { |
| 2987 | startX = legendArea.start.x + (legendArea.width - width) / 2; |
| 2988 | startY = legendArea.start.y + padding + listIndex * lineHeight; |
| 2989 | } else { |
| 2990 | if (listIndex == 0) { |
| 2991 | width = 0; |
| 2992 | } else { |
| 2993 | width = legendData.widthArr[listIndex - 1]; |
| 2994 | } |
| 2995 | startX = legendArea.start.x + padding + width; |
| 2996 | startY = legendArea.start.y + padding + (legendArea.height - height) / 2; |
| 2997 | } |
| 2998 | |
| 2999 | context.setFontSize(config.fontSize); |
| 3000 | for (let i = 0; i < itemList.length; i++) { |
| 3001 | let item = itemList[i]; |
| 3002 | item.area = [0, 0, 0, 0]; |
| 3003 | item.area[0] = startX; |
| 3004 | item.area[1] = startY; |
| 3005 | item.area[3] = startY + lineHeight; |
| 3006 | context.beginPath(); |
| 3007 | context.setLineWidth(1 * opts.pixelRatio); |
| 3008 | context.setStrokeStyle(item.show ? item.color : opts.legend.hiddenColor); |
| 3009 | context.setFillStyle(item.show ? item.color : opts.legend.hiddenColor); |
| 3010 | switch (item.legendShape) { |
| 3011 | case 'line': |
no test coverage detected