如何定义从现有&QUOT配套轴凹槽;步骤列表" [英] How to define matching axis notches from existing "step list"

查看:218
本文介绍了如何定义从现有&QUOT配套轴凹槽;步骤列表"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方法来对准刻度上的两个独立的轴,同时能​​够控制的台阶值(刻度线之间的价值),其中两个轴的开始标志0,最终在不同的最大值。

I need a way to align tick marks on two separate axis, while being able to control the "step" value (value between tick marks), where both axis start at mark 0 and end on a different maximum value.

为什么这个问题:

海军报,JS的图表包有一个选项来调整刻度线,但是当我做,我无法控制的步进值。然而,我可以直接控制步进值,但后来我失去对准刻度线的能力。不过,我可以恢复到定义自己的最大值和步长值,得到我所需要的(对准刻度线,同时保持所需的步进值),但我需要一些帮助。产生这个问题(阅读详细内容)。

Flot, the JS charting package has an option to align tick marks, but when I do, I cannot control the step value. I can however control the step value directly, but then I lose the ability to align tick marks. I can however revert to defining my own max and step values, to get what I need (aligned tick marks while maintaining desired step value), but I need some help. yielding this question (read on for details).

示例

让一个上轴a和b的最大值,是轴B上的最大值。

Let a be maximum value on axis A and b, be maximum value on axis B.

在这个例子中,让= 30,和b = 82。 比方说,我想6刻度线(而不是在轴终点计算额外的刻度标记)。在现实中,我猜在6尝试了几个后。

In this example, let a = 30, and b = 82. Let's say I want 6 tick marks (not counting the extra tick mark at end of axis). In reality I guessed at 6 after trying out a few.

在我有刻度线所需的电话号码,我可以做这样的事情:

Once I have a desired number of tick marks, I can do something like this:

  • 现在,需要弄清楚剔对准B轴
  • 六分之八十二= 13.67(不是一个很好的价值,我preFER东西更圆)
  • 的B最大值移动到90,其中90/6 = 15(好 - 我刚拿到B轴所需要的步长值)
  • 30 / 6 = 5 (I just go the needed step value for axis A)
  • Now need to figure out tick alignment for axis B
  • 82 / 6 = 13.67 (not a good value, I prefer something more rounded)
  • move max value of B to 90 , where 90 / 6 = 15 (good - I just got the needed step value for axis B)

最终结果

输入:

  • a_max = 30,b_max = 82
  • (在现实中a_max可能是28.5,29.42,b_max可能是84,85.345等)

输出:

  • a_adjusted_max = 30,b_adjusted_max = 90,
  • a_step = 5,b_step = 15
  • 在滴答数= 6(+1如果算上年底)

可视:

|---------|---------|---------|---------|---------|---------> A
0         5        10        15        20        25        30

|---------|---------|---------|---------|---------|---------> B
0        15        30        45        60        75        90

要求中的摘要

  • 需要步长值每个轴是一个1,2,5,10,15,20,25,50,100(例如为5对于A ,15 B)
  • 需要调整最大值为每个轴(例如是30 A,90 B)
  • 需要的刻度数匹配这两个轴
  • 蜱(可选)号是灵活的,但应该是随时随地的 4-12 的作为甜蜜点
  • 调整最大值为等于或大于原始最大值,并且位于一个舍入号码(即90是pfered超过82 $ P $如在我的上述例子)
  • Need step value for each axis to be one of 1, 2, 5, 10, 15, 20, 25, 50, 100 (in example was 5 for A, 15 for B)
  • Need adjusted max value for each axis (in example was 30 for A, 90 for B)
  • Need number of ticks to match for both axis
  • (optional) Number of ticks is flexible but should be anywhere between 4 and 12 as a sweet spot
  • adjusted max value is at or greater than original max value, and is located at a "rounded number" (i.e. 90 is prefered over 82 as in my above example)

的问题(问题)

  • 我需要删除大部分的猜测和自动刻度标记生成。
  • 即。首先,我需要更好的方式来获得的刻度标记数字,因为我猜到了,我想上面的刻度数,因为我想一个很好的一步到位的价值,它可以像1,2 ,5,10,15,20,25,50,100最大值开始4,并且可高达100。在罕见的情况下上升到500在大多数情况下的最大值留30-90之间。
  • I need to remove most of the guessing and automate tick mark generation.
  • i.e. at first, I Need better way to get number of tick marks because I guessed at number of tick marks I wanted above, because I wanted a good "step" value, which can be something like 1, 2, 5, 10, 15, 20, 25, 50, 100. Max values start at 4, and can go up to 100. In rarer cases go up to 500. In most cases the max values stay between 30-90.

我该怎么办呢?

推荐答案

下面是一个过程,我想出了。我假设你只需要整数。

Here's a procedure I came up with. I'm assuming you only want integers.

  • 从4至12
  • 选择一些蜱
  • 计算所需的步数在 A B 轴采用的刻度此号码
  • 找到多少,我们就不得不延长轴的 A 和轴的 B 使用这些步长值;添加这些数字相加,并记住结果
  • 重复从一开始就下一个刻度值
  • 我们选择蜱,让最低分数的数量;如果出现平局,我们选择蜱的数量较少
  • choose a number of ticks from 4 to 12
  • calculate the number of steps needed for the A and B axes using this number of ticks
  • find how much we would have to extend axis A and axis B using these step values; add these numbers together and remember the result
  • repeat from the start for the next tick value
  • we choose the number of ticks that gives the minimal score; if there is a tie we choose the smaller number of ticks

下面是一些例子的结果:

Here are some example results:

A = 30,B = 82 给4蜱

 0    10    20    30
 0    28    56    84

A = 8,B = 5 得到6蜱

 0     2     4     6     8    10
 0     1     2     3     4     5

下面是伪code:

a = range of A axis
b = range of B axis

tickList[] = {4,5,6,7,8,9,10,11,12}

// calculate the scores for each number of ticks
for i from 0 to length(tickList)-1
    ticks = tickList[i]

    // find the number of steps we would use for this number of ticks
    Astep = ceiling(a/(ticks-1))
    Bstep = ceiling(b/(ticks-1))

    // how much we would need to extend the A axis
    if (a%Astep != 0)
        Aextend[i] = Astep - a%Astep
    else
        Aextend[i] = 0
    end

    // how much we would need to extend the B axis
    if (b%Bstep != 0)
        Bextend[i] = Bstep - b%Bstep
    else
        Bextend[i] = 0
    end

    // the score is the total extending we would need to do
    score[i] = Aextend[i] + Bextend[i]

end


// find the number of ticks that minimizes the score
bestIdx = 0
bestScore = 1000;

for i from 0 to length(tickList);
    if (score[i] < bestScore)
        bestIdx = i
        bestScore = score[i]
    end
end

bestTick = tickList[bestIdx]
bestAstep = ceiling(a/(bestTick-1))
bestBstep = ceiling(b/(bestTick-1))

A 轴从 0 bestAstep bestAstep * bestTick

B 轴从 0 bestBstep bestBstep * bestTick

这篇关于如何定义从现有&QUOT配套轴凹槽;步骤列表&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆