export function shapeViewModel()

in packages/charts/src/chart_types/wordcloud/layout/viewmodel/viewmodel.ts [15:73]


export function shapeViewModel(spec: WordcloudSpec, theme: Theme, chartDimensions: Dimensions): ShapeViewModel {
  const { width, height } = chartDimensions;
  const { chartMargins: margin } = theme;
  const innerWidth = width - margin.left - margin.right;
  const innerHeight = height - margin.top - margin.bottom;

  const chartCenter = {
    x: width * margin.left + innerWidth / 2,
    y: height * margin.top + innerHeight / 2,
  };

  const {
    id,
    startAngle,
    endAngle,
    angleCount,
    padding,
    fontWeight,
    fontFamily,
    fontStyle,
    minFontSize,
    maxFontSize,
    spiral,
    exponent,
    data,
    weightFn,
    outOfRoomCallback,
  } = spec;

  const wordcloudViewModel: WordcloudViewModel = {
    startAngle,
    endAngle,
    angleCount,
    padding,
    fontWeight,
    fontFamily,
    fontStyle,
    minFontSize,
    maxFontSize,
    spiral,
    exponent,
    data,
    weightFn,
    outOfRoomCallback,
  };

  const pickQuads: PickFunction = (x, y) =>
    -innerWidth / 2 <= x && x <= innerWidth / 2 && -innerHeight / 2 <= y && y <= innerHeight / 2
      ? [wordcloudViewModel]
      : [];

  // combined viewModel
  return {
    chartCenter,
    wordcloudViewModel,
    pickQuads,
    specId: id,
  };
}