MCPcopy Create free account
hub / github.com/CoderOpen/waimai / drawMarkLine

Function drawMarkLine

front/components/u-charts/u-charts.js:1784–1840  ·  view source on GitHub ↗
(minRange, maxRange, opts, config, context)

Source from the content-addressed store, hash-verified

1782}
1783
1784function drawMarkLine(minRange, maxRange, opts, config, context) {
1785 let markLineOption = assign({}, {
1786 type: 'solid',
1787 dashLength: 4,
1788 data: []
1789 }, opts.extra.markLine);
1790 let startX = opts.area[3];
1791 let endX = opts.width - opts.padding[1];
1792 let points = calMarkLineData(minRange, maxRange, markLineOption.data, opts);
1793
1794 for (let i = 0; i < points.length; i++) {
1795 let item = assign({}, {
1796 lineColor: '#DE4A42',
1797 showLabel: false,
1798 labelFontColor: '#666666',
1799 labelBgColor: '#DFE8FF',
1800 labelBgOpacity: 0.8,
1801 yAxisIndex: 0
1802 }, points[i]);
1803
1804 if (markLineOption.type == 'dash') {
1805 context.setLineDash([markLineOption.dashLength, markLineOption.dashLength]);
1806 }
1807 context.setStrokeStyle(item.lineColor);
1808 context.setLineWidth(1 * opts.pixelRatio);
1809 context.beginPath();
1810 context.moveTo(startX, item.y);
1811 context.lineTo(endX, item.y);
1812 context.stroke();
1813 context.setLineDash([]);
1814 if (item.showLabel) {
1815 let labelText = opts.yAxis.format ? opts.yAxis.format(Number(item.value)) : item.value;
1816 context.setFontSize(config.fontSize);
1817 let textWidth = measureText(labelText, config.fontSize);
1818 let bgStartX = opts.padding[3] + config.yAxisTitleWidth - config.toolTipPadding;
1819 let bgEndX = Math.max(opts.area[3], textWidth + config.toolTipPadding * 2);
1820 let bgWidth = bgEndX - bgStartX;
1821
1822 let textX = bgStartX + (bgWidth - textWidth) / 2;
1823 let textY = item.y;
1824 context.setFillStyle(hexToRgb(item.labelBgColor, item.labelBgOpacity));
1825 context.setStrokeStyle(item.labelBgColor);
1826 context.setLineWidth(1 * opts.pixelRatio);
1827 context.beginPath();
1828 context.rect(bgStartX, textY - 0.5 * config.fontSize - config.toolTipPadding, bgWidth, config.fontSize + 2 * config.toolTipPadding);
1829 context.closePath();
1830 context.stroke();
1831 context.fill();
1832
1833 context.beginPath();
1834 context.setFontSize(config.fontSize);
1835 context.setFillStyle(item.labelFontColor);
1836 context.fillText(String(labelText), textX, textY + 0.5 * config.fontSize);
1837 context.stroke();
1838 }
1839 }
1840}
1841

Callers 1

drawChartsFunction · 0.85

Calls 3

calMarkLineDataFunction · 0.85
measureTextFunction · 0.85
hexToRgbFunction · 0.85

Tested by

no test coverage detected