MCPcopy
hub / github.com/pyrochlore/obsidian-tracker / renderBar

Function renderBar

src/rendering.ts:920–1020  ·  view source on GitHub ↗
(
    chartElements: ChartElements,
    renderInfo: RenderInfo,
    barInfo: BarInfo,
    dataset: Dataset,
    yAxisLocation: string,
    currBarSet: number,
    totalNumOfBarSets: number
)

Source from the content-addressed store, hash-verified

918}
919
920function renderBar(
921 chartElements: ChartElements,
922 renderInfo: RenderInfo,
923 barInfo: BarInfo,
924 dataset: Dataset,
925 yAxisLocation: string,
926 currBarSet: number,
927 totalNumOfBarSets: number
928) {
929 // console.log(dataset);
930 // console.log(barInfo);
931 // console.log("%d/%d", currBarSet, totalNumOfBarSets);
932
933 if (!renderInfo || !barInfo) return;
934
935 let barGap = 1;
936 let barSetWidth = renderInfo.dataAreaSize.width / dataset.getLength();
937 let barWidth = barSetWidth;
938 let currentDiaplayInd = currBarSet;
939 let totalDiaplaySet = totalNumOfBarSets;
940 if (barSetWidth - barGap > 0) {
941 barWidth = barSetWidth - barGap;
942 }
943 if (!renderInfo.stack) {
944 barWidth = barWidth / totalNumOfBarSets;
945 } else {
946 currentDiaplayInd = 0;
947 totalDiaplaySet = 1;
948 }
949
950 let portionLeft = (currBarSet + 1) / totalNumOfBarSets;
951
952 let yScale: any = null;
953 if (yAxisLocation === "left") {
954 yScale = chartElements.leftYScale;
955 } else if (yAxisLocation === "right") {
956 yScale = chartElements.rightYScale;
957 }
958
959 let bars = chartElements.dataArea
960 .selectAll("bar")
961 .data(
962 Array.from(dataset).filter(function (p: DataPoint) {
963 return p.value !== null;
964 })
965 )
966 .enter()
967 .append("rect")
968 .attr("x", function (p: DataPoint, i: number) {
969 if (i === 0 && barInfo.xAxisPadding === null) {
970 let portionVisible = currentDiaplayInd + 1 - totalDiaplaySet / 2.0;
971 if (portionVisible < 1.0) {
972 return (
973 chartElements.xScale(p.date) -
974 barSetWidth / 2.0 +
975 currentDiaplayInd * barWidth +
976 portionVisible * barWidth
977 );

Callers 1

renderBarChartFunction · 0.70

Calls 2

getLengthMethod · 0.80
getIdMethod · 0.45

Tested by

no test coverage detected