本文整理汇总了TypeScript中@/store.commit函数的典型用法代码示例。如果您正苦于以下问题:TypeScript commit函数的具体用法?TypeScript commit怎么用?TypeScript commit使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了commit函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: joinSegments
export function joinSegments(segmentData: SegmentData[][]): SeriesData[] {
// Use a map to join the data
const countsByName: { [key: string]: SeriesData } = {};
segmentData.forEach((innerSegment, index) => {
innerSegment.forEach((nameData) => {
const name = nameData.title;
const count = nameData.count;
if (!countsByName[name]) {
// Hasn't been added to the map yet
// Fill count with 0s
countsByName[name] = {
title: name,
counts: new Array(segmentData.length + 1).join('0').split('').map(parseFloat),
};
}
countsByName[name].counts[index] = count;
});
});
store.commit('log', `Joined ${segmentData.length} segments`);
// Turn our map into an array
return Array.from(Object.keys(countsByName).map((key) => {
return countsByName[key];
}));
}
示例2: InfiniteLine
const calculateFontSize = (
text: string,
startPoint: Point,
fontSlope: number,
opposite: LineSegment,
heightToFontSizeRatio: number,
) => {
// Where is our end point?
const fontLine = new InfiniteLine(fontSlope, startPoint);
let endPoint = fontLine.getIntersect(opposite);
if (DebugWave.isEnabled) {
DebugWave.drawLine(fontLine, 'cyan');
}
if (!endPoint) {
// If we miss opposite altogether, let's just stop there.
endPoint = fontLine.getPointOnLineAtX(
Math.min(
opposite.start.x,
opposite.end.y,
),
);
store.commit('log', `Had to emergency fix ${text}`);
if (!endPoint) {
return null;
}
}
const boxHeight = Math.abs(startPoint.y - endPoint.y);
const fontSize = Math.floor(boxHeight / heightToFontSizeRatio);
return fontSize;
};
示例3: cleanByMinPlays
export function cleanByMinPlays(data: SeriesData[], minPlays: number) {
const cleanedData = data.filter((obj) => {
let maxPlays = 0;
obj.counts.forEach((playCount) => {
if (playCount > maxPlays) {
maxPlays = playCount;
}
});
return maxPlays >= minPlays;
});
store.commit('log', `Before clean: ${data.length}, after clean: ${cleanedData.length}`);
return cleanedData;
}
示例4: splitTimeSpan
export function splitTimeSpan(splitBy: string, timeSpan: TimeSpan) {
const TIME_IN_SECONDS: { [key: string]: number } = {
week: 604800,
month: 2628000,
day: 86400,
};
const segments = [];
const interval = TIME_IN_SECONDS[splitBy];
for (let t = timeSpan.start; t < timeSpan.end; t += interval) {
segments.push(new TimeSpan(t, t + interval));
}
store.commit('log', `Time span: ${timeSpan.start} to ${timeSpan.end}, split into ${segments.length} segments`);
return segments;
}
示例5: getYLabel
export function getYLabel(peak: Peak, text: string, font: string): Label | null {
const TEST_FONT_SIZE = 3000;
const ITERATION_CACHE_SIZE = 2;
const MAXIMUM_ITERATIONS = 100;
const TYPE = {
Y1: 0,
Y2: 1,
Y3: 2,
Y4: 3,
};
const SETUP_CONFIG: { [key: number]: WaveConfig } = {};
SETUP_CONFIG[TYPE.Y1] = {
startPoint: 'bottom',
slopeModifier: -1,
opposite: 'A',
adjacent: 'D',
across: 'B',
};
SETUP_CONFIG[TYPE.Y2] = {
startPoint: 'bottom',
slopeModifier: 1,
opposite: 'B',
adjacent: 'C',
across: 'A',
};
SETUP_CONFIG[TYPE.Y3] = {
startPoint: 'top',
slopeModifier: 1,
opposite: 'C',
adjacent: 'B',
across: 'D',
};
SETUP_CONFIG[TYPE.Y4] = {
startPoint: 'top',
slopeModifier: -1,
opposite: 'D',
adjacent: 'A',
across: 'C',
};
/*
TODO merge this and the first method to figure out if it's Y type
*/
let peakType: number;
if (peak.A.slope < 0) {
peakType = TYPE.Y3;
} else if (peak.B.slope > 0) {
peakType = TYPE.Y4;
} else if (peak.C.slope > 0) {
peakType = TYPE.Y1;
} else {
peakType = TYPE.Y2;
}
if (DebugWave.isEnabled) {
store.commit('log', `Peak type: ${peakType}`);
}
/*
Set up initial state
*/
const cfg = SETUP_CONFIG[peakType];
let startPoint = (peak as any)[cfg.startPoint];
const opposite = (peak as any)[cfg.opposite];
const adjacent = (peak as any)[cfg.adjacent];
const across = (peak as any)[cfg.across];
const textDimensions = getTextDimensions(text, font, TEST_FONT_SIZE);
const heightToFontSizeRatio = textDimensions.height / TEST_FONT_SIZE;
const fontSlope = textDimensions.slope * cfg.slopeModifier;
// Hold on to previous iterations to check for bounces
const iterationCache = new Array(ITERATION_CACHE_SIZE);
let shouldIterate = true;
let iterationCount = 0;
let fontSize: number = 0;
// Iterate!
while (shouldIterate) {
if (DebugWave.isEnabled) {
DebugWave.drawPoint(startPoint, 'red');
DebugWave.drawTextBelowPoint(startPoint, iterationCount.toString());
store.commit('log', `Iteration ${iterationCount}: ${JSON.stringify(startPoint)}`);
}
let newStartPoint = performIteration(startPoint, fontSlope, opposite, across, adjacent, peakType);
if (!newStartPoint) {
return null;
}
// Calculate our new font size
const newFontSize = calculateFontSize(text, newStartPoint, fontSlope, opposite, heightToFontSizeRatio);
if (!newFontSize) {
return null;
}
fontSize = newFontSize;
// Sometimes we "bounce" between two (or three) different spots. In this case,
//.........这里部分代码省略.........