export function getSummaryDatasetsByStorageClass()

in client/src/components/billing/reports/charts/object-storage/get-datasets-by-storage-class.js [58:252]


export function getSummaryDatasetsByStorageClass (storageClass) {
  const currentDataset = {
    accumulative: {
      value: (item) => getCostDetailsSumm(
        item.costDetails,
        storageClass,
        LAYERS_KEYS.accumulativeCost
      ),
      options: {
        borderWidth: 3,
        tooltipValue: (currentValue, item) => {
          if (item) {
            const currentValue = getCostDetailsValue(
              item.costDetails,
              storageClass,
              LAYERS_KEYS.accumulativeCost
            ) || 0;
            const oldVersionsValue = getCostDetailsValue(
              item.costDetails,
              storageClass,
              LAYERS_KEYS.accumulativeOldVersionCost
            ) || 0;
            const current = costTickFormatter(currentValue);
            const oldVersion = costTickFormatter(oldVersionsValue);
            const total = costTickFormatter(currentValue + oldVersionsValue);
            return `${total} (current: ${current}; old versions: ${oldVersion})`;
          }
          return currentValue;
        }
      }
    },
    fact: {
      value: (item) => getCostDetailsSumm(
        item.costDetails,
        storageClass,
        'cost'
      ),
      options: {
        subTitle: 'cost',
        stack: 'current',
        tooltipValue: (currentValue, item) => {
          if (item) {
            const currentValue = getCostDetailsValue(
              item.costDetails,
              storageClass,
              LAYERS_KEYS.cost
            ) || 0;
            const oldVersionsValue = getCostDetailsValue(
              item.costDetails,
              storageClass,
              LAYERS_KEYS.oldVersionCost
            ) || 0;
            const current = costTickFormatter(currentValue);
            const oldVersion = costTickFormatter(oldVersionsValue);
            const total = costTickFormatter(currentValue + oldVersionsValue);
            return `${total} (current: ${current}; old versions: ${oldVersion})`;
          }
          return currentValue;
        }
      }
    }
  };

  const currentOldVersionsDataset = {
    accumulative: {
      value: (item) => getCostDetailsSumm(
        item.costDetails,
        storageClass,
        LAYERS_KEYS.accumulativeOldVersionCost
      ),
      options: {
        borderWidth: 2,
        backgroundColor: 'transparent',
        dashed: true,
        showTooltip: false
      }
    },
    fact: {
      value: (item) => getCostDetailsSumm(
        item.costDetails,
        storageClass,
        LAYERS_KEYS.oldVersionCost
      ),
      options: {
        borderWidth: 1,
        subTitle: 'cost',
        stack: 'current',
        backgroundColor: 'transparent',
        showTooltip: false
      }
    }
  };

  const previousDataset = {
    accumulative: {
      value: (item) => getCostDetailsSumm(
        item.previousCostDetails,
        storageClass,
        LAYERS_KEYS.accumulativeCost
      ),
      options: {
        isPrevious: true,
        tooltipValue: (currentValue, item) => {
          if (item) {
            const currentValue = getCostDetailsValue(
              item.previousCostDetails,
              storageClass,
              LAYERS_KEYS.accumulativeCost
            ) || 0;
            const oldVersionsValue = getCostDetailsValue(
              item.previousCostDetails,
              storageClass,
              LAYERS_KEYS.accumulativeOldVersionCost
            ) || 0;
            const current = costTickFormatter(currentValue);
            const oldVersion = costTickFormatter(oldVersionsValue);
            const total = costTickFormatter(currentValue + oldVersionsValue);
            return `${total} (current: ${current}; old versions: ${oldVersion})`;
          }
          return currentValue;
        }
      }
    },
    fact: {
      value: (item) => getCostDetailsSumm(
        item.previousCostDetails,
        storageClass,
        LAYERS_KEYS.cost
      ),
      options: {
        isPrevious: true,
        subTitle: 'cost',
        stack: 'previous',
        tooltipValue: (currentValue, item) => {
          if (item) {
            const currentValue = getCostDetailsValue(
              item.previousCostDetails,
              storageClass,
              LAYERS_KEYS.cost
            ) || 0;
            const oldVersionsValue = getCostDetailsValue(
              item.previousCostDetails,
              storageClass,
              LAYERS_KEYS.oldVersionCost
            ) || 0;
            const current = costTickFormatter(currentValue);
            const oldVersion = costTickFormatter(oldVersionsValue);
            const total = costTickFormatter(currentValue + oldVersionsValue);
            return `${total} (current: ${current}; old versions: ${oldVersion})`;
          }
          return currentValue;
        }
      }
    }
  };

  const previousOldVersionsDataset = {
    accumulative: {
      value: (item) => getCostDetailsSumm(
        item.previousCostDetails,
        storageClass,
        LAYERS_KEYS.accumulativeOldVersionCost
      ),
      options: {
        borderWidth: 2,
        backgroundColor: 'transparent',
        dashed: true,
        showTooltip: false,
        isPrevious: true
      }
    },
    fact: {
      value: (item) => getCostDetailsSumm(
        item.previousCostDetails,
        storageClass,
        LAYERS_KEYS.oldVersionCost
      ),
      options: {
        borderWidth: 1,
        subTitle: 'cost',
        stack: 'previous',
        backgroundColor: 'transparent',
        showTooltip: false,
        isPrevious: true
      }
    }
  };

  return [
    currentDataset,
    currentOldVersionsDataset,
    previousDataset,
    previousOldVersionsDataset
  ];
}