📄 logarithmicaxis.html
字号:
<FONT color="green">270</FONT> * log axis processing.<a name="line.270"></a><FONT color="green">271</FONT> *<a name="line.271"></a><FONT color="green">272</FONT> * @param range the new range.<a name="line.272"></a><FONT color="green">273</FONT> */<a name="line.273"></a><FONT color="green">274</FONT> public void setRange(Range range) {<a name="line.274"></a><FONT color="green">275</FONT> super.setRange(range); // call parent method<a name="line.275"></a><FONT color="green">276</FONT> setupSmallLogFlag(); // setup flag based on bounds values<a name="line.276"></a><FONT color="green">277</FONT> }<a name="line.277"></a><FONT color="green">278</FONT> <a name="line.278"></a><FONT color="green">279</FONT> /**<a name="line.279"></a><FONT color="green">280</FONT> * Sets up flag for log axis processing. Set true if negative values<a name="line.280"></a><FONT color="green">281</FONT> * not allowed and the lower bound is between 0 and 10.<a name="line.281"></a><FONT color="green">282</FONT> */<a name="line.282"></a><FONT color="green">283</FONT> protected void setupSmallLogFlag() {<a name="line.283"></a><FONT color="green">284</FONT> // set flag true if negative values not allowed and the<a name="line.284"></a><FONT color="green">285</FONT> // lower bound is between 0 and 10:<a name="line.285"></a><FONT color="green">286</FONT> double lowerVal = getRange().getLowerBound();<a name="line.286"></a><FONT color="green">287</FONT> this.smallLogFlag<a name="line.287"></a><FONT color="green">288</FONT> = (!this.allowNegativesFlag && lowerVal < 10.0 && lowerVal > 0.0);<a name="line.288"></a><FONT color="green">289</FONT> }<a name="line.289"></a><FONT color="green">290</FONT> <a name="line.290"></a><FONT color="green">291</FONT> /**<a name="line.291"></a><FONT color="green">292</FONT> * Sets up the number formatter object according to the<a name="line.292"></a><FONT color="green">293</FONT> * 'expTickLabelsFlag' flag.<a name="line.293"></a><FONT color="green">294</FONT> */<a name="line.294"></a><FONT color="green">295</FONT> protected void setupNumberFmtObj() {<a name="line.295"></a><FONT color="green">296</FONT> if (this.numberFormatterObj instanceof DecimalFormat) {<a name="line.296"></a><FONT color="green">297</FONT> //setup for "1e#"-style tick labels or regular<a name="line.297"></a><FONT color="green">298</FONT> // numeric tick labels, depending on flag:<a name="line.298"></a><FONT color="green">299</FONT> ((DecimalFormat) this.numberFormatterObj).applyPattern(<a name="line.299"></a><FONT color="green">300</FONT> this.expTickLabelsFlag ? "0E0" : "0.###"<a name="line.300"></a><FONT color="green">301</FONT> );<a name="line.301"></a><FONT color="green">302</FONT> }<a name="line.302"></a><FONT color="green">303</FONT> }<a name="line.303"></a><FONT color="green">304</FONT> <a name="line.304"></a><FONT color="green">305</FONT> /**<a name="line.305"></a><FONT color="green">306</FONT> * Returns the log10 value, depending on if values between 0 and<a name="line.306"></a><FONT color="green">307</FONT> * 1 are being plotted. If negative values are not allowed and<a name="line.307"></a><FONT color="green">308</FONT> * the lower bound is between 0 and 10 then a normal log is<a name="line.308"></a><FONT color="green">309</FONT> * returned; otherwise the returned value is adjusted if the<a name="line.309"></a><FONT color="green">310</FONT> * given value is less than 10.<a name="line.310"></a><FONT color="green">311</FONT> *<a name="line.311"></a><FONT color="green">312</FONT> * @param val the value.<a name="line.312"></a><FONT color="green">313</FONT> *<a name="line.313"></a><FONT color="green">314</FONT> * @return log<sub>10</sub>(val).<a name="line.314"></a><FONT color="green">315</FONT> */<a name="line.315"></a><FONT color="green">316</FONT> protected double switchedLog10(double val) {<a name="line.316"></a><FONT color="green">317</FONT> return this.smallLogFlag ? Math.log(val)<a name="line.317"></a><FONT color="green">318</FONT> / LOG10_VALUE : adjustedLog10(val);<a name="line.318"></a><FONT color="green">319</FONT> }<a name="line.319"></a><FONT color="green">320</FONT> <a name="line.320"></a><FONT color="green">321</FONT> /**<a name="line.321"></a><FONT color="green">322</FONT> * Returns an adjusted log10 value for graphing purposes. The first<a name="line.322"></a><FONT color="green">323</FONT> * adjustment is that negative values are changed to positive during<a name="line.323"></a><FONT color="green">324</FONT> * the calculations, and then the answer is negated at the end. The<a name="line.324"></a><FONT color="green">325</FONT> * second is that, for values less than 10, an increasingly large<a name="line.325"></a><FONT color="green">326</FONT> * (0 to 1) scaling factor is added such that at 0 the value is<a name="line.326"></a><FONT color="green">327</FONT> * adjusted to 1, resulting in a returned result of 0.<a name="line.327"></a><FONT color="green">328</FONT> *<a name="line.328"></a><FONT color="green">329</FONT> * @param val value for which log10 should be calculated.<a name="line.329"></a><FONT color="green">330</FONT> *<a name="line.330"></a><FONT color="green">331</FONT> * @return An adjusted log<sub>10</sub>(val).<a name="line.331"></a><FONT color="green">332</FONT> */<a name="line.332"></a><FONT color="green">333</FONT> public double adjustedLog10(double val) {<a name="line.333"></a><FONT color="green">334</FONT> boolean negFlag = (val < 0.0);<a name="line.334"></a><FONT color="green">335</FONT> if (negFlag) {<a name="line.335"></a><FONT color="green">336</FONT> val = -val; // if negative then set flag and make positive<a name="line.336"></a><FONT color="green">337</FONT> }<a name="line.337"></a><FONT color="green">338</FONT> if (val < 10.0) { // if < 10 then<a name="line.338"></a><FONT color="green">339</FONT> val += (10.0 - val) / 10; //increase so 0 translates to 0<a name="line.339"></a><FONT color="green">340</FONT> }<a name="line.340"></a><FONT color="green">341</FONT> //return value; negate if original value was negative:<a name="line.341"></a><FONT color="green">342</FONT> return negFlag ? -(Math.log(val) / LOG10_VALUE)<a name="line.342"></a><FONT color="green">343</FONT> : (Math.log(val) / LOG10_VALUE);<a name="line.343"></a><FONT color="green">344</FONT> }<a name="line.344"></a><FONT color="green">345</FONT> <a name="line.345"></a><FONT color="green">346</FONT> /**<a name="line.346"></a><FONT color="green">347</FONT> * Returns the largest (closest to positive infinity) double value that is<a name="line.347"></a><FONT color="green">348</FONT> * not greater than the argument, is equal to a mathematical integer and<a name="line.348"></a><FONT color="green">349</FONT> * satisfying the condition that log base 10 of the value is an integer<a name="line.349"></a><FONT color="green">350</FONT> * (i.e., the value returned will be a power of 10: 1, 10, 100, 1000, etc.).<a name="line.350"></a><FONT color="green">351</FONT> *<a name="line.351"></a><FONT color="green">352</FONT> * @param lower a double value below which a floor will be calcualted.<a name="line.352"></a><FONT color="green">353</FONT> *<a name="line.353"></a><FONT color="green">354</FONT> * @return 10<sup>N</sup> with N .. { 1 ... }<a name="line.354"></a><FONT color="green">355</FONT> */<a name="line.355"></a><FONT color="green">356</FONT> protected double computeLogFloor(double lower) {<a name="line.356"></a><FONT color="green">357</FONT> <a name="line.357"></a><FONT color="green">358</FONT> double logFloor;<a name="line.358"></a><FONT color="green">359</FONT> if (this.allowNegativesFlag) {<a name="line.359"></a><FONT color="green">360</FONT> //negative values are allowed<a name="line.360"></a><FONT color="green">361</FONT> if (lower > 10.0) { //parameter value is > 10<a name="line.361"></a><FONT color="green">362</FONT> // The Math.log() function is based on e not 10.<a name="line.362"></a><FONT color="green">363</FONT> logFloor = Math.log(lower) / LOG10_VALUE;<a name="line.363"></a><FONT color="green">364</FONT> logFloor = Math.floor(logFloor);<a name="line.364"></a><FONT color="green">365</FONT> logFloor = Math.pow(10, logFloor);<a name="line.365"></a><FONT color="green">366</FONT> }<a name="line.366"></a><FONT color="green">367</FONT> else if (lower < -10.0) { //parameter value is < -10<a name="line.367"></a><FONT color="green">368</FONT> //calculate log using positive value:<a name="line.368"></a><FONT color="green">369</FONT> logFloor = Math.log(-lower) / LOG10_VALUE;<a name="line.369"></a><FONT color="green">370</FONT> //calculate floor using negative value:<a name="line.370"></a><FONT color="green">371</FONT> logFloor = Math.floor(-logFloor);<a name="line.371"></a><FONT color="green">372</FONT> //calculate power using positive value; then negate<a name="line.372"></a><FONT color="green">373</FONT> logFloor = -Math.pow(10, -logFloor);<a name="line.373"></a><FONT color="green">374</FONT> }<a name="line.374"></a><FONT color="green">375</FONT> else {<a name="line.375"></a><FONT color="green">376</FONT> //parameter value is -10 > val < 10<a name="line.376"></a><FONT color="green">377</FONT> logFloor = Math.floor(lower); //use as-is<a name="line.377"></a><FONT color="green">378</FONT> }<a name="line.378"></a><FONT color="green">379</FONT> }<a name="line.379"></a><FONT color="green">380</FONT> else {<a name="line.380"></a><FONT color="green">381</FONT> //negative values not allowed<a name="line.381"></a><FONT color="green">382</FONT> if (lower > 0.0) { //parameter value is > 0<a name="line.382"></a><FONT color="green">383</FONT> // The Math.log() function is based on e not 10.<a name="line.383"></a><FONT color="green">384</FONT> logFloor = Math.log(lower) / LOG10_VALUE;<a name="line.384"></a><FONT color="green">385</FONT> logFloor = Math.floor(logFloor);<a name="line.385"></a><FONT color="green">386</FONT> logFloor = Math.pow(10, logFloor);<a name="line.386"></a><FONT color="green">387</FONT> }<a name="line.387"></a><FONT color="green">388</FONT> else {<a name="line.388"></a><FONT color="green">389</FONT> //parameter value is <= 0<a name="line.389"></a><FONT color="green">390</FONT> logFloor = Math.floor(lower); //use as-is<a name="line.390"></a><FONT color="green">391</FONT> }<a name="line.391"></a><FONT color="green">392</FONT> }<a name="line.392"></a><FONT color="green">393</FONT> return logFloor;<a name="line.393"></a><FONT color="green">394</FONT> }<a name="line.394"></a><FONT color="green">395</FONT> <a name="line.395"></a><FONT color="green">396</FONT> /**<a name="line.396"></a><FONT color="green">397</FONT> * Returns the smallest (closest to negative infinity) double value that is<a name="line.397"></a><FONT color="green">398</FONT> * not less than the argument, is equal to a mathematical integer and<a name="line.398"></a><FONT color="green">399</FONT> * satisfying the condition that log base 10 of the value is an integer<a name="line.399"></a><FONT color="green">400</FONT> * (i.e., the value returned will be a power of 10: 1, 10, 100, 1000, etc.).<a name="line.400"></a><FONT color="green">401</FONT> *<a name="line.401"></a><FONT color="green">402</FONT> * @param upper a double value above which a ceiling will be calcualted.<a name="line.402"></a><FONT color="green">403</FONT> *<a name="line.403"></a><FONT color="green">404</FONT> * @return 10<sup>N</sup> with N .. { 1 ... }<a name="line.404"></a><FONT color="green">405</FONT> */<a name="line.405"></a>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -