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,GAC7C,EAAsB,EAAoB,GAE5C,EAAuB,eAAiB,EAAoB,cAC9D,EAAuB,YAAc,EAAoB,cACzD,EAAuB,eAAiB,EAAoB,W,aAC/C,EAAS,EAAS,EAAwB,E,EArE/D,ECrEM,eAAiB,C,gBACJ,C,UACJ,C,SACA,E,eACO,E,aACF,G,WACF,sB,SACF,sBAKV,OAAS,GAET,kBAAoB,SAAC,EAAY,G,OACd,EAAU,SAAS,EAAW,cAE9B,UAAU,U,EAG7B,mBAAqB,SAAC,G,EACpB,KAAK,SAAS,SAAQ,SAAC,G,EACnB,UAAY,MAAM,GAAI,C,UACjB,IACV,EAAQ,WAEP,EAAQ,UAAU,a,EACZ,gBAAkB,mB,KAK1B,gBAAkB,C,WACV,SAAC,G,OACJ,EAAM,IAAM,C,sBACK,E,YAGf,SAAC,G,mBACS,G,EAEb,QAAQ,QAAU,MAAM,GAAI,eAAgB,EAAM,QAAQ,S,EAC1D,QAAQ,SAAS,OAAS,kB,EAC1B,QAAQ,OAAO,OAAO,OAAS,kB,YAG1B,W,OACF,EAAM,IAAI,sBAAuB,EACtB,OAAd,EAAM,K,EACF,M,GAEP,EAAM,QAAQ,UAAU,S,YAElB,SAAC,G,IACJ,EAAU,EAAM,QAAQ,QAAQ,gB,mBAEnB,GAEf,EAAQ,UAAU,SAClB,OAAO,EAAM,IAAI,sB,cACL,E","file":"/npm/chartjs-plugin-waterfall@1.0.3/lib/chartjs-plugin-waterfall.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/chartjs-plugin-waterfall@1.0.3/lib/chartjs-plugin-waterfall.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import groupBy from 'lodash.groupby';\n\nconst DEBUG = false;\n\nconst drawOnCanvas = (context, options, currentDatapointValues, nextDatapointValues) => {\n  let currentStackBase = currentDatapointValues.stackBase;\n  let nextStackBase = nextDatapointValues.stackBase;\n  let currentStackTopYPos = currentDatapointValues.stackTopYPos;\n  let nextStackTopYPos = nextDatapointValues.stackTopYPos;\n\n  /* If the heights match top to bottom or bottom to top then\n  flip the top coordinates to be at the bottom so that a horizontal step line is drawn */\n  if (currentStackTopYPos === nextStackBase) {\n    nextStackTopYPos = nextStackBase;\n    nextStackBase = nextDatapointValues.dummyStackBase;\n  } else if (currentStackBase === nextStackTopYPos) {\n    currentStackTopYPos = currentStackBase;\n    currentStackBase = currentDatapointValues.dummyStackBase;\n  }\n\n  // We need to flip the y co-ords if one of the datasets is negative and the other isn't\n  if (!currentDatapointValues.isPositive && nextDatapointValues.isPositive) {\n    nextStackTopYPos = nextStackBase;\n    nextStackBase = nextDatapointValues.stackTopYPos;\n  }\n\n  if (currentDatapointValues.isPositive && !nextDatapointValues.isPositive) {\n    currentStackTopYPos = currentStackBase;\n    currentStackBase = currentDatapointValues.stackTopYPos;\n  }\n\n  // Draws co-ords on the canvas to allow easier debugging\n  if (DEBUG) {\n    context.font = '9px Arial';\n    context.fillStyle = '#000';\n    context.fillText(`TR: ${currentDatapointValues.stackRightXPos.toFixed(0)}`, currentDatapointValues.stackRightXPos, currentStackTopYPos);\n    context.fillText(`TL: ${nextDatapointValues.stackLeftXPos.toFixed(0)}`, nextDatapointValues.stackLeftXPos, nextStackTopYPos);\n    context.fillText(`BL: ${nextStackBase.toFixed(0)}`, nextDatapointValues.stackLeftXPos, nextStackBase);\n    context.fillText(`BR: ${currentStackBase.toFixed(0)}`, currentDatapointValues.stackRightXPos, currentStackBase);\n  }\n\n  // Makes sure that each step line is consistent\n  const yStart = currentStackTopYPos > nextStackTopYPos ? currentStackTopYPos : nextStackTopYPos;\n  const yEnd = currentStackBase > nextStackBase ? currentStackBase : nextStackBase;\n\n  // Gradient from top of second box to bottom of both boxes\n  const gradient = context.createLinearGradient(0, yStart, 0, yEnd);\n\n  // Dataset options take priority if they are specified\n  const startColor = currentDatapointValues.options.startColor || options.startColor;\n  const endColor = currentDatapointValues.options.endColor || options.endColor;\n  const startColorStop = currentDatapointValues.options.startColorStop || options.startColorStop;\n  const endColorStop = currentDatapointValues.options.endColorStop || options.endColorStop;\n\n  gradient.addColorStop(startColorStop, startColor);\n  gradient.addColorStop(endColorStop, endColor);\n\n  context.fillStyle = gradient;\n\n  context.beginPath();\n\n  // top right of first box\n  context.lineTo(currentDatapointValues.stackRightXPos, currentStackTopYPos);\n  // top left of second box\n  context.lineTo(nextDatapointValues.stackLeftXPos, nextStackTopYPos);\n  // bottom left of second box\n  context.lineTo(nextDatapointValues.stackLeftXPos, nextStackBase);\n  // bottom right of first box\n  context.lineTo(currentDatapointValues.stackRightXPos, currentStackBase);\n\n  context.fill();\n};\n\nexport default (chart) => {\n  const context = chart.ctx;\n  const datasets = chart.data.datasets;\n  const options = chart.options.plugins.waterFallPlugin.stepLines;\n  const stackedDatasets = groupBy(datasets, 'stack');\n  const newDatasets = [];\n\n  const getModel = (dataset) => {\n    const firstKey = Object.keys(dataset._meta)[0];\n\n    return dataset._meta[firstKey].data[0]._model;\n  };\n\n  Object.keys(stackedDatasets).forEach((key) => {\n    const currentStackedDataset = stackedDatasets[key].filter(x => x.data[0] !== 0);\n\n    if (!currentStackedDataset.every(x => x.waterfall.dummyStack)) {\n      const nonDummyStacks = currentStackedDataset.filter(dataset => !dataset.waterfall.dummyStack);\n      const bases = nonDummyStacks.map(dataset => getModel(dataset).base);\n      const lowestBase = Math.max(...bases);\n\n      const dummStackBases = currentStackedDataset.map(dataset => getModel(dataset).base);\n      const lowestDummyStackBase = Math.max(...dummStackBases);\n\n      // Loop through each sub stack\n      const properties = currentStackedDataset.map((dataset) => {\n        const model = getModel(dataset);\n\n        return {\n          stackRightXPos: model.x + (model.width / 2),\n          stackLeftXPos: model.x - (model.width / 2),\n          stackTopYPos: model.y,\n          stackBase: lowestBase,\n          dummyStackBase: lowestDummyStackBase,\n          isPositive: dataset.data[0] > 0,\n          options: dataset.waterfall.stepLines,\n        };\n      });\n\n      newDatasets.push(properties);\n    }\n  });\n\n  // Gets the values for the steplines at the top of the stack\n  const getDatapointsValues = (dataset) => {\n    const index = dataset.length - 1;\n\n    return {\n      stackRightXPos: dataset[index].stackRightXPos,\n      stackLeftXPos: dataset[index].stackLeftXPos,\n      stackTopYPos: dataset[index].stackTopYPos,\n      stackBase: dataset[index].stackBase,\n      dummyStackBase: dataset[index].dummyStackBase,\n      isPositive: dataset[index].isPositive,\n      options: dataset[index].options,\n    };\n  };\n\n  for (let i = 0; i < newDatasets.length; i += 1) {\n    const currentDataSet = newDatasets[i];\n\n    if (i !== newDatasets.length - 1) {\n      const nextDataSet = newDatasets[i + 1];\n      const currentDatapointValues = getDatapointsValues(currentDataSet);\n      const nextDatapointValues = getDatapointsValues(nextDataSet);\n\n      if (currentDatapointValues.stackTopYPos === nextDatapointValues.stackTopYPos ||\n        currentDatapointValues.stackBase === nextDatapointValues.stackTopYPos ||\n        currentDatapointValues.stackTopYPos === nextDatapointValues.stackBase) {\n        drawOnCanvas(context, options, currentDatapointValues, nextDatapointValues);\n      }\n    }\n  }\n};\n","import merge from 'lodash.merge';\n\nimport drawStepLines from './drawStepLines';\n\nconst defaultOptions = {\n  waterFallPlugin: {\n    stepLines: {\n      enabled: true,\n      startColorStop: 0,\n      endColorStop: 0.6,\n      startColor: 'rgba(0, 0, 0, 0.55)', // opaque\n      endColor: 'rgba(0, 0, 0, 0)', // transparent\n    },\n  },\n};\n\nconst status = {};\n\nconst filterDummyStacks = (legendItem, chartData) => {\n  const currentDataset = chartData.datasets[legendItem.datasetIndex];\n\n  return !currentDataset.waterfall.dummyStack;\n};\n\nconst initializeDatasets = (chart) => {\n  chart.data.datasets.forEach((dataset) => {\n    dataset.waterfall = merge({}, {\n      stepLines: {},\n    }, dataset.waterfall);\n\n    if (dataset.waterfall.dummyStack) {\n      dataset.backgroundColor = 'rgba(0, 0, 0, 0)';\n    }\n  });\n};\n\nconst waterFallPlugin = {\n  beforeInit: (chart) => {\n    status[chart.id] = {\n      readyToDrawStepLines: false,\n    };\n  },\n  afterInit: (chart) => {\n    initializeDatasets(chart);\n\n    chart.options.plugins = merge({}, defaultOptions, chart.options.plugins);\n    chart.options.tooltips.filter = filterDummyStacks;\n    chart.options.legend.labels.filter = filterDummyStacks;\n\n    // Can't override onComplete function because it gets overwridden if user using React\n    setTimeout(() => {\n      status[chart.id].readyToDrawStepLines = true;\n      if (chart.ctx !== null) {\n        chart.draw();\n      }\n    }, chart.options.animation.duration);\n  },\n  afterDraw: (chart) => {\n    const options = chart.options.plugins.waterFallPlugin;\n\n    initializeDatasets(chart);\n\n    if (options.stepLines.enabled &&\n        status[chart.id].readyToDrawStepLines) {\n      drawStepLines(chart);\n    }\n  },\n};\n\nexport default waterFallPlugin;\n"]}