MCPcopy Index your code
hub / github.com/ChartGPU/ChartGPU / normalizeDash

Function normalizeDash

src/renderers/createReferenceLineRenderer.ts:116–147  ·  view source on GitHub ↗
(lineDash?: ReadonlyArray<number>)

Source from the content-addressed store, hash-verified

114};
115
116const normalizeDash = (lineDash?: ReadonlyArray<number>): PackedDash => {
117 if (!lineDash || lineDash.length === 0) {
118 return { dashCount: 0, dashTotal: 0, values: new Array<number>(MAX_DASH_VALUES).fill(0) };
119 }
120
121 const cleaned: number[] = [];
122 for (let i = 0; i < lineDash.length; i++) {
123 const v = lineDash[i];
124 if (typeof v === 'number' && Number.isFinite(v) && v > 0) cleaned.push(v);
125 }
126
127 if (cleaned.length === 0) {
128 return { dashCount: 0, dashTotal: 0, values: new Array<number>(MAX_DASH_VALUES).fill(0) };
129 }
130
131 // CSS behavior: odd-length dash arrays are repeated to make even length.
132 const normalized = cleaned.length % 2 === 1 ? cleaned.concat(cleaned) : cleaned;
133
134 const dashCount = Math.min(MAX_DASH_VALUES, normalized.length);
135 const values = new Array<number>(MAX_DASH_VALUES).fill(0);
136 let dashTotal = 0;
137 for (let i = 0; i < dashCount; i++) {
138 values[i] = normalized[i];
139 dashTotal += normalized[i];
140 }
141
142 if (!Number.isFinite(dashTotal) || dashTotal <= 0) {
143 return { dashCount: 0, dashTotal: 0, values: new Array<number>(MAX_DASH_VALUES).fill(0) };
144 }
145
146 return { dashCount, dashTotal, values };
147};
148
149export function createReferenceLineRenderer(device: GPUDevice, options?: ReferenceLineRendererOptions): ReferenceLineRenderer {
150 let disposed = false;

Callers 1

prepareFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected