Reset Marks in Line Series Teechart - teechart

I have added Marks in Line series, But when we are adding marks in same x-axis then it is showing both marks previously added and new one also. i wanted to show only last one.
m_ctrlChart.AddSeries(scLine);
m_ctrlChart.Series(0).AddNullXY(0, 5, "");
m_ctrlChart.Series(0).AddXY(22, 5, "C", 0); // Here we have added 'C' on 22.
m_ctrlChart.Series(0).AddXY(22, 5, "SMP", 0); // Again we have added SMP on 22.
m_ctrlChart.Series(0).AddXY(40, 5, "G", 0);
m_ctrlChart.Series(0).SetTitle(LPCTSTR("Line Series 0"));
CSeriesPointerItems pointerit = m_ctrlChart.Series(0).GetAsLine().GetPointer();
pointerit.SetVisible(TRUE);
pointerit.SetStyle(psStar);
pointerit.GetBrush().SetStyle(bsClear);
But we wanted to show 'SMP' on 22 x-axis and wanted to clear C from that location.
Thanks,
Prabhat.

TeeChart shows the both Marks "C" and "SMP" because you are adding two Points with the same XValue here:
m_ctrlChart.Series(0).AddXY(22, 5, "C", 0); // Here we have added 'C' on 22.
m_ctrlChart.Series(0).AddXY(22, 5, "SMP", 0); // Again we have added SMP on 22.
I understand you want to modify a Label, rather than adding a new point.
In that case, the first thing you need to know is the index of the point for the label to modify. In the code you posted, you made both calls consecutive, so, the point to be modified is the last on the series at that moment:
index = m_ctrlChart.Series(0).getCount()-1;
Alternatively, you can use the return value AddXY() call has given. Ie:
index = m_ctrlChart.Series(0).AddXY(22, 5, "C", 0); // Here we have added 'C' on 22.
Then, once you have the index of the point to modify, you are ready to use it:
m_ctrlChart.Series(0).SetPointLabel(index, "SMP");

Related

How to move an image in Lua?

I am new to Lua programming and I am having problems while trying to move an image from a set of coordinates to another.
What I am trying to create is to be used with the X-Plane flight simulator. There is a library called SASL (www.1-sim.com), that was created to make plugins (for X-Plane) creation easir, since the default language is C++ and many people find it difficult.
In general, SASL works as a bridge between Lua and X-Plane, in general lines, the scripts you write reads some data straight from X-Plane (DataRefs) while it is running and depending on the code you wrote its execute commands or many other things that it is possible.
So, when using SASL to create cockpit/panel gauges it uses a base file, named 'avionics.lua' that works as a class and loads all gauges you create for the specific aircraft you are working on. For example my avionics.lua file looks like this:
size = { 2048, 2048 }
components = {
flaps {};
};
where, 'size' is the size that will be used for things to be drawn and components is an array of gauges, in this case the flaps gauge.
The rest of the work is to create the gauge functionality and this is done in a separate file, in my case, called 'flaps.lua'.
Within flaps.lua, is where I need to code the flaps indicator functionality which is to load 2 images: one for the back ground and the second one for the flaps indicator.
The first image is a fixed image. The second one will move throught the 'y' axis based on the flaps indicator DataRef (flapsDegree property below).
The code below when X-Plane is running displays the background image and the flaps indicator on its first stage which is 0 as you can see on the image.
size = {78,100}
local flapsDegree = globalPropertyf("sim/cockpit2/controls/flap_ratio")
local background = loadImage("gfx/Flaps.png")
local indicator = loadImage("gfx/Flaps_Indicator.png")
local flaps = get(flapsPosition)
components = {
texture { position = {945, 1011, 60, 100}, image = background},
texture { position = {959, 1097, 30, 9}, image = indicator},
}
Image
Now, the problem comes when I need to implement the logic for moving the 'indicator' image through the 'y' axis.
I have tried this code without success:
if flaps == 0.333 then
indicator.position = {959, 1075, 30, 9}
end
So how could I accomplish that?
I am not familiar with the SALS library. I just had a quick look into it.
Everything you need to know is in the manuals on the website you linked.
In particular http://www.1-sim.com/files/SASL300.pdf
Everytime your screen is updated each components draw() function will be called.
So if you want to change something dynamically you have to put that into the component's draw function.
If you open the SALS sources you'll find basic components which show you how to use that stuff. One of them is needle.lua:
-- default angle
defineProperty("angle", 0)
-- no image
defineProperty("image")
function draw(self)
local w, h = getTextureSize(get(image))
local max = w
if h > max then
max = h
end
local rw = (w / max) * 100
local rh = (h / max) * 100
drawRotatedTexture(get(image), get(angle),
(100 - rw) / 2, (100 - rh) / 2, rw, rh)
end
If you check the manual you'll find that there is not only a drawRotatedTexture function but many other functions for drawing stuff. Just play around. Try drawTexture for your purpose.
If you don't know what you have to program, open every single lua file in the library and read it together with the Lua reference manual and the SALS documentation until you understand what is going on. Once you understand the existing code you can extend it with ease.

permanently modifying RGB gamma table

The following script sets a custom gamma table for the current display. It works for about a second before the screen resets to its default profile.
#!/usr/bin/swift
import CoreGraphics
var redTable: [CGGammaValue] = [0, 0]
var greenTable: [CGGammaValue] = [1, 0]
var blueTable: [CGGammaValue] = [0, 1]
CGSetDisplayTransferByTable(CGMainDisplayID(), 2, &redTable, &greenTable, &blueTable)
sleep(5)
What causes this reset without me calling CGDisplayRestoreColorSyncSettings() directly?
How would I go about permanently adjusting the gamma table?
OK, found it. I was running flux which reconfigured the display profile every second or so. Quitting the app fixed it.

Context menu to add column not working when defining columns property to hide some columns

I needed a way to create a spreadsheet where user can potentially paste in any no of columns. Currently pasting things in the spreadsheet does not work as mentioned here https://github.com/warpech/jquery-handsontable/issues/553, so I wanted to enable the context menu to add column. This works fine when you have plain array as data source and you are not setting the columns property, but if you do need to define the columns attribute then things dont work when setting the
contextMenu: ['col_right']
. I needed to define the columns property because I need to hide certain columns (as mentioned here https://github.com/warpech/jquery-handsontable/issues/120).
The only way to make things work would be to define custom action for context menu, but I am not sure how to go about it.
Here is a jsbin : http://jsfiddle.net/8V4Z5/1/
Thanks
Ok one work around that worked for me requires playing bit with the data structure. Seeing that I could only make context menu work when data source is plain array and "columns" property should not be defined , I had to provide plain array as data source. Example like:
var actualData = [
{"spreadSheetData":[ "Kia", "Nissan", "Toyota", "Honda"]},
{"year":"2008", "spreadSheetData":[10, 11, 12, 13]},
{"year":"2009", "spreadSheetData":[ 20, 11, 14, 13]},
{"year":"2010", "spreadSheetData":[30, 15, 12, 13]}
];
var data = [];
actualData.forEach(function(d){
data.push(d.spreadSheetData);
});
example: http://jsfiddle.net/Yw3WE/
As soon as you initialize a Handsontable with the columns option, you can no longer use the context menu to add a column.
A solution is to use the cell option instead.
To solve your issue, I replaced...
columns: [{
data: 1
}, {
data: 2
}, {
data: 3
}],
...with...
cells: function (row, col, prop) {
var cellProperties = {};
cellProperties.data = col;
return cellProperties;
},
Here's the working fiddle:
http://jsfiddle.net/oyxv3g9w/
Note that I also commented out a callback in the fiddle because the way it was implemented, it prevented the new column from being created despite the context menu item wasn't greyed out anymore.

Pygame and Tilesets, followed instructions for use, but I get "noneType" error

My version of Python is 3.2, and Pygame is 1.9.1.
I followed the first part of the instructions found here: http://wiki.sheep.art.pl/Tiled%20Map%20in%20PyGame, with a few adjustments to accommodate for my own tileset:
def load_tileset(filename, width, height):
image = pygame.image.load(filename).convert_alpha()
imageWidth, imageHeight = image.get_size()
tileSet = []
for tileX in range(0, 3):
line = []
tileSet.append(line)
for tileY in range(0, 3):
rect = (tileX*width, tileY*height, width, height)
line.append(image.subsurface(rect))
if __name__=='__main__':
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('Tiled Background')
screen.fill((240, 240, 255))
table = load_tileset('tableset.gif', 16, 16)
for x, row in enumerate(table):
for y, tile in enumerate(row):
screen.blit(tile, (x*24, y*24))
pygame.display.flip()
while pygame.event.wait().type != pygame.locals.QUIT:
pass
I get the Nonetype error in for x, row in enumerate(table):*. I've tried various things, even moving the tileset itself, and changing the file type. I've also tried other codes, such as range.
I have managed to load images in the past, this is just my first time trying to use a tile set. The tile set has 9 16x16 tiles, and there is some transparency in them (hence the convert_alpha()).
So, can anyone say why I got the NoneType error here? Is it something to do with the image?
(Note, the reason there's 3's in the "For tileX in range" is that it wouldn't accept the calculation as set fourth in the tutorial, so I just did the maths myself.)
Edit: Accidently typed: for x, row in range(table): instead of for x, row in enumerate(table): in description.
You aren't posting the full code, or have made a mistake: there's no for x, row in range(table) line in the code above. With this specific code, you seem to be trying to pull two variables from the range function, but it only returns one value at a time.
You probably meant to type for x, row in enumerate(table). In that case, you need to return an object when you call table = load_tileset('tableset.gif', 16, 16) because unless any given function is explicitly told to return an object, it'll return None and that's why the line is giving you trouble, because the type of None is Nonetype
Here's an example of a function returning None and then returning a string, a returned string:
def thisFuncReturnsNone():
pass
print 'what gets returned:', thisFuncReturnsNone()
>>> None
def thisFuncReturnsAString():
return 'a returned string'
print 'what gets returned a second time:', thisFuncReturnsAString()
>>> a returned string

Cocoa retain single object from array

In Cocoa, I get the array of windows of an app using the following code:
CFArrayRef windows;
AXError gettingWindowsResult = AXUIElementCopyAttributeValues(app, (CFStringRef)NSAccessibilityWindowsAttribute, 0, 999, &windows);
Then I check some values of those windows and keep the AXUIElementRef of one of them in a variable of my class. At the end of the method, I release the CFArrayRef to make sure I don't have any memory leaks:
if (windows != nil)
{
CFRelease(windows);
}
Though this makes it so that when I try to use the window I kept, I get a bad access error. So my question: is it necessary that I release the array? And if so, how do I prevent the bad access error?
Why not make a retained copy of the "AXUIElementRef" of the one element you want to keep?
To do this, figure out the index of the element you want to keep, and then make another call to the "AXUIElementCopyAttributeValues" function, only this time just pass the index for the element you desire and a "maxValue" of 1. For example, for the element at position 26:
AXError gettingWindowsResult = AXUIElementCopyAttributeValues(app, (CFStringRef)NSAccessibilityWindowsAttribute, 26, 1, &arrayOfOne);
Then you can safely call "CFRelease" on the "windows" array.

Resources