@websy/websy-designs 1.4.38 → 1.5.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.
@@ -6962,6 +6962,7 @@ class WebsyChart {
6962
6962
  lineWidth: 2,
6963
6963
  forceZero: true,
6964
6964
  grouping: 'grouped',
6965
+ groupPadding: 3,
6965
6966
  fontSize: 14,
6966
6967
  symbolSize: 20,
6967
6968
  showTrackingLine: true,
@@ -6970,7 +6971,8 @@ class WebsyChart {
6970
6971
  legendPosition: 'bottom',
6971
6972
  tooltipWidth: 200,
6972
6973
  brushHeight: 50,
6973
- minBandWidth: 30
6974
+ minBandWidth: 30,
6975
+ allowUnevenBands: true
6974
6976
  }
6975
6977
  this.elementId = elementId
6976
6978
  this.options = Object.assign({}, DEFAULTS, options)
@@ -6995,25 +6997,43 @@ class WebsyChart {
6995
6997
  xAxis += 'Brush'
6996
6998
  }
6997
6999
  xAxis += 'Axis'
6998
- let width = this[xAxis].step()
6999
7000
  let output
7000
- let domain = [...this[xAxis].domain()]
7001
- if (this.options.orientation === 'horizontal') {
7002
- domain = domain.reverse()
7003
- }
7004
- for (let j = 0; j < domain.length; j++) {
7005
- let breakA = this[xAxis](domain[j]) - (width / 2)
7006
- let breakB = breakA + width
7007
- if (input > breakA && input <= breakB) {
7008
- output = j
7009
- break
7001
+ let width = this.options.data[xAxis.replace('Brush', '').replace('Axis', '')].bandWidth
7002
+ if (this.customBottomRange) {
7003
+ for (let index = 0; index < this.customBottomRange.length; index++) {
7004
+ if (input > this.customBottomRange[index]) {
7005
+ if (this.customBottomRange[index + 1]) {
7006
+ if (input < this.customBottomRange[index + 1]) {
7007
+ output = index
7008
+ break
7009
+ }
7010
+ }
7011
+ else {
7012
+ output = index
7013
+ break
7014
+ }
7015
+ }
7010
7016
  }
7011
- }
7017
+ }
7018
+ else {
7019
+ let domain = [...this[xAxis].domain()]
7020
+ if (this.options.orientation === 'horizontal') {
7021
+ domain = domain.reverse()
7022
+ }
7023
+ for (let j = 0; j < domain.length; j++) {
7024
+ let breakA = this[xAxis](domain[j]) - (width / 2)
7025
+ let breakB = breakA + width
7026
+ if (input > breakA && input <= breakB) {
7027
+ output = j
7028
+ break
7029
+ }
7030
+ }
7031
+ }
7012
7032
  return output
7013
7033
  }
7014
7034
  let that = this
7015
7035
  this.brushed = function (event) {
7016
- console.log('brushing', event)
7036
+ console.log('brushing', event)
7017
7037
  that.brushedDomain = []
7018
7038
  let xAxis = 'bottom'
7019
7039
  let xAxisCaps = 'Bottom'
@@ -7021,6 +7041,9 @@ class WebsyChart {
7021
7041
  xAxis = 'left'
7022
7042
  xAxisCaps = 'Left'
7023
7043
  }
7044
+ if (!that[`${xAxis}Axis`]) {
7045
+ return
7046
+ }
7024
7047
  if (!that[`${xAxis}Axis`].invert) {
7025
7048
  that[`${xAxis}Axis`].invert = that.invertOverride
7026
7049
  }
@@ -7210,7 +7233,12 @@ else {
7210
7233
  }
7211
7234
  this.options.data.series.forEach(s => {
7212
7235
  if (this.options.data[xData].scale !== 'Time') {
7213
- xPoint = this[xAxis](this.parseX(xLabel))
7236
+ if (this.customBottomRange && this.customBottomRange.length > 0) {
7237
+ xPoint = this.customBottomRange[x0] + ((this.customBottomRange[x0 + 1] - this.customBottomRange[x0]) / 2)
7238
+ }
7239
+ else {
7240
+ xPoint = this[xAxis](this.parseX(xLabel))
7241
+ }
7214
7242
  s.data.forEach(d => {
7215
7243
  if (d.x.value === xLabel) {
7216
7244
  if (!tooltipTitle) {
@@ -7299,7 +7327,7 @@ else {
7299
7327
  onLeft: xPoint > this.plotWidth / 2
7300
7328
  }
7301
7329
  if (xPoint > this.plotWidth / 2) {
7302
- posOptions.left = xPoint - this.options.tooltipWidth + this.options.margin.left + this.options.margin.axisLeft + 15
7330
+ posOptions.left = xPoint - this.options.tooltipWidth - 15 // + this.options.margin.left + this.options.margin.axisLeft + 15)
7303
7331
  if (this.options.data[xData].scale !== 'Time') {
7304
7332
  // posOptions.left -= (this[xAxis].bandwidth())
7305
7333
  posOptions.left += 10
@@ -7308,7 +7336,7 @@ else {
7308
7336
  else {
7309
7337
  posOptions.left = xPoint + this.options.margin.left + this.options.margin.axisLeft + 15
7310
7338
  if (this.options.data[xData].scale !== 'Time') {
7311
- posOptions.left += (this[xAxis].bandwidth() / 2)
7339
+ posOptions.left += (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2)
7312
7340
  }
7313
7341
  }
7314
7342
  posOptions.top = this.options.margin.top + this.options.margin.axisTop
@@ -7316,7 +7344,7 @@ else {
7316
7344
  delete posOptions.onLeft
7317
7345
  let adjuster = 0
7318
7346
  if (this.options.data[xData].scale !== 'Time') {
7319
- adjuster = (this[xAxis].bandwidth() / 2) // - this.options.margin.top
7347
+ adjuster = (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2) // - this.options.margin.top
7320
7348
  }
7321
7349
  posOptions = {
7322
7350
  width: this.options.tooltipWidth,
@@ -7337,8 +7365,8 @@ else {
7337
7365
  // else {
7338
7366
  // xPoint = x0
7339
7367
  // }
7340
- if (this.options.data[xData].scale !== 'Time') {
7341
- xPoint += (this[xAxis].bandwidth() / 2) // - this.options.margin.top
7368
+ if (this.options.data[xData].scale !== 'Time' && this.customBottomRange.length === 0) {
7369
+ xPoint += (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2) // - this.options.margin.top
7342
7370
  }
7343
7371
  let trackingXStart = xPoint
7344
7372
  let trackingXEnd = xPoint
@@ -7407,6 +7435,7 @@ if (!this.options.data) {
7407
7435
  // tell the user no data has been provided
7408
7436
  }
7409
7437
  else {
7438
+ this.processedX = {}
7410
7439
  this.transition = d3.transition().duration(this.options.transitionDuration)
7411
7440
  if (this.options.data.bottom.scale && this.options.data.bottom.scale === 'Time') {
7412
7441
  this.parseX = function (input) {
@@ -7453,7 +7482,13 @@ else {
7453
7482
  // establish the space and size for the legend
7454
7483
  // the legend gets rendered so that we can get its actual size
7455
7484
  if (this.options.showLegend === true) {
7456
- let legendData = this.options.data.series.map((s, i) => ({value: s.label || s.key, color: s.color || this.options.colors[i % this.options.colors.length]}))
7485
+ let legendData = []
7486
+ if (this.options.legendData && this.options.legendData.length > 0) {
7487
+ legendData = this.options.legendData
7488
+ }
7489
+ else {
7490
+ this.options.data.series.map((s, i) => ({value: s.label || s.key, color: s.color || this.options.colors[i % this.options.colors.length]}))
7491
+ }
7457
7492
  if (this.options.legendPosition === 'top' || this.options.legendPosition === 'bottom') {
7458
7493
  this.legendArea.style('width', '100%')
7459
7494
  this.legend.options.align = 'center'
@@ -7625,18 +7660,30 @@ else {
7625
7660
  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
7626
7661
  this.brushNeeded = false
7627
7662
  if (this.options.orientation === 'vertical') {
7628
- if (this.options.maxBandWidth) {
7629
- this.plotWidth = Math.min(this.plotWidth, (this.options.data.bottom.data || []).length * this.options.maxBandWidth)
7663
+ this.options.data.bottom.totalValueCount = this.options.data.bottom.data.reduce((a, b) => {
7664
+ if (typeof b.valueCount === 'undefined') {
7665
+ return a + 1
7666
+ }
7667
+ return a + b.valueCount
7668
+ }, 0)
7669
+ if (this.options.maxBandWidth) {
7670
+ this.plotWidth = Math.min(this.plotWidth, (this.options.data.bottom.totalValueCount) * this.options.maxBandWidth)
7630
7671
  }
7631
7672
  // some if to check if brushing is needed
7632
- if (this.plotWidth / this.options.data.bottom.data.length < this.options.minBandWidth) {
7673
+ if (this.plotWidth / this.options.data.bottom.totalValueCount < this.options.minBandWidth) {
7633
7674
  this.brushNeeded = true
7634
7675
  this.plotHeight -= this.options.brushHeight
7635
7676
  }
7636
7677
  }
7637
7678
  else {
7638
7679
  // some if to check if brushing is needed
7639
- if (this.plotHeight / this.options.data.left.data.length < this.options.minBandWidth) {
7680
+ this.options.data.left.totalValueCount = this.options.data.left.data.reduce((a, b) => {
7681
+ if (typeof b.valueCount === 'undefined') {
7682
+ return a + 1
7683
+ }
7684
+ return a + b.valueCount
7685
+ }, 0)
7686
+ if (this.plotHeight / this.options.data.left.totalValueCount < this.options.minBandWidth) {
7640
7687
  this.brushNeeded = true
7641
7688
  this.plotWidth -= this.options.brushHeight
7642
7689
  }
@@ -7691,14 +7738,39 @@ else {
7691
7738
  // this.tooltip.transform(this.options.margin.left + this.options.margin.axisLeft, this.options.margin.top + this.options.margin.axisTop)
7692
7739
  // Configure the bottom axis
7693
7740
  let bottomDomain = this.createDomain('bottom')
7694
- let bottomBrushDomain = this.createDomain('bottom', true)
7741
+ let bottomBrushDomain = this.createDomain('bottom', true)
7742
+ let bottomRange = [0, this.plotWidth]
7743
+ this.customBottomRange = []
7744
+ if (this.options.allowUnevenBands === true) {
7745
+ 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') {
7746
+ let acc = 0
7747
+ this.customBottomRange = [0, ...this.options.data.bottom.data.map(d => {
7748
+ acc += d.valueCount
7749
+ return (this.plotWidth / this.options.data.bottom.totalValueCount) * acc
7750
+ })]
7751
+ }
7752
+ }
7753
+ this.options.data.bottom.step = this.plotWidth / this.options.data.bottom.totalValueCount
7754
+ this.options.data.bottom.bandWidth = this.options.data.bottom.step
7755
+ if (this.options.data.bottom.padding) {
7756
+ this.totalPadding = this.plotWidth * this.options.data.bottom.padding
7757
+ let rangeLength = bottomDomain.length
7758
+ if (this.customBottomRange.length > 0) {
7759
+ rangeLength = this.customBottomRange.length
7760
+ }
7761
+ this.bandPadding = (this.totalPadding / (rangeLength)) / 2
7762
+ this.options.data.bottom.bandWidth = (this.plotWidth - this.totalPadding) / this.options.data.bottom.totalValueCount
7763
+ }
7764
+ if (this.options.grouping === 'grouped' && this.options.data.series.length > 1) {
7765
+ this.options.data.bottom.bandWidth = this.options.data.bottom.bandWidth - (this.options.groupPadding * 2)
7766
+ }
7695
7767
  this.bottomAxis = d3[`scale${this.options.data.bottom.scale || 'Band'}`]()
7696
7768
  .domain(bottomDomain)
7697
- .range([0, this.plotWidth])
7769
+ .range(bottomRange)
7698
7770
  if (!this.brushInitialized) {
7699
7771
  this.bottomBrushAxis = d3[`scale${this.options.data.bottom.scale || 'Band'}`]()
7700
7772
  .domain(bottomBrushDomain)
7701
- .range([0, this.plotWidth])
7773
+ .range(bottomRange)
7702
7774
  }
7703
7775
  if (this.bottomAxis.nice) {
7704
7776
  // this.bottomAxis.nice()
@@ -7870,6 +7942,10 @@ else {
7870
7942
  .style('text-anchor', `${((this.options.data.bottom && this.options.data.bottom.rotate) || 0) === 0 ? 'middle' : 'end'}`)
7871
7943
  .style('transform-origin', ((this.options.data.bottom && this.options.data.bottom.rotate) || 0) === 0 ? '0 0' : `0 ${((this.options.data.bottom && this.options.data.bottom.fontSize) || this.options.fontSize)}px`)
7872
7944
  }
7945
+ if (this.customBottomRange.length > 0) {
7946
+ this.bottomAxisLayer.selectAll('g')
7947
+ .attr('transform', (d, i) => `translate(${this.customBottomRange[i] + ((this.customBottomRange[i + 1] - this.customBottomRange[i]) / 2)}, 0)`)
7948
+ }
7873
7949
  }
7874
7950
  // Configure the left axis
7875
7951
  let leftDomain = this.createDomain('left')
@@ -8015,6 +8091,8 @@ this.options.data.series.forEach((series, index) => {
8015
8091
  this.renderLabels(series, index)
8016
8092
  this.renderedKeys[series.key] = series.type
8017
8093
  })
8094
+ this.refLineLayer.selectAll('.reference-line').remove()
8095
+ this.refLineLayer.selectAll('.reference-line-label').remove()
8018
8096
  if (this.options.refLines && this.options.refLines.length > 0) {
8019
8097
  this.options.refLines.forEach(l => this.renderRefLine(l))
8020
8098
  }
@@ -8026,21 +8104,21 @@ const drawArea = (xAxis, yAxis, curveStyle) => {
8026
8104
  return d3
8027
8105
  .area()
8028
8106
  .x(d => {
8029
- return this[xAxis](this.parseX(d.x.value))
8107
+ return this[`${xAxis}Axis`](this.parseX(d.x.value))
8030
8108
  })
8031
8109
  .y0(d => {
8032
- return this[yAxis](0)
8110
+ return this[`${yAxis}Axis`](0)
8033
8111
  })
8034
8112
  .y1(d => {
8035
- return this[yAxis](isNaN(d.y.value) ? 0 : d.y.value)
8113
+ return this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)
8036
8114
  })
8037
8115
  .curve(d3[curveStyle || this.options.curveStyle])
8038
8116
  }
8039
- let xAxis = 'bottomAxis'
8040
- let yAxis = series.axis === 'secondary' ? 'rightAxis' : 'leftAxis'
8041
- if (this.options.orienation === 'horizontal') {
8042
- xAxis = series.axis === 'secondary' ? 'rightAxis' : 'leftAxis'
8043
- yAxis = 'bottomAxis'
8117
+ let xAxis = 'bottom'
8118
+ let yAxis = series.axis === 'secondary' ? 'right' : 'left'
8119
+ if (this.options.orientation === 'horizontal') {
8120
+ xAxis = series.axis === 'secondary' ? 'right' : 'left'
8121
+ yAxis = 'bottom'
8044
8122
  }
8045
8123
  let areas = this.areaLayer.selectAll(`.area_${series.key}`)
8046
8124
  .data([series.data])
@@ -8063,7 +8141,7 @@ areas.enter().append('path')
8063
8141
  .attr('d', d => drawArea(xAxis, yAxis, series.curveStyle)(d))
8064
8142
  .attr('class', `area_${series.key}`)
8065
8143
  .attr('id', `area_${series.key}`)
8066
- // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8144
+ .attr('transform', 'translate(' + (this.options.data[xAxis].scale === 'Time' ? 0 : this.options.data[`${xAxis}Axis`].bandWidth / 2) + ',0)')
8067
8145
  // .style('stroke-width', series.lineWidth || this.options.lineWidth)
8068
8146
  .attr('fill', series.color)
8069
8147
  // .style('fill-opacity', 0)
@@ -8086,15 +8164,14 @@ if (this.options.orientation === 'horizontal') {
8086
8164
  // if (this.options.data.series.length > 1 && this.options.grouping === 'grouped') {
8087
8165
  // barWidth = barWidth / this.options.data.series.length - 4
8088
8166
  // }
8089
- function getBarHeight (d, i, heightBounds, yAxis, xAxis) {
8090
- let barWidth = this[`${xAxis}Axis`].bandwidth()
8091
- let groupedBarWidth = (barWidth - 10) / this.options.data.series.length
8167
+ function getBarHeight (d, i, heightBounds, yAxis, xAxis) {
8092
8168
  let output
8093
8169
  if (this.options.orientation === 'horizontal') {
8094
- output = barWidth
8170
+ output = this.options.data[xAxis.replace('Brush', '')].bandWidth
8095
8171
  }
8096
8172
  else {
8097
- if (!getBarX.call(this, d, i, xAxis)) {
8173
+ let x = getBarX.call(this, d, i, xAxis)
8174
+ if (typeof x === 'undefined' || x === null) {
8098
8175
  return null
8099
8176
  }
8100
8177
  output = (this[`${yAxis}Axis`](0)) - this[`${yAxis}Axis`](Math.abs(d.y.value))
@@ -8104,26 +8181,19 @@ function getBarHeight (d, i, heightBounds, yAxis, xAxis) {
8104
8181
  }
8105
8182
  return output
8106
8183
  }
8107
- function getBarWidth (d, i, xAxis) {
8108
- let barWidth = this[`${xAxis}Axis`].bandwidth()
8109
- let groupedBarWidth = (barWidth - (xAxis.indexOf('Brush') === -1 ? 10 : 2)) / this.options.data.series.length
8184
+ function getBarWidth (d, i, xAxis) {
8110
8185
  let output
8111
- if (this.options.orientation === 'horizontal') {
8112
- // let width = this[`${yAxis}Axis`](d.y.value)
8186
+ if (this.options.orientation === 'horizontal') {
8113
8187
  let width = (this[`${yAxis}Axis`](0)) - this[`${yAxis}Axis`](Math.abs(d.y.value))
8114
8188
  acummulativeY[d.y.index] += width
8115
8189
  output = width
8116
8190
  }
8117
8191
  else {
8118
- if (!getBarX.call(this, d, i, xAxis)) {
8192
+ let x = getBarX.call(this, d, i, xAxis)
8193
+ if (typeof x === 'undefined' || x === null) {
8119
8194
  return null
8120
- }
8121
- if (this.options.grouping === 'grouped') {
8122
- output = Math.max(1, groupedBarWidth)
8123
- }
8124
- else {
8125
- output = Math.max(1, barWidth)
8126
- }
8195
+ }
8196
+ output = Math.max(1, this.options.data[xAxis.replace('Brush', '')].bandWidth)
8127
8197
  }
8128
8198
  if (isNaN(output)) {
8129
8199
  return 0
@@ -8131,8 +8201,11 @@ function getBarWidth (d, i, xAxis) {
8131
8201
  return output
8132
8202
  }
8133
8203
  function getBarX (d, i, xAxis) {
8134
- let barWidth = this[`${xAxis}Axis`].bandwidth()
8135
- let groupedBarWidth = (barWidth - (xAxis.indexOf('Brush') === -1 ? 10 : 2)) / this.options.data.series.length
8204
+ // let barWidth = this.plotWidth / this.options.data[xAxis.replace('Brush', '')].totalValueCount
8205
+ // if (this.options.data[xAxis.replace('Brush', '')].padding) {
8206
+ // barWidth = barWidth - (barWidth * this.options.data[xAxis.replace('Brush', '')].padding)
8207
+ // }
8208
+ // let groupedBarWidth = (barWidth - (xAxis.indexOf('Brush') === -1 ? 10 : 2)) / this.options.data[xAxis.replace('Brush', '')].totalValueCount
8136
8209
  let output
8137
8210
  if (this.options.orientation === 'horizontal') {
8138
8211
  if (this.options.grouping === 'stacked') {
@@ -8149,10 +8222,34 @@ function getBarX (d, i, xAxis) {
8149
8222
  }
8150
8223
  }
8151
8224
  else {
8152
- let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8153
- if (this.options.grouping === 'grouped') {
8154
- let barAdjustment = groupedBarWidth * index + (xAxis.indexOf('Brush') === -1 ? 5 : 1) // + (index > 0 ? 4 : 0)
8155
- output = this[`${xAxis}Axis`](this.parseX(d.x.value)) + barAdjustment
8225
+ // let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this.options.data[xAxis.replace('Brush', '')].bandWidth / 2
8226
+ let adjustment = this.customBottomRange[i] + (i * this.options.data[xAxis.replace('Brush', '')].bandWidth)
8227
+ if (this.options.grouping === 'grouped') {
8228
+ let xIndex = 0
8229
+ if (this.processedX[d.x.value]) {
8230
+ xIndex = Math.max(0, this.processedX[d.x.value].indexOf(d.y.tooltipLabel))
8231
+ }
8232
+ let barAdjustment =
8233
+ (this.options.data[xAxis.replace('Brush', '')].bandWidth * xIndex) +
8234
+ (xIndex * this.options.groupPadding * 2) + this.options.groupPadding +
8235
+ (xAxis.indexOf('Brush') === -1 ? this.bandPadding : 1)
8236
+ // let barAdjustment =
8237
+ // (this.options.data[xAxis.replace('Brush', '')].step * xIndex) +
8238
+ // this.options.groupPadding
8239
+ // // (xAxis.indexOf('Brush') === -1 ? this.bandPadding : 1)
8240
+ if (this.customBottomRange.length > 0) {
8241
+ output = this.customBottomRange[this[xAxis.replace('Brush', '') + 'Axis'].domain().indexOf(d.x.value)] + barAdjustment
8242
+ }
8243
+ else {
8244
+ output = this[`${xAxis}Axis`](this.parseX(d.x.value)) + barAdjustment
8245
+ }
8246
+ if (!this.processedX[d.x.value]) {
8247
+ this.processedX[d.x.value] = []
8248
+ }
8249
+ if (this.processedX[d.x.value].indexOf(d.y.tooltipLabel) === -1) {
8250
+ this.processedX[d.x.value].push(d.y.tooltipLabel)
8251
+ }
8252
+ console.log(d.x.value, d.y.tooltipLabel, xIndex, i, barAdjustment, output)
8156
8253
  }
8157
8254
  else {
8158
8255
  // output = this[`${xAxis}Axis`](this.parseX(d.x.value)) + (i * barWidth) + adjustment
@@ -8165,15 +8262,15 @@ function getBarX (d, i, xAxis) {
8165
8262
  return output
8166
8263
  }
8167
8264
  function getBarY (d, i, heightBounds, yAxis, xAxis) {
8168
- let barWidth = this[`${xAxis}Axis`].bandwidth()
8169
- let groupedBarWidth = (barWidth - 10) / this.options.data.series.length
8265
+ // let barWidth = this[`${xAxis}Axis`].bandwidth()
8266
+ // let groupedBarWidth = (barWidth - 10) / this.options.data.series.length
8170
8267
  let output
8171
8268
  if (this.options.orientation === 'horizontal') {
8172
8269
  if (this.options.grouping !== 'grouped') {
8173
8270
  output = this[`${xAxis}Axis`](this.parseX(d.x.value))
8174
8271
  }
8175
8272
  else {
8176
- output = this[`${xAxis}Axis`](this.parseX(d.x.value)) + ((d.y.index || i) * barWidth)
8273
+ output = this[`${xAxis}Axis`](this.parseX(d.x.value)) + ((d.y.index || i) * this.options.data[xAxis.replace('Brush', '')].barWidth)
8177
8274
  }
8178
8275
  }
8179
8276
  else {
@@ -8367,12 +8464,12 @@ function getLabelX (d, labelPosition = 'inside') {
8367
8464
  }
8368
8465
  }
8369
8466
  else {
8370
- return this[xAxis](this.parseX(d.x.value)) + (this[xAxis].bandwidth() / 2)
8467
+ return this[xAxis](this.parseX(d.x.value)) + (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2)
8371
8468
  }
8372
8469
  }
8373
8470
  function getLabelY (d, labelPosition = 'inside') {
8374
8471
  if (this.options.orientation === 'horizontal') {
8375
- return this[xAxis](this.parseX(d.x.value)) + (this[xAxis].bandwidth() / 2)
8472
+ return this[xAxis](this.parseX(d.x.value)) + (this.options.data[xAxis.replace('Axis', '')].bandWidth / 2)
8376
8473
  }
8377
8474
  else {
8378
8475
  if (this.options.grouping === 'stacked') {
@@ -8391,23 +8488,34 @@ const drawLine = (xAxis, yAxis, curveStyle) => {
8391
8488
  return d3
8392
8489
  .line()
8393
8490
  .x(d => {
8394
- let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8395
- return this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment
8491
+ if (this.options.orientation === 'horizontal') {
8492
+ return this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)
8493
+ }
8494
+ else {
8495
+ let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8496
+ return this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment
8497
+ }
8396
8498
  })
8397
8499
  .y(d => {
8398
- return this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)
8500
+ if (this.options.orientation === 'horizontal') {
8501
+ let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8502
+ return this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment
8503
+ }
8504
+ else {
8505
+ return this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)
8506
+ }
8399
8507
  })
8400
8508
  .curve(d3[curveStyle || this.options.curveStyle])
8401
8509
  }
8402
8510
  let xAxis = 'bottom'
8403
8511
  let yAxis = series.axis === 'secondary' ? 'right' : 'left'
8404
- if (this.options.orienation === 'horizontal') {
8512
+ if (this.options.orientation === 'horizontal') {
8405
8513
  xAxis = series.axis === 'secondary' ? 'right' : 'left'
8406
8514
  yAxis = 'bottom'
8407
8515
  }
8408
8516
  let xBrushAxis = 'bottomBrush'
8409
8517
  let yBrushAxis = 'leftBrush'
8410
- if (this.options.orienation === 'horizontal') {
8518
+ if (this.options.orientation === 'horizontal') {
8411
8519
  xBrushAxis = 'leftBrush'
8412
8520
  yBrushAxis = 'bottomBrush'
8413
8521
  }
@@ -8493,8 +8601,6 @@ if (this.options.orientation === 'horizontal') {
8493
8601
  xAttr = 'y'
8494
8602
  length = this.plotHeight
8495
8603
  }
8496
- this.refLineLayer.selectAll('.reference-line').remove()
8497
- this.refLineLayer.selectAll('.reference-line-label').remove()
8498
8604
  this.refLineLayer
8499
8605
  .append('line')
8500
8606
  .attr(`${yAttr}1`, this[`${yAxis}Axis`](data.value))
@@ -8543,7 +8649,7 @@ const drawSymbol = (size) => {
8543
8649
  }
8544
8650
  let xAxis = 'bottom'
8545
8651
  let yAxis = series.axis === 'secondary' ? 'right' : 'left'
8546
- if (this.options.orienation === 'horizontal') {
8652
+ if (this.options.orientation === 'horizontal') {
8547
8653
  xAxis = series.axis === 'secondary' ? 'right' : 'left'
8548
8654
  yAxis = 'bottom'
8549
8655
  }
@@ -8561,8 +8667,13 @@ symbols
8561
8667
  .attr('fill', series.fillSymbols ? series.color : 'white')
8562
8668
  .attr('stroke', series.color)
8563
8669
  .attr('transform', d => {
8564
- let adjustment = this.options.data[xAxis].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8565
- return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8670
+ let adjustment = (this.options.data[xAxis].scale === 'Time' || this.options.data[xAxis].scale === 'Linear') ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8671
+ if (this.options.orientation === 'horizontal') {
8672
+ return `translate(${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)}, ${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment})`
8673
+ }
8674
+ else {
8675
+ return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8676
+ }
8566
8677
  })
8567
8678
  // Enter
8568
8679
  symbols.enter()
@@ -8573,8 +8684,13 @@ symbols.enter()
8573
8684
  .attr('stroke', series.color)
8574
8685
  .attr('class', d => { return `symbol symbol_${series.key}` })
8575
8686
  .attr('transform', d => {
8576
- let adjustment = this.options.data[xAxis].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8577
- return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8687
+ let adjustment = (this.options.data[xAxis].scale === 'Time' || this.options.data[xAxis].scale === 'Linear') ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8688
+ if (this.options.orientation === 'horizontal') {
8689
+ return `translate(${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)}, ${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment})`
8690
+ }
8691
+ else {
8692
+ return `translate(${this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment}, ${this[`${yAxis}Axis`](isNaN(d.y.value) ? 0 : d.y.value)})`
8693
+ }
8578
8694
  })
8579
8695
 
8580
8696
  }
@@ -8678,9 +8794,9 @@ if (el) {
8678
8794
  if (el) {
8679
8795
  el.classList.remove('has-error')
8680
8796
  }
8681
- // const chartEl = document.getElementById(`${this.elementId}_chartContainer`)
8682
- // chartEl.classList.remove('hidden')
8683
- this.svg.classed('hidden', false)
8797
+ if (this.svg) {
8798
+ this.svg.classed('hidden', false)
8799
+ }
8684
8800
  const containerEl = document.getElementById(`${this.elementId}_errorContainer`)
8685
8801
  if (containerEl) {
8686
8802
  containerEl.classList.remove('active')
@@ -8695,8 +8811,10 @@ if (el) {
8695
8811
  el.classList.add('has-error')
8696
8812
  }
8697
8813
  // const chartEl = document.getElementById(`${this.elementId}_chartContainer`)
8698
- // chartEl.classList.add('hidden')
8699
- this.svg.classed('hidden', true)
8814
+ // chartEl.classList.add('hidden')
8815
+ if (this.svg) {
8816
+ this.svg.classed('hidden', true)
8817
+ }
8700
8818
  const containerEl = document.getElementById(`${this.elementId}_errorContainer`)
8701
8819
  if (containerEl) {
8702
8820
  containerEl.classList.add('active')