@websy/websy-designs 1.5.2 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1784,6 +1784,24 @@ class WebsyDropdown {
1784
1784
  }
1785
1785
  this.updateHeader(item)
1786
1786
  }
1787
+ setValue (value) {
1788
+ this.selectedItems = []
1789
+ if (Array.isArray(value)) {
1790
+ this.options.items.forEach(d => {
1791
+ if (value.indexOf(d.value) !== -1) {
1792
+ this.selectedItems.push(d.index)
1793
+ }
1794
+ })
1795
+ }
1796
+ else {
1797
+ this.options.items.forEach(d => {
1798
+ if (d.value === value) {
1799
+ this.selectedItems.push(d.index)
1800
+ }
1801
+ })
1802
+ }
1803
+ this.render()
1804
+ }
1787
1805
  updateHeader (item) {
1788
1806
  const el = document.getElementById(this.elementId)
1789
1807
  const headerEl = document.getElementById(`${this.elementId}_header`)
@@ -2184,6 +2202,7 @@ class WebsyForm {
2184
2202
  return
2185
2203
  }
2186
2204
  this.apiService = new WebsyDesigns.APIService('')
2205
+ this.fieldMap = {}
2187
2206
  this.elementId = elementId
2188
2207
  const el = document.getElementById(elementId)
2189
2208
  if (el) {
@@ -2232,6 +2251,15 @@ class WebsyForm {
2232
2251
  }
2233
2252
  })
2234
2253
  }
2254
+ get data () {
2255
+ const formEl = document.getElementById(`${this.elementId}Form`)
2256
+ const data = {}
2257
+ const temp = new FormData(formEl)
2258
+ temp.forEach((value, key) => {
2259
+ data[key] = value
2260
+ })
2261
+ return data
2262
+ }
2235
2263
  set data (d) {
2236
2264
  if (!this.options.fields) {
2237
2265
  this.options.fields = []
@@ -2311,6 +2339,7 @@ class WebsyForm {
2311
2339
  <form id="${this.elementId}Form" class="websy-form ${this.options.classes || ''}">
2312
2340
  `
2313
2341
  this.options.fields.forEach((f, i) => {
2342
+ this.fieldMap[f.field] = f
2314
2343
  if (f.component) {
2315
2344
  componentsToProcess.push(f)
2316
2345
  html += `
@@ -2381,6 +2410,25 @@ class WebsyForm {
2381
2410
  })
2382
2411
  }
2383
2412
  }
2413
+ setValue (field, value) {
2414
+ if (this.fieldMap[field]) {
2415
+ if (this.fieldMap[field].instance) {
2416
+ this.fieldMap[field].instance.setValue(value)
2417
+ }
2418
+ else {
2419
+ const el = document.getElementById(`${this.elementId}_input_${field}`)
2420
+ if (el) {
2421
+ el.value = value
2422
+ }
2423
+ else {
2424
+ console.error(`Input for ${field} does not exist in form.`)
2425
+ }
2426
+ }
2427
+ }
2428
+ else {
2429
+ console.error(`Field ${field} does not exist in form.`)
2430
+ }
2431
+ }
2384
2432
  submitForm () {
2385
2433
  const formEl = document.getElementById(`${this.elementId}Form`)
2386
2434
  const buttonEl = formEl.querySelector('button.websy-btn.submit')
@@ -2709,6 +2757,9 @@ class WebsyLogin {
2709
2757
  onSuccess: this.loginSuccess.bind(this),
2710
2758
  onError: this.loginFail.bind(this)
2711
2759
  }
2760
+ if (this.options.fields) {
2761
+ formOptions.fields = this.options.fields.concat(formOptions.fields)
2762
+ }
2712
2763
  this.loginForm = new WebsyDesigns.WebsyForm(`${this.elementId}_container`, Object.assign({}, this.options, formOptions))
2713
2764
  }
2714
2765
  else {
@@ -4734,25 +4785,7 @@ class WebsySignup {
4734
4785
  url: 'auth/signup'
4735
4786
  }
4736
4787
  this.elementId = elementId
4737
- this.options = Object.assign({}, DEFAULTS, options)
4738
- if (!this.options.fields) {
4739
- this.options.fields = [
4740
- {
4741
- label: this.options.loginType === 'email' ? 'Email' : 'Username',
4742
- placeholder: `Enter ${this.options.loginType === 'email' ? 'your email address' : 'your chosen Username'}`,
4743
- field: this.options.loginType,
4744
- type: this.options.loginType,
4745
- required: true
4746
- },
4747
- {
4748
- label: 'Password',
4749
- placeholder: 'Enter your password',
4750
- field: this.options.passwordField || 'password',
4751
- type: 'password',
4752
- required: true
4753
- }
4754
- ]
4755
- }
4788
+ this.options = Object.assign({}, DEFAULTS, options)
4756
4789
  const el = document.getElementById(this.elementId)
4757
4790
  if (el) {
4758
4791
  const formOptions = {
@@ -4762,7 +4795,25 @@ class WebsySignup {
4762
4795
  classes: (this.options.buttonClasses || []).join(' ') || ''
4763
4796
  },
4764
4797
  submitFn: this.submitForm.bind(this),
4765
- fields: this.options.fields
4798
+ fields: [
4799
+ {
4800
+ label: this.options.loginType === 'email' ? 'Email' : 'Username',
4801
+ placeholder: `Enter ${this.options.loginType === 'email' ? 'your email address' : 'your chosen Username'}`,
4802
+ field: this.options.loginType,
4803
+ type: this.options.loginType,
4804
+ required: true
4805
+ },
4806
+ {
4807
+ label: 'Password',
4808
+ placeholder: 'Enter your password',
4809
+ field: this.options.passwordField || 'password',
4810
+ type: 'password',
4811
+ required: true
4812
+ }
4813
+ ]
4814
+ }
4815
+ if (this.options.fields) {
4816
+ formOptions.fields = this.options.fields.concat(formOptions.fields)
4766
4817
  }
4767
4818
  this.signupForm = new WebsyDesigns.WebsyForm(this.elementId, Object.assign({}, this.options, formOptions))
4768
4819
  }
@@ -6982,6 +7033,7 @@ class WebsyChart {
6982
7033
  tooltipWidth: 200,
6983
7034
  brushHeight: 50,
6984
7035
  minBandWidth: 30,
7036
+ maxBandWidth: 100,
6985
7037
  allowUnevenBands: true
6986
7038
  }
6987
7039
  this.elementId = elementId
@@ -7009,99 +7061,124 @@ class WebsyChart {
7009
7061
  xAxis += 'Axis'
7010
7062
  let output
7011
7063
  let width = this.options.data[xAxis.replace('Brush', '').replace('Axis', '')].bandWidth
7012
- if (this.customBottomRange) {
7013
- for (let index = 0; index < this.customBottomRange.length; index++) {
7014
- if (input > this.customBottomRange[index]) {
7015
- if (this.customBottomRange[index + 1]) {
7016
- if (input < this.customBottomRange[index + 1]) {
7017
- output = index
7018
- break
7019
- }
7020
- }
7021
- else {
7064
+ // if (this.customBottomRange) {
7065
+ for (let index = 0; index < this.customBottomRange.length; index++) {
7066
+ if (input > this.customBottomRange[index]) {
7067
+ if (this.customBottomRange[index + 1]) {
7068
+ if (input < this.customBottomRange[index + 1]) {
7022
7069
  output = index
7023
7070
  break
7024
7071
  }
7025
7072
  }
7026
- }
7027
- }
7028
- else {
7029
- let domain = [...this[xAxis].domain()]
7030
- if (this.options.orientation === 'horizontal') {
7031
- domain = domain.reverse()
7032
- }
7033
- for (let j = 0; j < domain.length; j++) {
7034
- let breakA = this[xAxis](domain[j]) - (width / 2)
7035
- let breakB = breakA + width
7036
- if (input > breakA && input <= breakB) {
7037
- output = j
7073
+ else {
7074
+ output = index
7038
7075
  break
7039
7076
  }
7040
- }
7077
+ }
7041
7078
  }
7079
+ // }
7080
+ // else {
7081
+ // let domain = [...this[xAxis].domain()]
7082
+ // if (this.options.orientation === 'horizontal') {
7083
+ // domain = domain.reverse()
7084
+ // }
7085
+ // for (let j = 0; j < domain.length; j++) {
7086
+ // let breakA = this[xAxis](domain[j]) - (width / 2)
7087
+ // let breakB = breakA + width
7088
+ // if (input > breakA && input <= breakB) {
7089
+ // output = j
7090
+ // break
7091
+ // }
7092
+ // }
7093
+ // }
7042
7094
  return output
7043
7095
  }
7044
7096
  let that = this
7045
7097
  this.brushed = function (event) {
7046
- console.log('brushing', event)
7047
- that.brushedDomain = []
7048
- let xAxis = 'bottom'
7049
- let xAxisCaps = 'Bottom'
7050
- if (that.options.orientation === 'horizontal') {
7051
- xAxis = 'left'
7052
- xAxisCaps = 'Left'
7053
- }
7054
- if (!that[`${xAxis}Axis`]) {
7055
- return
7098
+ console.log('brushing', event)
7099
+ let newX = (that.options.margin.left + that.options.margin.axisLeft) + (1 - (event.selection[0] / ((that.plotWidth) / (that.widthForCalc + that.totalBandPadding))))
7100
+ if (that.plotArea) {
7101
+ that.plotArea.attr('transform', `translate(${newX}, ${that.options.margin.top + that.options.margin.axisTop})`)
7056
7102
  }
7057
- if (!that[`${xAxis}Axis`].invert) {
7058
- that[`${xAxis}Axis`].invert = that.invertOverride
7103
+ if (that.areaLayer) {
7104
+ that.areaLayer.attr('transform', `translate(${newX}, ${that.options.margin.top + that.options.margin.axisTop})`)
7059
7105
  }
7060
- let s = event.selection || that[`${xAxis}Axis`].range()
7061
- if (!event.selection || event.selection.length === 0) {
7062
- that.brushLayer
7063
- .select('.brush')
7064
- .call(that.brush)
7065
- .call(that.brush.move, s)
7066
- return
7106
+ if (that.lineLayer) {
7107
+ that.lineLayer.attr('transform', `translate(${newX}, ${that.options.margin.top + that.options.margin.axisTop})`)
7067
7108
  }
7068
- if (that.options.data[xAxis].scale && that.options.data[xAxis].scale === 'Time') {
7069
- that.brushedDomain = s.map(that[`${xAxis}BrushAxis`].invert, that[[`${xAxis}Axis`]])
7109
+ if (that.barLayer) {
7110
+ that.barLayer.attr('transform', `translate(${newX}, ${that.options.margin.top + that.options.margin.axisTop})`)
7070
7111
  }
7071
- else {
7072
- let startEndOrdinal = s.map((a, b) => that.bottomAxis.invert(a, b, true), that.bottomBrushAxis)
7073
- if (
7074
- startEndOrdinal &&
7075
- startEndOrdinal.length === 2 &&
7076
- typeof startEndOrdinal[0] !== 'undefined' &&
7077
- typeof startEndOrdinal[1] !== 'undefined'
7078
- ) {
7079
- let domain = []
7080
- let domainValues = [...that[`${xAxis}BrushAxis`].domain()]
7081
- for (let i = startEndOrdinal[0]; i < startEndOrdinal[1] + 1; i++) {
7082
- // domain.push(that.xRange[i])
7083
- that.brushedDomain.push(domainValues[i])
7084
- }
7085
- }
7112
+ if (that.labelLayer) {
7113
+ that.labelLayer.attr('transform', `translate(${newX}, ${that.options.margin.top + that.options.margin.axisTop})`)
7086
7114
  }
7087
- if (that.brushedDomain.length > 0) {
7088
- that[`${xAxis}Axis`].domain(that.brushedDomain)
7089
- that[`${xAxis}AxisLayer`].call(
7090
- d3[`axis${xAxisCaps}`](that[`${xAxis}Axis`])
7091
- )
7092
- }
7093
- if (that.leftAxis && that.bottomAxis) {
7094
- that.renderComponents()
7095
- if (that.options.orientation === 'vertical') {
7096
- // that.bottomAxisLayer.call(that.bAxisFunc)
7097
- if (that.options.data.bottom.rotate) {
7098
- that.bottomAxisLayer.selectAll('text')
7099
- .attr('transform', `rotate(${((that.options.data.bottom && that.options.data.bottom.rotate) || 0)})`)
7100
- .style('text-anchor', `${((that.options.data.bottom && that.options.data.bottom.rotate) || 0) === 0 ? 'middle' : 'end'}`)
7101
- .style('transform-origin', ((that.options.data.bottom && that.options.data.bottom.rotate) || 0) === 0 ? '0 0' : `0 ${((that.options.data.bottom && that.options.data.bottom.fontSize) || that.options.fontSize)}px`)
7102
- }
7103
- }
7104
- }
7115
+ if (that.symbolLayer) {
7116
+ that.symbolLayer.attr('transform', `translate(${newX}, ${that.options.margin.top + that.options.margin.axisTop})`)
7117
+ }
7118
+ if (that.refLineLayer) {
7119
+ that.refLineLayer.attr('transform', `translate(${newX}, ${that.options.margin.top + that.options.margin.axisTop})`)
7120
+ }
7121
+ if (that.bottomAxisLayer) {
7122
+ that.bottomAxisLayer.attr('transform', `translate(${newX}, ${that.options.margin.top + that.options.margin.axisTop + that.plotHeight})`)
7123
+ }
7124
+ // that.brushedDomain = []
7125
+ // let xAxis = 'bottom'
7126
+ // let xAxisCaps = 'Bottom'
7127
+ // if (that.options.orientation === 'horizontal') {
7128
+ // xAxis = 'left'
7129
+ // xAxisCaps = 'Left'
7130
+ // }
7131
+ // if (!that[`${xAxis}Axis`]) {
7132
+ // return
7133
+ // }
7134
+ // if (!that[`${xAxis}Axis`].invert) {
7135
+ // that[`${xAxis}Axis`].invert = that.invertOverride
7136
+ // }
7137
+ // let s = event.selection || that[`${xAxis}Axis`].range()
7138
+ // if (!event.selection || event.selection.length === 0) {
7139
+ // that.brushLayer
7140
+ // .select('.brush')
7141
+ // .call(that.brush)
7142
+ // .call(that.brush.move, s)
7143
+ // return
7144
+ // }
7145
+ // if (that.options.data[xAxis].scale && that.options.data[xAxis].scale === 'Time') {
7146
+ // that.brushedDomain = s.map(that[`${xAxis}BrushAxis`].invert, that[[`${xAxis}Axis`]])
7147
+ // }
7148
+ // else {
7149
+ // let startEndOrdinal = s.map((a, b) => that.bottomAxis.invert(a, b, true), that.bottomBrushAxis)
7150
+ // if (
7151
+ // startEndOrdinal &&
7152
+ // startEndOrdinal.length === 2 &&
7153
+ // typeof startEndOrdinal[0] !== 'undefined' &&
7154
+ // typeof startEndOrdinal[1] !== 'undefined'
7155
+ // ) {
7156
+ // let domain = []
7157
+ // let domainValues = [...that[`${xAxis}BrushAxis`].domain()]
7158
+ // for (let i = startEndOrdinal[0]; i < startEndOrdinal[1] + 1; i++) {
7159
+ // // domain.push(that.xRange[i])
7160
+ // that.brushedDomain.push(domainValues[i])
7161
+ // }
7162
+ // }
7163
+ // }
7164
+ // if (that.brushedDomain.length > 0) {
7165
+ // that[`${xAxis}Axis`].domain(that.brushedDomain)
7166
+ // that[`${xAxis}AxisLayer`].call(
7167
+ // d3[`axis${xAxisCaps}`](that[`${xAxis}Axis`])
7168
+ // )
7169
+ // }
7170
+ // if (that.leftAxis && that.bottomAxis) {
7171
+ // that.renderComponents()
7172
+ // if (that.options.orientation === 'vertical') {
7173
+ // // that.bottomAxisLayer.call(that.bAxisFunc)
7174
+ // if (that.options.data.bottom.rotate) {
7175
+ // that.bottomAxisLayer.selectAll('text')
7176
+ // .attr('transform', `rotate(${((that.options.data.bottom && that.options.data.bottom.rotate) || 0)})`)
7177
+ // .style('text-anchor', `${((that.options.data.bottom && that.options.data.bottom.rotate) || 0) === 0 ? 'middle' : 'end'}`)
7178
+ // .style('transform-origin', ((that.options.data.bottom && that.options.data.bottom.rotate) || 0) === 0 ? '0 0' : `0 ${((that.options.data.bottom && that.options.data.bottom.fontSize) || that.options.fontSize)}px`)
7179
+ // }
7180
+ // }
7181
+ // }
7105
7182
  }
7106
7183
  const el = document.getElementById(this.elementId)
7107
7184
  if (el) {
@@ -7243,12 +7320,12 @@ else {
7243
7320
  }
7244
7321
  this.options.data.series.forEach(s => {
7245
7322
  if (this.options.data[xData].scale !== 'Time') {
7246
- if (this.customBottomRange && this.customBottomRange.length > 0) {
7247
- xPoint = this.customBottomRange[x0] + ((this.customBottomRange[x0 + 1] - this.customBottomRange[x0]) / 2)
7248
- }
7249
- else {
7250
- xPoint = this[xAxis](this.parseX(xLabel))
7251
- }
7323
+ // if (this.customBottomRange && this.customBottomRange.length > 0) {
7324
+ xPoint = this.customBottomRange[x0] + ((this.customBottomRange[x0 + 1] - this.customBottomRange[x0]) / 2)
7325
+ // }
7326
+ // else {
7327
+ // xPoint = this[xAxis](this.parseX(xLabel))
7328
+ // }
7252
7329
  s.data.forEach(d => {
7253
7330
  if (d.x.value === xLabel) {
7254
7331
  if (!tooltipTitle) {
@@ -7370,6 +7447,10 @@ else {
7370
7447
  }
7371
7448
  }
7372
7449
  this.tooltip.setHeight(this.plotHeight)
7450
+ if (isNaN(posOptions.left)) {
7451
+ this.tooltip.hide()
7452
+ return
7453
+ }
7373
7454
  this.options.showTooltip && this.tooltip.show(tooltipTitle, tooltipHTML, posOptions)
7374
7455
  // }
7375
7456
  // else {
@@ -7404,20 +7485,22 @@ else {
7404
7485
  /* global d3 WebsyDesigns */
7405
7486
  this.defs = this.svg.append('defs')
7406
7487
  this.clip = this.defs.append('clipPath').attr('id', `${this.elementId}_clip`).append('rect')
7488
+ this.xAxisClip = this.defs.append('clipPath').attr('id', `${this.elementId}_xAxisClip`).append('rect')
7407
7489
  this.brushClip = this.defs.append('clipPath').attr('id', `${this.elementId}_brushclip`).append('rect')
7408
7490
  this.leftAxisLayer = this.svg.append('g').attr('class', 'left-axis-layer')
7409
7491
  this.rightAxisLayer = this.svg.append('g').attr('class', 'right-axis-layer')
7410
- this.bottomAxisLayer = this.svg.append('g').attr('class', 'bottom-axis-layer')
7492
+ this.bottomAxisLayer = this.svg.append('g').attr('class', 'bottom-axis-layer').attr('clip-path', `url(#${this.elementId}_xAxisClip)`).append('g')
7411
7493
  this.leftAxisLabel = this.svg.append('g').attr('class', 'left-axis-label-layer')
7412
7494
  this.rightAxisLabel = this.svg.append('g').attr('class', 'right-axis-label-layer')
7413
7495
  this.bottomAxisLabel = this.svg.append('g').attr('class', 'bottom-axis-label-layer')
7414
- this.plotArea = this.svg.append('g').attr('class', 'plot-layer')
7415
- this.areaLayer = this.svg.append('g').attr('class', 'area-layer')
7416
- this.lineLayer = this.svg.append('g').attr('class', 'line-layer')
7417
- this.barLayer = this.svg.append('g').attr('class', 'bar-layer')
7418
- this.labelLayer = this.svg.append('g').attr('class', 'label-layer')
7419
- this.symbolLayer = this.svg.append('g').attr('class', 'symbol-layer')
7420
- this.refLineLayer = this.svg.append('g').attr('class', 'refline-layer')
7496
+ this.plotArea = this.svg.append('g').attr('class', 'plot-layer').attr('clip-path', `url(#${this.elementId}_clip)`).append('g')
7497
+ this.areaLayer = this.svg.append('g').attr('class', 'area-layer').attr('clip-path', `url(#${this.elementId}_clip)`).append('g')
7498
+ this.lineLayer = this.svg.append('g').attr('class', 'line-layer').attr('clip-path', `url(#${this.elementId}_clip)`).append('g')
7499
+ this.barLayer = this.svg.append('g').attr('class', 'bar-layer').attr('clip-path', `url(#${this.elementId}_clip)`).append('g')
7500
+ // this.barLayer.attr('clip-path', `url(#${this.elementId}_clip)`)
7501
+ this.labelLayer = this.svg.append('g').attr('class', 'label-layer').attr('clip-path', `url(#${this.elementId}_clip)`).append('g')
7502
+ this.symbolLayer = this.svg.append('g').attr('class', 'symbol-layer').attr('clip-path', `url(#${this.elementId}_clip)`).append('g')
7503
+ this.refLineLayer = this.svg.append('g').attr('class', 'refline-layer').attr('clip-path', `url(#${this.elementId}_clip)`).append('g')
7421
7504
  this.trackingLineLayer = this.svg.append('g').attr('class', 'tracking-line-layer')
7422
7505
  this.trackingLineLayer.append('line').attr('class', 'tracking-line')
7423
7506
  this.tooltip = new WebsyDesigns.WebsyChartTooltip(this.svg)
@@ -7665,39 +7748,113 @@ else {
7665
7748
  this.options.margin.axisBottom = 0
7666
7749
  }
7667
7750
  }
7751
+ // At some point before this we need to add in logic to make space for any data point labels
7668
7752
  // Define the plot size
7669
7753
  this.plotWidth = this.width - this.options.margin.legendLeft - this.options.margin.legendRight - this.options.margin.left - this.options.margin.right - this.options.margin.axisLeft - this.options.margin.axisRight
7670
7754
  this.plotHeight = this.height - this.options.margin.legendTop - this.options.margin.legendBottom - this.options.margin.top - this.options.margin.bottom - this.options.margin.axisBottom - this.options.margin.axisTop
7671
7755
  this.brushNeeded = false
7672
- if (this.options.orientation === 'vertical') {
7673
- this.options.data.bottom.totalValueCount = this.options.data.bottom.data.reduce((a, b) => {
7674
- if (typeof b.valueCount === 'undefined') {
7675
- return a + 1
7676
- }
7677
- return a + b.valueCount
7678
- }, 0)
7679
- if (this.options.maxBandWidth) {
7680
- this.plotWidth = Math.min(this.plotWidth, (this.options.data.bottom.totalValueCount) * this.options.maxBandWidth)
7681
- }
7682
- // some if to check if brushing is needed
7683
- if (this.plotWidth / this.options.data.bottom.totalValueCount < this.options.minBandWidth) {
7684
- this.brushNeeded = true
7685
- this.plotHeight -= this.options.brushHeight
7756
+ let proposedBandWidth // distance between x axis data points.
7757
+ let maxBandWidthFits = false
7758
+ // Check to see if all bars at the max allowed width will fit
7759
+ this.bandPadding = 0
7760
+ this.totalBandPadding = 0
7761
+ this.brushBandPadding = 0
7762
+ this.totalBrushBandPadding = 0
7763
+ let noOfPoints = 0
7764
+ let noOfGroups = 0
7765
+ let plotable = 0
7766
+ if (this.options.maxBandWidth) {
7767
+ if (this.options.orientation === 'horizontal') {
7768
+ this.options.data.left.totalValueCount = this.options.data.left.data.reduce((a, b) => {
7769
+ if (typeof b.valueCount === 'undefined') {
7770
+ return a + 1
7771
+ }
7772
+ return a + b.valueCount
7773
+ }, 0)
7774
+ if (this.options.data.left.padding) {
7775
+ this.totalBandPadding = (this.plotHeight * this.options.data.left.padding)
7776
+ this.bandPadding = this.totalBandPadding / this.options.data.left.data.length
7777
+ this.totalBrushBandPadding = (this.plotHeight * this.options.data.left.padding)
7778
+ this.brushBandPadding = this.totalBandPadding / this.options.data.left.data.length
7779
+ }
7780
+ plotable = this.plotHeight - this.totalBandPadding
7781
+ noOfPoints = this.options.grouping === 'grouped' ? this.options.data.left.totalValueCount : this.options.data.left.data.length
7782
+ noOfGroups = this.options.data.left.data.length
7686
7783
  }
7687
- }
7688
- else {
7689
- // some if to check if brushing is needed
7690
- this.options.data.left.totalValueCount = this.options.data.left.data.reduce((a, b) => {
7691
- if (typeof b.valueCount === 'undefined') {
7692
- return a + 1
7784
+ else {
7785
+ this.options.data.bottom.totalValueCount = this.options.data.bottom.data.reduce((a, b) => {
7786
+ if (typeof b.valueCount === 'undefined') {
7787
+ return a + 1
7788
+ }
7789
+ return a + b.valueCount
7790
+ }, 0)
7791
+ if (this.options.data.bottom.padding) {
7792
+ this.totalBandPadding = (this.plotWidth * this.options.data.bottom.padding)
7793
+ this.bandPadding = this.totalBandPadding / this.options.data.bottom.data.length
7794
+ this.totalBrushBandPadding = (this.plotWidth * this.options.data.bottom.padding)
7795
+ this.brushBandPadding = this.totalBandPadding / this.options.data.bottom.data.length
7796
+ }
7797
+ plotable = this.plotWidth - this.totalBandPadding
7798
+ noOfPoints = this.options.grouping === 'grouped' ? this.options.data.bottom.totalValueCount : this.options.data.bottom.data.length
7799
+ noOfGroups = this.options.data.bottom.data.length
7800
+ }
7801
+ if (plotable / noOfPoints > this.options.maxBandWidth) {
7802
+ maxBandWidthFits = true
7803
+ proposedBandWidth = this.options.maxBandWidth
7804
+ }
7805
+ if (!maxBandWidthFits) {
7806
+ // Check to see if all bars at the min allowed width will fit
7807
+ if (plotable / noOfPoints < this.options.minBandWidth) {
7808
+ this.brushNeeded = true
7809
+ proposedBandWidth = this.options.minBandWidth
7810
+ if (this.options.orientation === 'horizontal') {
7811
+ this.plotWidth -= this.options.brushHeight
7812
+ }
7813
+ else {
7814
+ this.plotHeight -= this.options.brushHeight
7815
+ }
7693
7816
  }
7694
- return a + b.valueCount
7695
- }, 0)
7696
- if (this.plotHeight / this.options.data.left.totalValueCount < this.options.minBandWidth) {
7697
- this.brushNeeded = true
7698
- this.plotWidth -= this.options.brushHeight
7699
- }
7700
- }
7817
+ else {
7818
+ proposedBandWidth = plotable / noOfPoints
7819
+ }
7820
+ }
7821
+ }
7822
+ // if (this.options.minBandWidth) {
7823
+ // this.widthForCalc = this.options.data.bottom.totalValueCount * this.options.minBandWidth
7824
+ // if (this.options.data.bottom.padding) {
7825
+ // this.widthForCalc += (this.options.minBandWidth * this.options.data.bottom.padding) * this.options.data.bottom.totalValueCount
7826
+ // this.widthForCalc += (this.options.data.bottom.data.length * this.options.groupPadding * 2)
7827
+ // }
7828
+ // }
7829
+ // if (this.options.orientation === 'vertical') {
7830
+ // this.options.data.bottom.totalValueCount = this.options.data.bottom.data.reduce((a, b) => {
7831
+ // if (typeof b.valueCount === 'undefined') {
7832
+ // return a + 1
7833
+ // }
7834
+ // return a + b.valueCount
7835
+ // }, 0)
7836
+ // if (this.options.maxBandWidth) {
7837
+ // this.plotWidth = Math.min(this.plotWidth, (this.options.data.bottom.totalValueCount) * this.options.maxBandWidth)
7838
+ // }
7839
+ // // some if to check if brushing is needed
7840
+ // if (this.plotWidth / this.options.data.bottom.totalValueCount < this.options.minBandWidth) {
7841
+ // this.brushNeeded = true
7842
+ // this.plotHeight -= this.options.brushHeight
7843
+ // }
7844
+ // }
7845
+ // else {
7846
+ // // some if to check if brushing is needed
7847
+ // this.options.data.left.totalValueCount = this.options.data.left.data.reduce((a, b) => {
7848
+ // if (typeof b.valueCount === 'undefined') {
7849
+ // return a + 1
7850
+ // }
7851
+ // return a + b.valueCount
7852
+ // }, 0)
7853
+ // if (this.plotHeight / this.options.data.left.totalValueCount < this.options.minBandWidth) {
7854
+ // this.brushNeeded = true
7855
+ // this.plotWidth -= this.options.brushHeight
7856
+ // }
7857
+ // }
7701
7858
  // Translate the layers
7702
7859
  this.leftAxisLayer
7703
7860
  .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
@@ -7732,6 +7889,14 @@ else {
7732
7889
  .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
7733
7890
  this.brushLayer
7734
7891
  .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop + this.plotHeight + longestBottomBounds.height})`)
7892
+ this.clip
7893
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
7894
+ .attr('width', this.plotWidth)
7895
+ .attr('height', this.plotHeight)
7896
+ this.xAxisClip
7897
+ .attr('transform', `translate(${this.options.margin.left}, ${this.options.margin.top + this.options.margin.axisTop + this.plotHeight})`)
7898
+ .attr('width', this.plotWidth + this.options.margin.axisLeft)
7899
+ .attr('height', longestBottomBounds.height + 10)
7735
7900
  this.brushClip
7736
7901
  .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop + this.plotHeight + longestBottomBounds.height})`)
7737
7902
  .attr('width', this.plotWidth)
@@ -7748,39 +7913,80 @@ else {
7748
7913
  // this.tooltip.transform(this.options.margin.left + this.options.margin.axisLeft, this.options.margin.top + this.options.margin.axisTop)
7749
7914
  // Configure the bottom axis
7750
7915
  let bottomDomain = this.createDomain('bottom')
7751
- let bottomBrushDomain = this.createDomain('bottom', true)
7916
+ // let bottomBrushDomain = this.createDomain('bottom', true)
7917
+ let bottomBrushDomain = this.createDomain('bottom')
7752
7918
  let bottomRange = [0, this.plotWidth]
7919
+ let bottomBrushRange = [0, this.plotWidth]
7920
+ let leftRange = [this.plotHeight, 0]
7921
+ let leftBrushRange = [this.options.brushHeight, 0]
7922
+ if (this.options.orientation === 'horizontal') {
7923
+ leftBrushRange = [this.plotHeight, 0]
7924
+ }
7925
+ this.widthForCalc = (proposedBandWidth * noOfPoints) // + totalPadding
7753
7926
  this.customBottomRange = []
7754
- if (this.options.allowUnevenBands === true) {
7755
- if (this.options.data.bottom.data && this.options.data.bottom.data[0] && this.options.data.bottom.data[0].valueCount && this.options.data.bottom.scale === 'Ordinal') {
7756
- let acc = 0
7757
- this.customBottomRange = [0, ...this.options.data.bottom.data.map(d => {
7758
- acc += d.valueCount
7759
- return (this.plotWidth / this.options.data.bottom.totalValueCount) * acc
7760
- })]
7761
- }
7762
- }
7763
- this.options.data.bottom.step = this.plotWidth / this.options.data.bottom.totalValueCount
7764
- this.options.data.bottom.bandWidth = this.options.data.bottom.step
7765
- if (this.options.data.bottom.padding) {
7766
- this.totalPadding = this.plotWidth * this.options.data.bottom.padding
7767
- let rangeLength = bottomDomain.length
7768
- if (this.customBottomRange.length > 0) {
7769
- rangeLength = this.customBottomRange.length
7770
- }
7771
- this.bandPadding = (this.totalPadding / (rangeLength)) / 2
7772
- this.options.data.bottom.bandWidth = (this.plotWidth - this.totalPadding) / this.options.data.bottom.totalValueCount
7773
- }
7774
- if (this.options.grouping === 'grouped' && this.options.data.series.length > 1) {
7775
- this.options.data.bottom.bandWidth = this.options.data.bottom.bandWidth - (this.options.groupPadding * 2)
7927
+ this.customBottomDetailRange = []
7928
+ this.customBottomBrushRange = []
7929
+ this.customLeftRange = []
7930
+ this.customLeftDetailRange = []
7931
+ this.customLeftBrushRange = []
7932
+ // if (this.options.allowUnevenBands === true) {
7933
+ // always allow uneven bands
7934
+ let customRangeSide = 'Bottom'
7935
+ let customRangeSideLC = 'bottom'
7936
+ if (this.options.orientation === 'horizontal') {
7937
+ customRangeSide = 'Left'
7938
+ customRangeSideLC = 'left'
7939
+ }
7940
+ if (this.options.data[customRangeSideLC].data && this.options.data[customRangeSideLC].data[0] && (this.options.data[customRangeSideLC].data[0].valueCount || 1) && this.options.data[customRangeSideLC].scale === 'Ordinal') {
7941
+ let acc = 0
7942
+ this[`custom${customRangeSide}Range`] = [0, ...this.options.data[customRangeSideLC].data.map((d, index, arr) => {
7943
+ let adjustment = (this.bandPadding * index) + this.bandPadding
7944
+ // if (this.options.data.bottom.padding) {
7945
+ // adjustment = (this.widthForCalc * this.options.data.bottom.padding) / (arr.length * 2)
7946
+ // }
7947
+ let start = (this.widthForCalc / noOfPoints) * acc
7948
+ for (let i = 0; i < (d.valueCount || 1); i++) {
7949
+ let pos = i * proposedBandWidth
7950
+ this[`custom${customRangeSide}DetailRange`].push(start + adjustment + pos)
7951
+ }
7952
+ acc += (this.options.grouping !== 'stacked' ? (d.valueCount || 1) : 1)
7953
+ let end = (this.widthForCalc / noOfPoints) * acc
7954
+ // this.customBottomBrushRange.push((end + adjustment) * (this.plotWidth / this.widthForCalc))
7955
+ return end + adjustment
7956
+ })]
7957
+ acc = 0
7958
+ this[`custom${customRangeSide}BrushRange`] = [0, ...this.options.data[customRangeSideLC].data.map((d, index, arr) => {
7959
+ let adjustment = (this.brushBandPadding * index) + this.brushBandPadding
7960
+ acc += (this.options.grouping !== 'stacked' ? (d.valueCount || 1) : 1)
7961
+ return ((this.options.orientation === 'vertical' ? this.plotWidth : this.plotHeight) / noOfPoints) * acc
7962
+ })]
7776
7963
  }
7777
- this.bottomAxis = d3[`scale${this.options.data.bottom.scale || 'Band'}`]()
7964
+ // }
7965
+ let rangeLength = bottomDomain.length
7966
+ this.options.data.bottomBrush = {}
7967
+ this.options.data.leftBrush = {}
7968
+ if (this.options.orientation === 'vertical') {
7969
+ this.options.data.bottom.bandWidth = proposedBandWidth
7970
+ this.options.data.bottomBrush.bandWidth = (this.plotWidth - this.totalBandPadding) / noOfPoints
7971
+ }
7972
+ else {
7973
+ this.options.data.left.bandWidth = proposedBandWidth
7974
+ this.options.data.leftBrush.bandWidth = (this.plotHeight - this.totalBandPadding) / noOfPoints
7975
+ }
7976
+ this.brushBandPadding = this.totalBandPadding / noOfGroups
7977
+ if (this.options.orientation === 'vertical') {
7978
+ bottomRange = [0, (this.widthForCalc + this.totalBandPadding)]
7979
+ }
7980
+ else {
7981
+ leftRange = [(this.widthForCalc + this.totalBandPadding), 0]
7982
+ }
7983
+ this.bottomAxis = d3[`scale${this.options.data.bottom.scale || 'Ordinal'}`]()
7778
7984
  .domain(bottomDomain)
7779
7985
  .range(bottomRange)
7780
7986
  if (!this.brushInitialized) {
7781
- this.bottomBrushAxis = d3[`scale${this.options.data.bottom.scale || 'Band'}`]()
7987
+ this.bottomBrushAxis = d3[`scale${this.options.data.bottom.scale || 'Ordinal'}`]()
7782
7988
  .domain(bottomBrushDomain)
7783
- .range(bottomRange)
7989
+ .range(bottomBrushRange)
7784
7990
  }
7785
7991
  if (this.bottomAxis.nice) {
7786
7992
  // this.bottomAxis.nice()
@@ -7799,71 +8005,71 @@ else {
7799
8005
  brushThickness = this.plotHeight
7800
8006
  }
7801
8007
  else {
7802
- if (brushLength / bottomDomain.length < this.options.minBandWidth) {
7803
- brushEnd = this.plotWidth * ((this.plotWidth / this.options.minBandWidth) / bottomDomain.length)
8008
+ if (this.brushNeeded) {
8009
+ brushEnd = this.plotWidth * (this.plotWidth / (this.widthForCalc + this.totalBandPadding))
7804
8010
  }
7805
8011
  }
7806
8012
  this.brush = d3[brushMethod]()
7807
8013
  .extent([
7808
8014
  [0, 0],
7809
8015
  [brushLength, brushThickness]
7810
- ])
8016
+ ])
7811
8017
  .on('brush end', this.brushed)
7812
- const brushResizePath = d => {
7813
- let e = +(d.type === 'e')
7814
- let x = e ? 1 : -1
7815
- let y = this.options.brushHeight
7816
- return (
7817
- 'M' +
7818
- 0.5 * x +
7819
- ',' +
7820
- y +
7821
- 'A6,6 0 0 ' +
7822
- e +
7823
- ' ' +
7824
- 6.5 * x +
7825
- ',' +
7826
- (y + 6) +
7827
- 'V' +
7828
- (2 * y - 6) +
7829
- 'A6,6 0 0 ' +
7830
- e +
7831
- ' ' +
7832
- 0.5 * x +
7833
- ',' +
7834
- 2 * y +
7835
- 'Z' +
7836
- 'M' +
7837
- 2.5 * x +
7838
- ',' +
7839
- (y + 8) +
7840
- 'V' +
7841
- (2 * y - 8) +
7842
- 'M' +
7843
- 4.5 * x +
7844
- ',' +
7845
- (y + 8) +
7846
- 'V' +
7847
- (2 * y - 8)
7848
- )
7849
- }
7850
- this.brushHandle = this.brushLayer
7851
- .select('.brush')
7852
- .selectAll('.handle--custom')
7853
- .remove()
7854
- this.brushHandle = this.brushLayer
7855
- .select('.brush')
7856
- .selectAll('.handle--custom')
7857
- .data([{ type: 'w' }, { type: 'e' }])
7858
- .enter()
7859
- .append('path')
7860
- .attr('class', 'handle--custom')
7861
- .attr('stroke', 'transparent')
7862
- .attr('fill', 'transparent')
7863
- .attr('cursor', 'ew-resize')
7864
- .attr('d', brushResizePath)
8018
+ // const brushResizePath = d => {
8019
+ // let e = +(d.type === 'e')
8020
+ // let x = e ? 1 : -1
8021
+ // let y = this.options.brushHeight
8022
+ // return (
8023
+ // 'M' +
8024
+ // 0.5 * x +
8025
+ // ',' +
8026
+ // y +
8027
+ // 'A6,6 0 0 ' +
8028
+ // e +
8029
+ // ' ' +
8030
+ // 6.5 * x +
8031
+ // ',' +
8032
+ // (y + 6) +
8033
+ // 'V' +
8034
+ // (2 * y - 6) +
8035
+ // 'A6,6 0 0 ' +
8036
+ // e +
8037
+ // ' ' +
8038
+ // 0.5 * x +
8039
+ // ',' +
8040
+ // 2 * y +
8041
+ // 'Z' +
8042
+ // 'M' +
8043
+ // 2.5 * x +
8044
+ // ',' +
8045
+ // (y + 8) +
8046
+ // 'V' +
8047
+ // (2 * y - 8) +
8048
+ // 'M' +
8049
+ // 4.5 * x +
8050
+ // ',' +
8051
+ // (y + 8) +
8052
+ // 'V' +
8053
+ // (2 * y - 8)
8054
+ // )
8055
+ // }
8056
+ // this.brushHandle = this.brushLayer
8057
+ // .select('.brush')
8058
+ // .selectAll('.handle--custom')
8059
+ // .remove()
8060
+ // this.brushHandle = this.brushLayer
8061
+ // .select('.brush')
8062
+ // .selectAll('.handle--custom')
8063
+ // .data([{ type: 'w' }, { type: 'e' }])
8064
+ // .enter()
8065
+ // .append('path')
8066
+ // .attr('class', 'handle--custom')
8067
+ // .attr('stroke', 'transparent')
8068
+ // .attr('fill', 'transparent')
8069
+ // .attr('cursor', 'ew-resize')
8070
+ // .attr('d', brushResizePath)
7865
8071
  // BRUSH END
7866
- // this.brushArea.selectAll('*').remove()
8072
+ // this.brushLayer.selectAll('.handle').remove()
7867
8073
  if (this.brushNeeded) {
7868
8074
  if (!this.brushInitialized) {
7869
8075
  this.brushLayer.style('visibility', 'visible')
@@ -7873,11 +8079,14 @@ else {
7873
8079
  .call(this.brush)
7874
8080
  .call(this.brush.move, [0, brushEnd])
7875
8081
  }
8082
+ else {
8083
+ this.brushLayer.style('visibility', 'visible')
8084
+ }
7876
8085
  }
7877
8086
  else {
7878
8087
  this.brushLayer.style('visibility', 'hidden')
7879
8088
  // this.brushLayer.selectAll().remove()
7880
- this.brushArea.selectAll('*').remove()
8089
+ // this.brushArea.selectAll('*').remove()
7881
8090
  }
7882
8091
  if (this.options.margin.axisBottom > 0) {
7883
8092
  let timeFormatPattern = ''
@@ -7963,10 +8172,10 @@ else {
7963
8172
  let rightDomain = this.createDomain('right')
7964
8173
  this.leftAxis = d3[`scale${this.options.data.left.scale || 'Linear'}`]()
7965
8174
  .domain(leftDomain)
7966
- .range([this.plotHeight, 0])
8175
+ .range(leftRange)
7967
8176
  this.leftBrushAxis = d3[`scale${this.options.data.left.scale || 'Linear'}`]()
7968
8177
  .domain(leftBrushDomain)
7969
- .range([this.options.brushHeight, 0])
8178
+ .range(leftBrushRange)
7970
8179
  if (this.leftAxis.padding && this.options.data.left.padding) {
7971
8180
  this.leftAxis.padding(this.options.data.left.padding || 0)
7972
8181
  }
@@ -8114,7 +8323,13 @@ const drawArea = (xAxis, yAxis, curveStyle) => {
8114
8323
  return d3
8115
8324
  .area()
8116
8325
  .x(d => {
8117
- return this[`${xAxis}Axis`](this.parseX(d.x.value))
8326
+ // return this[`${xAxis}Axis`](this.parseX(d.x.value))
8327
+ let xIndex = this[xAxis + 'Axis'].domain().indexOf(d.x.value)
8328
+ let xPos = this[`custom${xAxis.toInitialCaps()}Range`][xIndex]
8329
+ if (this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1]) {
8330
+ xPos = xPos + ((this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1] - xPos) / 2)
8331
+ }
8332
+ return xPos
8118
8333
  })
8119
8334
  .y0(d => {
8120
8335
  return this[`${yAxis}Axis`](0)
@@ -8142,7 +8357,7 @@ areas
8142
8357
  // .style('stroke-width', series.lineWidth || this.options.lineWidth)
8143
8358
  // .attr('id', `line_${series.key}`)
8144
8359
  // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8145
- // .attr('fill', series.colour)
8360
+ .attr('fill', d => d[0].y.color || series.color)
8146
8361
  // .attr('stroke', 'transparent')
8147
8362
  .transition(this.transition)
8148
8363
  .attr('d', d => drawArea(xAxis, yAxis, series.curveStyle)(d))
@@ -8151,13 +8366,13 @@ areas.enter().append('path')
8151
8366
  .attr('d', d => drawArea(xAxis, yAxis, series.curveStyle)(d))
8152
8367
  .attr('class', `area_${series.key}`)
8153
8368
  .attr('id', `area_${series.key}`)
8154
- .attr('transform', 'translate(' + (this.options.data[xAxis].scale === 'Time' ? 0 : this.options.data[xAxis.replace('Brush', '')].bandWidth / 2) + ',0)')
8369
+ // .attr('transform', 'translate(' + (this.options.data[xAxis].scale === 'Time' ? 0 : this.options.data[xAxis].bandWidth / 2) + ',0)')
8155
8370
  // .style('stroke-width', series.lineWidth || this.options.lineWidth)
8156
- .attr('fill', series.color)
8371
+ .attr('fill', d => d[0].y.color || series.color)
8157
8372
  // .style('fill-opacity', 0)
8158
8373
  .attr('stroke', 'transparent')
8159
8374
  // .transition(this.transition)
8160
- .style('fill-opacity', series.opacity || 0.5)
8375
+ .style('fill-opacity', series.opacity || 0.3)
8161
8376
 
8162
8377
  }
8163
8378
  renderbar (series, index) {
@@ -8171,13 +8386,10 @@ if (this.options.orientation === 'horizontal') {
8171
8386
  xAxis = 'left'
8172
8387
  yAxis = 'bottom'
8173
8388
  }
8174
- // if (this.options.data.series.length > 1 && this.options.grouping === 'grouped') {
8175
- // barWidth = barWidth / this.options.data.series.length - 4
8176
- // }
8177
8389
  function getBarHeight (d, i, heightBounds, yAxis, xAxis) {
8178
8390
  let output
8179
8391
  if (this.options.orientation === 'horizontal') {
8180
- output = this.options.data[xAxis.replace('Brush', '')].bandWidth
8392
+ output = this.options.data[xAxis].bandWidth
8181
8393
  }
8182
8394
  else {
8183
8395
  let x = getBarX.call(this, d, i, xAxis)
@@ -8203,19 +8415,14 @@ function getBarWidth (d, i, xAxis) {
8203
8415
  if (typeof x === 'undefined' || x === null) {
8204
8416
  return null
8205
8417
  }
8206
- output = Math.max(1, this.options.data[xAxis.replace('Brush', '')].bandWidth)
8418
+ output = Math.max(1, this.options.data[xAxis].bandWidth - (xAxis.indexOf('Brush') !== -1 ? 2 : this.options.groupPadding * 2))
8207
8419
  }
8208
8420
  if (isNaN(output)) {
8209
8421
  return 0
8210
8422
  }
8211
8423
  return output
8212
8424
  }
8213
- function getBarX (d, i, xAxis) {
8214
- // let barWidth = this.plotWidth / this.options.data[xAxis.replace('Brush', '')].totalValueCount
8215
- // if (this.options.data[xAxis.replace('Brush', '')].padding) {
8216
- // barWidth = barWidth - (barWidth * this.options.data[xAxis.replace('Brush', '')].padding)
8217
- // }
8218
- // let groupedBarWidth = (barWidth - (xAxis.indexOf('Brush') === -1 ? 10 : 2)) / this.options.data[xAxis.replace('Brush', '')].totalValueCount
8425
+ function getBarX (d, i, xAxis) {
8219
8426
  let output
8220
8427
  if (this.options.orientation === 'horizontal') {
8221
8428
  if (this.options.grouping === 'stacked') {
@@ -8233,22 +8440,24 @@ function getBarX (d, i, xAxis) {
8233
8440
  }
8234
8441
  else {
8235
8442
  // let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this.options.data[xAxis.replace('Brush', '')].bandWidth / 2
8236
- let adjustment = this.customBottomRange[i] + (i * this.options.data[xAxis.replace('Brush', '')].bandWidth)
8443
+ // let adjustment = this[`custom${xAxis.toInitialCaps()}Range`][i] + (i * this.options.data[xAxis].bandWidth)
8237
8444
  if (this.options.grouping === 'grouped') {
8238
8445
  let xIndex = 0
8239
8446
  if (this.processedX[d.x.value]) {
8240
8447
  xIndex = Math.max(0, this.processedX[d.x.value].indexOf(d.y.tooltipLabel))
8241
8448
  }
8242
- let barAdjustment =
8243
- (this.options.data[xAxis.replace('Brush', '')].bandWidth * xIndex) +
8244
- (xIndex * this.options.groupPadding * 2) + this.options.groupPadding +
8245
- (xAxis.indexOf('Brush') === -1 ? this.bandPadding : 1)
8449
+ // let barAdjustment =
8450
+ // (this.options.data[xAxis].bandWidth * xIndex) +
8451
+ // (xIndex * this.options.groupPadding * 2) + this.options.groupPadding +
8452
+ // (xAxis.indexOf('Brush') === -1 ? this.bandPadding : 1)
8246
8453
  // let barAdjustment =
8247
8454
  // (this.options.data[xAxis.replace('Brush', '')].step * xIndex) +
8248
8455
  // this.options.groupPadding
8249
8456
  // // (xAxis.indexOf('Brush') === -1 ? this.bandPadding : 1)
8250
- if (this.customBottomRange.length > 0) {
8251
- output = this.customBottomRange[this[xAxis.replace('Brush', '') + 'Axis'].domain().indexOf(d.x.value)] + barAdjustment
8457
+ let barAdjustment = (this.options.data[xAxis].bandWidth * xIndex) + ((xAxis.indexOf('Brush') !== -1 ? this.brushBandPadding : this.bandPadding) / 2) + (xAxis.indexOf('Brush') !== -1 ? 1 : this.options.groupPadding)
8458
+ if (this[`custom${xAxis.toInitialCaps()}Range`].length > 0) {
8459
+ output = this[`custom${xAxis.toInitialCaps()}Range`][this[xAxis + 'Axis'].domain().indexOf(d.x.value)] + barAdjustment
8460
+ // output = this[`custom${xAxis.toInitialCaps().replace('Brush', '')}DetailRange`][this[xAxis + 'Axis'].domain().indexOf(d.x.value)]
8252
8461
  }
8253
8462
  else {
8254
8463
  output = this[`${xAxis}Axis`](this.parseX(d.x.value)) + barAdjustment
@@ -8259,11 +8468,10 @@ function getBarX (d, i, xAxis) {
8259
8468
  if (this.processedX[d.x.value].indexOf(d.y.tooltipLabel) === -1) {
8260
8469
  this.processedX[d.x.value].push(d.y.tooltipLabel)
8261
8470
  }
8262
- console.log(d.x.value, d.y.tooltipLabel, xIndex, i, barAdjustment, output)
8471
+ // console.log(d.x.value, d.y.tooltipLabel, xIndex, i, barAdjustment, output)
8263
8472
  }
8264
- else {
8265
- // output = this[`${xAxis}Axis`](this.parseX(d.x.value)) + (i * barWidth) + adjustment
8266
- output = this[`${xAxis}Axis`](this.parseX(d.x.value)) // + (i * barWidth)
8473
+ else {
8474
+ output = this[`custom${xAxis.toInitialCaps()}Range`][this[xAxis + 'Axis'].domain().indexOf(d.x.value)]
8267
8475
  }
8268
8476
  }
8269
8477
  if (isNaN(output)) {
@@ -8271,9 +8479,7 @@ function getBarX (d, i, xAxis) {
8271
8479
  }
8272
8480
  return output
8273
8481
  }
8274
- function getBarY (d, i, heightBounds, yAxis, xAxis) {
8275
- // let barWidth = this[`${xAxis}Axis`].bandwidth()
8276
- // let groupedBarWidth = (barWidth - 10) / this.options.data.series.length
8482
+ function getBarY (d, i, heightBounds, yAxis, xAxis) {
8277
8483
  let output
8278
8484
  if (this.options.orientation === 'horizontal') {
8279
8485
  if (this.options.grouping !== 'grouped') {
@@ -8285,7 +8491,10 @@ function getBarY (d, i, heightBounds, yAxis, xAxis) {
8285
8491
  }
8286
8492
  else {
8287
8493
  if (this.options.grouping === 'stacked') {
8288
- output = heightBounds - this[`${yAxis}Axis`](d.y.accumulative)
8494
+ let accH = getBarHeight.call(this, {x: d.x, y: { value: d.y.accumulative }}, i, heightBounds, yAxis, xAxis)
8495
+ let h = getBarHeight.call(this, d, i, heightBounds, yAxis, xAxis)
8496
+ // output = heightBounds - this[`${yAxis}Axis`](d.y.accumulative)
8497
+ output = (this[`${yAxis}Axis`](0)) - ((accH + h) * (d.y.accumulative < 0 ? 0 : 1))
8289
8498
  }
8290
8499
  else {
8291
8500
  let h = getBarHeight.call(this, d, i, heightBounds, yAxis, xAxis)
@@ -8365,12 +8574,12 @@ let bars = this.barLayer.selectAll(`.bar_${key}`)
8365
8574
  }
8366
8575
  renderLabels (series, index) {
8367
8576
  /* global series index d3 WebsyDesigns */
8368
- let xAxis = 'bottomAxis'
8369
- let yAxis = 'leftAxis'
8577
+ let xAxis = 'bottom'
8578
+ let yAxis = 'left'
8370
8579
  let that = this
8371
8580
  if (this.options.orientation === 'horizontal') {
8372
- xAxis = 'leftAxis'
8373
- yAxis = 'bottomAxis'
8581
+ xAxis = 'left'
8582
+ yAxis = 'bottom'
8374
8583
  }
8375
8584
  if (this.options.showLabels === true || series.showLabels === true) {
8376
8585
  // need to add logic to handle positioning options
@@ -8460,6 +8669,9 @@ if (this.options.showLabels === true || series.showLabels === true) {
8460
8669
  if (that.plotheight - getLabelX.call(that, d) < (that.options.labelSize || that.options.fontSize)) {
8461
8670
  this.setAttribute('y', +(this.getAttribute('y')) + 8)
8462
8671
  }
8672
+ if (series.labelPosition !== 'outside') {
8673
+ this.setAttribute('fill', that.options.labelColor || WebsyDesigns.WebsyUtils.getLightDark(d.y.color || d.color || series.color))
8674
+ }
8463
8675
  }
8464
8676
  })
8465
8677
  }
@@ -8474,19 +8686,28 @@ function getLabelX (d, labelPosition = 'inside') {
8474
8686
  }
8475
8687
  }
8476
8688
  else {
8477
- return this[xAxis](this.parseX(d.x.value)) + (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2)
8689
+ // return this[xAxis](this.parseX(d.x.value)) + (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2)
8690
+ let xIndex = this[xAxis + 'Axis'].domain().indexOf(d.x.value)
8691
+ let xPos = this[`custom${xAxis.toInitialCaps()}Range`][xIndex]
8692
+ if (this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1]) {
8693
+ xPos = xPos + ((this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1] - xPos) / 2)
8694
+ }
8695
+ return xPos
8478
8696
  }
8479
8697
  }
8480
8698
  function getLabelY (d, labelPosition = 'inside') {
8481
8699
  if (this.options.orientation === 'horizontal') {
8482
- return this[xAxis](this.parseX(d.x.value)) + (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2)
8700
+ return this[xAxis + 'Axis'](this.parseX(d.x.value)) + (this.options.data[xAxis].bandWidth / 2)
8483
8701
  }
8484
8702
  else {
8485
8703
  if (this.options.grouping === 'stacked') {
8486
- return this[yAxis](d.y.accumulative) + (this[yAxis](d.y.value) / (labelPosition === 'inside' ? 2 : 1))
8704
+ let accH = (this[`${yAxis}Axis`](0)) - this[`${yAxis}Axis`](Math.abs(d.y.accumulative))
8705
+ let h = (this[`${yAxis}Axis`](0)) - this[`${yAxis}Axis`](Math.abs(d.y.value))
8706
+ return (this[`${yAxis}Axis`](0)) - ((accH + h - (labelPosition === 'inside' ? h / 2 : 0)) * (d.y.accumulative < 0 ? 0 : 1))
8707
+ // return (this[`${yAxis}Axis`](0)) - (this[yAxis + 'Axis'](d.y.accumulative) - (this[yAxis + 'Axis'](d.y.value))) // / (labelPosition === 'inside' ? 2 : 1)))
8487
8708
  }
8488
8709
  else {
8489
- return this[yAxis](isNaN(d.y.value) ? 0 : d.y.value) - (this.options.labelSize || this.options.fontSize)
8710
+ return this[yAxis + 'Axis'](isNaN(d.y.value) ? 0 : d.y.value) - (this.options.labelSize || this.options.fontSize)
8490
8711
  }
8491
8712
  }
8492
8713
  }
@@ -8502,13 +8723,19 @@ const drawLine = (xAxis, yAxis, curveStyle) => {
8502
8723
  return this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)
8503
8724
  }
8504
8725
  else {
8505
- let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8506
- return this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment
8726
+ let xIndex = this[xAxis + 'Axis'].domain().indexOf(d.x.value)
8727
+ let xPos = this[`custom${xAxis.toInitialCaps()}Range`][xIndex]
8728
+ if (this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1]) {
8729
+ xPos = xPos + ((this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1] - xPos) / 2)
8730
+ }
8731
+ // let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this.options.data[xAxis].bandWidth / 2
8732
+ // return this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment
8733
+ return xPos
8507
8734
  }
8508
8735
  })
8509
8736
  .y(d => {
8510
8737
  if (this.options.orientation === 'horizontal') {
8511
- let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8738
+ let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this.options.data[xAxis].bandWidth / 2
8512
8739
  return this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment
8513
8740
  }
8514
8741
  else {
@@ -8543,7 +8770,7 @@ lines
8543
8770
  .style('stroke-width', series.lineWidth || this.options.lineWidth)
8544
8771
  // .attr('id', `line_${series.key}`)
8545
8772
  // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8546
- .attr('stroke', series.color)
8773
+ .attr('stroke', d => d[0].y.color || series.color)
8547
8774
  .attr('fill', 'transparent')
8548
8775
  .transition(this.transition)
8549
8776
  .attr('d', d => drawLine(xAxis, yAxis, series.curveStyle)(d))
@@ -8554,7 +8781,7 @@ lines.enter().append('path')
8554
8781
  .attr('id', `line_${series.key}`)
8555
8782
  // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8556
8783
  .style('stroke-width', series.lineWidth || this.options.lineWidth)
8557
- .attr('stroke', series.color)
8784
+ .attr('stroke', d => d[0].y.color || series.color)
8558
8785
  .attr('fill', 'transparent')
8559
8786
  // .transition(this.transition)
8560
8787
  .style('stroke-opacity', 1)
@@ -8677,12 +8904,25 @@ symbols
8677
8904
  .attr('fill', series.fillSymbols ? series.color : 'white')
8678
8905
  .attr('stroke', series.color)
8679
8906
  .attr('transform', d => {
8680
- let adjustment = (this.options.data[xAxis].scale === 'Time' || this.options.data[xAxis].scale === 'Linear') ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8907
+ // let adjustment = (this.options.data[xAxis].scale === 'Time' || this.options.data[xAxis].scale === 'Linear') ? 0 : this.options.data[xAxis].bandWidth / 2
8908
+ // if (this.options.orientation === 'horizontal') {
8909
+ // return `translate(${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)}, ${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment})`
8910
+ // }
8911
+ // else {
8912
+ // return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8913
+ // }
8914
+ let xIndex = this[xAxis + 'Axis'].domain().indexOf(d.x.value)
8915
+ let xPos = this[`custom${xAxis.toInitialCaps()}Range`][xIndex]
8916
+ if (this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1]) {
8917
+ xPos = xPos + ((this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1] - xPos) / 2)
8918
+ }
8919
+ let adjustment = (this.options.data[xAxis].scale === 'Time' || this.options.data[xAxis].scale === 'Linear') ? 0 : this.options.data[xAxis].bandWidth / 2
8681
8920
  if (this.options.orientation === 'horizontal') {
8682
- return `translate(${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)}, ${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment})`
8921
+ return `translate(${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)}, ${xPos})`
8683
8922
  }
8684
8923
  else {
8685
- return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8924
+ // return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8925
+ return `translate(${xPos}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8686
8926
  }
8687
8927
  })
8688
8928
  // Enter
@@ -8694,12 +8934,18 @@ symbols.enter()
8694
8934
  .attr('stroke', series.color)
8695
8935
  .attr('class', d => { return `symbol symbol_${series.key}` })
8696
8936
  .attr('transform', d => {
8697
- let adjustment = (this.options.data[xAxis].scale === 'Time' || this.options.data[xAxis].scale === 'Linear') ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8937
+ let xIndex = this[xAxis + 'Axis'].domain().indexOf(d.x.value)
8938
+ let xPos = this[`custom${xAxis.toInitialCaps()}Range`][xIndex]
8939
+ if (this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1]) {
8940
+ xPos = xPos + ((this[`custom${xAxis.toInitialCaps()}Range`][xIndex + 1] - xPos) / 2)
8941
+ }
8942
+ let adjustment = (this.options.data[xAxis].scale === 'Time' || this.options.data[xAxis].scale === 'Linear') ? 0 : this.options.data[xAxis].bandWidth / 2
8698
8943
  if (this.options.orientation === 'horizontal') {
8699
- return `translate(${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)}, ${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment})`
8944
+ return `translate(${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)}, ${xPos})`
8700
8945
  }
8701
8946
  else {
8702
- return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8947
+ // return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8948
+ return `translate(${xPos}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8703
8949
  }
8704
8950
  })
8705
8951
 
@@ -9366,3 +9612,9 @@ function usePayPal () {
9366
9612
  pps.src = '//www.paypal.com/sdk/js'
9367
9613
  document.getElementsByTagName('body')[0].appendChild(pps)
9368
9614
  }
9615
+
9616
+ String.prototype.toInitialCaps = function () {
9617
+ let letters = this.split('')
9618
+ let initial = letters.shift().toUpperCase()
9619
+ return initial + letters.join('')
9620
+ }