Skip to content

Commit b31ce7f

Browse files
committed
zooming, panning on log scale - fixes #1446
1 parent 01f865c commit b31ce7f

File tree

8 files changed

+110
-24
lines changed

8 files changed

+110
-24
lines changed

samples/react/line/logarithmic-line.html

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,17 @@
210210
seriesName: 'Logarithmic',
211211
labels: {
212212
formatter: labelFormatter,
213+
style: {
214+
fontWeight: 900,
215+
colors: 'rgb(0, 143, 251)'
216+
}
217+
},
218+
title: {
219+
text: 'Logarithmic',
220+
style: {
221+
fontWeight: 900,
222+
color: 'rgb(0, 143, 251)'
223+
}
213224
}
214225
},
215226
{
@@ -219,7 +230,18 @@
219230
tickAmount: 4,
220231
seriesName: 'Linear',
221232
labels: {
222-
formatter: labelFormatter
233+
formatter: labelFormatter,
234+
style: {
235+
fontWeight: 900,
236+
colors: 'rgb(0, 227, 150)'
237+
}
238+
},
239+
title: {
240+
text: 'Linear',
241+
style: {
242+
fontWeight: 900,
243+
color: 'rgb(0, 227, 150)'
244+
}
223245
}
224246
}
225247
]

samples/source/line/logarithmic-line.xml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ yaxis: [
137137
seriesName: 'Logarithmic',
138138
labels: {
139139
formatter: labelFormatter,
140+
style: {
141+
fontWeight: 900,
142+
colors: 'rgb(0, 143, 251)'
143+
}
144+
},
145+
title: {
146+
text: 'Logarithmic',
147+
style: {
148+
fontWeight: 900,
149+
color: 'rgb(0, 143, 251)'
150+
}
140151
}
141152
},
142153
{
@@ -146,7 +157,18 @@ yaxis: [
146157
tickAmount: 4,
147158
seriesName: 'Linear',
148159
labels: {
149-
formatter: labelFormatter
160+
formatter: labelFormatter,
161+
style: {
162+
fontWeight: 900,
163+
colors: 'rgb(0, 227, 150)'
164+
}
165+
},
166+
title: {
167+
text: 'Linear',
168+
style: {
169+
fontWeight: 900,
170+
color: 'rgb(0, 227, 150)'
171+
}
150172
}
151173
}
152174
]

samples/vanilla-js/line/logarithmic-line.html

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@
193193
seriesName: 'Logarithmic',
194194
labels: {
195195
formatter: labelFormatter,
196+
style: {
197+
fontWeight: 900,
198+
colors: 'rgb(0, 143, 251)'
199+
}
200+
},
201+
title: {
202+
text: 'Logarithmic',
203+
style: {
204+
fontWeight: 900,
205+
color: 'rgb(0, 143, 251)'
206+
}
196207
}
197208
},
198209
{
@@ -202,7 +213,18 @@
202213
tickAmount: 4,
203214
seriesName: 'Linear',
204215
labels: {
205-
formatter: labelFormatter
216+
formatter: labelFormatter,
217+
style: {
218+
fontWeight: 900,
219+
colors: 'rgb(0, 227, 150)'
220+
}
221+
},
222+
title: {
223+
text: 'Linear',
224+
style: {
225+
fontWeight: 900,
226+
color: 'rgb(0, 227, 150)'
227+
}
206228
}
207229
}
208230
]

samples/vue/line/logarithmic-line.html

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,17 @@
213213
seriesName: 'Logarithmic',
214214
labels: {
215215
formatter: labelFormatter,
216+
style: {
217+
fontWeight: 900,
218+
colors: 'rgb(0, 143, 251)'
219+
}
220+
},
221+
title: {
222+
text: 'Logarithmic',
223+
style: {
224+
fontWeight: 900,
225+
color: 'rgb(0, 143, 251)'
226+
}
216227
}
217228
},
218229
{
@@ -222,7 +233,18 @@
222233
tickAmount: 4,
223234
seriesName: 'Linear',
224235
labels: {
225-
formatter: labelFormatter
236+
formatter: labelFormatter,
237+
style: {
238+
fontWeight: 900,
239+
colors: 'rgb(0, 227, 150)'
240+
}
241+
},
242+
title: {
243+
text: 'Linear',
244+
style: {
245+
fontWeight: 900,
246+
color: 'rgb(0, 227, 150)'
247+
}
226248
}
227249
}
228250
]

src/modules/CoreUtils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ class CoreUtils {
336336
}
337337

338338
// Some config objects can be array - and we need to extend them correctly
339-
static extendArrayProps(configInstance, options) {
339+
static extendArrayProps(configInstance, options, w) {
340340
if (options.yaxis) {
341-
options = configInstance.extendYAxis(options)
341+
options = configInstance.extendYAxis(options, w)
342342
}
343343
if (options.annotations) {
344344
if (options.annotations.yaxis) {

src/modules/Responsive.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@ export default class Responsive {
3939
if (width > largestBreakpoint) {
4040
let options = CoreUtils.extendArrayProps(
4141
config,
42-
w.globals.initialConfig
42+
w.globals.initialConfig,
43+
w
4344
)
4445
newOptions = Utils.extend(options, newOptions)
4546
newOptions = Utils.extend(w.config, newOptions)
4647
this.overrideResponsiveOptions(newOptions)
4748
} else {
4849
for (let i = 0; i < res.length; i++) {
4950
if (width < res[i].breakpoint) {
50-
newOptions = CoreUtils.extendArrayProps(config, res[i].options)
51+
newOptions = CoreUtils.extendArrayProps(config, res[i].options, w)
5152
newOptions = Utils.extend(w.config, newOptions)
5253
this.overrideResponsiveOptions(newOptions)
5354
}
@@ -56,7 +57,7 @@ export default class Responsive {
5657
}
5758

5859
if (opts) {
59-
let options = CoreUtils.extendArrayProps(config, opts)
60+
let options = CoreUtils.extendArrayProps(config, opts, w)
6061
options = Utils.extend(w.config, options)
6162
options = Utils.extend(options, opts)
6263
iterateResponsiveOptions(options)

src/modules/helpers/UpdateHelpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default class UpdateHelpers {
5353

5454
if (options && typeof options === 'object') {
5555
ch.config = new Config(options)
56-
options = CoreUtils.extendArrayProps(ch.config, options)
56+
options = CoreUtils.extendArrayProps(ch.config, options, w)
5757

5858
// fixes #914, #623
5959
if (ch.w.globals.chartID !== this.ctx.w.globals.chartID) {

src/modules/settings/Config.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export default class Config {
145145
return opts
146146
}
147147

148-
extendYAxis(opts) {
148+
extendYAxis(opts, w) {
149149
let options = new Options()
150150

151151
if (
@@ -181,19 +181,20 @@ export default class Config {
181181
}
182182
})
183183

184+
let series = opts.series
185+
if (w && !series) {
186+
series = w.config.series
187+
}
188+
184189
// A logarithmic chart works correctly when each series has a corresponding y-axis
185190
// If this is not the case, we manually create yaxis for multi-series log chart
186-
if (
187-
isLogY &&
188-
opts.series.length !== opts.yaxis.length &&
189-
opts.series.length
190-
) {
191-
opts.yaxis = opts.series.map((s, i) => {
191+
if (isLogY && series.length !== opts.yaxis.length && series.length) {
192+
opts.yaxis = series.map((s, i) => {
192193
if (!s.name) {
193-
opts.series[i].name = `series-${i + 1}`
194+
series[i].name = `series-${i + 1}`
194195
}
195196
if (opts.yaxis[i]) {
196-
opts.yaxis[i].seriesName = opts.series[i].name
197+
opts.yaxis[i].seriesName = series[i].name
197198
return opts.yaxis[i]
198199
} else {
199200
const newYaxis = Utils.extend(options.yAxis, opts.yaxis[0])
@@ -203,11 +204,7 @@ export default class Config {
203204
})
204205
}
205206

206-
if (
207-
isLogY &&
208-
opts.series.length > 1 &&
209-
opts.series.length !== opts.yaxis.length
210-
) {
207+
if (isLogY && series.length > 1 && series.length !== opts.yaxis.length) {
211208
console.warn(
212209
'A multi-series logarithmic chart should have equal number of series and y-axes. Please make sure to equalize both.'
213210
)

0 commit comments

Comments
 (0)