當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript store.commit函數代碼示例

本文整理匯總了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];
  }));
}
開發者ID:taurheim,項目名稱:LastWave,代碼行數:29,代碼來源:util.ts

示例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;
};
開發者ID:taurheim,項目名稱:LastWave,代碼行數:34,代碼來源:waveY.ts

示例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;
}
開發者ID:taurheim,項目名稱:LastWave,代碼行數:15,代碼來源:util.ts

示例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;
}
開發者ID:taurheim,項目名稱:LastWave,代碼行數:16,代碼來源:util.ts

示例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,
//.........這裏部分代碼省略.........
開發者ID:taurheim,項目名稱:LastWave,代碼行數:101,代碼來源:waveY.ts


注:本文中的@/store.commit函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。